Partial Fix Issue 8578 - Demangle special symbols (__init, __Class, etc.... #725
Conversation
I think it should probably have a list of the symbols that are special-cased. You can find them by grepping the compiler source for calls to |
I don't think that demangling these special symbols is correct. Although they looks like D mangled symbols, they are not correct D language symbols. That's similar to C++ mangled symbols. |
@9rnsr I see your point, but these are mangled symbols produced only by D programming language compilers. As a practical matter, users of D will want to demangle these symbols, and if D library demanglers can't demangle them, then who will? |
No one. They are not D symbols, so they have no demangle names. I think we should follow the principle. |
I wonder why these have special mangling to start with. I think that should be changed in the compiler, using double-underscore prefixed names is enough to mark them "special". |
Because to prevent conflict with normal D symbols. Note that, the special symbols should reflect D's module scope - for example, the TypeInfo symbols for struct |
Why? If a user is seeing them in an error message, we might as well demangle them into a more human-friendly form. Isn't that the whole point of demangle? |
At the very least they should be demangled in stack traces. |
None of these appear in stack traces, they are typinfo/classinfo/vtbl etc |
Although I guess they could appear in linker errors? In that case a tool like RDMD could use |
Yep, all the time. |
I'm not sure I can follow. The mangling of static struct members preserves module info aswell. They could mangle just as that, the double underscore marks them as "special", very much like __ctor, __modtest, __unittest and others. |
We should make those symbols compliant to http://dlang.org/abi.html, either by chaging the ABI specs or the compiler. The simplest fix would be to reserve a mangling type for compiler/runtime internal data. |
@MartinNowak I assigned this to you :) |
Can't we just augment the mangling rules to say that the type 'Z' is for compiler internal symbols? |
I don't agree that we should not demangle these. The current situation makes debugging very difficult because these symbols are referenced all over the place, but unless you can demangle D symbols in your head, they are basically unreadable (ddemangle does not demangle them). If they don't follow current mangling rules, then we should either make them follow the rules, or we should change the rules to include them as special cases. I don't agree that people should be expected to know compiler internals just to be able to tell, for example, that a module constructor is being referenced, that's just an artificial unnecessary barrier to debugging. |
ping |
I'll see if I can add these to the spec and rebase. |
See discussion here: dlang/druntime#725 D already creates mangled names using the Z symbol for internal symbols, e.g. _D3foo3Bar6__vtblZ for the virtual table for class foo.Bar. The ABI makes no mention of these symbols. This pull request adds Z to the mangling ABI to make these official symbols. The linked pull request implements that demangling.
Rebased and updated to list symbols. ABI spec udpate here: dlang/dlang.org#628 |
LGTM. Let's do this. The D demangler really needs to be able to deal with these symbols. |
Auto-merge toggled on |
This reminds me, I should get around to modifying the original demangler to not use exceptions to parse, unless someone else wants to? |
Partial Fix Issue 8578 - Demangle special symbols (__init, __Class, etc....
That would be great. I always thought it to be very bad to use exceptions within the exception handler. The win32 druntime unittest usually crash for me if I don't run cv2pdb on it, and I suspect it is caused by this. |
That would be highly appreciated. |
Exceptions are only thrown on a buffer overrun, which isn't an expected occurrence. Is this really necessary? |
To elaborate, it should be possible to use demangle anywhere in D, and so from the outset I'd basically intended it to be @nogc, except that attribute didn't exist. It may be worth having two overloads to demangle--one where an output buffer is supplied and another where one is not. The one without would catch and reallocate and the other would return an error on buffer overrun. I absolutely don't want the code to be growing the buffer as needed as writes occur. |
Mostly fixes Issue 8578. The last case still contains mangled text, but the first four are fixed.
https://d.puremagic.com/issues/show_bug.cgi?id=8578