Handle -z unique/-z nounique in ld
authorVivek Das Mohapatra <vivek@collabora.com>
Mon, 14 Dec 2020 17:25:51 +0000 (17:25 +0000)
committerAlan Modra <amodra@gmail.com>
Tue, 15 Dec 2020 08:14:56 +0000 (18:44 +1030)
Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.

bfd/
* elflink.c (bfd_elf_size_dynamic_sections): Call
_bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section.
include/
* bfdlink.h (struct bfd_link_info): New field gnu_flags_1.
ld/
* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
Parse -z unique / -z nounique options.

bfd/ChangeLog
bfd/elflink.c
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/emultempl/elf.em

index e3a5c8a6eeb40ecac69b53936d5d706b0f4359ed..11b901a22042497976704be8fb5823c1209d5da8 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-15  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-14  Alan Modra  <amodra@gmail.com>
 
        * elf-bfd.h (struct elf_obj_tdata): Add being_created.
index 29b46f1568db10cda14dff9175c18a5bbade3f49..37af3efcb068380558887230fda284c2ee0b9bd1 100644 (file)
@@ -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;
        }
     }
index f19742eafb64d22ccede5080b9a9d94d47081f73..a8316ee1342aa8c8ea10d862c7238afa16c750ac 100644 (file)
@@ -1,6 +1,7 @@
 2020-12-15  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-11  Cary Coutant  <ccoutant@gmail.com>
 
index b92ef5408d54400a66ae6f14fb6703440d836e53..3019033ea22935f82f482bc77c07bcc70d37daff 100644 (file)
@@ -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;
 
index b649e6870b401aff70ec274271a84325902e95ab..3db7fc6a864cce5b291703227fd937322c64a76b 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-15  Vivek Das Mohapatra  <vivek@collabora.com>
+
+       * emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
+       Parse -z unique / -z nounique options.
+
 2020-12-14  Howard Chu  <hyc@symas.com>
 
        * libdep_plugin.c: New file: Processes archives that contain a
index cfdf60e1365ee8e84a25b283c8d43dd7b303e2f0..aa40c7829e529a19ce7411ed0263ebf2fce45aa6 100644 (file)
@@ -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)