[llvm-nm] Demangle Rust symbols

Add support for demangling Rust v0 symbols to llvm-nm by reusing
nonMicrosoftDemangle which supports both Itanium and Rust mangling.

Reviewed By: dblaikie, jhenderson

Differential Revision: https://reviews.llvm.org/D111937
This commit is contained in:
Tomasz Miąsko 2021-10-16 14:10:31 +02:00
parent c57ca33547
commit c3e07df607
2 changed files with 19 additions and 15 deletions

View File

@ -28,17 +28,27 @@ entry:
ret float 0.000000e+00
}
define i32 @_RNvC1a3baz(i32) #0 {
entry:
ret i32 1
}
; MANGLED: 0000000000000020 T _RNvC1a3baz
; MANGLED: 0000000000000010 T _Z3barf
; MANGLED: 0000000000000000 T _Z3fooi
; MACHO-MANGLED: 0000000000000020 T __RNvC1a3baz
; MACHO-MANGLED: 0000000000000010 T __Z3barf
; MACHO-MANGLED: 0000000000000000 T __Z3fooi
; COFF-MANGLED: 00000020 T _RNvC1a3baz
; COFF-MANGLED: 00000010 T _Z3barf
; COFF-MANGLED: 00000000 T _Z3fooi
; DEMANGLED: 0000000000000020 T a::baz
; DEMANGLED: 0000000000000010 T bar(float)
; DEMANGLED: 0000000000000000 T foo(int)
; COFF-DEMANGLED: 00000020 T a::baz
; COFF-DEMANGLED: 00000010 T bar(float)
; COFF-DEMANGLED: 00000000 T foo(int)

View File

@ -599,22 +599,16 @@ static void darwinPrintStab(MachOObjectFile *MachO, const NMSymbol &S) {
outs() << format(" %02x", NType);
}
static Optional<std::string> demangle(StringRef Name, bool StripUnderscore) {
if (StripUnderscore && !Name.empty() && Name[0] == '_')
Name = Name.substr(1);
static Optional<std::string> demangle(const std::string &Name,
bool StripUnderscore) {
const char *Mangled = Name.c_str();
if (StripUnderscore && Mangled[0] == '_')
Mangled = Mangled + 1;
if (!Name.startswith("_Z"))
return None;
int Status;
char *Undecorated =
itaniumDemangle(Name.str().c_str(), nullptr, nullptr, &Status);
if (Status != 0)
return None;
std::string S(Undecorated);
free(Undecorated);
return S;
std::string Demangled;
if (nonMicrosoftDemangle(Mangled, Demangled))
return Demangled;
return None;
}
static bool symbolIsDefined(const NMSymbol &Sym) {