[PATCH] elf: Copy elf_gnu_osabi_retain only for relocatable link

Alan Modra amodra@gmail.com
Fri Dec 18 11:04:39 GMT 2020


On Thu, Dec 17, 2020 at 07:59:45AM -0800, H.J. Lu via Binutils wrote:
> On Thu, Dec 17, 2020 at 7:25 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >
> > On Dez 17 2020, H.J. Lu wrote:
> >
> > > since SHF_GNU_RETAIN is in OS-specific range.
> >
> > Exactly.  Without the marking, the object cannot be properly
> > interpreted.
> >
> 
> Like this.

Looks good.

> 
> -- 
> H.J.

> From b64e25f781c1b3ade8a119b350d5b8db114ab514 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Thu, 17 Dec 2020 06:34:14 -0800
> Subject: [PATCH] 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.
> ---
>  bfd/elflink.c                  |  4 +++-
>  ld/testsuite/ld-elf/retain7.s  |  5 +++++
>  ld/testsuite/ld-elf/retain7a.d | 11 +++++++++++
>  ld/testsuite/ld-elf/retain7b.d | 10 ++++++++++
>  4 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 ld/testsuite/ld-elf/retain7.s
>  create mode 100644 ld/testsuite/ld-elf/retain7a.d
>  create mode 100644 ld/testsuite/ld-elf/retain7b.d
> 
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index 2489700da7..1b3398126f 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/testsuite/ld-elf/retain7.s b/ld/testsuite/ld-elf/retain7.s
> new file mode 100644
> index 0000000000..a6cc86988c
> --- /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 0000000000..544ff8a173
> --- /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 0000000000..0e5b12b335
> --- /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
> -- 
> 2.29.2
> 


-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list