binutils-gdb/ld/testsuite/ld-elf
Andrew Burgess 77f5e65ecf 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.
2017-03-09 21:11:05 +00:00
..
attributes.d
attributes.ld
attributes.s
audit.exp Check for shared lib support before running ld tests with -shared 2017-01-04 09:39:12 +10:30
audit.rd
begin.c
beginwarn.c
binutils.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
check-ptr-eq.c ld testsuite function pointer comparisons vs. hppa 2017-02-16 23:10:09 +10:30
comm1.c
comm-data1.s
comm-data1.sd
comm-data2.ld
comm-data2.rd
comm-data2.s
comm-data2.sd
comm-data2.xd
comm-data2r.rd
comm-data2r.sd
comm-data2r.xd
comm-data3.sd
comm-data3a.s
comm-data3b.s
comm-data4.d Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
comm-data4.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
comm-data5.d
comm-data5.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
comm-data.exp Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
commonpage1.d
commonpage2.d
compress1.s Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
compress1a.d
compress1b.d
compress1c.d
compress.exp [ld, testsuite] Don't print to stdout for "readelf -w" to avoid buffer overflow 2017-02-06 15:25:18 +00:00
compressed1a.d
compressed1b.d
compressed1c.d
compressed1d.d
compressed1e.d
data1.c
data1.h
data2.c
del.cc
depaudit2.rd
depaudit.rd
discard1.d
discard1.s
discard2.d
discard2.s
discard3.d
discard.ld
dl1.c
dl1.list
dl1.out
dl1main.c
dl2.c
dl2.list
dl2a.list
dl2a.out
dl2b.out
dl2main.c
dl2xxx.c
dl2xxx.list
dl3.cc
dl3.list
dl3a.out
dl3b.out
dl3header.h
dl3main.cc
dl4.c
dl4.list
dl4a.out
dl4b.out
dl4main.c
dl4xxx.c
dl4xxx.list
dl5.cc
dl5.out
dl6.c
dl6a.out
dl6amain.c
dl6b.out
dl6bmain.c
dl6cmain.c
dl6dmain.c
dummy.c
dwarf1.c
dwarf1.h
dwarf1.out
dwarf1main.c
dwarf2.err Relax dwarf2 expected error match 2017-02-17 18:02:40 +10:30
dwarf2a.c bfd/dwarf: Improve use of previously loaded dwarf information 2017-02-16 13:06:13 +00:00
dwarf2b.c bfd/dwarf: Improve use of previously loaded dwarf information 2017-02-16 13:06:13 +00:00
dwarf3.c bfd/dwarf: Improve use of previously loaded dwarf information 2017-02-16 13:06:13 +00:00
dwarf3.err Relax dwarf3 expected error match 2017-02-17 17:41:03 +10:30
dwarf.exp bfd/dwarf: Improve use of previously loaded dwarf information 2017-02-16 13:06:13 +00:00
dynamic1.d
dynamic1.ld
dynamic1.s
dynamic-1.c
dynamic-1.rd
dynamic-1.syms
dynbss1.c
dynsym1.d
eh1.d
eh1.s
eh1a.s
eh2.d
eh2a.s
eh3.d Align eh_frame FDEs according to their encoding 2017-03-05 14:49:54 +10:30
eh3.s
eh3a.s
eh4.d
eh4.s
eh4a.s
eh5.d
eh5.s
eh5a.s
eh5b.s
eh6.d Align eh_frame FDEs according to their encoding 2017-03-05 14:49:54 +10:30
eh6.s
eh-frame-hdr.d objdump: Better objdump section headers in wide mode 2017-01-20 09:05:41 +00:00
eh-frame-hdr.s
eh-group1.s
eh-group2.s
eh-group.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
ehdr_start-missing.d
ehdr_start-missing.t
ehdr_start-shared.d
ehdr_start-strongref.s
ehdr_start-userdef.d
ehdr_start-userdef.t
ehdr_start-weak.d
ehdr_start.d
ehdr_start.s
elf.exp Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
empty2.d
empty2.s
empty-implib.out
empty.d
empty.s
end.c
endhidden.c
endprotected.c
endsym.d Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
endsym.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
exclude1.s
exclude2.s
exclude3.s
exclude3a.d
exclude3b.d
exclude3c.d
exclude.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
export-class-def.s
export-class-dep.s
export-class-lib.s
export-class-lib.ver
export-class-ref.s
export-class.exp Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
export-class.sd
export-class.vd
expr1.d
expr1.s
expr1.t
fini0.s
fini1.s
fini2.s
fini3.s
fini.c
fini.out
finin.s
flags1.d Don't fudge p_vaddr when PHDR in segment 2016-12-13 09:37:37 +10:30
flags1.ld
flags1.s
foo0.s
foo1.s
foo2.s
foo3.s
foo.c
foo.map
foon.s
frame.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
frame.s
func1.c
gabiend.rt
gabinormal.rt
gap.s
global1.d
gnubegin.rS
gnunormal.rS
group1.d
group1a.s
group1b.s
group2.d
group3a.d
group3a.s
group3b.d
group3b.s
group4.d
group5.d
group6.d
group7.d
group8.s
group8a.d PRU LD Port 2016-12-31 12:04:11 +10:30
group8b.d PRU LD Port 2016-12-31 12:04:11 +10:30
group9.s
group9a.d PRU LD Port 2016-12-31 12:04:11 +10:30
group9b.d PRU LD Port 2016-12-31 12:04:11 +10:30
group10.d
group10.s
group.ld
hash.d
header.d
header.s
header.t
hidden.out
implib.rd
implib.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
indirect1a.c
indirect1b.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
indirect1c.c
indirect2.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
indirect3.out
indirect3a.c
indirect3b.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
indirect3c.c
indirect4.out
indirect4a.c
indirect4b.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
indirect4c.c
indirect.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
init0.s
init1.s
init2.s
init3.s
init-fini-arrays.d
init-fini-arrays.s
init-mixed.c
init-mixed.out
init.c
init.out
initn.s
libbarw.rd
linkinfo1.s
linkinfo1a.d
linkinfo1b.d
linkonce1.d
linkonce1a.s
linkonce1b.s
linkonce2.d
linkoncerdiff1.s
linkoncerdiff2.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
linkoncerdiff.d Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
lma.lnk
lma.s
loadaddr1.d hppa -z relro again 2017-02-16 23:09:38 +10:30
loadaddr1.t
loadaddr2.d hppa -z relro again 2017-02-16 23:09:38 +10:30
loadaddr2.t
loadaddr3.t
loadaddr3a.d hppa -z relro again 2017-02-16 23:09:38 +10:30
loadaddr3b.d
loadaddr.s
loadaddr.t
local1.d
local1.map
local1.s
main.c
maxpage1.d
maxpage1.s
maxpage2.d
maxpage3.t
maxpage3a.d
maxpage3b.d
maxpage3c.d
maxpage4.d
maxpage4.t
maxpage5.d
maxpage5.s
maxpage5.t
merge2.d
merge2.s
merge3.d
merge3.s
merge.d Nios2 dynobj handling fixes 2017-02-28 13:20:21 +10:30
merge.ld
merge.s
multibss1.d
multibss1.s
needed1.out
needed1a.c
needed1b.c
needed1c.c
needed2.ver
needed2a.c
needed2b.c
needed2c.c
needed3.c
new.cc
nobits-1.d Don't add PHDR for objcopy/strip or ld script specifying PHDRS 2016-12-13 09:37:59 +10:30
nobits-1.s
nobits-1.t
noload-1.d
noload-1.s
noload-1.t
noload-2.d
noload-3.d
noload-3.s
noload-3.t
normal.out
note-1.d Don't add PHDR for objcopy/strip or ld script specifying PHDRS 2016-12-13 09:37:59 +10:30
note-1.s
note-1.t
note-2.d Don't add PHDR for objcopy/strip or ld script specifying PHDRS 2016-12-13 09:37:59 +10:30
note-2.s
note-2.t
note-3.l
note-3.s
note-3.t
now-1.d
now-2.d
now-3.d
now-4.d
orphan2.d
orphan2.s
orphan3.d
orphan3a.s
orphan3b.s
orphan3c.s
orphan3d.s
orphan3e.s
orphan3f.s
orphan4.d
orphan4.ld
orphan4.s
orphan-5.d
orphan-5.l
orphan-6.d
orphan-6.l
orphan-7.d
orphan-7.map
orphan-8.d
orphan-8.map
orphan-9.d ld: better handling of lma region for orphan sections 2017-03-09 21:11:05 +00:00
orphan-9.ld ld: better handling of lma region for orphan sections 2017-03-09 21:11:05 +00:00
orphan-9.s ld: better handling of lma region for orphan sections 2017-03-09 21:11:05 +00:00
orphan-region.d
orphan-region.ld
orphan-region.s
orphan.d
orphan.ld
orphan.s
overlay.d
overlay.s
overlay.t
pass.out
pie.d
pr349-1.s
pr349-2.s
pr349.d
pr2404.out
pr2404a.c
pr2404b.c
pr9676-1.c
pr9676-2.c
pr9676-3.c
pr9676-4.c
pr9676.rd
pr9679-1.c
pr9679-2.c
pr9679.rd
pr11138-1.c
pr11138-1.map
pr11138-2.c
pr11138-2.map
pr11138.out
pr11304.d
pr11304a.s
pr11304b.s
pr12851.d PRU LD Port 2016-12-31 12:04:11 +10:30
pr12851.s
pr12975.d
pr12975.s
pr12975.t
pr13177.d
pr13177.s
pr13195.c
pr13195.d
pr13195.s
pr13195.t
pr13250-1.c
pr13250-2.c
pr13250-3.c
pr13839.d
pr13839.s
pr13839.t
pr14052.d
pr14052.t
pr14156a.d
pr14156b.d
pr14156c.d
pr14156c.t
pr14170a.s
pr14170b.s
pr14170c.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
pr14323-1.c
pr14323-2.c
pr14525.c
pr14525.out
pr14862-1.c
pr14862-2.c
pr14862.map
pr14862.out
pr14926.d PRU LD Port 2016-12-31 12:04:11 +10:30
pr14926.s
pr16322.d
pr16322.s
pr16452.map
pr16452.od
pr16452a.c
pr16452b.c
pr16457.od
pr16496a.c
pr16496a.map
pr16496b.c
pr16496b.od
pr16498a.d
pr16498a.s
pr16498a.t
pr16498b.d
pr16498b.t
pr17068.s
pr17068a.s
pr17068b.s
pr17068c.s
pr17068d.s
pr17068e.s
pr17068ez.s
pr17550-1.s
pr17550-2.s
pr17550-3.s
pr17550-4.s
pr17550a.d
pr17550b.d
pr17550c.d
pr17550d.d
pr17615.d
pr17615.s
pr18458a.c
pr18458b.c
pr18458c.c
pr18718.c ld testsuite function pointer comparisons vs. hppa 2017-02-16 23:10:09 +10:30
pr18720.out
pr18720.rd Properly hide hidden versioned symbol in executable 2016-11-28 08:03:46 -08:00
pr18720a.c ld testsuite function pointer comparisons vs. hppa 2017-02-16 23:10:09 +10:30
pr18720b.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
pr18720c.c
pr18735.d
pr18735.s
pr19005.d
pr19005.s
pr19005.t
pr19073.map
pr19073.rd
pr19073.s
pr19162.d
pr19162a.s
pr19162b.s
pr19539.d
pr19539.s
pr19539.t
pr19553.map
pr19553a.c
pr19553b.c
pr19553b.out
pr19553c.c PowerPC64 dot-sym testsuite fixes 2016-12-03 20:59:43 +10:30
pr19553c.out
pr19553d.c
pr19553d.out
pr19579a.c
pr19579b.c
pr19617.s
pr19617a.d
pr19617b.d
pr19617c.d
pr19698.d
pr19698.s
pr19698.t
pr19719a.c
pr19719b.c
pr19719c.c
pr19719d.c
pr19789.d
pr19789.s
pr20513a.d
pr20513a.s
pr20513b.d
pr20513b.s
pr20513c.d
pr20513d.d
pr20513e.d
pr20513f.d
pr20528a.d
pr20528a.s
pr20528b.d
pr20528b.s
pr20828-a.sd PR ld/20828: Remove leading `_' from symbols used in tests 2017-01-23 11:26:06 +00:00
pr20828-b.sd PR ld/20828: Remove leading `_' from symbols used in tests 2017-01-23 11:26:06 +00:00
pr20828-c.sd PR ld/20828: Remove leading `_' from symbols used in tests 2017-01-23 11:26:06 +00:00
pr20828-d.sd PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828-e.sd PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828-v.ld PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828-v.od PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828-v.s PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828-v.ver PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828.ld PR ld/20828: Move symbol version processing ahead of GC symbol sweep 2017-02-22 18:16:28 +00:00
pr20828.s PR ld/20828: Fix linker script symbols wrongly forced local with section GC 2017-01-18 18:30:34 +00:00
pr20828.ver PR ld/20828: Remove leading `_' from symbols used in tests 2017-01-23 11:26:06 +00:00
pr20995-2so.r Use dynrelro for symbols in relro sections too 2016-12-28 22:10:38 +10:30
pr20995.r dynrelro section for read-only dynamic symbols copied into executable 2016-12-26 13:47:51 +10:30
pr20995a.s dynrelro section for read-only dynamic symbols copied into executable 2016-12-26 13:47:51 +10:30
pr20995b.s dynrelro section for read-only dynamic symbols copied into executable 2016-12-26 13:47:51 +10:30
pr20995c.s Use dynrelro for symbols in relro sections too 2016-12-28 22:10:38 +10:30
preinit.c
preinit.out
provide-hidden-1.ld
provide-hidden-1.s
provide-hidden-2.ld
provide-hidden-2.s
provide-hidden-3.s
provide-hidden-4.s
provide-hidden-abs.nd
provide-hidden-def.nd
provide-hidden-dyn.nd
provide-hidden-dynabs.nd
provide-hidden-dynsec.nd
provide-hidden-s.ld
provide-hidden-s.nd
provide-hidden-sec.nd
provide-hidden.exp Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
rdynamic-1.c
rdynamic-1.rd
readelf.exp readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
rel.c
relmain.c
relmain.out
relocatable.d
relocatable.t
relro1.s
relro2.s
rpath-1.d
rpath-2.d
runpath-1.d
runpath-2.d
sec64k.exp Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
sec-to-seg1.s
sec-to-seg2.s
sec-to-seg-script-adjoining-pages.t
sec-to-seg-script-disjoint-pages.t
sec-to-seg-script-same-page.t
sec-to-seg.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
seg.d
seg.s
seg.t
shared.exp Avoid gcc-7 warning killing ld testcases 2017-03-02 10:40:06 +10:30
simple.s
stab.d
stack-exec.rd
stack-size.rd
stack.s
start.s
strtab.d
strtab.s
symbol1ref.s
symbol1w.s
symbol2ref.s
symbol2w.s
symbol3.s Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
symbol3w.s
symbolic-func.r
symbolic-func.s
table.s
tbss1.s
tbss2.s
tbss3.s
tbss.s
tdata1.s
tdata2.s
tdata3.s
textaddr1.d
textaddr2.d
textaddr3.d
textaddr4.d
textaddr5.d
textaddr6.d
textaddr7.d
tls_common.exp Run more ld tests when not native 2017-01-02 23:48:08 +10:30
tls_common.s
tls_gc.s
unknown2.d
unknown2.s
unknown.d
var1.d
var1.s
var1.t
ver_def-tic6x.vd readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
ver_def.ld readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
ver_def.s readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
ver_def.vd readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
ver_def.ver readelf: Fix incorrect "Version definition past end of section" message 2017-02-24 13:48:10 +00:00
warn1.d
warn2.d
warn3.d Testsuite fixes for hppa64-hpux 2017-02-25 19:13:34 +10:30
warn.out
weak-dyn-1.ld
weak-dyn-1.rd
weak-dyn-1a.s
weak-dyn-1b.s
weakdef1.c
wrap1.c
wrap1.out
wrap1a.c
wrap1b.c
wrap.exp Check for shared lib support before running ld tests with -shared 2017-01-04 09:39:12 +10:30
zlibbegin.rS
zlibnormal.rS