[Issue 23650] New: Using typeid with struct defined in in __traits(compiles, ...) causes linker error
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 23 08:53:23 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23650
Issue ID: 23650
Summary: Using typeid with struct defined in in
__traits(compiles, ...) causes linker error
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: blocker
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: teodor.dutu at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list