[PATCH v2] Support for SHF_GNU_RETAIN ELF Section Flag
Alan Modra
amodra@gmail.com
Thu Oct 1 11:39:07 GMT 2020
On Thu, Oct 01, 2020 at 11:50:33AM +0100, Jozef Lawrynowicz wrote:
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -14102,7 +14102,8 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
> || (elf_section_data (o)->this_hdr.sh_type
> == SHT_FINI_ARRAY)))
> || (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE
> - && elf_next_in_group (o) == NULL )))
> + && elf_next_in_group (o) == NULL)
> + || (elf_section_flags (o) & SHF_GNU_RETAIN)))
Flag bits in SHF_MASKOS depend on OS, so this needs a test of OSABI.
That can be done by checking elf_tdata (sub)->has_gnu_osabi for the
appropriate bit.
> {
> if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
> return FALSE;
> diff --git a/binutils/NEWS b/binutils/NEWS
> index c0dc73d7d8..6c7d3f3953 100644
> --- a/binutils/NEWS
> +++ b/binutils/NEWS
> @@ -4,6 +4,10 @@
> symbol names. In addition the --demangle=<style>, --no-demangle,
> --recurse-limit and --no-recurse-limit options are also now availale.
>
> +* Add support for the SHF_GNU_RETAIN ELF section flag.
> + This flag specifies that the section should not be garbage collected by the
> + linker if it is unused.
I would drop "if it is unused". The phrase doesn't really add
anything to a user's understanding.
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -6010,6 +6012,7 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
> case SHF_EXCLUDE: sindex = 18; break;
> case SHF_COMPRESSED: sindex = 20; break;
> case SHF_GNU_MBIND: sindex = 24; break;
> + case SHF_GNU_RETAIN: sindex = 26; break;
Again, interpretation of the bit depends on e_ident[EI_OSABI].
SHF_GNU_RETAIN should only be printed for ELFOSABI_GNU and
ELFOSABI_FREEBSD.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list