[PATCH] D30258: [ELF] - Implemented --no-dynamic-linker option

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 08:57:27 PST 2017


grimar created this revision.

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: https://github.com/torvalds/linux/blob/master/arch/x86/boot/compressed/Makefile#L52.
Though I think that x86/x64 bootloader does not really rely on it, I believe it ignores all phdrs except PT_LOAD for now:
https://github.com/torvalds/linux/blob/master/arch/x86/boot/compressed/misc.c#L301

But it is used for PPC: 
https://github.com/torvalds/linux/blob/ba6d973f78eb62ffebb32f6ef3334fc9a3b33d22/arch/powerpc/kernel/kexec_elf_64.c#L486


https://reviews.llvm.org/D30258

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Options.td
  ELF/Writer.cpp
  test/ELF/no-dynamic-linker.s


Index: test/ELF/no-dynamic-linker.s
===================================================================
--- test/ELF/no-dynamic-linker.s
+++ test/ELF/no-dynamic-linker.s
@@ -0,0 +1,8 @@
+# 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 --no-dynamic-linker -dynamic-linker foo %t.o %t.so -o %t
+# RUN: llvm-readobj --program-headers %t | FileCheck %s
+
+# CHECK-NOT: PT_INTERP
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -132,7 +132,8 @@
 }
 
 template <class ELFT> static bool needsInterpSection() {
-  return !Symtab<ELFT>::X->getSharedFiles().empty() &&
+  return !Config->NoDynamicLinker &&
+         !Symtab<ELFT>::X->getSharedFiles().empty() &&
          !Config->DynamicLinker.empty() &&
          !Script<ELFT>::X->ignoreInterpSection();
 }
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -148,6 +148,8 @@
 def no_demangle: F<"no-demangle">,
   HelpText<"Do not demangle symbol names">;
 
+def no_dynamic_linker: F<"no-dynamic-linker">;
+
 def no_export_dynamic: F<"no-export-dynamic">;
 def no_fatal_warnings: F<"no-fatal-warnings">;
 
@@ -357,7 +359,6 @@
 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">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -529,6 +529,7 @@
   Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false);
   Config->GdbIndex = Args.hasArg(OPT_gdb_index);
   Config->ICF = Args.hasArg(OPT_icf);
+  Config->NoDynamicLinker = Args.hasArg(OPT_no_dynamic_linker);
   Config->NoGnuUnique = Args.hasArg(OPT_no_gnu_unique);
   Config->NoUndefinedVersion = Args.hasArg(OPT_no_undefined_version);
   Config->Nostdlib = Args.hasArg(OPT_nostdlib);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -113,6 +113,7 @@
   bool ICF;
   bool Mips64EL = false;
   bool MipsN32Abi = false;
+  bool NoDynamicLinker;
   bool NoGnuUnique;
   bool NoUndefinedVersion;
   bool Nostdlib;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30258.89368.patch
Type: text/x-patch
Size: 2604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170222/5b710980/attachment.bin>


More information about the llvm-commits mailing list