From: Rui Ueyama Date: Fri, 19 Jul 2013 04:11:37 +0000 (+0000) Subject: [PECOFF][Driver] Add -defaultlib command line option. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=64b29d616b5171f4d8b2e1d07b63d8098506e3cb;p=platform%2Fupstream%2Fllvm.git [PECOFF][Driver] Add -defaultlib command line option. llvm-svn: 186650 --- diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index e65a0ab..d88a0ca 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -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 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 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". diff --git a/lld/lib/Driver/WinLinkOptions.td b/lld/lib/Driver/WinLinkOptions.td index 16ebcd3..a5354f4 100644 --- a/lld/lib/Driver/WinLinkOptions.td +++ b/lld/lib/Driver/WinLinkOptions.td @@ -9,6 +9,10 @@ def out : Separate<["-", "/"], "out">, HelpText<"Path to file to write output">; def out_c : Joined<["-", "/"], "out:">, Alias; +def defaultlib : Separate<["-", "/"], "defaultlib">, + HelpText<"Add the library to the list of input files">; +def defaultlib_c : Joined<["-", "/"], "defaultlib:">, Alias; + def stack : Separate<["-", "/"], "stack">, HelpText<"Size of the stack">; def stack_c: Joined<["-", "/"], "stack:">, Alias; diff --git a/lld/test/pecoff/importlib.test b/lld/test/pecoff/importlib.test index 663d4d1..395e7e7 100644 --- a/lld/test/pecoff/importlib.test +++ b/lld/test/pecoff/importlib.test @@ -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