diff --git a/llvm/test/tools/llvm-nm/XCOFF/Inputs/test_gcc.o b/llvm/test/tools/llvm-nm/XCOFF/Inputs/test_gcc.o new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@getTargetTriple()).isArch64Bit(); if (isa(Obj) || isa(Obj)) return false; + if (XCOFFObjectFile *XCOFFObj = dyn_cast(&Obj)) + return XCOFFObj->is64Bit(); + if (isa(Obj)) return false; if (TapiFile *Tapi = dyn_cast(&Obj)) @@ -599,10 +603,17 @@ outs() << format(" %02x", NType); } -static Optional demangle(StringRef Name, bool StripUnderscore) { +static Optional demangle(StringRef Name, bool StripUnderscore, + bool isXCOFF) { if (StripUnderscore && !Name.empty() && Name[0] == '_') Name = Name.substr(1); + bool isPutXCOFFLabelDotBack = false; + if (isXCOFF && !Name.empty() && Name[0] == '.') { + Name = Name.substr(1); + isPutXCOFFLabelDotBack = true; + } + if (!Name.startswith("_Z")) return None; @@ -613,6 +624,9 @@ return None; std::string S(Undecorated); + if (isPutXCOFFLabelDotBack) + S.insert(0, 1, '.'); + free(Undecorated); return S; } @@ -704,8 +718,9 @@ uint32_t SymFlags; std::string Name = S.Name; MachOObjectFile *MachO = dyn_cast(&Obj); + XCOFFObjectFile *XCOFFO = dyn_cast(&Obj); if (Demangle) { - if (Optional Opt = demangle(S.Name, MachO)) + if (Optional Opt = demangle(S.Name, MachO, XCOFFO)) Name = *Opt; } if (S.Sym.getRawDataRefImpl().p) { @@ -903,6 +918,45 @@ return '?'; } +static char getSymbolNMTypeChar(XCOFFObjectFile &Obj, symbol_iterator I) { + Expected TypeOrErr = I->getType(); + if (!TypeOrErr) { + consumeError(TypeOrErr.takeError()); + return '?'; + } + + uint32_t SymType = TypeOrErr.get(); + + if (SymType == SymbolRef::ST_Debug) + return 'N'; + + if (SymType == SymbolRef::ST_File) + return 'f'; + + Expected SymSecOrErr = I->getSection(); + + if (!SymSecOrErr) { + consumeError(SymSecOrErr.takeError()); + return '?'; + } + + section_iterator SecIter = SymSecOrErr.get(); + + if (SecIter == Obj.section_end()) + return '?'; + + if (SecIter->isText()) + return 't'; + + if (SecIter->isData()) + return 'd'; + + if (SecIter->isBSS()) + return 'b'; + + return '?'; +} + static char getSymbolNMTypeChar(COFFImportFile &Obj) { switch (Obj.getCOFFImportHeader()->getType()) { case COFF::IMPORT_CODE: @@ -1051,6 +1105,8 @@ Ret = getSymbolNMTypeChar(*IR, I); else if (COFFObjectFile *COFF = dyn_cast(&Obj)) Ret = getSymbolNMTypeChar(*COFF, I); + else if (XCOFFObjectFile *XCOFF = dyn_cast(&Obj)) + Ret = getSymbolNMTypeChar(*XCOFF, I); else if (COFFImportFile *COFFImport = dyn_cast(&Obj)) Ret = getSymbolNMTypeChar(*COFFImport); else if (MachOObjectFile *MachO = dyn_cast(&Obj)) @@ -1637,6 +1693,11 @@ S.Address = 0; if (isa(&Obj)) S.Size = ELFSymbolRef(Sym).getSize(); + + if (const XCOFFObjectFile *XCOFFObj = + dyn_cast(&Obj)) + S.Size = XCOFFObj->getSymbolSize(Sym.getRawDataRefImpl()); + if (PrintAddress && isa(Obj)) { SymbolRef SymRef(Sym); Expected AddressOrErr = SymRef.getAddress();