@@ -2992,9 +2992,10 @@ static SmallVector<const char *, 16>
2992
2992
getLinkerArgs (Compilation &C, DerivedArgList &Args, bool IncludeObj = false ) {
2993
2993
SmallVector<const char *, 16 > LibArgs;
2994
2994
SmallVector<std::string, 8 > LibPaths;
2995
- // Add search directories from LIBRARY_PATH env variable
2995
+ bool IsMSVC = C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ();
2996
+ // Add search directories from LIBRARY_PATH/LIB env variable
2996
2997
llvm::Optional<std::string> LibPath =
2997
- llvm::sys::Process::GetEnv (" LIBRARY_PATH" );
2998
+ llvm::sys::Process::GetEnv (IsMSVC ? " LIB " : " LIBRARY_PATH" );
2998
2999
if (LibPath) {
2999
3000
SmallVector<StringRef, 8 > SplitPaths;
3000
3001
const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, ' \0 ' };
@@ -3028,12 +3029,36 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
3028
3029
};
3029
3030
for (const auto *A : Args) {
3030
3031
std::string FileName = A->getAsString (Args);
3032
+ auto addLibArg = [&](StringRef LibName) -> bool {
3033
+ if (isStaticArchiveFile (LibName) ||
3034
+ (IncludeObj && isObjectFile (LibName.str ()))) {
3035
+ LibArgs.push_back (Args.MakeArgString (LibName));
3036
+ return true ;
3037
+ }
3038
+ return false ;
3039
+ };
3031
3040
if (A->getOption ().getKind () == Option::InputClass) {
3032
- StringRef Value (A->getValue ());
3033
- if (isStaticArchiveFile (Value) ||
3034
- (IncludeObj && isObjectFile (Value.str ()))) {
3035
- LibArgs.push_back (Args.MakeArgString (FileName));
3041
+ if (addLibArg (FileName))
3036
3042
continue ;
3043
+ }
3044
+ // Evaluate any libraries passed along after /link. These are typically
3045
+ // ignored by the driver and sent directly to the linker. When performing
3046
+ // offload, we should evaluate them at the driver level.
3047
+ if (A->getOption ().matches (options::OPT__SLASH_link)) {
3048
+ for (const std::string &Value : A->getValues ()) {
3049
+ // Add any libpath values.
3050
+ StringRef OptCheck (Value);
3051
+ if (OptCheck.startswith_insensitive (" -libpath:" ) ||
3052
+ OptCheck.startswith_insensitive (" /libpath:" ))
3053
+ LibPaths.emplace_back (Value.substr (std::string (" -libpath:" ).size ()));
3054
+ if (addLibArg (Value))
3055
+ continue ;
3056
+ for (auto LPath : LibPaths) {
3057
+ SmallString<128 > FullLib (LPath);
3058
+ llvm::sys::path::append (FullLib, Value);
3059
+ if (addLibArg (FullLib))
3060
+ continue ;
3061
+ }
3037
3062
}
3038
3063
}
3039
3064
if (A->getOption ().matches (options::OPT_Wl_COMMA) ||
@@ -3075,9 +3100,8 @@ getLinkerArgs(Compilation &C, DerivedArgList &Args, bool IncludeObj = false) {
3075
3100
llvm::StringSaver S (A);
3076
3101
llvm::cl::ExpandResponseFiles (
3077
3102
S,
3078
- C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ()
3079
- ? llvm::cl::TokenizeWindowsCommandLine
3080
- : llvm::cl::TokenizeGNUCommandLine,
3103
+ IsMSVC ? llvm::cl::TokenizeWindowsCommandLine
3104
+ : llvm::cl::TokenizeGNUCommandLine,
3081
3105
ExpandArgs);
3082
3106
for (StringRef EA : ExpandArgs)
3083
3107
addKnownValues (EA);
@@ -8350,11 +8374,10 @@ bool clang::driver::isStaticArchiveFile(const StringRef &FileName) {
8350
8374
if (!llvm::sys::path::has_extension (FileName))
8351
8375
// Any file with no extension should not be considered an Archive.
8352
8376
return false ;
8353
- StringRef Ext (llvm::sys::path::extension (FileName).drop_front ());
8354
8377
llvm::file_magic Magic;
8355
8378
llvm::identify_magic (FileName, Magic);
8356
8379
// Only .lib and archive files are to be considered.
8357
- return (Ext == " lib " || Magic == llvm::file_magic::archive);
8380
+ return (Magic == llvm::file_magic::archive);
8358
8381
}
8359
8382
8360
8383
bool clang::driver::willEmitRemarks (const ArgList &Args) {
0 commit comments