[Issue 21120] New: Inconsistent mangling of __init symbol
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Aug  5 11:22:22 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=21120
          Issue ID: 21120
           Summary: Inconsistent mangling of __init symbol
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johanengelen at weka.io
Testcase:
File three.d:
```
module one.two.three;
StructTemplate!B instatiation;
struct B
{
}
struct StructTemplate(Opts)
{
    void foo()
    {
        someTemplate!StructTemplate();
    }
}
template someTemplate(T) {
    pragma(msg, "_D" ~ T.mangleof[1..$] ~ "6__initZ");
    pragma(mangle, "_D" ~ T.mangleof[1..$] ~ "6__initZ")
    extern immutable typeof(T.init) initializer;
    void someTemplate()
    {
        auto ptr = &initializer;
    }
}
```
> dmd -of=/tmp/wrongmangle.o -c three.d
output: _D3one3two5three__T14StructTemplateTSQBjQBiQBh1BZQBe6__initZ
> nm /tmp/wrongmangle.o | grep ".*StructTemplate.*__initZ"
outputs:
0000000000000270 S
__D3one3two5three__T14StructTemplateTS3oneQBjQBi1BZQBf6__initZ
                 U
__D3one3two5three__T14StructTemplateTSQBjQBiQBh1BZQBe6__initZ
00000000000001b8 S
__D60TypeInfo_S3one3two5three__T14StructTemplateTSQBjQBiQBh1BZQBe6__initZ
As you can see there is an undefined symbol: the one that we defined using
pragma(mangle). The mangling is just slightly off to what the compiler defines.
Note that the defined symbol
`__D3one3two5three__T14StructTemplateTS3oneQBjQBi1BZQBf6__initZ` contains "one"
twice. Somehow, the repeated identifier detection/encoding does not work. It
_does_ work for the TypeInfo symbol (and all other symbols related to
`StructTemplate!B`.
This inconsistency between `T.mangleof` and the init symbol mangling is a
blocker for implementing a druntime hack to access the init symbol similar to
this article: 
http://dpldocs.info/this-week-in-d/Blog.Posted_2020_07_27.html#zero-runtime-classes
--
    
    
More information about the Digitalmars-d-bugs
mailing list