From: Michael J. Spencer Date: Thu, 7 Feb 2013 06:47:17 +0000 (+0000) Subject: [Driver] Add -L and -l support. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7799d15f6eabebd28a7a5e357d172aa3437adb35;p=platform%2Fupstream%2Fllvm.git [Driver] Add -L and -l support. llvm-svn: 174590 --- diff --git a/lld/include/lld/Core/LinkerOptions.h b/lld/include/lld/Core/LinkerOptions.h index 2eba90c..3f3b38a 100644 --- a/lld/include/lld/Core/LinkerOptions.h +++ b/lld/include/lld/Core/LinkerOptions.h @@ -111,33 +111,32 @@ struct LinkerOptions { , _relocatable(false) {} // This exists because MSVC doesn't support = default :( - LinkerOptions(LinkerOptions &&other) - : _input(std::move(other._input)) - , _llvmArgs(std::move(other._llvmArgs)) - , _deadStripRoots(std::move(other._deadStripRoots)) - , _target(std::move(other._target)) - , _outputPath(std::move(other._outputPath)) - , _entrySymbol(std::move(other._entrySymbol)) - , _baseAddress(other._baseAddress) - , _outputKind(other._outputKind) - , _outputCommands(other._outputCommands) - , _outputYAML(other._outputYAML) - , _noInhibitExec(other._noInhibitExec) - , _deadStrip(other._deadStrip) - , _globalsAreDeadStripRoots(other._globalsAreDeadStripRoots) - , _searchArchivesToOverrideTentativeDefinitions( - other._searchArchivesToOverrideTentativeDefinitions) - , _searchSharedLibrariesToOverrideTentativeDefinitions( - other._searchSharedLibrariesToOverrideTentativeDefinitions) - , _warnIfCoalesableAtomsHaveDifferentCanBeNull( - other._warnIfCoalesableAtomsHaveDifferentCanBeNull) - , _warnIfCoalesableAtomsHaveDifferentLoadName( - other._warnIfCoalesableAtomsHaveDifferentLoadName) - , _forceLoadArchives(other._forceLoadArchives) - , _textRelocations(other._textRelocations) - , _relocatable(other._relocatable) {} + LinkerOptions(LinkerOptions && other) + : _input(std::move(other._input)), + _inputSearchPaths(std::move(other._inputSearchPaths)), + _llvmArgs(std::move(other._llvmArgs)), + _deadStripRoots(std::move(other._deadStripRoots)), + _target(std::move(other._target)), + _outputPath(std::move(other._outputPath)), + _entrySymbol(std::move(other._entrySymbol)), + _baseAddress(other._baseAddress), _outputKind(other._outputKind), + _outputCommands(other._outputCommands), _outputYAML(other._outputYAML), + _noInhibitExec(other._noInhibitExec), _deadStrip(other._deadStrip), + _globalsAreDeadStripRoots(other._globalsAreDeadStripRoots), + _searchArchivesToOverrideTentativeDefinitions( + other._searchArchivesToOverrideTentativeDefinitions), + _searchSharedLibrariesToOverrideTentativeDefinitions( + other._searchSharedLibrariesToOverrideTentativeDefinitions), + _warnIfCoalesableAtomsHaveDifferentCanBeNull( + other._warnIfCoalesableAtomsHaveDifferentCanBeNull), + _warnIfCoalesableAtomsHaveDifferentLoadName( + other._warnIfCoalesableAtomsHaveDifferentLoadName), + _forceLoadArchives(other._forceLoadArchives), + _textRelocations(other._textRelocations), + _relocatable(other._relocatable) {} std::vector _input; + std::vector _inputSearchPaths; std::vector _llvmArgs; std::vector _deadStripRoots; std::string _target; diff --git a/lld/lib/Driver/CoreOptions.td b/lld/lib/Driver/CoreOptions.td index 7c5c6d4..34ba224e 100644 --- a/lld/lib/Driver/CoreOptions.td +++ b/lld/lib/Driver/CoreOptions.td @@ -7,6 +7,7 @@ def mllvm : Separate<["-"], "mllvm">, HelpText<"Options to pass to LLVM">; def output : Joined<["-"], "output=">; def entry : Joined<["-"], "entry=">; +def input_search_path : Joined<["-"], "input-search-path=">; def relocatable : Flag<["-"], "relocatable">; def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : Flag<["-"], "###">; diff --git a/lld/lib/Driver/Drivers.cpp b/lld/lib/Driver/Drivers.cpp index 3c143ef..55bb6b0 100644 --- a/lld/lib/Driver/Drivers.cpp +++ b/lld/lib/Driver/Drivers.cpp @@ -22,6 +22,8 @@ #include "llvm/ADT/Triple.h" #include "llvm/Option/Arg.h" #include "llvm/Option/Option.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace lld; @@ -146,12 +148,38 @@ public: if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_noinhibit_exec)) newArgs->AddFlagArg(A, _core.getOption(core::OPT_noinhibit_exec)); + // Copy search paths. + for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_L), + ie = _inputArgs->filtered_end(); + it != ie; ++it) { + newArgs->AddPositionalArg( + *it, _core.getOption(core::OPT_input_search_path), (*it)->getValue()); + _inputSearchPaths.push_back((*it)->getValue()); + } + // Copy input args. - for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_INPUT), + for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_INPUT, + ld::OPT_l), ie = _inputArgs->filtered_end(); - it != ie; ++it) { + it != ie; ++it) { + StringRef inputPath; + if ((*it)->getOption().getID() == ld::OPT_l) { + StringRef libName = (*it)->getValue(); + SmallString<128> p; + for (const auto &path : _inputSearchPaths) { + p = path; + llvm::sys::path::append(p, Twine("lib") + libName + ".a"); + if (llvm::sys::fs::exists(p.str())) { + inputPath = newArgs->MakeArgString(p); + break; + } + } + if (inputPath.empty()) + llvm_unreachable("Failed to lookup library!"); + } else + inputPath = (*it)->getValue(); newArgs->AddPositionalArg(*it, _core.getOption(core::OPT_INPUT), - (*it)->getValue()); + inputPath); } // Copy mllvm @@ -169,6 +197,8 @@ private: std::unique_ptr _inputArgs; core::CoreOptTable _core; ld::LDOptTable _opt; + // Local cache of search paths so we can do lookups on -l. + std::vector _inputSearchPaths; }; std::unique_ptr Driver::create( Driver::Flavor flavor @@ -221,6 +251,7 @@ LinkerOptions lld::generateOptions(const llvm::opt::ArgList &args) { ret._input.push_back(LinkerInput((*it)->getValue())); } + ret._inputSearchPaths = args.getAllArgValues(core::OPT_input_search_path); ret._llvmArgs = args.getAllArgValues(core::OPT_mllvm); ret._target = llvm::Triple::normalize(args.getLastArgValue(core::OPT_target)); ret._outputPath = args.getLastArgValue(core::OPT_output); diff --git a/lld/lib/Driver/LDOptions.td b/lld/lib/Driver/LDOptions.td index 22148aa..5ae82bb 100644 --- a/lld/lib/Driver/LDOptions.td +++ b/lld/lib/Driver/LDOptions.td @@ -19,10 +19,16 @@ def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : Flag<["-"], "###">; def emit_yaml : Flag<["-"], "emit-yaml">; def m : Separate<["-"], "m">; +def z : Separate<["-"], "z">; def static : Flag<["-"], "static">; +def start_group : Flag<["--"], "start-group">; +def end_group : Flag<["--"], "end-group">; +def build_id : Flag<["--"], "build-id">; def L : Joined<["-"], "L">; +def l : Joined<["-"], "l">; +def hash_style : Joined <["--"], "hash-style=">; def noinhibit_exec : Flag<["--"], "noinhibit-exec">, HelpText<"Retain the executable output file whenever it is still usable">; diff --git a/lld/test/Driver/lib-search.test b/lld/test/Driver/lib-search.test new file mode 100644 index 0000000..4433275 --- /dev/null +++ b/lld/test/Driver/lib-search.test @@ -0,0 +1,6 @@ +RUN: lld -flavor ld -### -L%p/../elf/Inputs b.o -lfnarchive 2>&1 \ +RUN: | FileCheck %s + +CHECK: -input-search-path={{[^ ]+}}elf/Inputs +CHECK: b.o +CHECK: {{[^ ]+}}elf/Inputs/libfnarchive.a diff --git a/lld/test/elf/Inputs/libfnarchive.x86_64 b/lld/test/elf/Inputs/libfnarchive.a similarity index 100% rename from lld/test/elf/Inputs/libfnarchive.x86_64 rename to lld/test/elf/Inputs/libfnarchive.a diff --git a/lld/test/elf/archive-elf-forceload.objtxt b/lld/test/elf/archive-elf-forceload.objtxt index 898ec2f..331cb99 100644 --- a/lld/test/elf/archive-elf-forceload.objtxt +++ b/lld/test/elf/archive-elf-forceload.objtxt @@ -23,7 +23,7 @@ # } # gcc -c main.c fn.c fn1.c -RUN: lld-core -reader ELF %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.x86_64 -force-load | FileCheck -check-prefix FORCELOAD %s +RUN: lld-core -reader ELF %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a -force-load | FileCheck -check-prefix FORCELOAD %s FORCELOAD: defined-atoms: FORCELOAD: - name: fn1 diff --git a/lld/test/elf/archive-elf.objtxt b/lld/test/elf/archive-elf.objtxt index 34e36d0..57d8f90 100644 --- a/lld/test/elf/archive-elf.objtxt +++ b/lld/test/elf/archive-elf.objtxt @@ -1,5 +1,5 @@ -# Tests the functionality of archive libraries reading -# and resolution +# Tests the functionality of archive libraries reading +# and resolution # Note: The binary files would not be required once we have support to generate # binary archives from textual(yaml) input # @@ -10,26 +10,26 @@ # fn(); # return 0; # } -# +# # archive file # int fn() # { # return 0; # } -# +# # int fn1() # { # return 0; # } # gcc -c main.c fn.c fn1.c -RUN: lld-core -reader ELF %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.x86_64 | FileCheck -check-prefix NOFORCELOAD %s +RUN: lld-core -reader ELF %p/Inputs/mainobj.x86_64 %p/Inputs/libfnarchive.a | FileCheck -check-prefix NOFORCELOAD %s -NOFORCELOAD: defined-atoms: +NOFORCELOAD: defined-atoms: NOFORCELOAD: - name: fn NOFORCELOAD: scope: global NOFORCELOAD: content: [ 55, 48, 89, E5, B8, 00, 00, 00, 00, 5D, C3 ] -NOFORCELOAD: absolute-atoms: +NOFORCELOAD: absolute-atoms: NOFORCELOAD: - name: main.c NOFORCELOAD: value: 0x0 NOFORCELOAD: - name: fn.c