diff --git a/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test b/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test index aefc0b0f0e16..59cf7155e2eb 100644 --- a/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test +++ b/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test @@ -6,28 +6,28 @@ # LLVM: Relocations [ # 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 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 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 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: warning: '[[FILE]]': unable to print relocation 4 in section 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 4 in SHT_REL section with index 3: invalid section index: 255 +# 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: 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: ] # GNU: Relocation section '.rel.text' at offset 0x41 contains 5 entries: # 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 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 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 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: warning: '[[FILE]]': unable to print relocation 4 in section 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 4 in SHT_REL section with index 3: invalid section index: 255 +# 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-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: 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 FileHeader: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index b81213d253d5..ca0f93cc1d61 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -747,10 +747,10 @@ protected: function_ref<void(const Elf_Shdr &)> OnSectionStart, function_ref<void(StringRef, uint64_t)> OnSectionEntry); - virtual void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) = 0; - virtual void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) = 0; + virtual void printRelReloc(const Elf_Rel &R, unsigned RelIndex, + const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0; + virtual void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, + const Elf_Shdr *Sec, const Elf_Shdr *SymTab) = 0; virtual void printRelrReloc(const Elf_Relr &R) = 0; void printRelocationsHelper(const Elf_Shdr &Sec); @@ -863,15 +863,15 @@ private: } void printHashedSymbol(const Elf_Sym *FirstSym, uint32_t Sym, StringRef StrTable, uint32_t Bucket); - void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) override; - void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) override; + void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) override; + void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) override; void printRelrReloc(const Elf_Relr &R) override; template <class RelTy> - void printRelRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const RelTy &R, unsigned RelIndex); + void printRelRelaReloc(const RelTy &R, unsigned RelIndex, const Elf_Shdr &Sec, + const Elf_Shdr *SymTab); template <class RelTy> void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName, const RelTy &R); @@ -932,13 +932,13 @@ public: void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override; private: - void printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) override; - void printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) override; + void printRelReloc(const Elf_Rel &R, unsigned RelIndex, const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) override; + void printRelaReloc(const Elf_Rela &R, unsigned RelIndex, const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) override; void printRelrReloc(const Elf_Relr &R) override; 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); template <class RelTy> void printDynamicRelocation(const RelTy &Rel); @@ -3601,15 +3601,17 @@ template <class ELFT> void GNUStyle<ELFT>::printGroupSections() { } template <class ELFT> -void GNUStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, SymTab, R, RelIndex); +void GNUStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template <class ELFT> -void GNUStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, SymTab, R, RelIndex); +void GNUStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } 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 RelTy> -void GNUStyle<ELFT>::printRelRelaReloc(unsigned SecIndex, - const Elf_Shdr *SymTab, const RelTy &R, - unsigned RelIndex) { +void GNUStyle<ELFT>::printRelRelaReloc(const RelTy &R, unsigned RelIndex, + const Elf_Shdr &Sec, + const Elf_Shdr *SymTab) { Expected<std::pair<const typename ELFT::Sym *, std::string>> Target = this->dumper()->getRelocationTarget(SymTab, R); if (!Target) this->reportUniqueWarning(createError( - "unable to print relocation " + Twine(RelIndex) + " in section " + - Twine(SecIndex) + ": " + toString(Target.takeError()))); + "unable to print relocation " + Twine(RelIndex) + " in " + + describe(this->Obj, Sec) + ": " + toString(Target.takeError()))); else printRelRelaReloc(/*Sym=*/Target->first, /*Name=*/Target->second, R); } @@ -5466,13 +5468,12 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) { SymTab = *SymTabOrErr; } - unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); unsigned RelNdx = 0; switch (Sec.sh_type) { case ELF::SHT_REL: if (Expected<Elf_Rel_Range> RangeOrErr = Obj.rels(&Sec)) { for (const Elf_Rel &R : *RangeOrErr) - printRelReloc(SecNdx, SymTab, R, ++RelNdx); + printRelReloc(R, ++RelNdx, &Sec, SymTab); } else { Warn(RangeOrErr.takeError()); } @@ -5480,7 +5481,7 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) { case ELF::SHT_RELA: if (Expected<Elf_Rela_Range> RangeOrErr = Obj.relas(&Sec)) { for (const Elf_Rela &R : *RangeOrErr) - printRelaReloc(SecNdx, SymTab, R, ++RelNdx); + printRelaReloc(R, ++RelNdx, &Sec, SymTab); } else { Warn(RangeOrErr.takeError()); } @@ -5499,14 +5500,14 @@ void DumpStyle<ELFT>::printRelocationsHelper(const Elf_Shdr &Sec) { } for (const Elf_Rel &R : Obj.decode_relrs(*RangeOrErr)) - printRelReloc(SecNdx, /*SymTab=*/nullptr, R, ++RelNdx); + printRelReloc(R, ++RelNdx, &Sec, /*SymTab=*/nullptr); break; } case ELF::SHT_ANDROID_REL: case ELF::SHT_ANDROID_RELA: if (Expected<std::vector<Elf_Rela>> RelasOrErr = Obj.android_relas(&Sec)) { for (const Elf_Rela &R : *RelasOrErr) - printRelaReloc(SecNdx, SymTab, R, ++RelNdx); + printRelaReloc(R, ++RelNdx, &Sec, SymTab); } else { Warn(RelasOrErr.takeError()); } @@ -6146,15 +6147,17 @@ template <class ELFT> void LLVMStyle<ELFT>::printRelocations() { } template <class ELFT> -void LLVMStyle<ELFT>::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, R, RelIndex, SymTab); +void LLVMStyle<ELFT>::printRelReloc(const Elf_Rel &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template <class ELFT> -void LLVMStyle<ELFT>::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, R, RelIndex, SymTab); +void LLVMStyle<ELFT>::printRelaReloc(const Elf_Rela &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } 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 RelTy> -void LLVMStyle<ELFT>::printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, - unsigned RelIndex, +void LLVMStyle<ELFT>::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex, + const Elf_Shdr &Sec, const Elf_Shdr *SymTab) { Expected<std::pair<const typename ELFT::Sym *, std::string>> Target = this->dumper()->getRelocationTarget(SymTab, Rel); if (!Target) { this->reportUniqueWarning(createError( - "unable to print relocation " + Twine(RelIndex) + " in section " + - Twine(SecIndex) + ": " + toString(Target.takeError()))); + "unable to print relocation " + Twine(RelIndex) + " in " + + describe(this->Obj, Sec) + ": " + toString(Target.takeError()))); return; }