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),
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".
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>;
# 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