[llvm] c3e07df - [llvm-nm] Demangle Rust symbols
Tomasz Miąsko via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 03:53:06 PST 2021
Author: Tomasz Miąsko
Date: 2021-11-12T12:46:59+01:00
New Revision: c3e07df6076045540574ce4fa5362742b52d91db
URL: https://github.com/llvm/llvm-project/commit/c3e07df6076045540574ce4fa5362742b52d91db
DIFF: https://github.com/llvm/llvm-project/commit/c3e07df6076045540574ce4fa5362742b52d91db.diff
LOG: [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
Added:
Modified:
llvm/test/tools/llvm-nm/X86/demangle.ll
llvm/tools/llvm-nm/llvm-nm.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-nm/X86/demangle.ll b/llvm/test/tools/llvm-nm/X86/demangle.ll
index b9f4b05241a25..cab2e09cc1d49 100644
--- a/llvm/test/tools/llvm-nm/X86/demangle.ll
+++ b/llvm/test/tools/llvm-nm/X86/demangle.ll
@@ -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)
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 2754dac46986d..0864985377cef 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -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);
-
- 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;
+static Optional<std::string> demangle(const std::string &Name,
+ bool StripUnderscore) {
+ const char *Mangled = Name.c_str();
+ if (StripUnderscore && Mangled[0] == '_')
+ Mangled = Mangled + 1;
+
+ std::string Demangled;
+ if (nonMicrosoftDemangle(Mangled, Demangled))
+ return Demangled;
+ return None;
}
static bool symbolIsDefined(const NMSymbol &Sym) {
More information about the llvm-commits
mailing list