[lld] r186650 - [PECOFF][Driver] Add -defaultlib command line option.

Rui Ueyama ruiu at google.com
Thu Jul 18 21:11:37 PDT 2013


Author: ruiu
Date: Thu Jul 18 23:11:37 2013
New Revision: 186650

URL: http://llvm.org/viewvc/llvm-project?rev=186650&view=rev
Log:
[PECOFF][Driver] Add -defaultlib command line option.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkOptions.td
    lld/trunk/test/pecoff/importlib.test

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=186650&r1=186649&r2=186650&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Jul 18 23:11:37 2013
@@ -290,6 +290,14 @@ bool WinLinkDriver::parse(int argc, cons
   if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out))
     info.setOutputPath(outpath->getValue());
 
+  // Handle -defaultlib
+  std::vector<StringRef> defaultLibs;
+  for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_defaultlib),
+                               ie = parsedArgs->filtered_end();
+       it != ie; ++it) {
+    defaultLibs.push_back((*it)->getValue());
+  }
+
   // Add input files
   std::vector<StringRef> inputPaths;
   for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT),
@@ -303,9 +311,16 @@ bool WinLinkDriver::parse(int argc, cons
     for (int i = doubleDashPosition + 1; i < argc; ++i)
       inputPaths.push_back(argv[i]);
 
-  for (const StringRef &path : inputPaths)
+  // Add input files specified via the command line.
+  for (const StringRef path : inputPaths)
     info.appendInputFileOrLibrary(path);
 
+  // Add the library files specified by -defaultlib option. The files
+  // specified by the option should have lower precedence than the other files
+  // added above, which is important for link.exe compatibility.
+  for (const StringRef path : defaultLibs)
+    info.appendLibraryFile(path);
+
   // If -out option was not specified, the default output file name is
   // constructed by replacing an extension of the first input file
   // with ".exe".

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=186650&r1=186649&r2=186650&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Thu Jul 18 23:11:37 2013
@@ -9,6 +9,10 @@ def out : Separate<["-", "/"], "out">,
     HelpText<"Path to file to write output">;
 def out_c : Joined<["-", "/"], "out:">, Alias<out>;
 
+def defaultlib : Separate<["-", "/"], "defaultlib">,
+    HelpText<"Add the library to the list of input files">;
+def defaultlib_c : Joined<["-", "/"], "defaultlib:">, Alias<defaultlib>;
+
 def stack : Separate<["-", "/"], "stack">,
     HelpText<"Size of the stack">;
 def stack_c: Joined<["-", "/"], "stack:">, Alias<stack>;

Modified: lld/trunk/test/pecoff/importlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/importlib.test?rev=186650&r1=186649&r2=186650&view=diff
==============================================================================
--- lld/trunk/test/pecoff/importlib.test (original)
+++ lld/trunk/test/pecoff/importlib.test Thu Jul 18 23:11:37 2013
@@ -9,6 +9,9 @@
 # RUN: lld -flavor link -out %t1 -subsystem console -libpath %p/Inputs \
 # RUN:    -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
 #
+# RUN: lld -flavor link -out %t1 -subsystem console -libpath %p/Inputs \
+# RUN:    -defaultlib vars.lib -- %t.obj && llvm-objdump -d %t1 | FileCheck %s
+#
 # RUN: LIB=%p/Inputs lld -flavor link -out %t1 -subsystem console \
 # RUN:    -- %t.obj vars.lib && llvm-objdump -d %t1 | FileCheck %s
 





More information about the llvm-commits mailing list