diff --git a/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test b/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test --- 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 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -747,10 +747,10 @@ function_ref OnSectionStart, function_ref 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 @@ } 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 - 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 void printRelRelaReloc(const Elf_Sym *Sym, StringRef SymbolName, const RelTy &R); @@ -932,13 +932,13 @@ void printMipsABIFlags(const ELFObjectFile *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 - 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 void printDynamicRelocation(const RelTy &Rel); @@ -3601,15 +3601,17 @@ } template -void GNUStyle::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, SymTab, R, RelIndex); +void GNUStyle::printRelReloc(const Elf_Rel &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template -void GNUStyle::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, SymTab, R, RelIndex); +void GNUStyle::printRelaReloc(const Elf_Rela &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template void GNUStyle::printRelrReloc(const Elf_Relr &R) { @@ -3618,15 +3620,15 @@ template template -void GNUStyle::printRelRelaReloc(unsigned SecIndex, - const Elf_Shdr *SymTab, const RelTy &R, - unsigned RelIndex) { +void GNUStyle::printRelRelaReloc(const RelTy &R, unsigned RelIndex, + const Elf_Shdr &Sec, + const Elf_Shdr *SymTab) { Expected> 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 @@ SymTab = *SymTabOrErr; } - unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front(); unsigned RelNdx = 0; switch (Sec.sh_type) { case ELF::SHT_REL: if (Expected 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 @@ case ELF::SHT_RELA: if (Expected 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 @@ } 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> 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 -void LLVMStyle::printRelReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rel &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, R, RelIndex, SymTab); +void LLVMStyle::printRelReloc(const Elf_Rel &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template -void LLVMStyle::printRelaReloc(unsigned SecIndex, const Elf_Shdr *SymTab, - const Elf_Rela &R, unsigned RelIndex) { - printRelRelaReloc(SecIndex, R, RelIndex, SymTab); +void LLVMStyle::printRelaReloc(const Elf_Rela &R, unsigned RelIndex, + const Elf_Shdr *Sec, + const Elf_Shdr *SymTab) { + printRelRelaReloc(R, RelIndex, *Sec, SymTab); } template void LLVMStyle::printRelrReloc(const Elf_Relr &R) { @@ -6163,15 +6166,15 @@ template template -void LLVMStyle::printRelRelaReloc(unsigned SecIndex, const RelTy &Rel, - unsigned RelIndex, +void LLVMStyle::printRelRelaReloc(const RelTy &Rel, unsigned RelIndex, + const Elf_Shdr &Sec, const Elf_Shdr *SymTab) { Expected> 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; }