View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038353 | FPC | Compiler | public | 2021-01-13 23:19 | 2021-01-15 00:18 |
Reporter | Pierre Muller | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | new | Resolution | open | ||
Product Version | 3.3.1 | ||||
Summary | 0038353: Internal x86_64 assembler generates wrong code with -Cg option | ||||
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 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 17c17 < 16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x8 --- > 16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4 20c20 < 23: R_X86_64_REX_GOTPCRELX U_$P$PROGRAM_$$_IS_ALIGNED-0x4 --- > 23: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4 25c25 < 33: R_X86_64_REX_GOTPCRELX U_$P$PROGRAM_$$_IS_ALIGNED-0x4 --- > 33: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4 27c27 < 3a: e8 00 00 00 00 callq 3f <U_$P$PROGRAM_$$_IS_ALIGNED+0x37> --- > 3a: e8 00 00 00 00 callq 3f <main+0x3f> 28a29 > ... | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | |||||
Attached Files |
|
|
Can you please also attach the logs you use? |
|
I suppose you mean the full output of objdump -dr muller@gcc10:~/pas/check$ fpc -iVDWSOSPTOTP 3.3.1 2021/01/14 3.3.1-r20:48150M linux x86_64 linux x86_64 (Note that this does not contain the last commit 48156) muller@gcc10:~/pas/check$ cat test-got-331-O2-Cg.log test-got.o: file format elf64-x86-64 Disassembly of section .text.n_main: 0000000000000000 <main>: 0: 50 push %rax 1: e8 00 00 00 00 callq 6 <main+0x6> 2: R_X86_64_PLT32 fpc_initializeunits-0x4 6: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # d <main+0xd> 9: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4 d: 48 89 c2 mov %rax,%rdx 10: 48 89 02 mov %rax,(%rdx) 13: 48 f7 05 00 00 00 00 testq $0xf,0x0(%rip) # 1e <main+0x1e> 1a: 0f 00 00 00 16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x4 1e: 74 10 je 30 <main+0x30> 20: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 27 <main+0x27> 23: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4 27: c6 00 00 movb $0x0,(%rax) 2a: eb 0e jmp 3a <main+0x3a> 2c: 0f 1f 40 00 nopl 0x0(%rax) 30: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 37 <main+0x37> 33: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_IS_ALIGNED-0x4 37: c6 00 01 movb $0x1,(%rax) 3a: e8 00 00 00 00 callq 3f <main+0x3f> 3b: R_X86_64_PLT32 fpc_do_exit-0x4 ... muller@gcc10:~/pas/check$ cat test-got-331-O2-Cg-al.log test-got.o: file format elf64-x86-64 Disassembly of section .text.n_main: 0000000000000000 <main>: 0: 50 push %rax 1: e8 00 00 00 00 callq 6 <main+0x6> 2: R_X86_64_PLT32 fpc_initializeunits-0x4 6: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # d <main+0xd> 9: R_X86_64_REX_GOTPCRELX U_$P$PROGRAM_$$_P-0x4 d: 48 89 c2 mov %rax,%rdx 10: 48 89 02 mov %rax,(%rdx) 13: 48 f7 05 00 00 00 00 testq $0xf,0x0(%rip) # 1e <main+0x1e> 1a: 0f 00 00 00 16: R_X86_64_GOTPCREL U_$P$PROGRAM_$$_P-0x8 1e: 74 10 je 30 <main+0x30> 20: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 27 <main+0x27> 23: R_X86_64_REX_GOTPCRELX U_$P$PROGRAM_$$_IS_ALIGNED-0x4 27: c6 00 00 movb $0x0,(%rax) 2a: eb 0e jmp 3a <main+0x3a> 2c: 0f 1f 40 00 nopl 0x0(%rax) 30: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 37 <main+0x37> 33: R_X86_64_REX_GOTPCRELX U_$P$PROGRAM_$$_IS_ALIGNED-0x4 37: c6 00 01 movb $0x1,(%rax) 3a: e8 00 00 00 00 callq 3f <U_$P$PROGRAM_$$_IS_ALIGNED+0x37> 3b: R_X86_64_PLT32 fpc_do_exit-0x4 |
|
I forgot this: muller@gcc10:~/pas/check$ as --version GNU assembler (GNU Binutils for Debian) 2.28 Copyright (C) 2017 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or later. This program has absolutely no warranty. This assembler was configured for a target of `x86_64-linux-gnu'. |
|
I just recompiled binutils 2.35 on gcc10, the output is the same as with binutils 2.28 for that source code. |
Date Modified | Username | Field | Change |
---|---|---|---|
2021-01-13 23:19 | Pierre Muller | New Issue | |
2021-01-14 21:55 | Florian | Note Added: 0128326 | |
2021-01-15 00:05 | Pierre Muller | Note Added: 0128333 | |
2021-01-15 00:06 | Pierre Muller | Note Added: 0128334 | |
2021-01-15 00:18 | Pierre Muller | Note Added: 0128335 |