Bug 24168 – Corrupted if TLS values are passed in ref parameters when compiling with -fPIE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-09-28T07:12:01Z
Last change time
2023-10-20T06:04:52Z
Keywords
pull
Assigned to
No Owner
Creator
[email protected]

Comments

Comment #0 by hinoda2002 — 2023-09-28T07:12:01Z
DMD version: v2.105.2 Linux Kernel: 5.15 Distro: Ubuntu 22.04 Code: ---- int i = 42; bool foo(ref int a) { return a == 42; } void main() { assert(foo(i)); } --- Output(console): --- $ dmd -fPIE -g -run pie.d [email protected](10): Assertion failure ---------------- ??:? [0x55b076c2bc48] ??:? [0x55b076c3cabb] ??:? [0x55b076c2bba1] ??:? [0x55b076c26721] ??:? [0x55b076c26501] ??:? [0x55b076c21fa5] ??:? [0x55b076c21800] ./pie.d:10 [0x55b076c21759] ??:? [0x55b076c21de6] ??:? [0x55b076c21c95] ??:? [0x55b076c21d6e] ??:? [0x55b076c21c95] ??:? [0x55b076c21bfe] ??:? [0x55b076c219e7] /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/core/internal/entrypoint.d:29 [0x55b076c21781] ??:? [0x7f596d0ffd8f] ??:? __libc_start_main [0x7f596d0ffe3f] ??:? [0x55b076c21654] --- Output(binary): --- $ objdump -dr -Mintel pie.o (snip) Disassembly of section .text._Dmain: 0000000000000000 <_Dmain>: 0: 55 push rbp 1: 48 8b ec mov rbp,rsp 4: 66 48 8d 3d 00 00 00 data16 lea rdi,[rip+0x0] # c <_Dmain+0xc> b: 00 8: R_X86_64_TPOFF32 _D3pie1ii-0x4 c: e8 00 00 00 00 call 11 <_Dmain+0x11> d: R_X86_64_PC32 _D3pie3fooFKiZb-0x4 11: 84 c0 test al,al 13: 75 11 jne 26 <_Dmain+0x26> 15: be 0a 00 00 00 mov esi,0xa 1a: 48 8d 3d 00 00 00 00 lea rdi,[rip+0x0] # 21 <_Dmain+0x21> 1d: R_X86_64_PC32 .rodata.str1.1-0x4 21: e8 00 00 00 00 call 26 <_Dmain+0x26> 22: R_X86_64_PLT32 _d_assertp-0x4 26: 31 c0 xor eax,eax 28: 5d pop rbp 29: c3 ret --- I guess this is a codegen bug, _Dmain should be something like this: --- 0000000000000000 <_Dmain>: 0: 55 push rbp 1: 48 8b ec mov rbp,rsp 4: 31 c0 xor eax,eax 6: 64 48 8b 08 mov rcx,QWORD PTR fs:[rax] a: 48 8d b9 00 00 00 00 lea rdi,[rcx+0x0] d: R_X86_64_TPOFF32 _D3pie1ii 11: e8 00 00 00 00 call 16 <_Dmain+0x16> 12: R_X86_64_PC32 _D3pie3fooFPiZb-0x4 16: 84 c0 test al,al 18: 75 11 jne 2b <_Dmain+0x2b> 1a: be 0a 00 00 00 mov esi,0xa 1f: 48 8d 3d 00 00 00 00 lea rdi,[rip+0x0] # 26 <_Dmain+0x26> 22: R_X86_64_PC32 .rodata.str1.1-0x4 26: e8 00 00 00 00 call 2b <_Dmain+0x2b> 27: R_X86_64_PLT32 _d_assertp-0x4 2b: 31 c0 xor eax,eax 2d: 5d pop rbp 2e: c3 ret ---
Comment #1 by hinoda2002 — 2023-09-28T07:16:31Z
I've tried with DMD2.088 (which -fPIE was introduced) and got the same result. Perhaps it has been this way all along.
Comment #2 by dlang-bot — 2023-10-18T01:42:45Z
@kubo39 created dlang/dmd pull request #15705 "Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters" fixing this issue: - Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters when compiling with -fPIE https://github.com/dlang/dmd/pull/15705
Comment #3 by dlang-bot — 2023-10-20T06:04:52Z
dlang/dmd pull request #15705 "Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters" was merged into master: - fe858d91b7df8a770765f78286395259cca0f697 by Hiroki Noda: Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters when compiling with -fPIE https://github.com/dlang/dmd/pull/15705