Bug 22489 – C header generation ignores custom mangling
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-11-07T19:46:33Z
Last change time
2022-03-27T12:20:06Z
Keywords
pull
Assigned to
No Owner
Creator
Richard Cattermole
Comments
Comment #0 by alphaglosined — 2021-11-07T19:46:33Z
```d
import std.traits : Parameters;
class Type {
this() {}
}
pragma(msg, creator.mangleof); // _D9onlineapp7creatorFZPv
pragma(mangle, "create_" ~ __traits(identifier, Type))
export extern(C) void* creator(Parameters!(Type.__ctor) args) {
pragma(msg, creator.mangleof); // create_Type
return cast(void*)(new Type(args));
}
pragma(msg, creator.mangleof); // create_Type
```
The assembly for creator is create_Type but with -HC it is being generated as creator.
Comment #1 by moonlightsentinel — 2022-01-21T18:50:42Z
`extern(C)` functions should just be exported by using the custom mangle as the identifier. `extern(C++)` functions probably need to be ignored because C++ doesn't have something like `pragma(mangle)`
Comment #2 by dlang-bot — 2022-03-27T10:37:50Z
@MoonlightSentinel created dlang/dmd pull request #13895 "Fix 22489 - dtoh: Handle custom mangling for functions (and globals)" fixing this issue:
- Fix 22489 - dtoh: Handle custom mangling for functions (and globals)
Explicit mangling provided via `pragma(mangle, "..")` cannot be mapped
to C++. For `extern(C)` function it's possible to emulate the behavior
by replacing the identifier with the custom mangling. This doesn't work
for `extern(C++)` functions, so they are ignored.
The same rationale + solution applies to global variables with custom
mangling.
https://github.com/dlang/dmd/pull/13895
Comment #3 by dlang-bot — 2022-03-27T12:20:06Z
dlang/dmd pull request #13895 "Fix 22489 - dtoh: Handle custom mangling for functions (and globals)" was merged into master:
- 0a2409ecb346f0fd3158c895574da755a8da3f1c by MoonlightSentinel:
Fix 22489 - dtoh: Handle custom mangling for functions (and globals)
Explicit mangling provided via `pragma(mangle, "..")` cannot be mapped
to C++. For `extern(C)` function it's possible to emulate the behavior
by replacing the identifier with the custom mangling. This doesn't work
for `extern(C++)` functions, so they are ignored.
The same rationale + solution applies to global variables with custom
mangling.
https://github.com/dlang/dmd/pull/13895