[lld] r249428 - [ELF2] Implement --{enable, disable}-new-dtags options.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 09:20:00 PDT 2015


Author: davide
Date: Tue Oct  6 11:20:00 2015
New Revision: 249428

URL: http://llvm.org/viewvc/llvm-project?rev=249428&view=rev
Log:
[ELF2] Implement --{enable, disable}-new-dtags options.

Added:
    lld/trunk/test/elf2/new-dtags.test
Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Options.td
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=249428&r1=249427&r2=249428&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Tue Oct  6 11:20:00 2015
@@ -31,6 +31,7 @@ struct Configuration {
   bool DiscardAll;
   bool DiscardLocals;
   bool DiscardNone;
+  bool EnableNewDtags = true;
   bool ExportDynamic;
   bool NoInhibitExec;
   bool NoUndefined;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249428&r1=249427&r2=249428&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Oct  6 11:20:00 2015
@@ -130,6 +130,7 @@ void LinkerDriver::link(ArrayRef<const c
   Config->DiscardAll = Args.hasArg(OPT_discard_all);
   Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
   Config->DiscardNone = Args.hasArg(OPT_discard_none);
+  Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags);
   Config->ExportDynamic = Args.hasArg(OPT_export_dynamic);
   Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec);
   Config->NoUndefined = Args.hasArg(OPT_no_undefined);

Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=249428&r1=249427&r2=249428&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Tue Oct  6 11:20:00 2015
@@ -14,6 +14,9 @@ def allow_multiple_definition: Flag<["--
 
 def allow_shlib_undefined : Flag<["--", "-"], "allow-shlib-undefined">;
 
+def disable_new_dtags : Flag<["--"], "disable-new-dtags">,
+  HelpText<"Disable new dynamic tags">;
+
 def discard_all : Flag<["-"], "discard-all">,
   HelpText<"Delete all local symbols">;
 
@@ -26,6 +29,9 @@ def discard_none : Flag<["-"], "discard-
 def dynamic_linker : Separate<["--", "-"], "dynamic-linker">,
   HelpText<"Which dynamic linker to use">;
 
+def enable_new_dtags : Flag<["--"], "enable-new-dtags">,
+  HelpText<"Enable new dynamic tags">;
+
 def entry : Separate<["--", "-"], "entry">, MetaVarName<"<entry>">,
   HelpText<"Name of entry point symbol">;
 
@@ -96,7 +102,6 @@ def O3 : Flag<["-"], "O3">;
 def as_needed : Flag<["--"], "as-needed">;
 def build_id : Flag<["--"], "build-id">;
 def eh_frame_hdr : Flag<["--"], "eh-frame-hdr">;
-def enable_new_dtags : Flag<["--"], "enable-new-dtags">;
 def end_group : Flag<["--"], "end-group">;
 def gc_sections : Flag<["--"], "gc-sections">;
 def hash_style : Joined<["--"], "hash-style=">;

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249428&r1=249427&r2=249428&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct  6 11:20:00 2015
@@ -228,7 +228,7 @@ template <class ELFT> void DynamicSectio
   ++NumEntries; // DT_HASH
 
   if (!Config->RPath.empty()) {
-    ++NumEntries; // DT_RUNPATH
+    ++NumEntries; // DT_RUNPATH / DT_RPATH
     DynStrSec.add(Config->RPath);
   }
 
@@ -294,7 +294,17 @@ template <class ELFT> void DynamicSectio
   WritePtr(DT_HASH, HashSec.getVA());
 
   if (!Config->RPath.empty())
-    WriteVal(DT_RUNPATH, DynStrSec.getFileOff(Config->RPath));
+
+    // If --enable-new-dtags is set lld emits DT_RUNPATH
+    // instead of DT_RPATH. The two tags are functionally
+    // equivalent except for the following:
+    // - DT_RUNPATH is searched after LD_LIBRARY_PATH, while
+    // DT_RPATH is searched before.
+    // - DT_RUNPATH is used only to search for direct
+    // dependencies of the object it's contained in, while
+    // DT_RPATH is used for indirect dependencies as well.
+    WriteVal(Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH,
+             DynStrSec.getFileOff(Config->RPath));
 
   if (!Config->SoName.empty())
     WriteVal(DT_SONAME, DynStrSec.getFileOff(Config->SoName));

Added: lld/trunk/test/elf2/new-dtags.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/new-dtags.test?rev=249428&view=auto
==============================================================================
--- lld/trunk/test/elf2/new-dtags.test (added)
+++ lld/trunk/test/elf2/new-dtags.test Tue Oct  6 11:20:00 2015
@@ -0,0 +1,18 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: lld -flavor gnu2 %t.o -rpath=/somepath -shared --disable-new-dtags -o %t
+// RUN: lld -flavor gnu2 %t.o -rpath=/somepath -shared --enable-new-dtags -o %t2
+// RUN: llvm-readobj --dynamic-table %t | FileCheck --check-prefix=DISABLE %s 
+// RUN: llvm-readobj --dynamic-table %t2 | FileCheck --check-prefix=ENABLE %s 
+
+// DISABLE: DynamicSection [
+// DISABLE:   0x000000000000000F RPATH                /somepath
+// DISABLE-NOT: RUNPATH
+// DISABLE: ]
+
+// ENABLE: DynamicSection [
+// ENABLE:   0x000000000000001D RUNPATH              /somepath
+// ENABLE-NOT: RPATH
+// ENABLE: ]
+
+.global _start
+_start:




More information about the llvm-commits mailing list