Browse Source
As shown in https://sourceware.org/bugzilla/show_bug.cgi?id=25490 --gc-sections will silently remove __patchable_function_entries section and generate corrupt result. This patch adds the section flag 'o' to .section directive: .section __patchable_function_entries,"awo",@progbits,foo .section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat .section __patchable_function_entries,"awo",@progbits,bar,unique,4 .section __patchable_function_entries,"awoG",@progbits,foo,foo,comdat,unique,1 which specifies the symbol name which the section references. Assmebler will set its elf_linked_to_section to a local section where the symbol is defined. Linker is updated to call mark_hook if gc_mark of any of its linked-to sections is set after all sections, except for backend specific ones, have been garbage collected. bfd/ PR gas/25381 * bfd-in2.h: Regenerated. * elflink.c (_bfd_elf_gc_mark_extra_sections): Call mark_hook on section if gc_mark of any of its linked-to sections is set and don't set gc_mark again. * section.c (asection): Add linked_to_symbol_name to map_head union. gas/ PR gas/25381 * config/obj-elf.c (get_section): Also check linked_to_symbol_name. (obj_elf_change_section): Also set map_head.linked_to_symbol_name. (obj_elf_parse_section_letters): Handle the 'o' flag. (build_group_lists): Renamed to ... (build_additional_section_info): This. Set elf_linked_to_section from map_head.linked_to_symbol_name. (elf_adjust_symtab): Updated. * config/obj-elf.h (elf_section_match): Add linked_to_symbol_name. * doc/as.texi: Document the 'o' flag. * testsuite/gas/elf/elf.exp: Run PR gas/25381 tests. * testsuite/gas/elf/section18.d: New file. * testsuite/gas/elf/section18.s: Likewise. * testsuite/gas/elf/section19.d: Likewise. * testsuite/gas/elf/section19.s: Likewise. * testsuite/gas/elf/section20.d: Likewise. * testsuite/gas/elf/section20.s: Likewise. * testsuite/gas/elf/section21.d: Likewise. * testsuite/gas/elf/section21.l: Likewise. * testsuite/gas/elf/section21.s: Likewise. ld/ PR ld/24526 PR ld/25021 PR ld/25490 * testsuite/ld-elf/elf.exp: Run PR ld/25490 tests. * testsuite/ld-elf/pr24526.d: New file. * testsuite/ld-elf/pr24526.s: Likewise. * testsuite/ld-elf/pr25021.d: Likewise. * testsuite/ld-elf/pr25021.s: Likewise. * testsuite/ld-elf/pr25490-2-16.rd: Likewise. * testsuite/ld-elf/pr25490-2-32.rd: Likewise. * testsuite/ld-elf/pr25490-2-64.rd: Likewise. * testsuite/ld-elf/pr25490-2.s: Likewise. * testsuite/ld-elf/pr25490-3-16.rd: Likewise. * testsuite/ld-elf/pr25490-3-32.rd: Likewise. * testsuite/ld-elf/pr25490-3-64.rd: Likewise. * testsuite/ld-elf/pr25490-3.s: Likewise. * testsuite/ld-elf/pr25490-4-16.rd: Likewise. * testsuite/ld-elf/pr25490-4-32.rd: Likewise. * testsuite/ld-elf/pr25490-4-64.rd: Likewise. * testsuite/ld-elf/pr25490-4.s: Likewise. * testsuite/ld-elf/pr25490-5-16.rd: Likewise. * testsuite/ld-elf/pr25490-5-32.rd: Likewise. * testsuite/ld-elf/pr25490-5-64.rd: Likewise. * testsuite/ld-elf/pr25490-5.s: Likewise. * testsuite/ld-elf/pr25490-6-16.rd: Likewise. * testsuite/ld-elf/pr25490-6-32.rd: Likewise. * testsuite/ld-elf/pr25490-6-64.rd: Likewise. * testsuite/ld-elf/pr25490-6.s: Likewise.binutils-2_35-branch
44 changed files with 578 additions and 11 deletions
@ -0,0 +1,8 @@ |
|||
#readelf: -SW |
|||
#name: linked-to section 1 |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WAL +.* |
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WAL +.* |
|||
#pass |
|||
@ -0,0 +1,13 @@ |
|||
.text |
|||
foo: |
|||
.section __patchable_function_entries,"awo",%progbits,foo |
|||
.dc.a .LPFE1 |
|||
.text |
|||
.LPFE1: |
|||
.byte 0 |
|||
.section __patchable_function_entries,"awo",%progbits,bar |
|||
.dc.a .LPFE2 |
|||
.text |
|||
bar: |
|||
.LPFE2: |
|||
.byte 0 |
|||
@ -0,0 +1,8 @@ |
|||
#readelf: -SW |
|||
#name: linked-to section 2 |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WAL +.* |
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WAL +.* |
|||
#pass |
|||
@ -0,0 +1,13 @@ |
|||
.section .text,"ax",%progbits,unique,20 |
|||
foo: |
|||
.section __patchable_function_entries,"awo",%progbits,foo,unique,2 |
|||
.dc.a .LPFE1 |
|||
.section .text,"ax",%progbits,unique,20 |
|||
.LPFE1: |
|||
.byte 0 |
|||
.section __patchable_function_entries,"awo",%progbits,bar,unique,102 |
|||
.dc.a .LPFE2 |
|||
.section .text,"ax",%progbits,unique,2 |
|||
bar: |
|||
.LPFE2: |
|||
.byte 0 |
|||
@ -0,0 +1,17 @@ |
|||
#readelf: -SWg |
|||
#name: linked-to section 3 |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WALG +.* |
|||
#... |
|||
+\[ *[0-9]+\] +__patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+[248] +00 +WALG +.* |
|||
#... |
|||
COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains [0-9]+ sections: |
|||
\[Index\] Name |
|||
#... |
|||
\[[ 0-9]+\] __patchable_function_entries |
|||
#... |
|||
COMDAT group section \[[ 0-9]+\] `.group' \[bar\] contains [0-9]+ sections: |
|||
#... |
|||
\[[ 0-9]+\] __patchable_function_entries |
|||
#pass |
|||
@ -0,0 +1,13 @@ |
|||
.section .text,"axG",%progbits,foo,comdat |
|||
foo: |
|||
.section __patchable_function_entries,"awoG",%progbits,foo,foo,comdat |
|||
.dc.a .LPFE1 |
|||
.section .text,"axG",%progbits,foo,comdat |
|||
.LPFE1: |
|||
.byte 0 |
|||
.section __patchable_function_entries,"awoG",%progbits,bar,bar,comdat,unique,4 |
|||
.dc.a .LPFE2 |
|||
.section .text,"axG",%progbits,bar,comdat,unique,24 |
|||
bar: |
|||
.LPFE2: |
|||
.byte 0 |
|||
@ -0,0 +1,2 @@ |
|||
#name: incorrect linked-to symbols |
|||
#error_output: section21.l |
|||
@ -0,0 +1,5 @@ |
|||
[^:]*: Assembler messages: |
|||
[^:]*:11: Error: junk at end of line, first unrecognized character is `1' |
|||
#... |
|||
[^:]*: Error: undefined linked-to symbol `bar' on section `__patchable_function_entries' |
|||
[^:]*: Error: undefined linked-to symbol `foo' on section `__patchable_function_entries' |
|||
@ -0,0 +1,15 @@ |
|||
.section __patchable_function_entries,"awo",%progbits,bar |
|||
.dc.a .LPFE1 |
|||
.text |
|||
.LPFE1: |
|||
.byte 0 |
|||
.section __patchable_function_entries,"awo",%progbits,foo |
|||
.dc.a .LPFE2 |
|||
.text |
|||
.LPFE2: |
|||
.dc.a foo |
|||
.section __patchable_function_entries,"awo",%progbits,1foo |
|||
.dc.a .LPFE3 |
|||
.text |
|||
.LPFE3: |
|||
.byte 0 |
|||
@ -0,0 +1,9 @@ |
|||
#ld: --gc-sections -e _start |
|||
#target: [check_gc_sections_available] |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] \.bar +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +AL .* |
|||
#... |
|||
+\[ *[0-9]+\] \.zed +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +AL .* |
|||
#pass |
|||
@ -0,0 +1,13 @@ |
|||
.text |
|||
.globl _start |
|||
_start: |
|||
.byte 0 |
|||
.section .note,"",%note |
|||
.dc.a .foo |
|||
|
|||
.section .foo,"a" |
|||
.dc.a 0 |
|||
.section .bar,"ao",%progbits,.foo |
|||
.dc.a 0 |
|||
.section .zed,"ao",%progbits,.foo |
|||
.dc.a 0 |
|||
@ -0,0 +1,7 @@ |
|||
#ld: --gc-sections -e _start |
|||
#target: [check_gc_sections_available] |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] \.stack_sizes +PROGBITS +0+ +[0-9a-f]+ 0+1 +00 +L +[0-9] .* |
|||
#pass |
|||
@ -0,0 +1,22 @@ |
|||
.section .text.live,"ax",%progbits |
|||
.globl live |
|||
live: |
|||
.byte 0 |
|||
|
|||
.section .stack_sizes,"o",%progbits,.text.live,unique,0 |
|||
.byte 1 |
|||
|
|||
.section .text.dead,"ax",%progbits |
|||
.globl dead |
|||
dead: |
|||
.byte 1 |
|||
|
|||
.section .stack_sizes,"o",%progbits,.text.dead,unique,1 |
|||
.byte 2 |
|||
|
|||
.section .text.main,"ax",%progbits |
|||
.globl _start |
|||
_start: |
|||
.byte 0 |
|||
.section .note,"",%note |
|||
.dc.a live |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-2.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+2 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-2.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+4 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-2.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,9 @@ |
|||
.text |
|||
.globl _start |
|||
.type _start, %function |
|||
_start: |
|||
.section __patchable_function_entries,"awo",%progbits,_start |
|||
.dc.a .LPFE1 |
|||
.text |
|||
.LPFE1: |
|||
.byte 0 |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-3.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+2 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-3.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+4 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-3.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,18 @@ |
|||
.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 |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-4.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+4 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-4.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-4.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -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 .note,"",%note |
|||
.dc.a bar |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-5.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+4 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-5.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-5.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,17 @@ |
|||
.text |
|||
.type bar, %function |
|||
bar: |
|||
.section __patchable_function_entries,"awo",%progbits,bar |
|||
.dc.a .LPFE1 |
|||
.text |
|||
.LPFE1: |
|||
.byte 0 |
|||
.text |
|||
.globl _start |
|||
.type _start, %function |
|||
_start: |
|||
.section __patchable_function_entries,"awo",%progbits,_start |
|||
.dc.a .LPFE2 |
|||
.text |
|||
.LPFE2: |
|||
.byte 0 |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-6.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+6 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-6.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+c +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,7 @@ |
|||
#source: pr25490-6.s |
|||
#ld: --gc-sections -e _start |
|||
#readelf: -SW |
|||
|
|||
#... |
|||
+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+18 +00 +WAL +[0-9] +0 +[1248] |
|||
#pass |
|||
@ -0,0 +1,30 @@ |
|||
.section .text,"axG",%progbits,bar,comdat |
|||
.globl bar |
|||
.type bar, %function |
|||
bar: |
|||
.section __patchable_function_entries,"awo",%progbits,bar |
|||
.dc.a .LPFE1 |
|||
.section .text,"axG",%progbits,bar,comdat |
|||
.LPFE1: |
|||
.byte 0 |
|||
.section .text,"axG",%progbits,foo,comdat |
|||
.globl foo |
|||
.type foo, %function |
|||
foo: |
|||
.section __patchable_function_entries,"awo",%progbits,foo,unique,0 |
|||
.dc.a .LPFE2 |
|||
.section .text,"axG",%progbits,foo,comdat |
|||
.LPFE2: |
|||
.byte 0 |
|||
.section .text,"axG",%progbits,_start,comdat,unique,1 |
|||
.globl _start |
|||
.type _start, %function |
|||
_start: |
|||
.section __patchable_function_entries,"awoG",%progbits,_start,_start,comdat,unique,3 |
|||
.dc.a .LPFE3 |
|||
.section .text,"axG",%progbits,_start,comdat,unique,1 |
|||
.LPFE3: |
|||
.byte 0 |
|||
.section .note,"",%note |
|||
.dc.a foo |
|||
.dc.a bar |
|||
Loading…
Reference in new issue