This is an archive of the discontinued LLVM Phabricator instance.

[Symbolize][MinGW] Support demangling i386 call-conv-decorated C++ names
ClosedPublic

Authored by alvinhochun on Feb 14 2023, 2:50 PM.

Details

Summary

On i386 Windows, after C++ names have been Itanium-mangled, the C name
mangling specific to its call convention may also be applied on top.
This change teaches symbolizer to be able to demangle this type of
mangled names.

As part of this change, demanglePE32ExternCFunc has also been modified
to fix unwanted stripping for vectorcall names when the demangled name
is supposed to contain a leading _. Notice that the vectorcall
mangling does not add either an _ or @ prefix. The old code always
tries to strip the prefix first, which for Itanium mangled names in
vectorcall, the leading underscore of the Itanium name gets stripped
instead and breaks the Itanium demangler.

Diff Detail

Event Timeline

alvinhochun created this revision.Feb 14 2023, 2:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2023, 2:50 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
alvinhochun requested review of this revision.Feb 14 2023, 2:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2023, 2:50 PM
mstorsjo added inline comments.Feb 15 2023, 12:15 AM
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
674

I see that the demanglePE32ExternCFunc function is restructured a fair bit here, but I kinda fail to see exactly what the intent is - is this a functional change, and in what cases does it change the output/behaviour?

706

This part of the change makes sense!

I'm a bit undecided about whether the current flow in the function is the best/ideal/most correct one etc, but it probably works just right for all practical cases.

(For macho/darwin, where is the leading underscore stripped out?)

llvm/test/DebugInfo/symbolize-demangling-mingw32.s
22

Hmm, both this symbol and g above, aren't technically valid manglings on i386 at all (although they can be considered reasonable internal symbols anyway, where tools/users could use any names they want).

Would it be useful to add a test for a plain __cdecl function with C mangling, i.e. just a plain underscore prefix?

alvinhochun added inline comments.Feb 15 2023, 1:09 AM
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
674

It fixes some unwanted stripping for vectorcall names. Notice that the vectorcall mangling does not add either an _ or @ prefix. The old code always tries to strip the prefix first, which for Itanium mangled names in vectorcall, the leading underscore of the Itanium name gets stripped instead, which breaks the Itanium demangler.

706

For macho/darwin, where is the leading underscore stripped out?

Looks like it happens way earlier when loading symbols into SymbolizeObjectFile: https://github.com/llvm/llvm-project/blob/462227f1150fc4a12f95a7a101de477c06d35ba7/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp#L212-L214

llvm/test/DebugInfo/symbolize-demangling-mingw32.s
22

True, I agree it should test a mangled __cdecl C name, and I might as well also add a test each for the other calling conventions.

mstorsjo added inline comments.Feb 15 2023, 1:15 AM
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
674

Oh, I see - thanks!

I think it'd be good to call out this explicitly in the commit message, as it wasn't obvious to me on the first read through. Now after you've pointed it out, it's quite obvious though :-)

llvm/test/DebugInfo/symbolize-demangling-mingw32.s
22

Yeah, plain C symbols with all calling conventions would be good too - thanks!

alvinhochun edited the summary of this revision. (Show Details)

Update test and commit message as suggested.

mstorsjo accepted this revision.Feb 15 2023, 2:41 AM

LGTM, thanks!

This revision is now accepted and ready to land.Feb 15 2023, 2:41 AM

Thanks. I shall wait for the pre-merge checks to complete before committing. Can this still be backported to 16 now given we are already past rc2?

Thanks. I shall wait for the pre-merge checks to complete before committing. Can this still be backported to 16 now given we are already past rc2?

I guess that's up to @thieta and @tstellar; we can at least file the backport request and let them judge. The change in itself seems very low risk in any case.