aboutsummaryrefslogtreecommitdiff
path: root/binutils
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
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')
-rw-r--r--binutils/ChangeLog16
-rw-r--r--binutils/NEWS4
-rw-r--r--binutils/readelf.c53
-rw-r--r--binutils/testsuite/binutils-all/readelf-maskos-1a.d10
-rw-r--r--binutils/testsuite/binutils-all/readelf-maskos-1b.d12
-rw-r--r--binutils/testsuite/binutils-all/readelf-maskos.s11
-rw-r--r--binutils/testsuite/binutils-all/readelf.exp9
-rw-r--r--binutils/testsuite/binutils-all/retain1.s104
-rw-r--r--binutils/testsuite/binutils-all/retain1a.d18
-rw-r--r--binutils/testsuite/binutils-all/retain1b.d46
-rw-r--r--binutils/testsuite/lib/binutils-common.exp5
11 files changed, 280 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 2124c59..e8bcd97 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,19 @@
+2020-11-18 Jozef Lawrynowicz <jozef.l@mittosystems.com>
+
+ * 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.
+
2020-11-17 Howard Chu <hyc@symas.com>
* ar.c (main): Place the libdeps record in the second archive
diff --git a/binutils/NEWS b/binutils/NEWS
index 02a19ea..e74b6a2 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -12,6 +12,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.
+
Changes in 2.35:
* Changed readelf's display of symbol names when wide mode is not enabled.
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)
{
diff --git a/binutils/testsuite/binutils-all/readelf-maskos-1a.d b/binutils/testsuite/binutils-all/readelf-maskos-1a.d
new file mode 100644
index 0000000..7b27358
--- /dev/null
+++ b/binutils/testsuite/binutils-all/readelf-maskos-1a.d
@@ -0,0 +1,10 @@
+#name: Unknown SHF_MASKOS value in section
+#source: readelf-maskos.s
+#notarget: [supports_gnu_osabi] msp430-*-elf visium-*-elf
+#xfail: arm-*-elf
+#readelf: -S --wide
+# PR26722 for the arm-*-elf XFAIL
+
+#...
+ \[[ 0-9]+\] .data.retain_var.*WAo.*
+#pass
diff --git a/binutils/testsuite/binutils-all/readelf-maskos-1b.d b/binutils/testsuite/binutils-all/readelf-maskos-1b.d
new file mode 100644
index 0000000..2cbb58a
--- /dev/null
+++ b/binutils/testsuite/binutils-all/readelf-maskos-1b.d
@@ -0,0 +1,12 @@
+#name: -t (section details) for unknown SHF_MASKOS value in section
+#source: readelf-maskos.s
+#notarget: [supports_gnu_osabi] msp430-*-elf visium-*-elf
+#xfail: arm-*-elf
+#readelf: -S -t --wide
+# PR26722 for the arm-*-elf XFAIL
+
+#...
+ \[[ 0-9]+\] .data.retain_var
+ PROGBITS +0+ +[0-9a-f]+ +[0-9a-f]+ +[0-9a-f]+ +0 +0 +(1|2|4|8)
+ \[00200003\]: WRITE, ALLOC, OS \(00200000\)
+#pass
diff --git a/binutils/testsuite/binutils-all/readelf-maskos.s b/binutils/testsuite/binutils-all/readelf-maskos.s
new file mode 100644
index 0000000..d671119
--- /dev/null
+++ b/binutils/testsuite/binutils-all/readelf-maskos.s
@@ -0,0 +1,11 @@
+ .section .data.retain_var,"0x200003"
+ .global retain_var
+ .type retain_var, %object
+retain_var:
+ .long 2
+
+ .section .text._start,"ax"
+ .global _start
+ .type _start, %function
+_start:
+ .word 0
diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp
index 1fb36ae..9d1d496 100644
--- a/binutils/testsuite/binutils-all/readelf.exp
+++ b/binutils/testsuite/binutils-all/readelf.exp
@@ -364,8 +364,15 @@ readelf_wi_test
readelf_compressed_wa_test
readelf_dump_test
-run_dump_test "pr25543"
+# These dump tests require an assembler.
+if {[which $AS] != 0} then {
+ run_dump_test "pr25543"
+ run_dump_test "retain1a"
+ run_dump_test "retain1b"
+ run_dump_test "readelf-maskos-1a"
+ run_dump_test "readelf-maskos-1b"
+}
# PR 13482 - Check for off-by-one errors when dumping .note sections.
if {![binutils_assemble $srcdir/$subdir/version.s tmpdir/version.o]} then {
diff --git a/binutils/testsuite/binutils-all/retain1.s b/binutils/testsuite/binutils-all/retain1.s
new file mode 100644
index 0000000..f7716fa
--- /dev/null
+++ b/binutils/testsuite/binutils-all/retain1.s
@@ -0,0 +1,104 @@
+ .global discard0
+ .section .bss.discard0,"aw"
+ .type discard0, %object
+discard0:
+ .zero 2
+
+ .global discard1
+ .section .bss.discard1,"aw"
+ .type discard1, %object
+discard1:
+ .zero 2
+
+ .global discard2
+ .section .data.discard2,"aw"
+ .type discard2, %object
+discard2:
+ .word 1
+
+ .section .bss.sdiscard0,"aw"
+ .type sdiscard0, %object
+sdiscard0:
+ .zero 2
+
+ .section .bss.sdiscard1,"aw"
+ .type sdiscard1, %object
+sdiscard1:
+ .zero 2
+
+ .section .data.sdiscard2,"aw"
+ .type sdiscard2, %object
+sdiscard2:
+ .word 1
+
+ .section .text.fndiscard0,"ax"
+ .global fndiscard0
+ .type fndiscard0, %function
+fndiscard0:
+ .word 0
+
+ .global retain0
+ .section .bss.retain0,"awR"
+ .type retain0, %object
+retain0:
+ .zero 2
+
+ .global retain1
+ .section .bss.retain1,"awR"
+ .type retain1, %object
+retain1:
+ .zero 2
+
+ .global retain2
+ .section .data.retain2,"awR"
+ .type retain2, %object
+retain2:
+ .word 1
+
+ .section .bss.sretain0,"awR"
+ .type sretain0, %object
+sretain0:
+ .zero 2
+
+ .section .bss.sretain1,"awR"
+ .type sretain1, %object
+sretain1:
+ .zero 2
+
+ .section .data.sretain2,"aRw"
+ .type sretain2, %object
+sretain2:
+ .word 1
+
+ .section .text.fnretain1,"Rax"
+ .global fnretain1
+ .type fnretain1, %function
+fnretain1:
+ .word 0
+
+ .section .text.fndiscard2,"ax"
+ .global fndiscard2
+ .type fndiscard2, %function
+fndiscard2:
+ .word 0
+
+ .section .bss.lsretain0,"awR"
+ .type lsretain0.2, %object
+lsretain0.2:
+ .zero 2
+
+ .section .bss.lsretain1,"aRw"
+ .type lsretain1.1, %object
+lsretain1.1:
+ .zero 2
+
+ .section .data.lsretain2,"aRw"
+ .type lsretain2.0, %object
+lsretain2.0:
+ .word 1
+
+ .section .text._start,"ax"
+ .global _start
+ .type _start, %function
+_start:
+ .word 0
diff --git a/binutils/testsuite/binutils-all/retain1a.d b/binutils/testsuite/binutils-all/retain1a.d
new file mode 100644
index 0000000..6397ac5
--- /dev/null
+++ b/binutils/testsuite/binutils-all/retain1a.d
@@ -0,0 +1,18 @@
+#name: readelf SHF_GNU_RETAIN
+#source: retain1.s
+#target: [supports_gnu_osabi]
+#readelf: -S --wide
+
+#...
+ \[[ 0-9]+\] .bss.retain0.*WAR.*
+ \[[ 0-9]+\] .bss.retain1.*WAR.*
+ \[[ 0-9]+\] .data.retain2.*WAR.*
+ \[[ 0-9]+\] .bss.sretain0.*WAR.*
+ \[[ 0-9]+\] .bss.sretain1.*WAR.*
+ \[[ 0-9]+\] .data.sretain2.*WAR.*
+ \[[ 0-9]+\] .text.fnretain1.*AXR.*
+#...
+ \[[ 0-9]+\] .bss.lsretain0.*WAR.*
+ \[[ 0-9]+\] .bss.lsretain1.*WAR.*
+ \[[ 0-9]+\] .data.lsretain2.*WAR.*
+#pass
diff --git a/binutils/testsuite/binutils-all/retain1b.d b/binutils/testsuite/binutils-all/retain1b.d
new file mode 100644
index 0000000..12bc388
--- /dev/null
+++ b/binutils/testsuite/binutils-all/retain1b.d
@@ -0,0 +1,46 @@
+#name: -t (section details) for readelf SHF_GNU_RETAIN
+#source: retain1.s
+#target: [supports_gnu_osabi]
+#readelf: -S -t --wide
+
+#...
+ \[[ 0-9]+\] .bss.retain0
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .bss.retain1
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .data.retain2
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .bss.sretain0
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .bss.sretain1
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .data.sretain2
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .text.fnretain1
+#...
+ \[0+200006\]: ALLOC, EXEC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .bss.lsretain0
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .bss.lsretain1
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#...
+ \[[ 0-9]+\] .data.lsretain2
+#...
+ \[0+200003\]: WRITE, ALLOC, GNU_RETAIN
+#pass
diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index b9a1e6e..a43639b 100644
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -195,13 +195,15 @@ proc match_target { target } {
# True if the ELF target supports setting the ELF header OSABI field
# to ELFOSABI_GNU or ELFOSABI_FREEBSD, a requirement for STT_GNU_IFUNC
-# symbol and SHF_GNU_MBIND section support.
+# symbol and SHF_GNU_MBIND or SHF_GNU_RETAIN section support.
#
# This generally depends on the target OS only, however there are a
# number of exceptions for bare metal targets as follows. The MSP430
# and Visium targets set OSABI to ELFOSABI_STANDALONE. Likewise
# non-EABI ARM targets set OSABI to ELFOSABI_ARM
#
+# Non-Linux HPPA defaults to ELFOSABI_HPUX.
+#
# Note that some TI C6X targets use ELFOSABI_C6000_* but one doesn't,
# so we don't try to sort out tic6x here. (The effect is that linker
# testcases will generally need to exclude tic6x or use a -m option.)
@@ -227,6 +229,7 @@ proc supports_gnu_osabi {} {
}
if { [istarget "arm*-*-*"]
|| [istarget "msp430-*-*"]
+ || [istarget "hppa-unknown-elf"]
|| [istarget "visium-*-*"] } {
return 0
}