From: H.J. Lu Date: Fri, 18 Dec 2020 12:24:26 +0000 (-0800) Subject: elf: Copy elf_gnu_osabi_retain only for relocatable link X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=04f8967487515179cc6dfc7c828f77eeb75c08d3;p=binutils-gdb.git elf: Copy elf_gnu_osabi_retain only for relocatable link 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. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index cb72b1380c1..582add86d20 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-12-18 H.J. Lu + + 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 * elf32-microblaze.c (dbg): Delete unused variable. diff --git a/bfd/elflink.c b/bfd/elflink.c index 2489700da76..1b3398126f0 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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; diff --git a/ld/ChangeLog b/ld/ChangeLog index 34d58d4fcbb..392165b978a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2020-12-18 H.J. Lu + + 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 H.J. Lu diff --git a/ld/testsuite/ld-elf/retain7.s b/ld/testsuite/ld-elf/retain7.s new file mode 100644 index 00000000000..a6cc86988c2 --- /dev/null +++ b/ld/testsuite/ld-elf/retain7.s @@ -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 index 00000000000..544ff8a1735 --- /dev/null +++ b/ld/testsuite/ld-elf/retain7a.d @@ -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 index 00000000000..0e5b12b335a --- /dev/null +++ b/ld/testsuite/ld-elf/retain7b.d @@ -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