forked from OSchip/llvm-project
[llvm-readobj/elf] - Refine signature of print*Reloc methods.
This makes the interface cleaner and slightly improves messages reported. Differential revision: https://reviews.llvm.org/D87086
This commit is contained in:
parent
fe0972d3e4
commit
b7c1810986
|
@ -6,28 +6,28 @@
|
||||||
|
|
||||||
# LLVM: Relocations [
|
# LLVM: Relocations [
|
||||||
# LLVM-NEXT: Section (3) .rel.text {
|
# LLVM-NEXT: Section (3) .rel.text {
|
||||||
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
||||||
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
||||||
# LLVM-NEXT: 0x2 R_X86_64_NONE - 0x0
|
# LLVM-NEXT: 0x2 R_X86_64_NONE - 0x0
|
||||||
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 4 in section 3: invalid section index: 255
|
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
|
||||||
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 5 in section 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
|
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
|
||||||
# LLVM-NEXT: }
|
# LLVM-NEXT: }
|
||||||
# LLVM-NEXT: Section (4) .rela.text {
|
# LLVM-NEXT: Section (4) .rela.text {
|
||||||
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
|
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
|
||||||
# LLVM-NEXT: }
|
# LLVM-NEXT: }
|
||||||
# LLVM-NEXT: ]
|
# LLVM-NEXT: ]
|
||||||
|
|
||||||
# GNU: Relocation section '.rel.text' at offset 0x41 contains 5 entries:
|
# GNU: Relocation section '.rel.text' at offset 0x41 contains 5 entries:
|
||||||
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
|
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
|
||||||
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
||||||
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 2 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
|
||||||
# GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE
|
# GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE
|
||||||
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 4 in section 3: invalid section index: 255
|
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
|
||||||
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 5 in section 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
|
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
|
||||||
# GNU-EMPTY:
|
# GNU-EMPTY:
|
||||||
# GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 1 entries:
|
# GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 1 entries:
|
||||||
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
|
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
|
||||||
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
|
# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
|
||||||
|
|
||||||
--- !ELF
|
--- !ELF
|
||||||
FileHeader:
|
FileHeader:
|
||||||
|
|
|
@ -747,10 +747,10 @@ protected:
|
||||||
function_ref<void(const Elf_Shdr &)> OnSectionStart,
|
function_ref<void(const Elf_Shdr &)> OnSectionStart,
|
||||||
function_ref<void(StringRef, uint64_t)> OnSectionEntry);
|
function_ref<void(StringRef, uint64_t)> OnSectionEntry);
|
||||||
|
|
||||||
virtual void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
virtual void printRelReloc(const Elf_Rel &R, unsigned RelIndex,
|
||||||
const Elf_Rel &R, unsigned RelIndex) = 0;
|
const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0;
|
||||||
virtual void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
virtual void printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
|
||||||
const Elf_Rela &R, unsigned RelIndex) = 0;
|
const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0;
|
||||||
virtual void printRelrReloc(const Elf_Relr &R) = 0;
|
virtual void printRelrReloc(const Elf_Relr &R) = 0;
|
||||||
void printRelocationsHelper(const Elf_Shdr &Sec);
|
void printRelocationsHelper(const Elf_Shdr &Sec);
|
||||||
|
|
||||||
|
@ -863,15 +863,15 @@ private:
|
||||||
}
|
}
|
||||||
void printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym,
|
void printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym,
|
||||||
StringRef StrTable, uint32_t Bucket);
|
StringRef StrTable, uint32_t Bucket);
|
||||||
void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec,
|
||||||
const Elf_Rel &R, unsigned RelIndex) override;
|
const Elf_Shdr *SymTab) override;
|
||||||
void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec,
|
||||||
const Elf_Rela &R, unsigned RelIndex) override;
|
const Elf_Shdr *SymTab) override;
|
||||||
void printRelrReloc(const Elf_Relr &R) override;
|
void printRelrReloc(const Elf_Relr &R) override;
|
||||||
|
|
||||||
template <class RelTy>
|
template <class RelTy>
|
||||||
void printRelRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
|
||||||
const RelTy &R, unsigned RelIndex);
|
const Elf_Shdr *SymTab);
|
||||||
template <class RelTy>
|
template <class RelTy>
|
||||||
void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
|
void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName,
|
||||||
const RelTy &R);
|
const RelTy &R);
|
||||||
|
@ -932,13 +932,13 @@ public:
|
||||||
void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
|
void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec,
|
||||||
const Elf_Rel &R, unsigned RelIndex) override;
|
const Elf_Shdr *SymTab) override;
|
||||||
void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec,
|
||||||
const Elf_Rela &R, unsigned RelIndex) override;
|
const Elf_Shdr *SymTab) override;
|
||||||
void printRelrReloc(const Elf_Relr &R) override;
|
void printRelrReloc(const Elf_Relr &R) override;
|
||||||
template <class RelTy>
|
template <class RelTy>
|
||||||
void printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, unsigned RelIndex,
|
void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec,
|
||||||
const Elf_Shdr *SymTab);
|
const Elf_Shdr *SymTab);
|
||||||
template <class RelTy> void printDynamicRelocation(const RelTy &Rel);
|
template <class RelTy> void printDynamicRelocation(const RelTy &Rel);
|
||||||
|
|
||||||
|
@ -3601,15 +3601,17 @@ template <class ELFT> void GNUStyle<ELFT>::printGroupSections() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void GNUStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void GNUStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex,
|
||||||
const Elf_Rel &R, unsigned RelIndex) {
|
const Elf_Shdr *Sec,
|
||||||
printRelRelaReloc(SecIndex, SymTab, R, RelIndex);
|
const Elf_Shdr *SymTab) {
|
||||||
|
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void GNUStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void GNUStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
|
||||||
const Elf_Rela &R, unsigned RelIndex) {
|
const Elf_Shdr *Sec,
|
||||||
printRelRelaReloc(SecIndex, SymTab, R, RelIndex);
|
const Elf_Shdr *SymTab) {
|
||||||
|
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT> void GNUStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
template <class ELFT> void GNUStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
||||||
|
@ -3618,15 +3620,15 @@ template <class ELFT> void GNUStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
template <class RelTy>
|
template <class RelTy>
|
||||||
void GNUStyle<ELFT>::printRelRelaReloc(unsigned SecIndex,
|
void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R, unsigned RelIndex,
|
||||||
const Elf_Shdr *SymTab, const RelTy &R,
|
const Elf_Shdr &Sec,
|
||||||
unsigned RelIndex) {
|
const Elf_Shdr *SymTab) {
|
||||||
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
|
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
|
||||||
this->dumper()->getRelocationTarget(SymTab, R);
|
this->dumper()->getRelocationTarget(SymTab, R);
|
||||||
if (!Target)
|
if (!Target)
|
||||||
this->reportUniqueWarning(createError(
|
this->reportUniqueWarning(createError(
|
||||||
"unable to print relocation " + Twine(RelIndex) + " in section " +
|
"unable to print relocation " + Twine(RelIndex) + " in " +
|
||||||
Twine(SecIndex) + ": " + toString(Target.takeError())));
|
describe(this->Obj, Sec) + ": " + toString(Target.takeError())));
|
||||||
else
|
else
|
||||||
printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R);
|
printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R);
|
||||||
}
|
}
|
||||||
|
@ -5466,13 +5468,12 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
|
||||||
SymTab = *SymTabOrErr;
|
SymTab = *SymTabOrErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front();
|
|
||||||
unsigned RelNdx = 0;
|
unsigned RelNdx = 0;
|
||||||
switch (Sec.sh_type) {
|
switch (Sec.sh_type) {
|
||||||
case ELF::SHT_REL:
|
case ELF::SHT_REL:
|
||||||
if (Expected<Elf_Rel_Range> RangeOrErr = Obj.rels(&Sec)) {
|
if (Expected<Elf_Rel_Range> RangeOrErr = Obj.rels(&Sec)) {
|
||||||
for (const Elf_Rel &R : *RangeOrErr)
|
for (const Elf_Rel &R : *RangeOrErr)
|
||||||
printRelReloc(SecNdx, SymTab, R, ++RelNdx);
|
printRelReloc(R, ++RelNdx, &Sec, SymTab);
|
||||||
} else {
|
} else {
|
||||||
Warn(RangeOrErr.takeError());
|
Warn(RangeOrErr.takeError());
|
||||||
}
|
}
|
||||||
|
@ -5480,7 +5481,7 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
|
||||||
case ELF::SHT_RELA:
|
case ELF::SHT_RELA:
|
||||||
if (Expected<Elf_Rela_Range> RangeOrErr = Obj.relas(&Sec)) {
|
if (Expected<Elf_Rela_Range> RangeOrErr = Obj.relas(&Sec)) {
|
||||||
for (const Elf_Rela &R : *RangeOrErr)
|
for (const Elf_Rela &R : *RangeOrErr)
|
||||||
printRelaReloc(SecNdx, SymTab, R, ++RelNdx);
|
printRelaReloc(R, ++RelNdx, &Sec, SymTab);
|
||||||
} else {
|
} else {
|
||||||
Warn(RangeOrErr.takeError());
|
Warn(RangeOrErr.takeError());
|
||||||
}
|
}
|
||||||
|
@ -5499,14 +5500,14 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr))
|
for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr))
|
||||||
printRelReloc(SecNdx, /*SymTab=*/nullptr, R, ++RelNdx);
|
printRelReloc(R, ++RelNdx, &Sec, /*SymTab=*/nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ELF::SHT_ANDROID_REL:
|
case ELF::SHT_ANDROID_REL:
|
||||||
case ELF::SHT_ANDROID_RELA:
|
case ELF::SHT_ANDROID_RELA:
|
||||||
if (Expected<std::vector<Elf_Rela>> RelasOrErr = Obj.android_relas(&Sec)) {
|
if (Expected<std::vector<Elf_Rela>> RelasOrErr = Obj.android_relas(&Sec)) {
|
||||||
for (const Elf_Rela &R : *RelasOrErr)
|
for (const Elf_Rela &R : *RelasOrErr)
|
||||||
printRelaReloc(SecNdx, SymTab, R, ++RelNdx);
|
printRelaReloc(R, ++RelNdx, &Sec, SymTab);
|
||||||
} else {
|
} else {
|
||||||
Warn(RelasOrErr.takeError());
|
Warn(RelasOrErr.takeError());
|
||||||
}
|
}
|
||||||
|
@ -6146,15 +6147,17 @@ template <class ELFT> void LLVMStyle<ELFT>::printRelocations() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void LLVMStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void LLVMStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex,
|
||||||
const Elf_Rel &R, unsigned RelIndex) {
|
const Elf_Shdr *Sec,
|
||||||
printRelRelaReloc(SecIndex, R, RelIndex, SymTab);
|
const Elf_Shdr *SymTab) {
|
||||||
|
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void LLVMStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab,
|
void LLVMStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex,
|
||||||
const Elf_Rela &R, unsigned RelIndex) {
|
const Elf_Shdr *Sec,
|
||||||
printRelRelaReloc(SecIndex, R, RelIndex, SymTab);
|
const Elf_Shdr *SymTab) {
|
||||||
|
printRelRelaReloc(R, RelIndex, *Sec, SymTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT> void LLVMStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
template <class ELFT> void LLVMStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
||||||
|
@ -6163,15 +6166,15 @@ template <class ELFT> void LLVMStyle<ELFT>::printRelrReloc(const Elf_Relr &R) {
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
template <class RelTy>
|
template <class RelTy>
|
||||||
void LLVMStyle<ELFT>::printRelRelaReloc(unsigned SecIndex, const RelTy &Rel,
|
void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex,
|
||||||
unsigned RelIndex,
|
const Elf_Shdr &Sec,
|
||||||
const Elf_Shdr *SymTab) {
|
const Elf_Shdr *SymTab) {
|
||||||
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
|
Expected<std::pair<const typename ELFT::Sym *, std::string>> Target =
|
||||||
this->dumper()->getRelocationTarget(SymTab, Rel);
|
this->dumper()->getRelocationTarget(SymTab, Rel);
|
||||||
if (!Target) {
|
if (!Target) {
|
||||||
this->reportUniqueWarning(createError(
|
this->reportUniqueWarning(createError(
|
||||||
"unable to print relocation " + Twine(RelIndex) + " in section " +
|
"unable to print relocation " + Twine(RelIndex) + " in " +
|
||||||
Twine(SecIndex) + ": " + toString(Target.takeError())));
|
describe(this->Obj, Sec) + ": " + toString(Target.takeError())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue