diff options
| author | Rui Ueyama <ruiu@google.com> | 2015-06-19 22:39:48 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2015-06-19 22:39:48 +0000 |
| commit | f00df0af2d0587ead9e36b7161206187e7b24622 (patch) | |
| tree | 1b7dce831b2f059e1e7066a0473265758b39ce95 | |
| parent | 7b62aec0d32a1df8b14f8d2803e5576aecbf9b57 (diff) | |
| download | bcm5719-llvm-f00df0af2d0587ead9e36b7161206187e7b24622.tar.gz bcm5719-llvm-f00df0af2d0587ead9e36b7161206187e7b24622.zip | |
COFF: Fix precedence between LIB and /libpath.
/libpath should take precedence over LIB.
Previously, LIB took precedence over /libpath.
llvm-svn: 240182
| -rw-r--r-- | lld/COFF/Driver.cpp | 20 | ||||
| -rw-r--r-- | lld/COFF/Driver.h | 7 | ||||
| -rw-r--r-- | lld/test/COFF/libpath.test | 26 |
3 files changed, 22 insertions, 31 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index d89624c350b..c03102ec0e2 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -191,20 +191,16 @@ Optional<StringRef> LinkerDriver::findLib(StringRef Filename) { } // Parses LIB environment which contains a list of search paths. -std::vector<StringRef> LinkerDriver::getSearchPaths() { - std::vector<StringRef> Ret; - // Add current directory as first item of the search paths. - Ret.push_back(""); +void LinkerDriver::addLibSearchPaths() { Optional<std::string> EnvOpt = Process::GetEnv("LIB"); if (!EnvOpt.hasValue()) - return Ret; + return; StringRef Env = Alloc.save(*EnvOpt); while (!Env.empty()) { StringRef Path; std::tie(Path, Env) = Env.split(';'); - Ret.push_back(Path); + SearchPaths.push_back(Path); } - return Ret; } static WindowsSubsystem inferSubsystem() { @@ -251,6 +247,12 @@ bool LinkerDriver::link(int Argc, const char *Argv[]) { return false; } + // Construct search path list. + SearchPaths.push_back(""); + for (auto *Arg : Args->filtered(OPT_libpath)) + SearchPaths.push_back(Arg->getValue()); + addLibSearchPaths(); + // Handle /out if (auto *Arg = Args->getLastArg(OPT_out)) Config->OutputFile = Arg->getValue(); @@ -287,10 +289,6 @@ bool LinkerDriver::link(int Argc, const char *Argv[]) { } Config->MachineType = MTOrErr.get(); - // Handle /libpath - for (auto *Arg : Args->filtered(OPT_libpath)) - SearchPaths.push_back(Arg->getValue()); - // Handle /nodefaultlib:<filename> for (auto *Arg : Args->filtered(OPT_nodefaultlib)) Config->NoDefaultLibs.insert(doFindLib(Arg->getValue())); diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index 0918dcffa15..53bac0057f4 100644 --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -64,7 +64,7 @@ private: class LinkerDriver { public: - LinkerDriver() : Alloc(AllocAux), SearchPaths(getSearchPaths()) {} + LinkerDriver() : Alloc(AllocAux) {} bool link(int Argc, const char *Argv[]); // Used by the resolver to parse .drectve section contents. @@ -86,10 +86,11 @@ private: StringRef doFindLib(StringRef Filename); // Parses LIB environment which contains a list of search paths. - // The returned list always contains "." as the first element. - std::vector<StringRef> getSearchPaths(); + void addLibSearchPaths(); + // Library search path. The first element is always "" (current directory). std::vector<StringRef> SearchPaths; + std::set<std::string> VisitedFiles; // Driver is the owner of all opened files. diff --git a/lld/test/COFF/libpath.test b/lld/test/COFF/libpath.test index 8db5389068e..b304dc38643 100644 --- a/lld/test/COFF/libpath.test +++ b/lld/test/COFF/libpath.test @@ -1,26 +1,18 @@ -# RUN: mkdir -p %t/a %t/b +# RUN: mkdir -p %t/a %t/b %t/c # RUN: cp %p/Inputs/std64.lib %t/a/ # RUN: cp %p/Inputs/std64.lib %t/b/ +# RUN: cp %p/Inputs/std64.lib %t/c/ # RUN: env LIB=%t/a lld -flavor link2 /out:%t.exe /entry:main /verbose \ -# RUN: std64.lib /subsystem:console \ -# RUN: %p/Inputs/hello64.obj /libpath:%t/b >& %t.log +# RUN: std64.lib /subsystem:console %p/Inputs/hello64.obj \ +# RUN: /libpath:%t/b /libpath:%t/c > %t.log # RUN: FileCheck -check-prefix=CHECK1 %s < %t.log -# RUN: lld -flavor link2 /out:%t.exe /entry:main /verbose std64.lib \ -# RUN: /subsystem:console %p/Inputs/hello64.obj \ -# RUN: /libpath:%t/a /libpath:%t/b >& %t.log -# RUN: FileCheck -check-prefix=CHECK1 %s < %t.log - -CHECK1: Reading {{.*}}/a/std64.lib - -# RUN: env LIB=%t/b lld -flavor link2 /out:%t.exe /entry:main /verbose \ -# RUN: /subsystem:console std64.lib %p/Inputs/hello64.obj \ -# RUN: /libpath:%t/a >& %t.log -# RUN: FileCheck -check-prefix=CHECK2 %s < %t.log +CHECK1: b{{[/\\]}}std64.lib -# RUN: lld -flavor link2 /out:%t.exe /entry:main /verbose /subsystem:console \ -# RUN: std64.lib %p/Inputs/hello64.obj /libpath:%t/b /libpath:%t/a >& %t.log +# RUN: lld -flavor link2 /out:%t.exe /entry:main /verbose \ +# RUN: std64.lib /subsystem:console %p/Inputs/hello64.obj \ +# RUN: /libpath:%t/a /libpath:%t/b /libpath:%t/c > %t.log # RUN: FileCheck -check-prefix=CHECK2 %s < %t.log -CHECK2: Reading {{.*}}/b/std64.lib +CHECK2: a{{[/\\]}}std64.lib |

