[lld] r240182 - COFF: Fix precedence between LIB and /libpath.

Rui Ueyama ruiu at google.com
Fri Jun 19 15:39:49 PDT 2015


Author: ruiu
Date: Fri Jun 19 17:39:48 2015
New Revision: 240182

URL: http://llvm.org/viewvc/llvm-project?rev=240182&view=rev
Log:
COFF: Fix precedence between LIB and /libpath.

/libpath should take precedence over LIB.
Previously, LIB took precedence over /libpath.

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Driver.h
    lld/trunk/test/COFF/libpath.test

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=240182&r1=240181&r2=240182&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Jun 19 17:39:48 2015
@@ -191,20 +191,16 @@ Optional<StringRef> LinkerDriver::findLi
 }
 
 // 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
     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
   }
   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()));

Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=240182&r1=240181&r2=240182&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Fri Jun 19 17:39:48 2015
@@ -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.

Modified: lld/trunk/test/COFF/libpath.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/libpath.test?rev=240182&r1=240181&r2=240182&view=diff
==============================================================================
--- lld/trunk/test/COFF/libpath.test (original)
+++ lld/trunk/test/COFF/libpath.test Fri Jun 19 17:39:48 2015
@@ -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





More information about the llvm-commits mailing list