[RFC,v4,2/6] Handle -z unique/-z nounique in ld

Message ID 88348d3fac7e648b53d8e8fbe4abb24fe3556355.1594308457.git.vivek@collabora.com
State New
Headers show
Series
  • binutils patches for DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE
Related show

Commit Message

David Faust via Binutils July 9, 2020, 3:29 p.m.
Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.
---
 bfd/elflink.c       | 5 ++++-
 include/bfdlink.h   | 3 +++
 ld/emultempl/elf.em | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)

-- 
2.11.0

Patch

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 998b72f228..be6ba056f4 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -7132,7 +7132,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/bfdlink.h b/include/bfdlink.h
index 7163433383..e66c324040 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -649,6 +649,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/emultempl/elf.em b/ld/emultempl/elf.em
index 356f34538b..32e8754ab7 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -805,6 +805,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)