aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorJozef Lawrynowicz <jozef.l@mittosystems.com>2020-11-18 11:51:13 +0000
committerJozef Lawrynowicz <jozef.l@mittosystems.com>2020-11-18 11:51:13 +0000
commit99fabbc9739a87ba3433e66792e93b773896790e (patch)
tree6a52b12cc648532f3b38fd102cec221a207188ba /binutils/readelf.c
parent40d9d2fd796a184f04a83ca4442fd78034b5e00b (diff)
downloadgdb-99fabbc9739a87ba3433e66792e93b773896790e.zip
gdb-99fabbc9739a87ba3433e66792e93b773896790e.tar.gz
gdb-99fabbc9739a87ba3433e66792e93b773896790e.tar.bz2
Support SHF_GNU_RETAIN ELF section flag
The SHF_GNU_RETAIN section flag is an extension to the GNU ELF OSABI. It is defined as follows: ========================================================= Section Attribute Flags +-------------------------------------+ | Name | Value | +-------------------------------------+ | SHF_GNU_RETAIN | 0x200000 (1 << 21) | +-------------------------------------+ SHF_GNU_RETAIN The link editor should not garbage collect the section. ========================================================= The .section directive accepts the "R" flag, which indicates SHF_GNU_RETAIN should be applied to the section. There is not a direct mapping of SHF_GNU_RETAIN to the BFD section flag SEC_KEEP. Keeping these flags distinct allows SHF_GNU_RETAIN sections to be explicitly removed by placing them in /DISCARD/. bfd/ChangeLog: * elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_retain. (struct elf_obj_tdata): Increase has_gnu_osabi to 4 bits. * elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_retain for SHF_GNU_RETAIN. (_bfd_elf_final_write_processing): Report if SHF_GNU_RETAIN is not supported by the OSABI. Adjust error messages. * elflink.c (elf_link_input_bfd): Copy enabled has_gnu_osabi bits from input BFD to output BFD. (bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set. binutils/ChangeLog: * NEWS: Announce SHF_GNU_RETAIN support. * readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN. Recognize SHF_GNU_RETAIN and SHF_GNU_MBIND only for supported OSABIs. * testsuite/binutils-all/readelf.exp: Run new tests. Don't run run_dump_test when there isn't an assembler available. * testsuite/lib/binutils-common.exp (supports_gnu_osabi): Adjust comment. * testsuite/binutils-all/readelf-maskos-1a.d: New test. * testsuite/binutils-all/readelf-maskos-1b.d: New test. * testsuite/binutils-all/readelf-maskos.s: New test. * testsuite/binutils-all/retain1.s: New test. * testsuite/binutils-all/retain1a.d: New test. * testsuite/binutils-all/retain1b.d: New test. gas/ChangeLog: * NEWS: Announce SHF_GNU_RETAIN support. * config/obj-elf.c (obj_elf_change_section): Merge SHF_GNU_RETAIN bit between section declarations. (obj_elf_parse_section_letters): Handle 'R' flag. Handle numeric flag values within the SHF_MASKOS range. (obj_elf_section): Validate SHF_GNU_RETAIN usage. * doc/as.texi: Document 'R' flag to .section directive. * testsuite/gas/elf/elf.exp: Run new tests. * testsuite/gas/elf/section10.d: Unset SHF_GNU_RETAIN bit. * testsuite/gas/elf/section10.s: Likewise. * testsuite/gas/elf/section22.d: New test. * testsuite/gas/elf/section22.s: New test. * testsuite/gas/elf/section23.s: New test. * testsuite/gas/elf/section23a.d: New test. * testsuite/gas/elf/section23b.d: New test. * testsuite/gas/elf/section23b.err: New test. * testsuite/gas/elf/section24.l: New test. * testsuite/gas/elf/section24.s: New test. * testsuite/gas/elf/section24a.d: New test. * testsuite/gas/elf/section24b.d: New test. include/ChangeLog: * elf/common.h (SHF_GNU_RETAIN): Define. ld/ChangeLog: * NEWS: Announce support for SHF_GNU_RETAIN. * ld.texi (garbage collection): Document SHF_GNU_RETAIN. (Output Section Discarding): Likewise. * testsuite/ld-elf/elf.exp: Run new tests. * testsuite/ld-elf/retain1.s: New test. * testsuite/ld-elf/retain1a.d: New test. * testsuite/ld-elf/retain1b.d: New test. * testsuite/ld-elf/retain2.d: New test. * testsuite/ld-elf/retain2.ld: New test. * testsuite/ld-elf/retain2.map: New test. * testsuite/ld-elf/retain3.d: New test. * testsuite/ld-elf/retain3.s: New test. * testsuite/ld-elf/retain4.d: New test. * testsuite/ld-elf/retain4.s: New test. * testsuite/ld-elf/retain5.d: New test. * testsuite/ld-elf/retain5.map: New test. * testsuite/ld-elf/retain5lib.s: New test. * testsuite/ld-elf/retain5main.s: New test. * testsuite/ld-elf/retain6a.d: New test. * testsuite/ld-elf/retain6b.d: New test. * testsuite/ld-elf/retain6lib.s: New test. * testsuite/ld-elf/retain6main.s: New test.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 6373852..f6a074b 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -5996,6 +5996,8 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
/* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
/* VLE specific. */
/* 25 */ { STRING_COMMA_LEN ("VLE") },
+ /* GNU specific. */
+ /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
};
if (do_section_details)
@@ -6028,7 +6030,6 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
case SHF_TLS: sindex = 9; break;
case SHF_EXCLUDE: sindex = 18; break;
case SHF_COMPRESSED: sindex = 20; break;
- case SHF_GNU_MBIND: sindex = 24; break;
default:
sindex = -1;
@@ -6080,10 +6081,28 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
if (flag == SHF_PPC_VLE)
sindex = 25;
break;
+ default:
+ break;
+ }
+ switch (filedata->file_header.e_ident[EI_OSABI])
+ {
+ case ELFOSABI_GNU:
+ case ELFOSABI_FREEBSD:
+ if (flag == SHF_GNU_RETAIN)
+ sindex = 26;
+ /* Fall through */
+ case ELFOSABI_NONE:
+ if (flag == SHF_GNU_MBIND)
+ /* We should not recognize SHF_GNU_MBIND for
+ ELFOSABI_NONE, but binutils as of 2019-07-23 did
+ not set the EI_OSABI header byte. */
+ sindex = 24;
+ break;
default:
break;
}
+ break;
}
if (sindex != -1)
@@ -6126,7 +6145,6 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
case SHF_TLS: *p = 'T'; break;
case SHF_EXCLUDE: *p = 'E'; break;
case SHF_COMPRESSED: *p = 'C'; break;
- case SHF_GNU_MBIND: *p = 'D'; break;
default:
if ((filedata->file_header.e_machine == EM_X86_64
@@ -6136,14 +6154,37 @@ get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
*p = 'l';
else if (filedata->file_header.e_machine == EM_ARM
&& flag == SHF_ARM_PURECODE)
- *p = 'y';
+ *p = 'y';
else if (filedata->file_header.e_machine == EM_PPC
&& flag == SHF_PPC_VLE)
- *p = 'v';
+ *p = 'v';
else if (flag & SHF_MASKOS)
{
- *p = 'o';
- sh_flags &= ~ SHF_MASKOS;
+ switch (filedata->file_header.e_ident[EI_OSABI])
+ {
+ case ELFOSABI_GNU:
+ case ELFOSABI_FREEBSD:
+ if (flag == SHF_GNU_RETAIN)
+ {
+ *p = 'R';
+ break;
+ }
+ /* Fall through */
+ case ELFOSABI_NONE:
+ if (flag == SHF_GNU_MBIND)
+ {
+ /* We should not recognize SHF_GNU_MBIND for
+ ELFOSABI_NONE, but binutils as of 2019-07-23 did
+ not set the EI_OSABI header byte. */
+ *p = 'D';
+ break;
+ }
+ /* Fall through */
+ default:
+ *p = 'o';
+ sh_flags &= ~SHF_MASKOS;
+ break;
+ }
}
else if (flag & SHF_MASKPROC)
{