Internal x86_64 assembler generates wrong code with -Cg option
Original Reporter info from Mantis: Pierre @PierreMuller
-
Reporter name: Pierre Muller
Original Reporter info from Mantis: Pierre @PierreMuller
- Reporter name: Pierre Muller
Description:
Current trunk compiler using internal and external assembler generate different relocation code with -O2 option.
For x86_64-openbsd target, -Cg option is default (generate_pic_code),
which leads to
https://www.freepascal.org/testsuite/cgi-bin/new-testsuite2.cgi?run1id=550120&run2id=550150&previousrunid=549871&noskipped=1&failedonly=1&action=Show%2FCompare
Example code below is extracted from tvectorcall1.pp test,
I do not know the exact difference between R_X86_64_REX_GOTPCRELX and R_X86_64_GOTPCREL,
but the main issue it the offset for this relocation is wrong in the internal assembler
17c17
< 16: R_X86_64_GOTPCREL U_P
PROGRAM_$$_P-0x8
---
16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4<br/>
leading to the loading of a GOT entry in-between two real entries.
This error exists at least for x86_64-linux and x86_64-openbsd
(the later does not require the -Cg option, as it is default)
Steps to reproduce:
Compile test-got.pp (in between >>>> lines)
var
p : pointer;
is_aligned : boolean;
begin
p:=@p;
if (PtrUInt(@p) and $F) <> 0 then
is_aligned:=false
else
is_aligned:=true;
end.
ppcx64 -O2 -Cg test-got
objdump -dr test-got.o > test-got-trunk-O2-Cg.log
ppcx64 -O2 -Cg -al test-got
objdump -dr test-got.o > test-got-trunk-O2-Cg-al.log
diff test-got-trunk-O2-Cg-al.log test-got-trunk-O2-Cg.log
gives the following output:
muller@gcc10:~/pas/check$ diff test-got-trunk-O2-Cg-al.log test-got-trunk-O2-Cg.log
12c12
< 9: R_X86_64_REX_GOTPCRELX U_P
PROGRAM_$$_P-0x4
---
9: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4<br/>
17c17
< 16: R_X86_64_GOTPCREL U_P
PROGRAM_$$_P-0x8
---
16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4<br/>
20c20
< 23: R_X86_64_REX_GOTPCRELX U_P
PROGRAM_$$_IS_ALIGNED-0x4
---
23: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4<br/>
25c25
< 33: R_X86_64_REX_GOTPCRELX U_P
PROGRAM_$$_IS_ALIGNED-0x4
---
33: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4<br/>
27c27
< 3a: e8 00 00 00 00 callq 3f &LtPos;U_P
PROGRAM_$$_IS_ALIGNED+0x37>
---
3a: e8 00 00 00 00 callq 3f &LtPos;main+0x3f>
28a29
...
Mantis conversion info:
- Mantis ID: 38353
- Version: 3.3.1
- Fixed in revision: 49252 (#17e3c31b)