[PECOFF][Driver] Add -defaultlib command line option.
authorRui Ueyama <ruiu@google.com>
Fri, 19 Jul 2013 04:11:37 +0000 (04:11 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 19 Jul 2013 04:11:37 +0000 (04:11 +0000)
llvm-svn: 186650

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

index e65a0ab..d88a0ca 100644 (file)
@@ -290,6 +290,14 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
   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, const char *argv[],
     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".
index 16ebcd3..a5354f4 100644 (file)
@@ -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>;
index 663d4d1..395e7e7 100644 (file)
@@ -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