diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2017-01-17 19:12:54 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2017-03-09 21:11:05 +0000 |
commit | 77f5e65ecfb669ea1d2fd74b74fbbf0d0c20daf8 (patch) | |
tree | 8f95fab82f74b90fdf19092ff922685c299667b3 /config/mh-ppc-aix | |
parent | a87ded7b88a85b40f2aec5e5b6c972dd7b74b3a9 (diff) | |
download | gdb-77f5e65ecfb669ea1d2fd74b74fbbf0d0c20daf8.zip gdb-77f5e65ecfb669ea1d2fd74b74fbbf0d0c20daf8.tar.gz gdb-77f5e65ecfb669ea1d2fd74b74fbbf0d0c20daf8.tar.bz2 |
ld: better handling of lma region for orphan sections
When picking an lma_region for an orphan section we currently create a
new lang_output_section_statement_type and then populate this with the
orphan section.
The problem is that the lang_output_section_statement_type has a prev
pointer that links back to the previous output section. For non-orphan
output sections, that are created in linker script order, the prev
pointer will point to the output section that appears previous in linker
script order, as you'd probably expect.
The problem is that orphan sections are placed after processing the
linker script, and so, in the case of an output section created for an
orphan input section, the prev pointer actually points to the last
output section created.
This causes some unexpected behaviour when the orphan section is not
placed after the last non-orphan section that was created.
For example, consider this linker script:
MEMORY {
TEXT : ORIGIN = 0x200, LENGTH = 0x10
RODATA : ORIGIN = 0x400, LENGTH = 0x10
}
SECTIONS {
.text : {*(.text) } AT>TEXT
.data : AT(0x300) { *(.data) }
.rodata : { *(.rodata) } AT>RODATA
}
If we are processing an orphan section '.data.1' and decide to place
this after '.data', then the output section created will have a prev
pointer that references the '.rodata' output section. The result of
this is that '.data.1' will actually be assigned to the RODATA lma
region, which is probably not the expected behaviour.
The reason why '.data.1' is placed into the lma region of the '.rodata'
section is that lma region propagation is done at the time we create the
output section, based on the previous output section pointer, which is
really just a last-output-section-created pointer at that point in time,
though the prev point is fixed up later to reflect the true order of the
output sections.
The solution I propose in this commit is to move the propagation of lma
regions into a separate pass of the linker, rather than performing this
as part of the enter/exit of output sections during linker script
parsing.
During this later phase we have all of the output sections to hand, and
the prev/next points have been fixed up by this point to reflect the
actual placement ordering.
There's a new test to cover this issue that passes on a range of
targets, however, some targets generate additional sections, or have
stricter memory region size requirements that make it harder to come
up with a generic pass pattern, that still tests the required
features. For now I've set the test to ignore these targets.
ld/ChangeLog:
* ldlang.c (lang_leave_output_section_statement): Move lma_region
logic to...
(lang_propagate_lma_regions): ...this new function.
(lang_process): Call new function.
* testsuite/ld-elf/orphan-9.d: New file.
* testsuite/ld-elf/orphan-9.ld: New file.
* testsuite/ld-elf/orphan-9.s: New file.
* NEWS: Mention change in behaviour.
Diffstat (limited to 'config/mh-ppc-aix')
0 files changed, 0 insertions, 0 deletions