Expand Up
@@ -139,7 +139,7 @@ struct DynRegionInfo {
template <typename ELFT>
class ELFDumper : public ObjDumper {
public:
ELFDumper (const ELFFile <ELFT> *Obj , ScopedPrinter &Writer);
ELFDumper (const object::ELFObjectFile <ELFT> *ObjF , ScopedPrinter &Writer);
void printFileHeaders () override ;
void printSections () override ;
Expand Down
Expand Up
@@ -181,18 +181,19 @@ class ELFDumper : public ObjDumper {
TYPEDEF_ELF_TYPES (ELFT)
DynRegionInfo checkDRI (DynRegionInfo DRI) {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
if (DRI.Addr < Obj->base () ||
(const uint8_t *)DRI.Addr + DRI.Size > Obj->base () + Obj->getBufSize ())
error (llvm::object::object_error::parse_failed);
return DRI;
}
DynRegionInfo createDRIFrom (const Elf_Phdr *P, uintX_t EntSize) {
return checkDRI ({Obj ->base () + P->p_offset , P->p_filesz , EntSize});
return checkDRI ({ObjF-> getELFFile () ->base () + P->p_offset , P->p_filesz , EntSize});
}
DynRegionInfo createDRIFrom (const Elf_Shdr *S) {
return checkDRI ({Obj ->base () + S->sh_offset , S->sh_size , S->sh_entsize });
return checkDRI ({ObjF-> getELFFile () ->base () + S->sh_offset , S->sh_size , S->sh_entsize });
}
void parseDynamicTable (ArrayRef<const Elf_Phdr *> LoadSegments);
Expand All
@@ -206,7 +207,7 @@ class ELFDumper : public ObjDumper {
void LoadVersionNeeds (const Elf_Shdr *ec) const ;
void LoadVersionDefs (const Elf_Shdr *sec) const ;
const ELFO *Obj ;
const object::ELFObjectFile<ELFT> *ObjF ;
DynRegionInfo DynRelRegion;
DynRegionInfo DynRelaRegion;
DynRegionInfo DynRelrRegion;
Expand Down
Expand Up
@@ -289,6 +290,7 @@ void ELFDumper<ELFT>::printSymbolsHelper(bool IsDynamic) const {
StringRef StrTable, SymtabName;
size_t Entries = 0 ;
Elf_Sym_Range Syms (nullptr , nullptr );
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
if (IsDynamic) {
StrTable = DynamicStringTable;
Syms = dynamic_symbols ();
Expand Down
Expand Up
@@ -451,7 +453,7 @@ template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
namespace llvm {
template <class ELFT >
static std::error_code createELFDumper (const ELFFile <ELFT> *Obj,
static std::error_code createELFDumper (const ELFObjectFile <ELFT> *Obj,
ScopedPrinter &Writer,
std::unique_ptr<ObjDumper> &Result) {
Result.reset (new ELFDumper<ELFT>(Obj, Writer));
Expand All
@@ -463,19 +465,19 @@ std::error_code createELFDumper(const object::ObjectFile *Obj,
std::unique_ptr<ObjDumper> &Result) {
// Little-endian 32-bit
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
return createELFDumper (ELFObj-> getELFFile () , Writer, Result);
return createELFDumper (ELFObj, Writer, Result);
// Big-endian 32-bit
if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
return createELFDumper (ELFObj-> getELFFile () , Writer, Result);
return createELFDumper (ELFObj, Writer, Result);
// Little-endian 64-bit
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
return createELFDumper (ELFObj-> getELFFile () , Writer, Result);
return createELFDumper (ELFObj, Writer, Result);
// Big-endian 64-bit
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
return createELFDumper (ELFObj-> getELFFile () , Writer, Result);
return createELFDumper (ELFObj, Writer, Result);
return readobj_error::unsupported_obj_file_format;
}
Expand All
@@ -488,7 +490,7 @@ template <class ELFT>
void ELFDumper<ELFT>::LoadVersionNeeds(const Elf_Shdr *sec) const {
unsigned vn_size = sec->sh_size ; // Size of section in bytes
unsigned vn_count = sec->sh_info ; // Number of Verneed entries
const char *sec_start = (const char *)Obj ->base () + sec->sh_offset ;
const char *sec_start = (const char *)ObjF-> getELFFile () ->base () + sec->sh_offset ;
const char *sec_end = sec_start + vn_size;
// The first Verneed entry is at the start of the section.
const char *p = sec_start;
Expand Down
Expand Up
@@ -522,7 +524,7 @@ template <class ELFT>
void ELFDumper<ELFT>::LoadVersionDefs(const Elf_Shdr *sec) const {
unsigned vd_size = sec->sh_size ; // Size of section in bytes
unsigned vd_count = sec->sh_info ; // Number of Verdef entries
const char *sec_start = (const char *)Obj ->base () + sec->sh_offset ;
const char *sec_start = (const char *)ObjF-> getELFFile () ->base () + sec->sh_offset ;
const char *sec_end = sec_start + vd_size;
// The first Verdef entry is at the start of the section.
const char *p = sec_start;
Expand Down
Expand Up
@@ -700,13 +702,13 @@ static void printVersionDependencySection(ELFDumper<ELFT> *Dumper,
template <typename ELFT> void ELFDumper<ELFT>::printVersionInfo() {
// Dump version symbol section.
printVersionSymbolSection (this , Obj , dot_gnu_version_sec, W);
printVersionSymbolSection (this , ObjF-> getELFFile () , dot_gnu_version_sec, W);
// Dump version definition section.
printVersionDefinitionSection (this , Obj , dot_gnu_version_d_sec, W);
printVersionDefinitionSection (this , ObjF-> getELFFile () , dot_gnu_version_d_sec, W);
// Dump version dependency section.
printVersionDependencySection (this , Obj , dot_gnu_version_r_sec, W);
printVersionDependencySection (this , ObjF-> getELFFile () , dot_gnu_version_r_sec, W);
}
template <typename ELFT>
Expand All
@@ -727,7 +729,7 @@ StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab,
// Get the corresponding version index entry
const Elf_Versym *vs = unwrapOrError (
Obj ->template getEntry <Elf_Versym>(dot_gnu_version_sec, entry_index));
ObjF-> getELFFile () ->template getEntry <Elf_Versym>(dot_gnu_version_sec, entry_index));
size_t version_index = vs->vs_index & ELF::VERSYM_VERSION;
// Special markers for unversioned symbols.
Expand Down
Expand Up
@@ -760,6 +762,7 @@ StringRef ELFDumper<ELFT>::getSymbolVersion(StringRef StrTab,
template <typename ELFT>
StringRef ELFDumper<ELFT>::getStaticSymbolName(uint32_t Index) const {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
StringRef StrTable = unwrapOrError (Obj->getStringTableForSymtab (*DotSymtabSec));
Elf_Sym_Range Syms = unwrapOrError (Obj->symbols (DotSymtabSec));
if (Index >= Syms.size ())
Expand Down
Expand Up
@@ -807,6 +810,7 @@ void ELFDumper<ELFT>::getSectionNameIndex(const Elf_Sym *Symbol,
if (SectionIndex == SHN_XINDEX)
SectionIndex = unwrapOrError (object::getExtendedSymbolTableIndex<ELFT>(
Symbol, FirstSym, ShndxTable));
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
const typename ELFT::Shdr *Sec =
unwrapOrError (Obj->getSection (SectionIndex));
SectionName = unwrapOrError (Obj->getSectionName (Sec));
Expand Down
Expand Up
@@ -1375,9 +1379,11 @@ static const char *getElfMipsOptionsOdkType(unsigned Odk) {
}
template <typename ELFT>
ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer)
: ObjDumper(Writer), Obj(Obj) {
ELFDumper<ELFT>::ELFDumper(const object::ELFObjectFile<ELFT> *ObjF,
ScopedPrinter &Writer)
: ObjDumper(Writer), ObjF(ObjF) {
SmallVector<const Elf_Phdr *, 4 > LoadSegments;
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
for (const Elf_Phdr &Phdr : unwrapOrError (Obj->program_headers ())) {
if (Phdr.p_type == ELF::PT_DYNAMIC) {
DynamicTable = createDRIFrom (&Phdr, sizeof (Elf_Dyn));
Expand Down
Expand Up
@@ -1458,7 +1464,7 @@ void ELFDumper<ELFT>::parseDynamicTable(
uint64_t Delta = VAddr - Phdr.p_vaddr ;
if (Delta >= Phdr.p_filesz )
report_fatal_error (" Virtual address is not in any segment" );
return Obj ->base () + Phdr.p_offset + Delta;
return ObjF-> getELFFile () ->base () + Phdr.p_offset + Delta;
};
uint64_t SONameOffset = 0 ;
Expand Down
Expand Up
@@ -1557,51 +1563,51 @@ typename ELFDumper<ELFT>::Elf_Relr_Range ELFDumper<ELFT>::dyn_relrs() const {
template <class ELFT >
void ELFDumper<ELFT>::printFileHeaders() {
ELFDumperStyle->printFileHeaders (Obj );
ELFDumperStyle->printFileHeaders (ObjF-> getELFFile () );
}
template <class ELFT >
void ELFDumper<ELFT>::printSections() {
ELFDumperStyle->printSections (Obj );
ELFDumperStyle->printSections (ObjF-> getELFFile () );
}
template <class ELFT >
void ELFDumper<ELFT>::printRelocations() {
ELFDumperStyle->printRelocations (Obj );
ELFDumperStyle->printRelocations (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printProgramHeaders() {
ELFDumperStyle->printProgramHeaders (Obj );
ELFDumperStyle->printProgramHeaders (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printDynamicRelocations() {
ELFDumperStyle->printDynamicRelocations (Obj );
ELFDumperStyle->printDynamicRelocations (ObjF-> getELFFile () );
}
template <class ELFT >
void ELFDumper<ELFT>::printSymbols() {
ELFDumperStyle->printSymbols (Obj );
ELFDumperStyle->printSymbols (ObjF-> getELFFile () );
}
template <class ELFT >
void ELFDumper<ELFT>::printDynamicSymbols() {
ELFDumperStyle->printDynamicSymbols (Obj );
ELFDumperStyle->printDynamicSymbols (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printHashHistogram() {
ELFDumperStyle->printHashHistogram (Obj );
ELFDumperStyle->printHashHistogram (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printCGProfile() {
ELFDumperStyle->printCGProfile (Obj );
ELFDumperStyle->printCGProfile (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printNotes() {
ELFDumperStyle->printNotes (Obj );
ELFDumperStyle->printNotes (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printELFLinkerOptions() {
ELFDumperStyle->printELFLinkerOptions (Obj );
ELFDumperStyle->printELFLinkerOptions (ObjF-> getELFFile () );
}
static const char *getTypeString (unsigned Arch, uint64_t Type) {
Expand Down
Expand Up
@@ -1842,9 +1848,9 @@ void ELFDumper<ELFT>::printValue(uint64_t Type, uint64_t Value) {
template <class ELFT >
void ELFDumper<ELFT>::printUnwindInfo() {
const unsigned Machine = Obj ->getHeader ()->e_machine ;
const unsigned Machine = ObjF-> getELFFile () ->getHeader ()->e_machine ;
if (Machine == EM_386 || Machine == EM_X86_64) {
DwarfCFIEH::PrinterContext<ELFT> Ctx (W, Obj );
DwarfCFIEH::PrinterContext<ELFT> Ctx (W, ObjF );
return Ctx.printUnwindInformation ();
}
W.startLine () << " UnwindInfo not implemented.\n " ;
Expand All
@@ -1853,6 +1859,7 @@ void ELFDumper<ELFT>::printUnwindInfo() {
namespace {
template <> void ELFDumper<ELF32LE>::printUnwindInfo() {
const ELFFile<ELF32LE> *Obj = ObjF->getELFFile ();
const unsigned Machine = Obj->getHeader ()->e_machine ;
if (Machine == EM_ARM) {
ARM::EHABI::PrinterContext<ELF32LE> Ctx (W, Obj, DotSymtabSec);
Expand Down
Expand Up
@@ -1895,7 +1902,7 @@ void ELFDumper<ELFT>::printDynamicTable() {
uintX_t Tag = Entry.getTag ();
++I;
W.startLine () << " " << format_hex (Tag, Is64 ? 18 : 10 , opts::Output != opts::GNU) << " "
<< format (" %-21s" , getTypeString (Obj ->getHeader ()->e_machine , Tag));
<< format (" %-21s" , getTypeString (ObjF-> getELFFile () ->getHeader ()->e_machine , Tag));
printValue (Tag, Entry.getVal ());
OS << " \n " ;
}
Expand Down
Expand Up
@@ -1962,6 +1969,7 @@ void ELFDumper<ELFT>::printAttributes() {
namespace {
template <> void ELFDumper<ELF32LE>::printAttributes() {
const ELFFile<ELF32LE> *Obj = ObjF->getELFFile ();
if (Obj->getHeader ()->e_machine != EM_ARM) {
W.startLine () << " Attributes not implemented.\n " ;
return ;
Expand Down
Expand Up
@@ -2247,6 +2255,7 @@ MipsGOTParser<ELFT>::getPltSym(const Entry *E) const {
}
template <class ELFT > void ELFDumper<ELFT>::printMipsPLTGOT() {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
if (Obj->getHeader ()->e_machine != EM_MIPS)
reportError (" MIPS PLT GOT is available for MIPS targets only" );
Expand Down
Expand Up
@@ -2331,6 +2340,7 @@ static int getMipsRegisterSize(uint8_t Flag) {
}
template <class ELFT > void ELFDumper<ELFT>::printMipsABIFlags() {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
const Elf_Shdr *Shdr = findSectionByName (*Obj, " .MIPS.abiflags" );
if (!Shdr) {
W.startLine () << " There is no .MIPS.abiflags section in the file.\n " ;
Expand Down
Expand Up
@@ -2376,6 +2386,7 @@ static void printMipsReginfoData(ScopedPrinter &W,
}
template <class ELFT > void ELFDumper<ELFT>::printMipsReginfo() {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
const Elf_Shdr *Shdr = findSectionByName (*Obj, " .reginfo" );
if (!Shdr) {
W.startLine () << " There is no .reginfo section in the file.\n " ;
Expand All
@@ -2393,6 +2404,7 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
}
template <class ELFT > void ELFDumper<ELFT>::printMipsOptions() {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
const Elf_Shdr *Shdr = findSectionByName (*Obj, " .MIPS.options" );
if (!Shdr) {
W.startLine () << " There is no .MIPS.options section in the file.\n " ;
Expand Down
Expand Up
@@ -2422,6 +2434,7 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsOptions() {
}
template <class ELFT > void ELFDumper<ELFT>::printStackMap() const {
const ELFFile<ELFT> *Obj = ObjF->getELFFile ();
const Elf_Shdr *StackMapSection = nullptr ;
for (const auto &Sec : unwrapOrError (Obj->sections ())) {
StringRef Name = unwrapOrError (Obj->getSectionName (&Sec));
Expand All
@@ -2442,11 +2455,11 @@ template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
}
template <class ELFT > void ELFDumper<ELFT>::printGroupSections() {
ELFDumperStyle->printGroupSections (Obj );
ELFDumperStyle->printGroupSections (ObjF-> getELFFile () );
}
template <class ELFT > void ELFDumper<ELFT>::printAddrsig() {
ELFDumperStyle->printAddrsig (Obj );
ELFDumperStyle->printAddrsig (ObjF-> getELFFile () );
}
static inline void printFields (formatted_raw_ostream &OS, StringRef Str1,
Expand Down