diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h --- a/llvm/include/llvm/Object/XCOFFObjectFile.h +++ b/llvm/include/llvm/Object/XCOFFObjectFile.h @@ -370,7 +370,7 @@ const void *getPointerToSymbolTable() const { return SymbolTblPtr; } Expected getSymbolSectionName(XCOFFSymbolRef Ref) const; - + unsigned getSymbolSectionID(SymbolRef Sym) const; XCOFFSymbolRef toSymbolRef(DataRefImpl Ref) const; // File header related interfaces. @@ -525,6 +525,15 @@ Expected getName() const; bool isFunction() const; + bool isExternal() const; + bool isWeakExternal() const; + bool isUndefined() const; + bool isCommon() const; + bool isFileRecord() const; + bool isDebug() const; + bool isSectionDefinition() const; + bool isHidden() const; + bool isExported() const; bool isCsectSymbol() const; Expected getXCOFFCsectAuxRef() const; diff --git a/llvm/lib/Object/SymbolSize.cpp b/llvm/lib/Object/SymbolSize.cpp --- a/llvm/lib/Object/SymbolSize.cpp +++ b/llvm/lib/Object/SymbolSize.cpp @@ -12,6 +12,7 @@ #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/MachO.h" #include "llvm/Object/Wasm.h" +#include "llvm/Object/XCOFFObjectFile.h" using namespace llvm; using namespace object; @@ -30,7 +31,8 @@ return M->getSectionID(Sec); if (isa(&O)) return Sec.getIndex(); - + if (isa(&O)) + return Sec.getIndex(); return cast(O).getSectionID(Sec); } @@ -39,6 +41,8 @@ return M->getSymbolSectionID(Sym); if (const auto *M = dyn_cast(&O)) return M->getSymbolSectionId(Sym); + if (const auto *M = dyn_cast(&O)) + return M->getSymbolSectionID(Sym); return cast(O).getSymbolSectionID(Sym); } diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -25,6 +25,7 @@ static const uint8_t FunctionSym = 0x20; static const uint16_t NoRelMask = 0x0001; +static const uint32_t SymVisMask = 0xF000; static const size_t SymbolAuxTypeOffset = 17; // Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer @@ -207,7 +208,22 @@ Expected XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const { - llvm_unreachable("Not yet implemented!"); + XCOFFSymbolRef XCOFFSymRef(Symb, this); + if (XCOFFSymRef.isUndefined()) + return SymbolRef::ST_Unknown; + if (XCOFFSymRef.isCommon()) + return SymbolRef::ST_Data; + if (XCOFFSymRef.isDebug() || XCOFFSymRef.isSectionDefinition()) + return SymbolRef::ST_Debug; + if (XCOFFSymRef.isFileRecord()) + return SymbolRef::ST_File; + if (XCOFFSymRef.isFunction()) + return SymbolRef::ST_Function; + + int16_t SecNum = XCOFFSymRef.getSectionNumber(); + if (isReservedSectionNumber(SecNum)) + return SymbolRef::ST_Data; + return SymbolRef::ST_Other; } @@ -386,8 +402,24 @@ } Expected XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const { - uint32_t Result = 0; - llvm_unreachable("Not yet implemented!"); + uint32_t Result = SymbolRef::SF_None; + XCOFFSymbolRef XCOFFSymRef(Symb, this); + if (XCOFFSymRef.isExternal() || XCOFFSymRef.isWeakExternal()) + Result |= SymbolRef::SF_Global; + if (XCOFFSymRef.isWeakExternal() && XCOFFSymRef.getNumberOfAuxEntries()) + Result |= SymbolRef::SF_Weak; + if (XCOFFSymRef.isUndefined()) + Result |= SymbolRef::SF_Undefined; + if (XCOFFSymRef.isFileRecord() || XCOFFSymRef.isSectionDefinition()) + Result |= SymbolRef::SF_FormatSpecific; + if (XCOFFSymRef.getSectionNumber() == XCOFF::N_ABS) + Result |= SymbolRef::SF_Absolute; + if (XCOFFSymRef.isCommon()) + Result |= SymbolRef::SF_Common; + if (XCOFFSymRef.isHidden()) + Result |= SymbolRef::SF_Hidden; + if (XCOFFSymRef.isExported()) + Result |= SymbolRef::SF_Exported; return Result; } @@ -506,6 +538,11 @@ } } +unsigned XCOFFObjectFile::getSymbolSectionID(SymbolRef Sym) const { + XCOFFSymbolRef XCOFFSymRef(Sym.getRawDataRefImpl(), this); + return XCOFFSymRef.getSectionNumber(); +} + bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber) { return (SectionNumber <= 0 && SectionNumber >= -2); } @@ -804,6 +841,49 @@ return (OwningObjectPtr->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT); } +bool XCOFFSymbolRef::isExternal() const { + return getStorageClass() == XCOFF::C_EXT; +} + +bool XCOFFSymbolRef::isWeakExternal() const { + return getStorageClass() == XCOFF::C_WEAKEXT; +} + +bool XCOFFSymbolRef::isUndefined() const { + return ((isExternal() && getSectionNumber() == XCOFF::N_UNDEF && + getSymbolType() == 0) || isWeakExternal()); +} + +bool XCOFFSymbolRef::isCommon() const { + return ((getStorageClass() == XCOFF::C_EXT && + getSectionNumber() == XCOFF::N_UNDEF && getSymbolType() != 0)); +} + +bool XCOFFSymbolRef::isFileRecord() const { + return getStorageClass() == XCOFF::C_FILE; +} + +bool XCOFFSymbolRef::isDebug() const { + return getSectionNumber() == XCOFF::N_DEBUG; +} + +bool XCOFFSymbolRef::isSectionDefinition() const { + bool isAppdomainGlobal = + getStorageClass() == XCOFF::C_EXT && getSectionNumber() == XCOFF::N_ABS; + bool isOrdinarySection = getStorageClass() == XCOFF::C_STAT; + if (!getNumberOfAuxEntries()) + return false; + return isAppdomainGlobal || isOrdinarySection; +} + +bool XCOFFSymbolRef::isHidden() const { + return (getSymbolType() & SymVisMask) == XCOFF::SYM_V_HIDDEN; +} + +bool XCOFFSymbolRef::isExported() const { + return (getSymbolType() & SymVisMask) == XCOFF::SYM_V_EXPORTED; +} + bool XCOFFSymbolRef::isCsectSymbol() const { XCOFF::StorageClass SC = getStorageClass(); return (SC == XCOFF::C_EXT || SC == XCOFF::C_WEAKEXT || diff --git a/llvm/test/tools/llvm-objdump/XCOFF/Inputs/basic32.o b/llvm/test/tools/llvm-objdump/XCOFF/Inputs/basic32.o new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@: +# LINES32: ; .main(): +# LINES32-NEXT: ; /basic.c:1 +# LINES32-NEXT: 0: 38 60 00 00 li 3, 0 +# LINES32-NEXT: ; /basic.c:3 +# LINES32-NEXT: 4: 48 00 00 04 b 0x8 +# LINES32-NEXT: ; /basic.c:4 +# LINES32-NEXT: 8: 4e 80 00 20 blr +# LINES32-NEXT: c: 00 00 00 00 +# LINES32-NEXT: 10: 00 00 20 40 +# LINES32-NEXT: 14: 00 00 00 01 +# LINES32-NEXT: 18: 00 00 00 0c +# LINES32-NEXT: 1c: 00 04 6d 61 +# LINES32-NEXT: 20: 69 6e 00 00 xori 14, 11, 0 + +# LINES64: Inputs/basic64.o: file format aix5coff64-rs6000 +# LINES64: Disassembly of section .text: +# LINES64: 0000000000000000 <.main>: +# LINES64: ; .main(): +# LINES64-NEXT: ; /basic.c:1 +# LINES64-NEXT: 0: 38 60 00 00 li 3, 0 +# LINES64-NEXT: ; /basic.c:3 +# LINES64-NEXT: 4: 48 00 00 04 b 0x8 +# LINES64-NEXT: ; /basic.c:4 +# LINES64-NEXT: 8: 4e 80 00 20 blr +# LINES64-NEXT: c: 00 00 00 00 +# LINES64-NEXT: 10: 00 00 20 40 +# LINES64-NEXT: 14: 00 00 00 01 +# LINES64-NEXT: 18: 00 00 00 0c +# LINES64-NEXT: 1c: 00 04 6d 61 +# LINES64-NEXT: 20: 69 6e 00 00 xori 14, 11, 0