, _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;
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<["-"], "###">;
#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;
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
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
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);
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">;
--- /dev/null
+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
# }
# 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
-# 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
#
# 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