--- /dev/null
+## Test llvm-nm demangling of symbols for XCOFF object files.
+## Test following symbols:
+## 1. Empty name
+## 2. Name consisting solely of .
+## 3. Name starting with . that can't be demangled
+## 4. Name starting with . that can be demangled
+## 5. Name not starting with . that can't be demangled
+## 6. Name not starting with . that can be demangled
+
+# RUN: yaml2obj --docnum=1 %s -o %t.o
+# RUN: llvm-nm --demangle --format=just-symbols %t.o 2>&1 | FileCheck %s --check-prefix=NM-DEMANGLE --match-full-lines
+
+# NM-DEMANGLE: {{$}}
+# NM-DEMANGLE-NEXT: .
+# NM-DEMANGLE-NEXT: ._5func1i
+# NM-DEMANGLE-NEXT: .func1(int)
+# NM-DEMANGLE-NEXT: L5func0v
+# NM-DEMANGLE-NEXT: func0()
+
+--- !XCOFF
+FileHeader:
+ MagicNumber: 0x1DF
+Sections:
+ - Name: .text
+ Flags: [ STYP_TEXT ]
+ - Name: .data
+ Flags: [ STYP_DATA ]
+Symbols:
+ - Name: ""
+ Section: .text
+ - Name: .
+ Section: .text
+ - Name: ._Z5func1i
+ Section: .text
+ - Name: ._5func1i
+ Section: .text
+ - Name: _ZL5func0v
+ Section: .data
+ - Name: L5func0v
+ Section: .data
outs() << format(" %02x", NType);
}
-static Optional<std::string> demangle(const std::string &Name,
- bool StripUnderscore) {
- const char *Mangled = Name.c_str();
- if (StripUnderscore && Mangled[0] == '_')
- Mangled = Mangled + 1;
-
+static Optional<std::string> demangle(StringRef Name) {
std::string Demangled;
- if (nonMicrosoftDemangle(Mangled, Demangled))
+ if (nonMicrosoftDemangle(Name.str().c_str(), Demangled))
return Demangled;
return None;
}
+static Optional<std::string> demangleXCOFF(StringRef Name) {
+ if (Name.empty() || Name[0] != '.')
+ return demangle(Name);
+
+ Name = Name.drop_front();
+ 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.drop_front();
+ return demangle(Name);
+}
+
static bool symbolIsDefined(const NMSymbol &Sym) {
return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v';
}
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) {