From a56d0e84dacea51e80981a731182a89ea0289947 Mon Sep 17 00:00:00 2001 From: zhijian Date: Mon, 21 Nov 2022 10:11:12 -0500 Subject: [XCOFF] llvm-readobj support display symbol table of loader section of xcoff object file. Reviewers: James Henderson, Esme Yi Differential Revision: https://reviews.llvm.org/D135887 --- llvm/lib/Object/XCOFFObjectFile.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'llvm/lib/Object/XCOFFObjectFile.cpp') diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp index c758e35..061c47d 100644 --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -89,6 +89,34 @@ uint8_t XCOFFRelocation::getRelocatedLength() const { template struct ExceptionSectionEntry; template struct ExceptionSectionEntry; +template +Expected getLoaderSecSymNameInStrTbl(const T *LoaderSecHeader, + uint64_t Offset) { + if (LoaderSecHeader->LengthOfStrTbl > Offset) + return (reinterpret_cast(LoaderSecHeader) + + LoaderSecHeader->OffsetToStrTbl + Offset); + + return createError("entry with offset 0x" + Twine::utohexstr(Offset) + + " in the loader section's string table with size 0x" + + Twine::utohexstr(LoaderSecHeader->LengthOfStrTbl) + + " is invalid"); +} + +Expected LoaderSectionSymbolEntry32::getSymbolName( + const LoaderSectionHeader32 *LoaderSecHeader32) const { + const NameOffsetInStrTbl *NameInStrTbl = + reinterpret_cast(SymbolName); + if (NameInStrTbl->IsNameInStrTbl != XCOFFSymbolRef::NAME_IN_STR_TBL_MAGIC) + return generateXCOFFFixedNameStringRef(SymbolName); + + return getLoaderSecSymNameInStrTbl(LoaderSecHeader32, NameInStrTbl->Offset); +} + +Expected LoaderSectionSymbolEntry64::getSymbolName( + const LoaderSectionHeader64 *LoaderSecHeader64) const { + return getLoaderSecSymNameInStrTbl(LoaderSecHeader64, Offset); +} + uintptr_t XCOFFObjectFile::getAdvancedSymbolEntryAddress(uintptr_t CurrentAddress, uint32_t Distance) { -- cgit v1.1