diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2017-08-17 11:29:04 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2017-08-24 12:41:34 +0100 |
commit | 5b5f4e6f8cd250e07ec98278f7223e57b3d3bb0c (patch) | |
tree | 55cb14623b168c916e2afa381d57f7e0e93a291d /ld/testsuite | |
parent | 34bb2571d40e1ca323a1b60e0827a25047890faa (diff) | |
download | gdb-5b5f4e6f8cd250e07ec98278f7223e57b3d3bb0c.zip gdb-5b5f4e6f8cd250e07ec98278f7223e57b3d3bb0c.tar.gz gdb-5b5f4e6f8cd250e07ec98278f7223e57b3d3bb0c.tar.bz2 |
ld: Early detection of orphans we know will be discarded
When processing an orphan section we first call lang_place_orphans, this
function handles a few sections for which the behaviour is known COMMON
sections, or sections marked as SEC_EXCLUDE.
Any orphans that are not handled in lang_place_orphans are passed on to
ldlang_place_orphan, this is where we decide where to put the orphan,
and then call lang_add_section to perform the actual orphan placement.
We previously had a larger set of checks at the start of the function
lang_add_section to discard some sections that we _knew_ should not be
added into the output file, this was where .group sections (in a final
link) and .debug* sections (with --strip-debug) were dropped.
The problem with dropping these sections at the lang_add_section stage
is that a user might also be using --orphan-handling=error to prevent
orphans. If they are then they should not be get errors about sections
that we know will be discarded, and which are not mentioned in the
linker script.
The solution proposed in this patch is to move the "will this section be
discarded" check into a separate function, and use this in
lang_place_orphans to have the early discard phase discard sections that
we know should not be included in the output file.
ld/ChangeLog:
PR 21961
* ldlang.c (lang_discard_section_p): New function.
(lang_add_section): Checks moved out into new function, which is
now called.
(lang_place_orphans): Call lang_discard_section_p instead of
duplicating some of the checks from lang_add_section.
* testsuite/ld-elf/orphan-11.d: New file.
* testsuite/ld-elf/orphan-11.ld: New file.
* testsuite/ld-elf/orphan-11.s: New file.
* testsuite/ld-elf/orphan-12.d: New file.
* testsuite/ld-elf/orphan-12.s: New file.
Diffstat (limited to 'ld/testsuite')
-rw-r--r-- | ld/testsuite/ld-elf/orphan-11.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/orphan-11.ld | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/orphan-11.s | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/orphan-12.d | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/orphan-12.s | 8 |
5 files changed, 53 insertions, 0 deletions
diff --git a/ld/testsuite/ld-elf/orphan-11.d b/ld/testsuite/ld-elf/orphan-11.d new file mode 100644 index 0000000..3daefba --- /dev/null +++ b/ld/testsuite/ld-elf/orphan-11.d @@ -0,0 +1,9 @@ +#source: orphan-11.s +#ld: -T orphan-11.ld --orphan-handling=error +#objdump: -wh +#notarget: d30v-* dlx-* fr30-* frv-* ft32-* i860-* i960-* iq2000-* mn10200-* moxie-* ms1-* msp430-* mt-* pj-* + +#... + . \.text .* + . \.data .* +#pass diff --git a/ld/testsuite/ld-elf/orphan-11.ld b/ld/testsuite/ld-elf/orphan-11.ld new file mode 100644 index 0000000..74c7789 --- /dev/null +++ b/ld/testsuite/ld-elf/orphan-11.ld @@ -0,0 +1,16 @@ +SECTIONS +{ + . = SIZEOF_HEADERS; + .text : { *(.text .text.*) } + .data : { *(.data .data.*) } + .bss : { *(.bss .bss.*) *(COMMON) } + .sbss : { *(.sbss .sbss.*) } + .note : { *(.note .note.*) } + .rela : { *(.rela .rela.*) } + .rel : { *(.rel .rel.*) } + + /DISCARD/ : { + *(.reginfo) *(.MIPS.abiflags) *(.trampolines) *(.iplt*) + *(.note*) *(.got*) *(.igot*) *(.*.attributes) *(.*.info) + *(.pdr) "linker stubs*"(*) } +} diff --git a/ld/testsuite/ld-elf/orphan-11.s b/ld/testsuite/ld-elf/orphan-11.s new file mode 100644 index 0000000..3d7961b --- /dev/null +++ b/ld/testsuite/ld-elf/orphan-11.s @@ -0,0 +1,11 @@ + .section .text.foo,"axG",%progbits,foo_group + .word 0 + + .section .data.foo,"waG",%progbits,foo_group + .word 1 + + .section .text, "ax" + .word 0 + + .section .data, "wa" + .word 1 diff --git a/ld/testsuite/ld-elf/orphan-12.d b/ld/testsuite/ld-elf/orphan-12.d new file mode 100644 index 0000000..71a8c93 --- /dev/null +++ b/ld/testsuite/ld-elf/orphan-12.d @@ -0,0 +1,9 @@ +#source: orphan-12.s +#ld: -T orphan-11.ld --strip-debug --orphan-handling=error +#objdump: -wh +#notarget: d30v-* dlx-* fr30-* frv-* ft32-* i860-* i960-* iq2000-* mn10200-* moxie-* ms1-* msp430-* mt-* pj-* + +#... + . \.text .* + . \.data .* +#pass diff --git a/ld/testsuite/ld-elf/orphan-12.s b/ld/testsuite/ld-elf/orphan-12.s new file mode 100644 index 0000000..f9cbcf7 --- /dev/null +++ b/ld/testsuite/ld-elf/orphan-12.s @@ -0,0 +1,8 @@ + .section .debug_info, "",%progbits + .word 0 + + .section .text, "ax" + .word 0 + + .section .data, "wa" + .word 1 |