Bug 25490 - __patchable_function_entries section doesn't work with --gc-sections
Summary: __patchable_function_entries section doesn't work with --gc-sections
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL: https://sourceware.org/ml/binutils/20...
Keywords:
Depends on:
Blocks: 25381
  Show dependency treegraph
 
Reported: 2020-02-01 13:25 UTC by H.J. Lu
Modified: 2020-02-07 03:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2020-02-01 13:25:44 UTC
[hjl@gnu-cfl-2 pr93492]$ cat x.i
void 
_start (void)
{
}
[hjl@gnu-cfl-2 pr93492]$ gcc -c -fpatchable-function-entry=1 x.i
[hjl@gnu-cfl-2 pr93492]$ readelf -SW x.o | grep __patch
  [ 4] __patchable_function_entries PROGBITS        0000000000000000 000048 000008 00  WA  0   0  1
  [ 5] .rela__patchable_function_entries RELA            0000000000000000 000200 000018 18   I 11   4  8
[hjl@gnu-cfl-2 pr93492]$ ld x.o
[hjl@gnu-cfl-2 pr93492]$ readelf -SW a.out | grep __patch
  [ 4] __patchable_function_entries PROGBITS        0000000000404000 003000 000008 00  WA  0   0  1
[hjl@gnu-cfl-2 pr93492]$ ld --gc-sections x.o
[hjl@gnu-cfl-2 pr93492]$ readelf -SW a.out | grep __patch
[hjl@gnu-cfl-2 pr93492]$
Comment 1 H.J. Lu 2020-02-01 16:28:34 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2020-02/msg00009.html
Comment 2 H.J. Lu 2020-02-01 17:19:46 UTC
An updated patch is at

https://sourceware.org/ml/binutils/2020-02/msg00010.html
Comment 3 Sourceware Commits 2020-02-07 02:09:16 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b7d072167715829eed0622616f6ae0182900de3e

commit b7d072167715829eed0622616f6ae0182900de3e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 6 18:04:58 2020 -0800

    ELF: Support the section flag 'o' in .section directive
    
    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.
Comment 4 Sourceware Commits 2020-02-07 03:42:41 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5242a0a000ad7d3f2fa1cd0023f692d53261b302

commit 5242a0a000ad7d3f2fa1cd0023f692d53261b302
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 6 19:37:54 2020 -0800

    ld: Issue an error for GC on __patchable_function_entries section
    
    __patchable_function_entries section is generated by a compiler with
    -fpatchable-function-entry=XX.  The assembly code looks like this:
    
    ---
    	.text
    	.globl	_start
    	.type	_start, %function
    _start:
    	.section __patchable_function_entries,"aw",%progbits
    	.dc.a	.LPFE1
    	.text
    .LPFE1:
    	.byte 0
    ---
    
    But --gc-sections will silently remove __patchable_function_entries
    section and generate corrupt result.  This patch disallows garbage
    collection on __patchable_function_entries section without linked-to
    section.
    
    bfd/
    
    	PR ld/25490
    	* elflink.c (_bfd_elf_gc_mark_extra_sections): Issue an error
    	for garbage collection on __patchable_function_entries section
    	without linked-to section.
    
    ld/
    
    	PR ld/25490
    	* testsuite/ld-elf/pr25490-1.d: New file.
    	* testsuite/ld-elf/pr25490-1.s: Likewise.
Comment 5 H.J. Lu 2020-02-07 03:46:02 UTC
Fixed for 2.35.