[PATCH] D111937: [llvm-nm] Demangle Rust symbols
Tomasz Miąsko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 16 05:16:04 PDT 2021
tmiasko created this revision.
tmiasko added reviewers: dblaikie, jhenderson.
Herald added subscribers: rupprecht, JDevlieghere.
tmiasko requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
Add support for demangling Rust v0 symbols to llvm-nm by reusing
nonMicrosoftDemangle which supports both Itanium and Rust mangling.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111937
Files:
llvm/test/tools/llvm-nm/X86/demangle.ll
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -599,22 +599,16 @@
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) {
Index: llvm/test/tools/llvm-nm/X86/demangle.ll
===================================================================
--- llvm/test/tools/llvm-nm/X86/demangle.ll
+++ llvm/test/tools/llvm-nm/X86/demangle.ll
@@ -28,17 +28,27 @@
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111937.380173.patch
Type: text/x-patch
Size: 2109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211016/035d3ef6/attachment.bin>
More information about the llvm-commits
mailing list