https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81996
Segher Boessenkool <segher at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |segher at gcc dot gnu.org Known to fail| |8.0 --- Comment #4 from Segher Boessenkool <segher at gcc dot gnu.org> --- Hi! (In reply to Sergei Trofimovich from comment #2) > gcc master is slightly better here but is still inefficient in fPIC mode: > > gcc -O2 -fno-PIC: > > f: > mflr 3 > blr > > gcc -O2 -fPIC: > > f: > stwu 1,-16(1) > mflr 0 > stw 0,20(1) > stw 30,8(1) > lwz 9,0(1) > lwz 0,20(1) > lwz 3,4(9) > lwz 30,8(1) > mtlr 0 > addi 1,1,16 > blr This code looks fine. But it is *without* -fstack-protector-all, and with it indeed a problem shows up: === f: stwu 1,-48(1) mflr 0 stw 0,52(1) # save at old r1+4 stw 30,40(1) lwz 9,-28680(2) stw 9,28(1) li 9,0 lwz 9,32(1) # tries to get the old r1; but that is at r1+48 ! lwz 10,28(1) lwz 8,-28680(2) xor. 10,10,8 li 8,0 lwz 3,4(9) # and load from old r1+4 bne 0,.L5 lwz 0,52(1) lwz 30,40(1) addi 1,1,48 mtlr 0 blr .L5: bl __stack_chk_fail@plt === Confirmed. (Needs -m32).