diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-01-04 12:37:49 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-01-04 12:38:05 -0800 |
commit | cd6d537c48fa862e8a5888b648102d7b2330ef81 (patch) | |
tree | 1ab9bc928a0acb1a3acc04f6d985338ae45f279e /ld | |
parent | e4ad960a577405c4d0f7593f439ad560fabc9d49 (diff) | |
download | fsf-binutils-gdb-cd6d537c48fa862e8a5888b648102d7b2330ef81.zip fsf-binutils-gdb-cd6d537c48fa862e8a5888b648102d7b2330ef81.tar.gz fsf-binutils-gdb-cd6d537c48fa862e8a5888b648102d7b2330ef81.tar.bz2 |
elf: Allow mixed ordered/unordered inputs for non-relocatable link
For non-relocatable link with SHF_LINK_ORDER inputs, allow mixed indirect
and data inputs with ordered and unordered inputs:
1. Add pattern to bfd_section for the matching section name pattern in
linker script and update BFD_FAKE_SECTION.
2. Sort the consecutive bfd_indirect_link_order sections with the same
pattern to allow linker script to overdide input section order.
3. Place unordered sections before ordered sections.
4. Change the offsets of the indirect input sections only.
bfd/
PR ld/26256
* elflink.c (compare_link_order): Place unordered sections before
ordered sections.
(elf_fixup_link_order): Add a link info argument. Allow mixed
ordered and unordered input sections for non-relocatable link.
Sort the consecutive bfd_indirect_link_order sections with the
same pattern. Change the offsets of the bfd_indirect_link_order
sections only.
(bfd_elf_final_link): Pass info to elf_fixup_link_order.
* section.c (bfd_section): Add pattern.
(BFD_FAKE_SECTION): Initialize pattern to NULL.
* bfd-in2.h: Regenerated.
gas/
PR ld/26256
* config/obj-elf.c (obj_elf_change_section): Also filter out
SHF_LINK_ORDER.
ld/
PR ld/26256
* ldlang.c (gc_section_callback): Set pattern.
* testsuite/ld-elf/pr26256-1.s: New file.
* testsuite/ld-elf/pr26256-1.t: Likewise.
* testsuite/ld-elf/pr26256-1a.d: Likewise.
* testsuite/ld-elf/pr26256-1b.d: Likewise.
* testsuite/ld-elf/pr26256-2.s: Likewise.
* testsuite/ld-elf/pr26256-2.t: Likewise.
* testsuite/ld-elf/pr26256-2a.d: Likewise.
* testsuite/ld-elf/pr26256-2b-alt.d: Likewise.
* testsuite/ld-elf/pr26256-2b.d: Likewise.
* testsuite/ld-elf/pr26256-3.s: Likewise.
* testsuite/ld-elf/pr26256-3a.d: Likewise.
* testsuite/ld-elf/pr26256-3a.t: Likewise.
* testsuite/ld-elf/pr26256-3b.d: Likewise.
* testsuite/ld-elf/pr26256-3b.t: Likewise.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 19 | ||||
-rw-r--r-- | ld/ldlang.c | 4 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-1.s | 20 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-1.t | 13 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-1a.d | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-1b.d | 7 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-2.s | 32 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-2.t | 9 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-2a.d | 20 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-2b-alt.d | 21 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-2b.d | 22 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-3.s | 27 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-3a.d | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-3a.t | 17 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-3b.d | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-elf/pr26256-3b.t | 16 |
16 files changed, 256 insertions, 1 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 8d45491..1fe689a 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,22 @@ +2021-01-04 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/26256 + * ldlang.c (gc_section_callback): Set pattern. + * testsuite/ld-elf/pr26256-1.s: New file. + * testsuite/ld-elf/pr26256-1.t: Likewise. + * testsuite/ld-elf/pr26256-1a.d: Likewise. + * testsuite/ld-elf/pr26256-1b.d: Likewise. + * testsuite/ld-elf/pr26256-2.s: Likewise. + * testsuite/ld-elf/pr26256-2.t: Likewise. + * testsuite/ld-elf/pr26256-2a.d: Likewise. + * testsuite/ld-elf/pr26256-2b-alt.d: Likewise. + * testsuite/ld-elf/pr26256-2b.d: Likewise. + * testsuite/ld-elf/pr26256-3.s: Likewise. + * testsuite/ld-elf/pr26256-3a.d: Likewise. + * testsuite/ld-elf/pr26256-3a.t: Likewise. + * testsuite/ld-elf/pr26256-3b.d: Likewise. + * testsuite/ld-elf/pr26256-3b.t: Likewise. + 2021-01-04 Alan Modra <amodra@gmail.com> PR 26822 diff --git a/ld/ldlang.c b/ld/ldlang.c index 32450fb..8cbeda6 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -7488,7 +7488,7 @@ lang_reset_memory_regions (void) static void gc_section_callback (lang_wild_statement_type *ptr, - struct wildcard_list *sec ATTRIBUTE_UNUSED, + struct wildcard_list *sec, asection *section, struct flag_info *sflag_info ATTRIBUTE_UNUSED, lang_input_statement_type *file ATTRIBUTE_UNUSED, @@ -7498,6 +7498,8 @@ gc_section_callback (lang_wild_statement_type *ptr, should be as well. */ if (ptr->keep_sections) section->flags |= SEC_KEEP; + if (sec) + section->pattern = sec->spec.name; } /* Iterate over sections marking them against GC. */ diff --git a/ld/testsuite/ld-elf/pr26256-1.s b/ld/testsuite/ld-elf/pr26256-1.s new file mode 100644 index 0000000..7351f76 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-1.s @@ -0,0 +1,20 @@ + .section .text.bar,"ax",%progbits + .globl bar + .type bar, %function +bar: + .section __patchable_function_entries,"awo",%progbits,bar + .dc.a .LPFE1 + .section .text.bar,"ax",%progbits +.LPFE1: + .byte 0 + .section .text._start,"ax",%progbits + .globl _start + .type _start, %function +_start: + .section __patchable_function_entries,"awo",%progbits,_start + .dc.a .LPFE2 + .section .text._start,"ax",%progbits +.LPFE2: + .byte 0 + .section .init.data,"aw",%progbits + .byte 0 diff --git a/ld/testsuite/ld-elf/pr26256-1.t b/ld/testsuite/ld-elf/pr26256-1.t new file mode 100644 index 0000000..f93fff9 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-1.t @@ -0,0 +1,13 @@ +SECTIONS +{ + .text : { *(.text*) } + .init.data : + { + *(.init.data); + *(__patchable_function_entries); + } + /DISCARD/ : + { + *(.reginfo) *(.MIPS.abiflags) *(.MIPS.options) *(.trampolines) + } +} diff --git a/ld/testsuite/ld-elf/pr26256-1a.d b/ld/testsuite/ld-elf/pr26256-1a.d new file mode 100644 index 0000000..025ace0 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-1a.d @@ -0,0 +1,7 @@ +#source: pr26256-1.s +#ld: -e _start -T pr26256-1.t +#nm: -n + +#... +[0-9a-f]+ T _start +#pass diff --git a/ld/testsuite/ld-elf/pr26256-1b.d b/ld/testsuite/ld-elf/pr26256-1b.d new file mode 100644 index 0000000..760c6d8 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-1b.d @@ -0,0 +1,7 @@ +#source: pr26256-1.s +#ld: -e _start +#nm: -n + +#... +[0-9a-f]+ T _start +#pass diff --git a/ld/testsuite/ld-elf/pr26256-2.s b/ld/testsuite/ld-elf/pr26256-2.s new file mode 100644 index 0000000..70e3693 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-2.s @@ -0,0 +1,32 @@ + .section .text,"ax",%progbits,unique,0 + .globl text0 +text0: + .nop + .section .text,"ax",%progbits,unique,1 + .globl text1 +text1: + .nop + .section .linkorder,"ao",%progbits,0,unique,0 + .globl linkorder2 +linkorder2: + .byte 0 + .section .linkorder,"ao",%progbits,text0 + .globl linkorder0 +linkorder0: + .byte 1 + .section .linkorder,"ao",%progbits,text1 + .globl linkorder1 +linkorder1: + .byte 2 + .section .linkorder,"a",%progbits + .globl linkorder3 +linkorder3: + .byte 3 + .section .linkorder,"ao",%progbits,0,unique,3 + .globl linkorder4 +linkorder4: + .byte 4 + .text + .global _start +_start: + .nop diff --git a/ld/testsuite/ld-elf/pr26256-2.t b/ld/testsuite/ld-elf/pr26256-2.t new file mode 100644 index 0000000..0c5e5bc --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-2.t @@ -0,0 +1,9 @@ +SECTIONS +{ + .linkorder : { *(.linkorder.*) } + .text : { *(.text) } + /DISCARD/ : + { + *(.reginfo) *(.MIPS.abiflags) *(.MIPS.options) *(.trampolines) + } +} diff --git a/ld/testsuite/ld-elf/pr26256-2a.d b/ld/testsuite/ld-elf/pr26256-2a.d new file mode 100644 index 0000000..03804d8 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-2a.d @@ -0,0 +1,20 @@ +#source: pr26256-2.s +#ld: -e _start -T pr26256-2.t +#nm: -n +#xfail: [is_generic] + +#... +[0-9a-f]+ R linkorder2 +#... +[0-9a-f]+ R linkorder3 +#... +[0-9a-f]+ R linkorder4 +#... +[0-9a-f]+ R linkorder0 +#... +[0-9a-f]+ R linkorder1 +#... +[0-9a-f]+ T text0 +#... +[0-9a-f]+ T text1 +#pass diff --git a/ld/testsuite/ld-elf/pr26256-2b-alt.d b/ld/testsuite/ld-elf/pr26256-2b-alt.d new file mode 100644 index 0000000..f2f03a0 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-2b-alt.d @@ -0,0 +1,21 @@ +#source: pr26256-2.s +#ld: -e _start +#nm: -n +#target: fr30-*-* iq2000-*-* ip2k-*-* xstormy16-*-* +# These targets place .linkorder sections before .text sections. + +#... +[0-9a-f]+ R linkorder2 +#... +[0-9a-f]+ R linkorder3 +#... +[0-9a-f]+ R linkorder4 +#... +[0-9a-f]+ R linkorder0 +#... +[0-9a-f]+ R linkorder1 +#... +[0-9a-f]+ T text0 +#... +[0-9a-f]+ T text1 +#pass diff --git a/ld/testsuite/ld-elf/pr26256-2b.d b/ld/testsuite/ld-elf/pr26256-2b.d new file mode 100644 index 0000000..60c3bff --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-2b.d @@ -0,0 +1,22 @@ +#source: pr26256-2.s +#ld: -e _start +#nm: -n +#xfail: [is_generic] +#notarget: fr30-*-* iq2000-*-* ip2k-*-* xstormy16-*-* +# These targets place .linkorder sections before .text sections. + +#... +[0-9a-f]+ T text0 +#... +[0-9a-f]+ T text1 +#... +[0-9a-f]+ R linkorder2 +#... +[0-9a-f]+ R linkorder3 +#... +[0-9a-f]+ R linkorder4 +#... +[0-9a-f]+ R linkorder0 +#... +[0-9a-f]+ R linkorder1 +#pass diff --git a/ld/testsuite/ld-elf/pr26256-3.s b/ld/testsuite/ld-elf/pr26256-3.s new file mode 100644 index 0000000..baad9dc --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-3.s @@ -0,0 +1,27 @@ + .text + .global _start +_start: + .long 0x33333333 + .long 0x33333333 + .long 0x33333333 + .long 0x33333333 + + .section .rosection,"a" + .byte 9 + + .section .text.bar,"a",%progbits + .long 0x22222222 + .long 0x22222222 + .long 0x22222222 + .long 0x22222222 + .section .text.foo,"a",%progbits + .long 0x11111111 + .long 0x11111111 + .long 0x11111111 + .long 0x11111111 + .section .rodata.foo,"ao",%progbits,.text.foo + .byte 1 + .section .rodata.bar,"a",%progbits + .byte 2 + .section .rodata.bar,"ao",%progbits,.text.bar + .byte 3 diff --git a/ld/testsuite/ld-elf/pr26256-3a.d b/ld/testsuite/ld-elf/pr26256-3a.d new file mode 100644 index 0000000..4546f0a --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-3a.d @@ -0,0 +1,11 @@ +#source: pr26256-3.s +#ld: -e _start -T pr26256-3a.t +#readelf: -x .rodata -x .text + +Hex dump of section \'.rodata\': + 0x[a-f0-9]+ +00010203 +040907 +.+ + +Hex dump of section \'.text\': + 0x[a-f0-9]+ +22222222 +22222222 +22222222 +.+ + 0x[a-f0-9]+ +11111111 +11111111 +11111111 +.+ + 0x[a-f0-9]+ +33333333 +33333333 +33333333 +.+ diff --git a/ld/testsuite/ld-elf/pr26256-3a.t b/ld/testsuite/ld-elf/pr26256-3a.t new file mode 100644 index 0000000..12f6fd1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-3a.t @@ -0,0 +1,17 @@ +SECTIONS +{ + .rodata : + { + BYTE(0) + *(.rodata.foo) + *(.rodata.bar) + BYTE(4) + *(.rosection) + BYTE(7) + } + .text : {*(.text.bar) *(.text.foo)} + /DISCARD/ : + { + *(.reginfo) *(.MIPS.abiflags) *(.MIPS.options) *(.trampolines) + } +} diff --git a/ld/testsuite/ld-elf/pr26256-3b.d b/ld/testsuite/ld-elf/pr26256-3b.d new file mode 100644 index 0000000..7d6dff2 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-3b.d @@ -0,0 +1,12 @@ +#source: pr26256-3.s +#ld: -e _start -T pr26256-3b.t +#readelf: -x .rodata -x .text +#xfail: [is_generic] + +Hex dump of section \'.rodata\': + 0x[a-f0-9]+ +00020301 +040907 +.+ + +Hex dump of section \'.text\': + 0x[a-f0-9]+ +22222222 +22222222 +22222222 +.+ + 0x[a-f0-9]+ +11111111 +11111111 +11111111 +.+ + 0x[a-f0-9]+ +33333333 +33333333 +33333333 +.+ diff --git a/ld/testsuite/ld-elf/pr26256-3b.t b/ld/testsuite/ld-elf/pr26256-3b.t new file mode 100644 index 0000000..952c8d2 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26256-3b.t @@ -0,0 +1,16 @@ +SECTIONS +{ + .rodata : + { + BYTE(0) + *(.rodata*) + BYTE(4) + *(.rosection) + BYTE(7) + } + .text : {*(.text.bar) *(.text.foo)} + /DISCARD/ : + { + *(.reginfo) *(.MIPS.abiflags) *(.MIPS.options) *(.trampolines) + } +} |