This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [RFC] ld: add new --enable-new-dtags-only flag


With the --enable-new-dtags flag, you can generate DT_RUNPATH in
addition to DT_RPATH.  But the former tag isn't terribly useful
so long as the latter is still being generated.  So add a new
option to suppress that.

The proposed option name isn't great, but it's in line with the
existing --neable-new-dtags flag.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

[Being lazy on CL writing until we hammer out the proposal]
---
 bfd/elflink.c         | 14 ++++++++++----
 gold/layout.cc        |  3 ++-
 gold/options.h        |  3 +++
 include/bfdlink.h     |  3 +++
 ld/emultempl/elf32.em | 10 +++++++++-
 ld/ld.texinfo         |  8 ++++++--
 6 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 661b2eb..b70d995 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5748,13 +5748,19 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
 
 	  indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, rpath,
 				      TRUE);
-	  if (indx == (bfd_size_type) -1
-	      || !_bfd_elf_add_dynamic_entry (info, DT_RPATH, indx))
+	  if (indx == (bfd_size_type) -1)
 	    return FALSE;
 
-	  if  (info->new_dtags)
+	  if (!info->new_dtags_only)
+	    {
+	      if (!_bfd_elf_add_dynamic_entry (info, DT_RPATH, indx))
+		return FALSE;
+	    }
+
+	  if (info->new_dtags)
 	    {
-	      _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx);
+	      if (!info->new_dtags_only)
+		_bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx);
 	      if (!_bfd_elf_add_dynamic_entry (info, DT_RUNPATH, indx))
 		return FALSE;
 	    }
diff --git a/gold/layout.cc b/gold/layout.cc
index f7f0e7e..5083e24 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -4645,7 +4645,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
 	    }
 	}
 
-      odyn->add_string(elfcpp::DT_RPATH, rpath_val);
+      if (!parameters->options().enable_new_dtags_only())
+	odyn->add_string(elfcpp::DT_RPATH, rpath_val);
       if (parameters->options().enable_new_dtags())
 	odyn->add_string(elfcpp::DT_RUNPATH, rpath_val);
     }
diff --git a/gold/options.h b/gold/options.h
index 38f0c00..65ff03b 100644
--- a/gold/options.h
+++ b/gold/options.h
@@ -908,6 +908,9 @@ class General_options
 		N_("Enable use of DT_RUNPATH and DT_FLAGS"),
 		N_("Disable use of DT_RUNPATH and DT_FLAGS"));
 
+  DEFINE_enable(new_dtags_only, options::EXACTLY_TWO_DASHES, '\0', false,
+		N_("Skip the use of DT_RPATH"), NULL);
+
   DEFINE_bool(noinhibit_exec, options::TWO_DASHES, '\0', false,
 	      N_("Create an output file even if errors occur"), NULL);
 
diff --git a/include/bfdlink.h b/include/bfdlink.h
index bf44dee..3920d12 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -368,6 +368,9 @@ struct bfd_link_info
   /* TRUE if the new ELF dynamic tags are enabled. */
   unsigned int new_dtags: 1;
 
+  /* TRUE if only the new ELF dynamic tags are used (skips old tags).  */
+  unsigned int new_dtags_only: 1;
+
   /* FALSE if .eh_frame unwind info should be generated for PLT and other
      linker created sections, TRUE if it should be omitted.  */
   unsigned int no_ld_generated_unwind_info: 1;
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index d30a0ad..405cfc3 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -2120,7 +2120,8 @@ fragment <<EOF
 
 #define OPTION_DISABLE_NEW_DTAGS	(400)
 #define OPTION_ENABLE_NEW_DTAGS		(OPTION_DISABLE_NEW_DTAGS + 1)
-#define OPTION_GROUP			(OPTION_ENABLE_NEW_DTAGS + 1)
+#define OPTION_ENABLE_NEW_DTAGS_ONLY	(OPTION_ENABLE_NEW_DTAGS + 1)
+#define OPTION_GROUP			(OPTION_ENABLE_NEW_DTAGS_ONLY + 1)
 #define OPTION_EH_FRAME_HDR		(OPTION_GROUP + 1)
 #define OPTION_EXCLUDE_LIBS		(OPTION_EH_FRAME_HDR + 1)
 #define OPTION_HASH_STYLE		(OPTION_EXCLUDE_LIBS + 1)
@@ -2159,6 +2160,7 @@ fragment <<EOF
     {"depaudit", required_argument, NULL, 'P'},
     {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
     {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
+    {"enable-new-dtags-only", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS_ONLY},
     {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
     {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
     {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
@@ -2222,6 +2224,10 @@ fragment <<EOF
       link_info.new_dtags = TRUE;
       break;
 
+    case OPTION_ENABLE_NEW_DTAGS_ONLY:
+      link_info.new_dtags_only = TRUE;
+      break;
+
     case OPTION_EH_FRAME_HDR:
       link_info.eh_frame_hdr = TRUE;
       break;
@@ -2402,6 +2408,8 @@ fragment <<EOF
   fprintf (file, _("\
   --enable-new-dtags          Enable new dynamic tags\n"));
   fprintf (file, _("\
+  --enable-new-dtags-only     Only use new dynamic tags (omit old dynamic tags)\n"));
+  fprintf (file, _("\
   --eh-frame-hdr              Create .eh_frame_hdr section\n"));
   fprintf (file, _("\
   --exclude-libs=LIBS         Make all symbols in LIBS hidden\n"));
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index c7ae2a5..bdab407 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -2099,15 +2099,19 @@ generated code sections like PLT.  This option is on by default
 if linker generated unwind info is supported.
 
 @kindex --enable-new-dtags
+@kindex --enable-new-dtags-only
 @kindex --disable-new-dtags
 @item --enable-new-dtags
+@itemx --enable-new-dtags-only
 @itemx --disable-new-dtags
 This linker can create the new dynamic tags in ELF. But the older ELF
 systems may not understand them. If you specify
 @option{--enable-new-dtags}, the dynamic tags will be created as needed.
 If you specify @option{--disable-new-dtags}, no new dynamic tags will be
-created. By default, the new dynamic tags are not created. Note that
-those options are only available for ELF systems.
+created. If you specify @option{--enable-new-dtags-only} in conjunction
+with @option{--enable-new-dtags}, then older dynamic tags will be omitted
+when new dynamic tags replace them. By default, the new dynamic tags are
+not created. Note that those options are only available for ELF systems.
 
 @kindex --hash-size=@var{number}
 @item --hash-size=@var{number}
-- 
1.8.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]