[lld] r182889 - [lld][elf] Add --dynamic-linker option to the ELF linker.
Shankar Easwaran
shankare at codeaurora.org
Wed May 29 15:51:01 PDT 2013
Author: shankare
Date: Wed May 29 17:51:01 2013
New Revision: 182889
URL: http://llvm.org/viewvc/llvm-project?rev=182889&view=rev
Log:
[lld][elf] Add --dynamic-linker option to the ELF linker.
Users can override the default value of the dynamic linker to be set to the
one that appears in the command line. The path can even be empty!.
Added a test for the option.
Added:
lld/trunk/test/elf/options/
lld/trunk/test/elf/options/dynamic-linker.test
Modified:
lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
lld/trunk/lib/Driver/GnuLdDriver.cpp
lld/trunk/lib/Driver/LDOptions.td
lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=182889&r1=182888&r2=182889&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Wed May 29 17:51:01 2013
@@ -81,10 +81,18 @@ public:
return false;
}
- virtual StringRef getInterpreter() const {
+ /// \brief The path to the dynamic interpreter
+ virtual StringRef getDefaultInterpreter() const {
return "/lib64/ld-linux-x86-64.so.2";
}
+ /// \brief The dynamic linker path set by the --dynamic-linker option
+ virtual StringRef getInterpreter() const {
+ if (_dynamicLinkerArg)
+ return _dynamicLinkerPath;
+ return getDefaultInterpreter();
+ }
+
/// \brief Does the output have dynamic sections.
virtual bool isDynamic() const;
@@ -106,6 +114,13 @@ public:
void setIsStaticExecutable(bool v) { _isStaticExecutable = v; }
void setMergeCommonStrings(bool v) { _mergeCommonStrings = v; }
void setUseShlibUndefines(bool use) { _useShlibUndefines = use; }
+
+ /// \brief Set the dynamic linker path
+ void setInterpreter(StringRef dynamicLinker) {
+ _dynamicLinkerArg = true;
+ _dynamicLinkerPath = dynamicLinker;
+ }
+
void appendSearchPath(StringRef dirPath) {
_inputSearchPaths.push_back(dirPath);
}
@@ -129,12 +144,14 @@ protected:
bool _mergeCommonStrings;
bool _runLayoutPass;
bool _useShlibUndefines;
+ bool _dynamicLinkerArg;
std::vector<StringRef> _inputSearchPaths;
llvm::BumpPtrAllocator _extraStrings;
std::unique_ptr<Reader> _elfReader;
std::unique_ptr<Reader> _yamlReader;
std::unique_ptr<Writer> _writer;
std::unique_ptr<Reader> _linkerScriptReader;
+ StringRef _dynamicLinkerPath;
};
} // end namespace lld
Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=182889&r1=182888&r2=182889&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Wed May 29 17:51:01 2013
@@ -193,6 +193,11 @@ GnuLdDriver::parse(int argc, const char
if (parsedArgs->getLastArg(OPT_use_shlib_undefs))
options->setUseShlibUndefines(true);
+ // Handle --dynamic-linker
+ if (llvm::opt::Arg *dynamicLinker =
+ parsedArgs->getLastArg(OPT_dynamic_linker))
+ options->setInterpreter(dynamicLinker->getValue());
+
// Handle -Lxxx
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_L),
ie = parsedArgs->filtered_end();
Modified: lld/trunk/lib/Driver/LDOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/LDOptions.td?rev=182889&r1=182888&r2=182889&view=diff
==============================================================================
--- lld/trunk/lib/Driver/LDOptions.td (original)
+++ lld/trunk/lib/Driver/LDOptions.td Wed May 29 17:51:01 2013
@@ -18,8 +18,9 @@ def output : Separate<["-"], "o">,
def relocatable : Flag<["--"], "relocatable">;
def relocatable_r : Flag<["-"], "r">, Alias<relocatable>;
-def dynamic_linker : Separate<["-"], "dynamic-linker">;
-
+def dynamic_linker : Joined<["--"], "dynamic-linker=">,
+ HelpText<"Set the path to the dynamic linker">;
+def dynamic_linker_alias : Separate<["-"], "dynamic-linker">, Alias<dynamic_linker>;
def m : Separate<["-"], "m">;
def z : Separate<["-"], "z">;
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp?rev=182889&r1=182888&r2=182889&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Wed May 29 17:51:01 2013
@@ -22,7 +22,8 @@
#include "llvm/Support/Path.h"
namespace lld {
-ELFTargetInfo::ELFTargetInfo(llvm::Triple triple, std::unique_ptr<TargetHandlerBase> targetHandler)
+ELFTargetInfo::ELFTargetInfo(llvm::Triple triple,
+ std::unique_ptr<TargetHandlerBase> targetHandler)
: _outputFileType(elf::ET_EXEC),
_triple(triple),
_targetHandler(std::move(targetHandler)),
@@ -32,11 +33,10 @@ ELFTargetInfo::ELFTargetInfo(llvm::Tripl
_noInhibitExec(false),
_mergeCommonStrings(false),
_runLayoutPass(true),
- _useShlibUndefines(false) {}
+ _useShlibUndefines(false),
+ _dynamicLinkerArg(false) {}
-bool ELFTargetInfo::is64Bits() const {
- return getTriple().isArch64Bit();
-}
+bool ELFTargetInfo::is64Bits() const { return getTriple().isArch64Bit(); }
bool ELFTargetInfo::isLittleEndian() const {
// TODO: Do this properly. It is not defined purely by arch.
Added: lld/trunk/test/elf/options/dynamic-linker.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/options/dynamic-linker.test?rev=182889&view=auto
==============================================================================
--- lld/trunk/test/elf/options/dynamic-linker.test (added)
+++ lld/trunk/test/elf/options/dynamic-linker.test Wed May 29 17:51:01 2013
@@ -0,0 +1,14 @@
+# This tests the functionality of specifying dynamic-linker argument in the
+# command line
+RUN: lld -flavor gnu --dynamic-linker="/xyz.so" %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t
+RUN: llvm-objdump -s %t | FileCheck -check-prefix=DYNAMICINTERP1 %s
+RUN: lld -flavor gnu --dynamic-linker="" %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t1
+RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=DYNAMICINTERP2 %s
+RUN: lld -flavor gnu -dynamic-linker /xyz.so %p/../Inputs/foo.o.x86-64 --noinhibit-exec -o %t2
+RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=DYNAMICINTERP1 %s
+
+DYNAMICINTERP1:Contents of section .interp:
+DYNAMICINTERP1: 400158 2f78797a 2e736f00 /xyz.so.
+DYNAMICINTERP2:Contents of section .interp:
+DYNAMICINTERP2: 400158 00
+
More information about the llvm-commits
mailing list