[lld] r296097 - [ELF] - Implemented --no-dynamic-linker option
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 24 00:26:19 PST 2017
Author: grimar
Date: Fri Feb 24 02:26:18 2017
New Revision: 296097
URL: http://llvm.org/viewvc/llvm-project?rev=296097&view=rev
Log:
[ELF] - Implemented --no-dynamic-linker option
Feature is used for producing static-linked PIE executables
(https://gcc.gnu.org/ml/gcc/2015-06/msg00008.html)
And was implemented in GNU ld https://gcc.gnu.org/ml/gcc/2015-08/msg00099.html
I also found it in linux kernel build system,
though I think that x86/x64 bootloader does not really rely on it.
Seems it used for PPC though.
Differential revision: https://reviews.llvm.org/D30258
Added:
lld/trunk/test/ELF/no-dynamic-linker.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=296097&r1=296096&r2=296097&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Feb 24 02:26:18 2017
@@ -434,6 +434,13 @@ static DiscardPolicy getDiscardOption(op
return DiscardPolicy::None;
}
+static StringRef getDynamicLinkerOption(opt::InputArgList &Args) {
+ auto *Arg = Args.getLastArg(OPT_dynamic_linker, OPT_no_dynamic_linker);
+ if (!Arg || Arg->getOption().getID() == OPT_no_dynamic_linker)
+ return "";
+ return Arg->getValue();
+}
+
static StripPolicy getStripOption(opt::InputArgList &Args) {
if (auto *Arg = Args.getLastArg(OPT_strip_all, OPT_strip_debug)) {
if (Arg->getOption().getID() == OPT_strip_all)
@@ -548,8 +555,6 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->Trace = Args.hasArg(OPT_trace);
Config->Verbose = Args.hasArg(OPT_verbose);
Config->WarnCommon = Args.hasArg(OPT_warn_common);
-
- Config->DynamicLinker = getString(Args, OPT_dynamic_linker);
Config->Entry = getString(Args, OPT_entry);
Config->Fini = getString(Args, OPT_fini, "_fini");
Config->Init = getString(Args, OPT_init, "_init");
@@ -582,6 +587,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZStackSize = getZOptionValue(Args, "stack-size", 0);
Config->ZWxneeded = hasZOption(Args, "wxneeded");
+ Config->DynamicLinker = getDynamicLinkerOption(Args);
Config->OFormatBinary = isOutputFormatBinary(Args);
Config->SectionStartMap = getSectionStartMap(Args);
Config->SortSection = getSortKind(Args);
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=296097&r1=296096&r2=296097&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Fri Feb 24 02:26:18 2017
@@ -148,6 +148,9 @@ def no_define_common: F<"no-define-commo
def no_demangle: F<"no-demangle">,
HelpText<"Do not demangle symbol names">;
+def no_dynamic_linker: F<"no-dynamic-linker">,
+ HelpText<"Inhibit output of .interp section">;
+
def no_export_dynamic: F<"no-export-dynamic">;
def no_fatal_warnings: F<"no-fatal-warnings">;
@@ -357,7 +360,6 @@ def no_add_needed: F<"no-add-needed">;
def no_allow_shlib_undefined: F<"no-allow-shlib-undefined">;
def no_copy_dt_needed_entries: F<"no-copy-dt-needed-entries">,
Alias<no_add_needed>;
-def no_dynamic_linker: F<"no-dynamic-linker">;
def no_mmap_output_file: F<"no-mmap-output-file">;
def no_warn_common: F<"no-warn-common">;
def no_warn_mismatch: F<"no-warn-mismatch">;
Added: lld/trunk/test/ELF/no-dynamic-linker.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/no-dynamic-linker.s?rev=296097&view=auto
==============================================================================
--- lld/trunk/test/ELF/no-dynamic-linker.s (added)
+++ lld/trunk/test/ELF/no-dynamic-linker.s Fri Feb 24 02:26:18 2017
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %tso.o
+# RUN: ld.lld -shared %tso.o -o %t.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+
+# RUN: ld.lld -dynamic-linker foo --no-dynamic-linker %t.o %t.so -o %t
+# RUN: llvm-readobj --program-headers %t | FileCheck %s --check-prefix=NODL
+# NODL-NOT: PT_INTERP
+
+# RUN: ld.lld --no-dynamic-linker -dynamic-linker foo %t.o %t.so -o %t
+# RUN: llvm-readobj --program-headers %t | FileCheck %s --check-prefix=WITHDL
+# WITHDL: PT_INTERP
More information about the llvm-commits
mailing list