[PATCH] [GNU] Implement --enable-new-dtags/--disable-new-dtags

Davide Italiano davide at freebsd.org
Mon Apr 6 14:35:43 PDT 2015


Updated.


http://reviews.llvm.org/D8836

Files:
  include/lld/ReaderWriter/ELFLinkingContext.h
  lib/Driver/GnuLdDriver.cpp
  lib/Driver/GnuLdOptions.td
  lib/ReaderWriter/ELF/OutputELFWriter.h

Index: include/lld/ReaderWriter/ELFLinkingContext.h
===================================================================
--- include/lld/ReaderWriter/ELFLinkingContext.h
+++ include/lld/ReaderWriter/ELFLinkingContext.h
@@ -292,6 +292,18 @@
   bool alignSegments() const { return _alignSegments; }
   void setAlignSegments(bool align) { _alignSegments = align; }
 
+  /// \brief Enable new dtags.
+  /// If this flag is set lld emits DT_RUNPATH instead of
+  /// DT_RUNPATH. They are functionally equivalent except for
+  /// the following two differences:
+  /// - 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.
+  bool getEnableNewDtags() const { return _enableNewDtags; }
+  void setEnableNewDtags(bool e) { _enableNewDtags = e; }
+
   /// \brief Strip symbols.
   bool stripSymbols() const { return _stripSymbols; }
   void setStripSymbols(bool strip) { _stripSymbols = strip; }
@@ -346,6 +358,7 @@
   bool _demangle = true;
   bool _stripSymbols = false;
   bool _alignSegments = true;
+  bool _enableNewDtags = false;
   bool _collectStats = false;
   bool _armTarget1Rel = false;
   uint64_t _maxPageSize = 0x1000;
Index: lib/Driver/GnuLdDriver.cpp
===================================================================
--- lib/Driver/GnuLdDriver.cpp
+++ lib/Driver/GnuLdDriver.cpp
@@ -620,6 +620,10 @@
       ctx->addRpathLink(path);
   }
 
+  // Enable new dynamic tags.
+  if (parsedArgs->hasArg(OPT_enable_newdtags))
+    ctx->setEnableNewDtags(true);
+
   // Support --wrap option.
   for (auto *arg : parsedArgs->filtered(OPT_wrap))
     ctx->addWrapForSymbol(arg->getValue());
Index: lib/Driver/GnuLdOptions.td
===================================================================
--- lib/Driver/GnuLdOptions.td
+++ lib/Driver/GnuLdOptions.td
@@ -231,6 +231,12 @@
 //===----------------------------------------------------------------------===//
 def grp_customopts : OptionGroup<"opts">,
      HelpText<"CUSTOM OPTIONS">;
+def disable_newdtags: Flag<["--"], "disable-new-dtags">,
+     HelpText<"Disable new dynamic tags">,
+     Group<grp_customopts>;
+def enable_newdtags: Flag<["--"], "enable-new-dtags">,
+     HelpText<"Enable new dynamic tags">,
+     Group<grp_customopts>;
 def rosegment: Flag<["--"], "rosegment">,
      HelpText<"Put read-only non-executable sections in their own segment">,
      Group<grp_customopts>;
Index: lib/ReaderWriter/ELF/OutputELFWriter.h
===================================================================
--- lib/ReaderWriter/ELF/OutputELFWriter.h
+++ lib/ReaderWriter/ELF/OutputELFWriter.h
@@ -280,7 +280,7 @@
     auto rpath = new (_alloc) std::string(join(rpathList.begin(),
       rpathList.end(), ":"));
     Elf_Dyn dyn;
-    dyn.d_tag = DT_RPATH;
+    dyn.d_tag = (_ctx.getEnableNewDtags()) ? DT_RUNPATH : DT_RPATH;
     dyn.d_un.d_val = _dynamicStringTable->addString(*rpath);
     _dynamicTable->addEntry(dyn);
   }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8836.23294.patch
Type: text/x-patch
Size: 3086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150406/cf4a5c64/attachment.bin>


More information about the llvm-commits mailing list