[PATCH] D113106: demangle xcoff label symbol for llvm-nm
Digger Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 19 11:34:14 PST 2021
DiggerLin updated this revision to Diff 388581.
DiggerLin added a comment.
add a empty symbol name test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113106/new/
https://reviews.llvm.org/D113106
Files:
llvm/test/tools/llvm-nm/XCOFF/demangle.test
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
@@ -619,10 +619,7 @@
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(StringRef Name) {
if (!Name.startswith("_Z"))
return None;
@@ -637,6 +634,24 @@
return S;
}
+static Optional<std::string> demangleXCOFF(StringRef Name) {
+ if (!Name.empty() && Name[0] == '.')
+ Name = Name.substr(1);
+ else
+ return demangle(Name);
+
+ Optional<std::string> DemangledName = demangle(Name);
+ if (DemangledName)
+ return "." + *DemangledName;
+ return None;
+}
+
+static Optional<std::string> demangleMachO(StringRef Name) {
+ if (!Name.empty() && Name[0] == '_')
+ Name = Name.substr(1);
+ return demangle(Name);
+}
+
static bool symbolIsDefined(const NMSymbol &Sym) {
return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v';
}
@@ -725,7 +740,12 @@
std::string Name = S.Name;
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
if (Demangle) {
- if (Optional<std::string> Opt = demangle(S.Name, MachO))
+ function_ref<Optional<std::string>(StringRef)> Fn = ::demangle;
+ if (Obj.isXCOFF())
+ Fn = demangleXCOFF;
+ if (Obj.isMachO())
+ Fn = demangleMachO;
+ if (Optional<std::string> Opt = Fn(S.Name))
Name = *Opt;
}
if (S.Sym.getRawDataRefImpl().p) {
Index: llvm/test/tools/llvm-nm/XCOFF/demangle.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/XCOFF/demangle.test
@@ -0,0 +1,31 @@
+## Test llvm-nm demangling of symbols for XCOFF object files.
+# RUN: llvm-nm --demangle %p/Inputs/test_xlclang.o | FileCheck --check-prefix=NM-DEMANGLE %s
+
+## test_xlclang.o is generated by the following source compiled with IBM xlclang++ in aix os.
+## int value = 0;
+##
+## __attribute__ ((weak)) int weak_value = 5;
+##
+## static int func0 () {
+## return value;
+## }
+##
+## int func1 (int i) {
+## return func0() * i;
+## }
+
+# NM-DEMANGLE: 00000000 t
+# NM-DEMANGLE-NEXT: 00000040 T .func1(int)
+# NM-DEMANGLE-NEXT: 00000000 t .func0()
+# NM-DEMANGLE-NEXT: 00000120 b .bss
+# NM-DEMANGLE-NEXT: 00000100 d .data
+# NM-DEMANGLE-NEXT: 00000000 f .file
+# NM-DEMANGLE-NEXT: 00000000 t .text
+# NM-DEMANGLE-NEXT: 00000100 d TOC
+# NM-DEMANGLE-NEXT: 00000104 d func1(int)
+# NM-DEMANGLE-NEXT: 0000010c D func1(int)
+# NM-DEMANGLE-NEXT: 00000100 d value
+# NM-DEMANGLE-NEXT: 00000118 D value
+# NM-DEMANGLE-NEXT: 00000108 d weak_value
+# NM-DEMANGLE-NEXT: 0000011c W weak_value
+~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113106.388581.patch
Type: text/x-patch
Size: 2852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211119/ede75b71/attachment.bin>
More information about the llvm-commits
mailing list