On OS X, all symbol names by default have a leading underscore. For example, the C `printf` function is represented as `_printf`. This mangling scheme is expected at least by the system GDB and several other tools, which strip the leading underscore when rendering symbol names. Currently (DMD 2.060 Git), however, extern(D) symbols only have a single leading underscore as well. For example, `void foo()` in a module called test becomes `_D4test3fooFZv`, which in turn would be displayed by GDB as `D4test3fooFZv` This seems wrong, as the D ABI requires a leading underscore as part of the symbol name itself. If another underscore was added, it would e.g. the above function to be correctly displayed in GDB as `_D4test3fooFZv`. This is not merely a cosmetic issue, as other compilers have to follow the same ABI. My proposal would be to modify the Mach obj backend of DMD to also emit the additional underscore, instead of modifying LDC (and possibly GDC as well), because: 1) It would cause the names to be displayed as described in the spec in the tools. 2) The LLVM toolchain adds the underscore automatically, which seems to be a strong indication of the common practice, and 3) indeed, GCC also emits C++ functions with two underscores, e.g. __ZN4llvm10error_code7successEv (and the ABI describes the mangling with a single leading underscore as well). I already have a set of changes for this ready to be submitted as a pull request, in case this route is agreed on.
The D demangling code in newer GDB versions also seems to expect two underscores, see issue 8172. Will try to test my changes more thoroughly and put together a pull request asap.
I would think yes, D symbols emitted to the object file on OS X should have extra underscore. And .mangleof should produce the symbol without the extra underscore as it does today. extern(C++) has opposite problem. The extra underscore is present in object file (correct) but is also present in .mangleof symbol. It should be stripped from the .mangleof symbol. Note: ldc merge-2.067 does this now which caused test compilable/test7030.d to fail, which is how I got here. I think LDC is correct. -- demo -- void dfun(int); extern(C++) void cxxfun(int); extern (C) void cfun(int); pragma(msg, dfun.mangleof); pragma(msg, cxxfun.mangleof); pragma(msg, cfun.mangleof); dmd 2.067 produces: _D10showmangle4dfunFiZv __Z6cxxfuni cfun where obj file has these symbols: U _D10showmangle4dfunFiZv U __Z6cxxfuni U _cfun
*** Issue 15748 has been marked as a duplicate of this issue. ***
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/db2976599db44f2163986ba9cb541afd7cfa8471 fix Issue 8207 - extern(D) symbols should include another underscore 1. Removed ABI name fiddling from the front-end. 2. Removed `Target.prefixName` and C++ tests for matching `__Z`. 3. Prepend prefixes for C++ and D symbols in the backend only for the targets that require it (Win32, OSX). 4. Removed `RTLSYM__DINVARIANT` runtime library symbol, name is now the same on all targets. 5. Correctly set C++ mangling on `LINK.cpp` symbols, before they were all being set as D mangled symbols. 6. Use System mangling as synonym for do not modify symbol. 7. Added workaround for `extern(D) ___tls_get_addr`. https://github.com/dlang/dmd/commit/9691eba9441f7f165359716f80f46486ea09fb46 Merge pull request #7620 from ibuclaw/ingcc2 fix Issue 8207 - extern(D) symbols should include another underscore merged-on-behalf-of: unknown