diff options
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r-- | tools/llvm-readobj/ELFDumper.cpp | 34 | ||||
-rw-r--r-- | tools/llvm-readobj/MachODumper.cpp | 46 | ||||
-rw-r--r-- | tools/llvm-readobj/ObjDumper.h | 1 | ||||
-rw-r--r-- | tools/llvm-readobj/llvm-readobj.cpp | 6 |
4 files changed, 67 insertions, 20 deletions
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 0931cb70f6d8..99969fd469f9 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -58,6 +58,7 @@ public: void printAttributes() override; void printMipsPLTGOT() override; void printMipsABIFlags() override; + void printMipsReginfo() override; private: typedef ELFFile<ELFT> ELFO; @@ -147,12 +148,12 @@ getSectionNameIndex(const ELFO &Obj, typename ELFO::Elf_Sym_Iter Symbol, SectionName = "Processor Specific"; else if (Symbol->isOSSpecific()) SectionName = "Operating System Specific"; - else if (Symbol->isReserved()) - SectionName = "Reserved"; else if (Symbol->isAbsolute()) SectionName = "Absolute"; else if (Symbol->isCommon()) SectionName = "Common"; + else if (Symbol->isReserved() && SectionIndex != SHN_XINDEX) + SectionName = "Reserved"; else { if (SectionIndex == SHN_XINDEX) SectionIndex = Obj.getSymbolTableIndex(&*Symbol); @@ -233,7 +234,7 @@ static const EnumEntry<unsigned> ElfMachineType[] = { LLVM_READOBJ_ENUM_ENT(ELF, EM_386 ), LLVM_READOBJ_ENUM_ENT(ELF, EM_68K ), LLVM_READOBJ_ENUM_ENT(ELF, EM_88K ), - LLVM_READOBJ_ENUM_ENT(ELF, EM_486 ), + LLVM_READOBJ_ENUM_ENT(ELF, EM_IAMCU ), LLVM_READOBJ_ENUM_ENT(ELF, EM_860 ), LLVM_READOBJ_ENUM_ENT(ELF, EM_MIPS ), LLVM_READOBJ_ENUM_ENT(ELF, EM_S370 ), @@ -1424,3 +1425,30 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsABIFlags() { W.printFlags("Flags 1", Flags->flags1, makeArrayRef(ElfMipsFlags1)); W.printHex("Flags 2", Flags->flags2); } + +template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() { + const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo"); + if (!Shdr) { + W.startLine() << "There is no .reginfo section in the file.\n"; + return; + } + ErrorOr<ArrayRef<uint8_t>> Sec = Obj->getSectionContents(Shdr); + if (!Sec) { + W.startLine() << "The .reginfo section is empty.\n"; + return; + } + if (Sec->size() != sizeof(Elf_Mips_RegInfo<ELFT>)) { + W.startLine() << "The .reginfo section has a wrong size.\n"; + return; + } + + auto *Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Sec->data()); + + DictScope GS(W, "MIPS RegInfo"); + W.printHex("GP", Reginfo->ri_gp_value); + W.printHex("General Mask", Reginfo->ri_gprmask); + W.printHex("Co-Proc Mask0", Reginfo->ri_cprmask[0]); + W.printHex("Co-Proc Mask1", Reginfo->ri_cprmask[1]); + W.printHex("Co-Proc Mask2", Reginfo->ri_cprmask[2]); + W.printHex("Co-Proc Mask3", Reginfo->ri_cprmask[3]); +} diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 40691a222f04..aeb563a25ff3 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -469,35 +469,47 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, DataRefImpl DR = Reloc.getRawDataRefImpl(); MachO::any_relocation_info RE = Obj->getRelocation(DR); bool IsScattered = Obj->isRelocationScattered(RE); - SmallString<32> SymbolNameOrOffset("0x"); - if (IsScattered) { - // Scattered relocations don't really have an associated symbol - // for some reason, even if one exists in the symtab at the correct address. - SymbolNameOrOffset += utohexstr(Obj->getScatteredRelocationValue(RE)); - } else { + bool IsExtern = !IsScattered && Obj->getPlainRelocationExternal(RE); + + StringRef TargetName; + if (IsExtern) { symbol_iterator Symbol = Reloc.getSymbol(); if (Symbol != Obj->symbol_end()) { - StringRef SymbolName; - if (error(Symbol->getName(SymbolName))) + if (error(Symbol->getName(TargetName))) return; - SymbolNameOrOffset = SymbolName; - } else - SymbolNameOrOffset += utohexstr(Obj->getPlainRelocationSymbolNum(RE)); + } + } else if (!IsScattered) { + section_iterator SecI = Obj->getRelocationSection(DR); + if (SecI != Obj->section_end()) { + if (error(SecI->getName(TargetName))) + return; + } } + if (TargetName.empty()) + TargetName = "-"; if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printHex("Offset", Offset); W.printNumber("PCRel", Obj->getAnyRelocationPCRel(RE)); W.printNumber("Length", Obj->getAnyRelocationLength(RE)); - if (IsScattered) - W.printString("Extern", StringRef("N/A")); - else - W.printNumber("Extern", Obj->getPlainRelocationExternal(RE)); W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE)); - W.printString("Symbol", SymbolNameOrOffset); - W.printNumber("Scattered", IsScattered); + if (IsScattered) { + W.printHex("Value", Obj->getScatteredRelocationValue(RE)); + } else { + const char *Kind = IsExtern ? "Symbol" : "Section"; + W.printNumber(Kind, TargetName, Obj->getPlainRelocationSymbolNum(RE)); + } } else { + SmallString<32> SymbolNameOrOffset("0x"); + if (IsScattered) { + // Scattered relocations don't really have an associated symbol for some + // reason, even if one exists in the symtab at the correct address. + SymbolNameOrOffset += utohexstr(Obj->getScatteredRelocationValue(RE)); + } else { + SymbolNameOrOffset = TargetName; + } + raw_ostream& OS = W.startLine(); OS << W.hex(Offset) << " " << Obj->getAnyRelocationPCRel(RE) diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h index 5750d6ffd286..323f5e319cf3 100644 --- a/tools/llvm-readobj/ObjDumper.h +++ b/tools/llvm-readobj/ObjDumper.h @@ -43,6 +43,7 @@ public: // Only implemented for MIPS ELF at this time. virtual void printMipsPLTGOT() { } virtual void printMipsABIFlags() { } + virtual void printMipsReginfo() { } // Only implemented for PE/COFF. virtual void printCOFFImports() { } diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index be7bbe94d9ea..f960796a4cb9 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -152,6 +152,10 @@ namespace opts { cl::opt<bool> MipsABIFlags("mips-abi-flags", cl::desc("Display the MIPS.abiflags section")); + // -mips-reginfo + cl::opt<bool> MipsReginfo("mips-reginfo", + cl::desc("Display the MIPS .reginfo section")); + // -coff-imports cl::opt<bool> COFFImports("coff-imports", cl::desc("Display the PE/COFF import table")); @@ -296,6 +300,8 @@ static void dumpObject(const ObjectFile *Obj) { Dumper->printMipsPLTGOT(); if (opts::MipsABIFlags) Dumper->printMipsABIFlags(); + if (opts::MipsReginfo) + Dumper->printMipsReginfo(); } if (opts::COFFImports) Dumper->printCOFFImports(); |