elf: Copy elf_gnu_osabi_retain only for relocatable link
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 18 Dec 2020 12:24:26 +0000 (04:24 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 18 Dec 2020 12:24:36 +0000 (04:24 -0800)
Copy elf_gnu_osabi_retain from input only for relocatable link since
SHF_GNU_RETAIN has no impact on non-relocatable outputs.

bfd/

PR ld/27091
* elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain
from input only for relocatable link.

ld/

PR ld/27091
* testsuite/ld-elf/retain7.s: New file.
* testsuite/ld-elf/retain7a.d: Likewise.
* testsuite/ld-elf/retain7b.d: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/retain7.s [new file with mode: 0644]
ld/testsuite/ld-elf/retain7a.d [new file with mode: 0644]
ld/testsuite/ld-elf/retain7b.d [new file with mode: 0644]

index cb72b1380c19678ca925281108d29c14d0f8d29d..582add86d20556dc31a13020c4e9047aad84b30b 100644 (file)
@@ -1,3 +1,9 @@
+2020-12-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27091
+       * elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain
+       from input only for relocatable link.
+
 2020-12-18  Alan Modra  <amodra@gmail.com>
 
        * elf32-microblaze.c (dbg): Delete unused variable.
index 2489700da76b68bb58822faabcab69b9a73ec159..1b3398126f090507c50923180424bef626a4e24d 100644 (file)
@@ -10806,7 +10806,9 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
       || bed->elf_osabi == ELFOSABI_GNU
       || bed->elf_osabi == ELFOSABI_FREEBSD)
     elf_tdata (output_bfd)->has_gnu_osabi
-      |= elf_tdata (input_bfd)->has_gnu_osabi;
+      |= (elf_tdata (input_bfd)->has_gnu_osabi
+         & (bfd_link_relocatable (flinfo->info)
+            ? -1 : ~elf_gnu_osabi_retain));
 
   /* Read the local symbols.  */
   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
index 34d58d4fcbbe0ac785d7010dbe9f6c0089cc19c6..392165b978a88d74a512f0cb979bf412af9ea628 100644 (file)
@@ -1,3 +1,10 @@
+2020-12-18  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/27091
+       * testsuite/ld-elf/retain7.s: New file.
+       * testsuite/ld-elf/retain7a.d: Likewise.
+       * testsuite/ld-elf/retain7b.d: Likewise.
+
 2020-12-16  Howard Chu <hyc@symas.com>
            H.J. Lu  <hongjiu.lu@intel.com>
 
diff --git a/ld/testsuite/ld-elf/retain7.s b/ld/testsuite/ld-elf/retain7.s
new file mode 100644 (file)
index 0000000..a6cc869
--- /dev/null
@@ -0,0 +1,5 @@
+       .type _start,"function"
+       .section .text,"axR",%progbits
+       .global _start
+_start:
+       .nop
diff --git a/ld/testsuite/ld-elf/retain7a.d b/ld/testsuite/ld-elf/retain7a.d
new file mode 100644 (file)
index 0000000..544ff8a
--- /dev/null
@@ -0,0 +1,11 @@
+#name: SHF_GNU_RETAIN 7a
+#source: retain7.s
+#ld: -e _start --gc-sections
+#notarget: ![supports_gnu_osabi] ![check_gc_sections_available]
+#readelf: -h
+
+#failif
+ELF Header:
+#...
+  OS/ABI:                            UNIX - GNU
+#pass
diff --git a/ld/testsuite/ld-elf/retain7b.d b/ld/testsuite/ld-elf/retain7b.d
new file mode 100644 (file)
index 0000000..0e5b12b
--- /dev/null
@@ -0,0 +1,10 @@
+#name: SHF_GNU_RETAIN 7a
+#source: retain7.s
+#ld: -r
+#notarget: ![supports_gnu_osabi] ![check_gc_sections_available]
+#readelf: -h
+
+ELF Header:
+#...
+  OS/ABI:                            UNIX - GNU
+#pass