Browse Source
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.binutils-2_36-branch
55 changed files with 943 additions and 41 deletions
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -0,0 +1,19 @@ |
|||
#readelf: -h -S --wide |
|||
#name: SHF_GNU_RETAIN sections 22 |
|||
#notarget: ![supports_gnu_osabi] |
|||
|
|||
#... |
|||
+OS/ABI: +UNIX - GNU |
|||
#... |
|||
\[..\] .text.discard0[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AX.* |
|||
#... |
|||
\[..\] .data.discard1[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WA.* |
|||
#... |
|||
\[..\] .bss.discard2[ ]+NOBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WA.* |
|||
#... |
|||
\[..\] .bss.retain0[ ]+NOBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAR.* |
|||
#... |
|||
\[..\] .data.retain1[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAR.* |
|||
#... |
|||
\[..\] .text.retain2[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXR.* |
|||
#pass |
|||
@ -0,0 +1,34 @@ |
|||
.section .text.discard0,"ax",%progbits |
|||
.global discard0 |
|||
.type discard0, %function |
|||
discard0: |
|||
.word 0 |
|||
|
|||
.section .data.discard1,"aw" |
|||
.global discard1 |
|||
.type discard1, %object |
|||
discard1: |
|||
.word 1 |
|||
|
|||
.section .bss.discard2,"aw" |
|||
.global discard2 |
|||
.type discard2, %object |
|||
discard2: |
|||
.zero 2 |
|||
|
|||
.section .bss.retain0,"awR",%nobits |
|||
.global retain0 |
|||
.type retain0, %object |
|||
retain0: |
|||
.zero 2 |
|||
|
|||
.section .data.retain1,"awR",%progbits |
|||
.type retain1, %object |
|||
retain1: |
|||
.word 1 |
|||
|
|||
.section .text.retain2,"axR",%progbits |
|||
.global retain2 |
|||
.type retain2, %function |
|||
retain2: |
|||
.word 0 |
|||
@ -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 |
|||
@ -0,0 +1,10 @@ |
|||
#name: SHF_GNU_RETAIN set with numeric flag value in .section |
|||
#source: section23.s |
|||
#target: [supports_gnu_osabi] |
|||
#readelf: -h -S --wide |
|||
|
|||
#... |
|||
+OS/ABI: +UNIX - GNU |
|||
#... |
|||
\[..\] .data.retain_var[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAR.* |
|||
#pass |
|||
@ -0,0 +1,6 @@ |
|||
#name: SHF_GNU_RETAIN set with numeric flag value in .section for non-GNU OSABI target |
|||
#source: section23.s |
|||
#error_output: section23b.err |
|||
#target: msp430-*-elf visium-*-elf |
|||
|
|||
# This test only runs for targets which set ELFOSABI_STANDALONE. |
|||
@ -0,0 +1,2 @@ |
|||
.*: Assembler messages: |
|||
.*:1: Error: GNU_RETAIN section is supported only by GNU and FreeBSD targets |
|||
@ -0,0 +1,38 @@ |
|||
.section .text,"ax",%progbits |
|||
.word 0 |
|||
.section .data,"aw" |
|||
.word 0 |
|||
.section .bss,"aw",%nobits |
|||
.word 0 |
|||
.section .rodata,"a" |
|||
.word 0 |
|||
|
|||
/* Test that we can set the 'R' flag on an existing section. */ |
|||
.section .text,"axR",%progbits |
|||
.word 0 |
|||
.section .data,"awR" |
|||
.word 0 |
|||
.section .bss,"awR",%nobits |
|||
.word 0 |
|||
.section .rodata,"aR" |
|||
.word 0 |
|||
|
|||
/* Test that the 'R' flag does not get clobbered when the section is switched |
|||
back to. */ |
|||
.section .text,"ax",%progbits |
|||
.word 0 |
|||
.section .data,"aw" |
|||
.word 0 |
|||
.section .bss,"aw",%nobits |
|||
.word 0 |
|||
.section .rodata,"a" |
|||
.word 0 |
|||
|
|||
.section .text |
|||
.word 0 |
|||
.section .data |
|||
.word 0 |
|||
.section .bss |
|||
.word 0 |
|||
.section .rodata |
|||
.word 0 |
|||
@ -0,0 +1,17 @@ |
|||
#name: Merge SHF_GNU_RETAIN for non-unique sections |
|||
#notarget: ![supports_gnu_osabi] |
|||
#source: section24.s |
|||
#readelf: -h -S --wide |
|||
|
|||
#... |
|||
+OS/ABI: +UNIX - GNU |
|||
#... |
|||
\[..\] .text[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AXR .* |
|||
#... |
|||
\[..\] .data[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAR .* |
|||
#... |
|||
\[..\] .bss[ ]+NOBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 WAR .* |
|||
#... |
|||
\[..\] .rodata[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 AR .* |
|||
#pass |
|||
|
|||
@ -0,0 +1,10 @@ |
|||
#name: Merge SHF_GNU_RETAIN for non-unique sections (check no unmerged) |
|||
#notarget: ![supports_gnu_osabi] |
|||
#source: section24.s |
|||
#readelf: -S --wide |
|||
|
|||
#failif |
|||
#... |
|||
\[..\] .(text|data|bss|rodata)[ ]+PROGBITS[ ]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ 00 [^R] .* |
|||
#pass |
|||
|
|||
@ -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 |
|||
@ -0,0 +1,27 @@ |
|||
#name: SHF_GNU_RETAIN 1a |
|||
#source: retain1.s |
|||
#ld: -e _start --gc-sections |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#DUMPPROG: nm |
|||
|
|||
#... |
|||
[0-9a-f]+ . fnretain1 |
|||
#... |
|||
[0-9a-f]+ . lsretain0.2 |
|||
#... |
|||
[0-9a-f]+ . lsretain1.1 |
|||
#... |
|||
[0-9a-f]+ . lsretain2.0 |
|||
#... |
|||
[0-9a-f]+ . retain0 |
|||
#... |
|||
[0-9a-f]+ . retain1 |
|||
#... |
|||
[0-9a-f]+ . retain2 |
|||
#... |
|||
[0-9a-f]+ . sretain0 |
|||
#... |
|||
[0-9a-f]+ . sretain1 |
|||
#... |
|||
[0-9a-f]+ . sretain2 |
|||
#pass |
|||
@ -0,0 +1,10 @@ |
|||
#name: SHF_GNU_RETAIN 1b |
|||
#source: retain1.s |
|||
#ld: -e _start --gc-sections |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#nm: -n |
|||
|
|||
#failif |
|||
#... |
|||
[0-9a-f]+ . .*discard.* |
|||
#... |
|||
@ -0,0 +1,5 @@ |
|||
#name: SHF_GNU_RETAIN 2 (remove SHF_GNU_RETAIN sections by placing in /DISCARD/) |
|||
#source: retain1.s |
|||
#ld: -e _start -Map=retain2.map --gc-sections --script=retain2.ld |
|||
#map: retain2.map |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
@ -0,0 +1,7 @@ |
|||
SECTIONS |
|||
{ |
|||
/DISCARD/ : |
|||
{ |
|||
*(.text.fnretain1) |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
# Test that .text.fnretain1, which has the SHF_GNU_RETAIN flag, can still be |
|||
# explicitly discarded from the output file. |
|||
|
|||
#... |
|||
Discarded input sections |
|||
|
|||
.text.* |
|||
#... |
|||
.data.* |
|||
#... |
|||
.bss.* |
|||
#... |
|||
.bss.discard0.* |
|||
#... |
|||
.bss.discard1.* |
|||
#... |
|||
.data.discard2.* |
|||
#... |
|||
.bss.sdiscard0.* |
|||
#... |
|||
.bss.sdiscard1.* |
|||
#... |
|||
.data.sdiscard2.* |
|||
#... |
|||
.text.fndiscard0.* |
|||
#... |
|||
.text.fnretain1.* |
|||
#... |
|||
.text.fndiscard2.* |
|||
#... |
|||
Memory Configuration |
|||
#pass |
|||
@ -0,0 +1,11 @@ |
|||
#name: SHF_GNU_RETAIN 3 (keep sections referenced by retained sections) |
|||
#source: retain3.s |
|||
#ld: -e _start --gc-sections |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#DUMPPROG: nm |
|||
|
|||
#... |
|||
[0-9a-f]+ . bar |
|||
#... |
|||
[0-9a-f]+ . foo |
|||
#pass |
|||
@ -0,0 +1,19 @@ |
|||
/* The retention of bar should also prevent foo from being gc'ed, since bar |
|||
references foo. */ |
|||
.section .text.foo,"ax" |
|||
.global foo |
|||
.type foo, %function |
|||
foo: |
|||
.word 0 |
|||
|
|||
.section .text.bar,"axR" |
|||
.global bar |
|||
.type bar, %function |
|||
bar: |
|||
.long foo |
|||
|
|||
.section .text._start,"ax" |
|||
.global _start |
|||
.type _start, %function |
|||
_start: |
|||
.word 0 |
|||
@ -0,0 +1,9 @@ |
|||
#name: SHF_GNU_RETAIN 4 (keep orphaned sections when not discarding) |
|||
#source: retain4.s |
|||
#ld: -e _start --gc-sections --orphan-handling=place |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#DUMPPROG: nm |
|||
|
|||
#... |
|||
[0-9a-f]+ . orphaned_fn |
|||
#pass |
|||
@ -0,0 +1,13 @@ |
|||
/* A section that doesn't match any linker script input section rules but |
|||
has SHF_GNU_RETAIN applied should not be garbage collected. */ |
|||
.section .orphaned_section,"axR" |
|||
.global orphaned_fn |
|||
.type orphaned_fn, %function |
|||
orphaned_fn: |
|||
.word 0 |
|||
|
|||
.section .text._start,"ax" |
|||
.global _start |
|||
.type _start, %function |
|||
_start: |
|||
.word 0 |
|||
@ -0,0 +1,11 @@ |
|||
#name: SHF_GNU_RETAIN 5 (don't pull SHF_GNU_RETAIN section out of lib) |
|||
#source: retain5main.s |
|||
#ld: --gc-sections -e _start --print-gc-sections -Ltmpdir -lretain5 -Map=retain5.map |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#map: retain5.map |
|||
#DUMPPROG: nm |
|||
|
|||
#failif |
|||
#... |
|||
[0-9a-f]+ . foo |
|||
#... |
|||
@ -0,0 +1,5 @@ |
|||
# Check that the library was actually loaded to catch any false PASS. |
|||
|
|||
#... |
|||
LOAD tmpdir/libretain5.a |
|||
#pass |
|||
@ -0,0 +1,6 @@ |
|||
/* The link will fail if foo is included because undefined_sym is not defined. */ |
|||
.section .text.foo,"axR" |
|||
.global foo |
|||
.type foo, %function |
|||
foo: |
|||
.long undefined_sym |
|||
@ -0,0 +1,5 @@ |
|||
.section .text._start,"ax" |
|||
.global _start |
|||
.type _start, %function |
|||
_start: |
|||
.word 0 |
|||
@ -0,0 +1,13 @@ |
|||
#name: SHF_GNU_RETAIN 6a (pull section out of lib required by SHF_GNU_RETAIN section) |
|||
#source: retain6main.s |
|||
#ld: --gc-sections -e _start -u bar -Ltmpdir -lretain6 |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#DUMPPROG: nm |
|||
|
|||
#... |
|||
[0-9a-f]+ . bar |
|||
#... |
|||
[0-9a-f]+ . retain_from_lib |
|||
#... |
|||
[0-9a-f]+ . retained_fn |
|||
#pass |
|||
@ -0,0 +1,10 @@ |
|||
#name: SHF_GNU_RETAIN 6b (pull section out of lib required by SHF_GNU_RETAIN section) |
|||
#source: retain6main.s |
|||
#ld: --gc-sections -e _start -u bar -Ltmpdir -lretain6 |
|||
#notarget: ![supports_gnu_osabi] ![check_gc_sections_available] |
|||
#DUMPPROG: nm |
|||
|
|||
#failif |
|||
#... |
|||
[0-9a-f]+ . .*discard.* |
|||
#... |
|||
@ -0,0 +1,17 @@ |
|||
.section .text.bar,"ax" |
|||
.global bar |
|||
.type bar, %function |
|||
bar: |
|||
.word 0 |
|||
|
|||
.section .text.retain_from_lib,"axR" |
|||
.global retain_from_lib |
|||
.type retain_from_lib, %function |
|||
retain_from_lib: |
|||
.word 0 |
|||
|
|||
.section .text.discard_from_lib,"ax" |
|||
.global discard_from_lib |
|||
.type discard_from_lib, %function |
|||
discard_from_lib: |
|||
.word 0 |
|||
@ -0,0 +1,13 @@ |
|||
/* Undefined symbol reference in retained section .text.retained_fn requires |
|||
symbol definition to be pulled out of library. */ |
|||
.section .text.retained_fn,"axR" |
|||
.global retained_fn |
|||
.type retained_fn, %function |
|||
retained_fn: |
|||
.long bar |
|||
|
|||
.section .text._start,"ax" |
|||
.global _start |
|||
.type _start, %function |
|||
_start: |
|||
.word 0 |
|||
Loading…
Reference in new issue