Bug 23650 – Using typeid with struct defined in in __traits(compiles, ...) causes linker error

Status
REOPENED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-01-23T08:53:23Z
Last change time
2024-12-13T19:26:54Z
Keywords
pull
Assigned to
No Owner
Creator
Teodor Dutu
Moved to GitHub: dmd#18149 →

Comments

Comment #0 by teodor.dutu — 2023-01-23T08:53:23Z
The following code compiles fine to the object file, but linking fails with: /usr/bin/ld: implicit.o:(.data._D41TypeInfo_S8bug4mainFZ9__lambda1MFZ1S6__initZ+0x28): undefined reference to `_D8bug4mainFZ9__lambda1MFZ1S6__initZ' --- __gshared int x; void main() { static assert(__traits(compiles, { struct S { int *p = &x; } auto t = typeid(S); })); } --- The reason is that the init symbol of the TypeInfo is defined and requires a relocation to S.init which is undefined: $ readelf -r bug.o [...] Relocation section '.rela.data._D36TypeInfo_S3bug4mainFZ9__lambda1MFZ1S6__initZ' at offset 0x900 contains 5 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000000 001f00000001 R_X86_64_64 0000000000000000 _D15TypeInfo_Struct6__ + 0 000000000018 001b00000001 R_X86_64_64 0000000000000000 _D36TypeInfo_S3bug4mai + 88 000000000028 002000000001 R_X86_64_64 0000000000000000 _D3bug4mainFZ9__lambda + 0 000000000070 002100000001 R_X86_64_64 0000000000000000 _D10TypeInfo_l6__initZ + 0 000000000080 002200000001 R_X86_64_64 0000000000000000 _D6object__T10RTInfoIm + 0 This is blocking https://github.com/dlang/dmd/pull/14664.
Comment #1 by dlang-bot — 2023-01-24T13:14:45Z
@RazvanN7 created dlang/dmd pull request #14844 "Fix Issue 23650 - Using typeid with struct defined in in __traits(compiles, ...) causes linker error" fixing this issue: - Fix Issue 23650 - Using typeid with struct defined in in __traits(compiles, ...) causes linker error https://github.com/dlang/dmd/pull/14844
Comment #2 by dlang-bot — 2023-01-26T10:25:42Z
dlang/dmd pull request #14844 "Fix Issue 23650 - Using typeid with struct defined in __traits(compiles, ...) causes linker error" was merged into master: - 8c4151300d4d4160fb00208d65b2e38e3b7e4b23 by RazvanN7: Fix Issue 23650 - Using typeid with struct defined in __traits(compiles, ...) causes linker error https://github.com/dlang/dmd/pull/14844
Comment #3 by kinke — 2024-07-02T17:36:22Z
Reopening, as the fix was reverted in v2.110, as it introduced a regression (https://issues.dlang.org/show_bug.cgi?id=24599), in https://github.com/dlang/dmd/pull/15868.
Comment #4 by robert.schadek — 2024-12-13T19:26:54Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18149 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB