Bug 110729 - -fpatchable-function-entries: __patchable_function_entries has wrong sh_link
Summary: -fpatchable-function-entries: __patchable_function_entries has wrong sh_link
Status: RESOLVED DUPLICATE of bug 99889
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 13.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-19 06:20 UTC by Fangrui Song
Modified: 2023-07-21 05:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 13.1.0
Known to fail: 12.3.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2023-07-19 06:20:39 UTC
Noticed by Ziwei Mao.

% cat a.c
void f() {}
void g() {}
void h() {}
% gcc -ffunction-sections -fpatchable-function-entry=2 -c a.c
% gcc -ffunction-sections -fpatchable-function-entry=2 -S a.c

a.o has .text.f, .text.g, and .text.h, but just one __patchable_function_entries section.

% grep __patchable_function_entries a.s
        .section        __patchable_function_entries,"awo",@progbits,f
        .section        __patchable_function_entries,"awo",@progbits,f
        .section        __patchable_function_entries,"awo",@progbits,f

I think the second and the third __patchable_function_entries should reference g and h, respectively. Otherwise, if f is discarded by ld --gc-sections, the whole __patchable_function_entries (also used by g and h) will be discarded.
(Also, if g is discarded, its __patchable_function_entries fragment may be retained if f is retained.)
Comment 1 Andrew Pinski 2023-07-19 06:24:40 UTC
This was fixed in GCC 13:
f:
.LFB0:
        .cfi_startproc
        .section        __patchable_function_entries,"awo",@progbits,.LPFE0
        .align 8
        .quad   .LPFE0
        .section        .text.f
.LPFE0:
...
g:
.LFB1:
        .cfi_startproc
        .section        __patchable_function_entries,"awo",@progbits,.LPFE1
        .align 8
        .quad   .LPFE1
        .section        .text.g
.LPFE1:
...
h:
.LFB2:
        .cfi_startproc
        .section        __patchable_function_entries,"awo",@progbits,.LPFE2
        .align 8
        .quad   .LPFE2
        .section        .text.h
.LPFE2:
Comment 2 Andrew Pinski 2023-07-19 06:26:39 UTC
Dup of bug 105169.

*** This bug has been marked as a duplicate of bug 105169 ***
Comment 3 Andrew Pinski 2023-07-19 06:27:56 UTC
Actually maybe PR 99889 fixed it ...
Comment 4 GCC Commits 2023-07-21 05:18:55 UTC
The master branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:6894581ac453361e3fb4e1ffd54f9499acb87466

commit r14-2693-g6894581ac453361e3fb4e1ffd54f9499acb87466
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Fri Jul 21 00:16:29 2023 -0500

    testsuite: Add a test case for PR110729 [PR110729]
    
    As PR110729 reported, there was one issue for .section
    __patchable_function_entries with -ffunction-sections, that
    is we put the same symbol as link_to section symbol for all
    functions wrongly.  The commit r13-4294 for PR99889 has
    fixed this with the corresponding label LPFE* which sits in
    the function_section.
    
    As Fangrui suggested [1], this patch is to add a bit more
    test coverage.  I didn't find a good way to check all
    linked_to symbols are different, so I checked for LPFE[012].
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624866.html
    
            PR testsuite/110729
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/pr110729.c: New test.
Comment 5 Kewen Lin 2023-07-21 05:49:55 UTC

*** This bug has been marked as a duplicate of bug 99889 ***