[lld] r174590 - [Driver] Add -L and -l support.
Michael J. Spencer
bigcheesegs at gmail.com
Wed Feb 6 22:47:17 PST 2013
Author: mspencer
Date: Thu Feb 7 00:47:17 2013
New Revision: 174590
URL: http://llvm.org/viewvc/llvm-project?rev=174590&view=rev
Log:
[Driver] Add -L and -l support.
Added:
lld/trunk/test/Driver/lib-search.test
lld/trunk/test/elf/Inputs/libfnarchive.a
- copied, changed from r174589, lld/trunk/test/elf/Inputs/libfnarchive.x86_64
Removed:
lld/trunk/test/elf/Inputs/libfnarchive.x86_64
Modified:
lld/trunk/include/lld/Core/LinkerOptions.h
lld/trunk/lib/Driver/CoreOptions.td
lld/trunk/lib/Driver/Drivers.cpp
lld/trunk/lib/Driver/LDOptions.td
lld/trunk/test/elf/archive-elf-forceload.objtxt
lld/trunk/test/elf/archive-elf.objtxt
Modified: lld/trunk/include/lld/Core/LinkerOptions.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkerOptions.h?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkerOptions.h (original)
+++ lld/trunk/include/lld/Core/LinkerOptions.h Thu Feb 7 00:47:17 2013
@@ -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<LinkerInput> _input;
+ std::vector<std::string> _inputSearchPaths;
std::vector<std::string> _llvmArgs;
std::vector<std::string> _deadStripRoots;
std::string _target;
Modified: lld/trunk/lib/Driver/CoreOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CoreOptions.td?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CoreOptions.td (original)
+++ lld/trunk/lib/Driver/CoreOptions.td Thu Feb 7 00:47:17 2013
@@ -7,6 +7,7 @@ def mllvm : Separate<["-"], "mllvm">, He
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<["-"], "###">;
Modified: lld/trunk/lib/Driver/Drivers.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Drivers.cpp?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Drivers.cpp (original)
+++ lld/trunk/lib/Driver/Drivers.cpp Thu Feb 7 00:47:17 2013
@@ -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<llvm::opt::InputArgList> _inputArgs;
core::CoreOptTable _core;
ld::LDOptTable _opt;
+ // Local cache of search paths so we can do lookups on -l.
+ std::vector<std::string> _inputSearchPaths;
};
std::unique_ptr<Driver> Driver::create( Driver::Flavor flavor
@@ -221,6 +251,7 @@ LinkerOptions lld::generateOptions(const
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);
Modified: lld/trunk/lib/Driver/LDOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/LDOptions.td?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/lib/Driver/LDOptions.td (original)
+++ lld/trunk/lib/Driver/LDOptions.td Thu Feb 7 00:47:17 2013
@@ -19,10 +19,16 @@ def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : F
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">;
Added: lld/trunk/test/Driver/lib-search.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/lib-search.test?rev=174590&view=auto
==============================================================================
--- lld/trunk/test/Driver/lib-search.test (added)
+++ lld/trunk/test/Driver/lib-search.test Thu Feb 7 00:47:17 2013
@@ -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
Copied: lld/trunk/test/elf/Inputs/libfnarchive.a (from r174589, lld/trunk/test/elf/Inputs/libfnarchive.x86_64)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/libfnarchive.a?p2=lld/trunk/test/elf/Inputs/libfnarchive.a&p1=lld/trunk/test/elf/Inputs/libfnarchive.x86_64&r1=174589&r2=174590&rev=174590&view=diff
==============================================================================
Binary files - no diff available.
Removed: lld/trunk/test/elf/Inputs/libfnarchive.x86_64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/libfnarchive.x86_64?rev=174589&view=auto
==============================================================================
Binary file - no diff available.
Modified: lld/trunk/test/elf/archive-elf-forceload.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/archive-elf-forceload.objtxt?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/test/elf/archive-elf-forceload.objtxt (original)
+++ lld/trunk/test/elf/archive-elf-forceload.objtxt Thu Feb 7 00:47:17 2013
@@ -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
Modified: lld/trunk/test/elf/archive-elf.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/archive-elf.objtxt?rev=174590&r1=174589&r2=174590&view=diff
==============================================================================
--- lld/trunk/test/elf/archive-elf.objtxt (original)
+++ lld/trunk/test/elf/archive-elf.objtxt Thu Feb 7 00:47:17 2013
@@ -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
More information about the llvm-commits
mailing list