llvm / llvm/llvm-project

[PowerPC] On PPC64LE, clang -fpatchable-function-entry=1 records function beginning instead of first NOP emitted

Open
#163,706 5 comments 0 reactions 0 assignees View on GitHub
backend:PowerPC
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

On PPC64 little-endian Linux -fpatchable-function-entry support is added with PR#151569. __patchable_function_entries records the current function beginning when there are no prefix NOPs. But on ppc64le, this ends up pointing at Global Entry Point instead of the first NOP emitted.

> $ cat test.c
> __attribute__((noinline)) void foo(void) {}
>
> int main() {
> foo();
> return 0;
> }
> $
> $
> $
> $ clang -g -O0 -fpatchable-function-entry=1 -c test.c -o test.o
> $
> $
> $
> $ objdump -d test.o
>
> test.o: file format elf64-powerpcle
>
>
> Disassembly of section .text:
>
> 0000000000000000 :
> 0: 00 00 00 60 nop
> 4: 20 00 80 4e blr
> ...
> 14: 00 00 00 60 nop
> 18: 00 00 00 60 nop
> 1c: 00 00 00 60 nop
>
> 0000000000000020 :
> 20: 00 00 4c 3c addis r2,r12,0
> 24: 00 00 42 38 addi r2,r2,0
> 28: 00 00 00 60 nop
> 2c: a6 02 08 7c mflr r0
> 30: f8 ff e1 fb std r31,-8(r1)
> 34: 91 ff 21 f8 stdu r1,-112(r1)
> 38: 80 00 01 f8 std r0,128(r1)
> 3c: 78 0b 3f 7c mr r31,r1
> 40: 00 00 60 38 li r3,0
> 44: 64 00 7f 90 stw r3,100(r31)
> 48: 01 00 00 48 bl 48
> 4c: 00 00 00 60 nop
> 50: 00 00 60 38 li r3,0
> 54: 70 00 21 38 addi r1,r1,112
> 58: 10 00 01 e8 ld r0,16(r1)
> 5c: f8 ff e1 eb ld r31,-8(r1)
> 60: a6 03 08 7c mtlr r0
> 64: 20 00 80 4e blr
> ...
> $
> $
> $
> $ objdump -r -j __patchable_function_entries test.o
>
> test.o: file format elf64-powerpcle
>
> RELOCATION RECORDS FOR [__patchable_function_entries]:
> OFFSET TYPE VALUE
> 0000000000000000 R_PPC64_ADDR64 .text
>
>
> RELOCATION RECORDS FOR [__patchable_function_entries]:
> OFFSET TYPE VALUE
> 0000000000000000 R_PPC64_ADDR64 .text+0x0000000000000020
>
>
> $

Expected the second record to point at .text+0x28 instead of .text+0x20

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided test.c example using clang -g -O0 -fpatchable-function-entry=1 and inspect the PPC64LE handling of __patchable_function_entries. Compare the relocation output from objdump with the disassembly; done means the second record points to .text+0x28, the first NOP, rather than .text+0x20.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.