[RFC][PATCH v6 2/6] Handle -z unique/-z nounique in ld

Vivek Das Mohapatra vivek@collabora.com
Mon Dec 14 17:25:51 GMT 2020


Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.
---
 bfd/ChangeLog       | 46 +++++----------------------------------------
 bfd/elflink.c       |  5 ++++-
 include/ChangeLog   |  1 +
 include/bfdlink.h   |  3 +++
 ld/ChangeLog        |  5 +++++
 ld/emultempl/elf.em |  4 ++++
 6 files changed, 22 insertions(+), 42 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 99c275ce4f..81f64bb9c4 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2020-12-09  Vivek Das Mohapatra  <vivek@collabora.com>
+
+	* elflink.c (bfd_elf_size_dynamic_sections): Call
+	_bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section.
+
 2020-12-07  Siddhesh Poyarekar  <siddhesh@sourceware.org>
 
 	PR 26945
@@ -1813,47 +1818,6 @@
 	* elfxx-x86.h (elf_x86_link_hash_table): Remove
 	readonly_dynrelocs_against_ifunc.
 
-2020-06-09  Alan Modra  <amodra@gmail.com>
-
-	* elf64-ppc.c (struct ppc_link_hash_table): Delete
-	maybe_local_ifunc_resolver field.
-	(build_global_entry_stubs_and_plt): Set local_ifunc_resolver in
-	cases where maybe_local_ifunc_resolver was set.
-	(ppc64_elf_relocate_section): Likewise.
-	(ppc64_elf_finish_dynamic_sections): Downgrade ifunc with textrel
-	error to a warning.
-
-2020-06-08  H.J. Lu  <hongjiu.lu@intel.com>
-
-	* elf-bfd.h (elf_link_hash_entry): Add tlsdesc_plt and
-	tlsdesc_got.
-	* elf32-arm.c (elf32_arm_link_hash_table): Remove tlsdesc_plt
-	and dt_tlsdesc_got.
-	(elf32_arm_size_dynamic_sections): Updated.  Clear
-	root.tlsdesc_plt for DF_BIND_NOW.
-	(elf32_arm_finish_dynamic_sections): Updated.
-	(elf32_arm_output_arch_local_syms): Likewise.
-	* elf32-nds32.c (nds32_elf_size_dynamic_sections): Updated.
-	Clear root.tlsdesc_plt for DF_BIND_NOW.
-	(nds32_elf_finish_dynamic_sections): Updated.
-	* elf32-nds32.h (elf_nds32_link_hash_table): Remove
-	dt_tlsdesc_plt and dt_tlsdesc_got.
-	* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Updated.
-	* elfnn-aarch64.c (elf_aarch64_link_hash_table): Remove
-	tlsdesc_plt and dt_tlsdesc_got.
-	(elfNN_aarch64_allocate_dynrelocs): Updated.
-	(elfNN_aarch64_finish_dynamic_sections): Likewise.
-	(elfNN_aarch64_size_dynamic_sections): Updated.  Clear
-	root.tlsdesc_plt for DF_BIND_NOW.  Don't check DF_BIND_NOW
-	twice.
-	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Updated.
-	(_bfd_x86_elf_size_dynamic_sections): Likewise.
-	(_bfd_x86_elf_finish_dynamic_sections): Likewise.
-	* elfxx-x86.h (elf_x86_link_hash_table): Remove tlsdesc_plt and
-	tlsdesc_got.
-
-2020-06-07  H.J. Lu  <hongjiu.lu@intel.com>
-
 	* elf32-tic6x.c (elf32_bed): Defined the default to
 	elf32_tic6x_bed.
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 29b46f1568..700f451cb6 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -7178,7 +7178,10 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
 	      || !_bfd_elf_add_dynamic_entry (info, DT_SYMTAB, 0)
 	      || !_bfd_elf_add_dynamic_entry (info, DT_STRSZ, strsize)
 	      || !_bfd_elf_add_dynamic_entry (info, DT_SYMENT,
-					      bed->s->sizeof_sym))
+					      bed->s->sizeof_sym)
+              || (info->gnu_flags_1
+                  && !_bfd_elf_add_dynamic_entry (info, DT_GNU_FLAGS_1,
+                                                  info->gnu_flags_1)))
 	    return FALSE;
 	}
     }
diff --git a/include/ChangeLog b/include/ChangeLog
index ca67c7fd9b..268dc2de6d 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,6 +1,7 @@
 2020-12-09  Vivek Das Mohapatra  <vivek@collabora.com>
 
 	* elf/common.h (DT_GNU_FLAGS_1, DF_GNU_1_UNIQUE): Define.
+	* bfdlink.h (struct bfd_link_info): New field gnu_flags_1.
 
 2020-12-07  Nick Clifton  <nickc@redhat.com>
 
diff --git a/include/bfdlink.h b/include/bfdlink.h
index b92ef5408d..3019033ea2 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -655,6 +655,9 @@ struct bfd_link_info
   /* May be used to set DT_FLAGS_1 for ELF. */
   bfd_vma flags_1;
 
+  /* May be used to set DT_GNU_FLAGS_1 for ELF. */
+  bfd_vma gnu_flags_1;
+
   /* May be used to set ELF visibility for __start_* / __stop_.  */
   unsigned int start_stop_visibility;
 
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9e72b31c9f..ba795aaafb 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
+2020-12-09  Vivek Das Mohapatra  <vivek@collabora.com>
+
+	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
+	Parse -z unique / -z nounique options.
+
 2020-12-05  Maciej W. Rozycki  <macro@linux-mips.org>
 
 	* testsuite/ld-vax-elf/got-local-exe-off-hidden.dd: New test
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index cfdf60e136..f2b6b552c3 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -809,6 +809,10 @@ fragment <<EOF
 	  link_info.flags |= (bfd_vma) DF_ORIGIN;
 	  link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
 	}
+      else if (strcmp (optarg, "unique") == 0)
+        link_info.gnu_flags_1 |= (bfd_vma) DF_GNU_1_UNIQUE;
+      else if (strcmp (optarg, "nounique") == 0)
+        link_info.gnu_flags_1 &= ~(bfd_vma) DF_GNU_1_UNIQUE;
       else if (strcmp (optarg, "combreloc") == 0)
 	link_info.combreloc = TRUE;
       else if (strcmp (optarg, "nocombreloc") == 0)
-- 
2.20.1



More information about the Binutils mailing list