https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101324
Bug ID: 101324
Summary: powerpc64le: hashst appears before mflr at -O1 or
higher
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: tuliom at ascii dot art.br
Target Milestone: ---
Created attachment 51105
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51105&action=edit
__memmove_ppc extracted from glibc
When using ROP (-mrop-protect), it's expected that generated code reads the
value from LR (mflr) and hash it later (hashst).
This works well at -O0.
However, at -O1 and higher, we're seeing cases where hashst appears before
mflr.
I'm attaching an example extracted from glibc.
You can reproduce the issue with command:
gcc -S -O1 -mrop-protect -mcpu=power10 memmove-ppc64.i -o -
The generated asm contains the following:
__memmove_ppc:
.LFB6:
.cfi_startproc
.localentry __memmove_ppc,1
hashst 0,-40(1)
std 28,-32(1)
stdu 1,-80(1)
.cfi_def_cfa_offset 80
.cfi_offset 28, -32
mr 28,3
subf 9,4,3
cmpld 0,9,5
bge 0,.L17
std 31,72(1)
.cfi_offset 31, -8
add 4,4,5
add 31,3,5
cmpldi 0,5,15
ble 0,.L4
mflr 0
...