https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93194

            Bug ID: 93194
           Summary: -fpatchable-function-entries :
                    __patchable_function_entries has wrong sh_flags and
                    sh_addralign
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

% cat a.c
void f(){}
% gcc -fpatchable-function-entry=3 -c a.c
% readelf -S a.o
...
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00     
0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040 00000a 00  AX 
0   0  1
  [ 2] .data             PROGBITS        0000000000000000 00004a 000000 00  WA 
0   0  1
  [ 3] .bss              NOBITS          0000000000000000 00004a 000000 00  WA 
0   0  1
  [ 4] __patchable_function_entries PROGBITS        0000000000000000 00004a
000008 00   A  0   0  1
  [ 5] .rela__patchable_function_entries RELA            0000000000000000
0001a0 000018 18   I 10   4  8


sh_addralign of __patchable_function_entries should be 8 on ELF64 platforms, 4
on ELF32 platforms, instead of 1.

__patchable_function_entries should have the SHF_WRITE flag. A
__patchable_function_entries entry is relocated by a symbolic relocation (e.g.
R_X86_64_64, R_AARCH64_ABS64, R_PPC64_ADDR64).
In -shared or -pie mode, the linker will create a dynamic relocation,

* non-preemptible (STB_LOCAL / non-STV_DEFAULT / -Bsymbolic / not-shared /
--dynamic-list excluded / etc): relative relocation (e.g. R_X86_64_RELATIVE)
* preemptible: symbolic relocation (e.g. R_X86_64_64)


(We can't emit an offset relative to the image base (.quad .Lfoo - .Lbase),
because differences across sections are generally not representable. A symbolic
relocation gives the runtime code information about the symbol names, which may
be desirable.)

Reply via email to