Why export external(C) generate mangled names?
mipri
mipri at minimaltype.com
Fri Oct 25 15:27:40 UTC 2019
On Friday, 25 October 2019 at 10:31:15 UTC, Suliman wrote:
> I thought that export extern(C) is needed for C compatibility.
This is only the case for toplevel functions. If there's any
nesting,
you still get D mangling but you get C calling conventions.
> But When I am compiling follow code
>
> export extern(C)
> {
> void foo()
> {
> }
> }
There's no mangling with this code for me. I have to add a struct
{}
around it to see mangling.
>
> I am getting section that have mangled names:
>
Look with: objdump -dwr --no-show-raw-insn <filename>
You'll get output like
000000000042d5f8 <foo>:
42d5f8: push %rbp
42d5f9: mov %rsp,%rbp
42d5fc: pop %rbp
42d5fd: retq
...
000000000042d600 <_D4x1244test3barMUZv>:
42d600: push %rbp
42d601: mov %rsp,%rbp
42d604: pop %rbp
42d605: retq
for
extern(C) void foo() {}
struct test {
export extern(C) {
void bar() {}
}
}
A note about this was added to the documentation with
https://github.com/dlang/dlang.org/pull/1911/files
but it might be easy to miss since it's not in InterfaceToC
More information about the Digitalmars-d
mailing list