diff --git a/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test b/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test --- a/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test +++ b/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test @@ -260,18 +260,22 @@ ## Show we print a warning when the symbol index of a dynamic relocation is too ## large (goes past the end of the dynamic symbol table). # RUN: yaml2obj --docnum=5 %s -o %t12 -# RUN: llvm-readobj --dyn-relocations %t12 2>&1 | FileCheck %s -DFILE=%t12 --check-prefix=LLVM-INVALID-DYNSYM -# RUN: llvm-readelf --dyn-relocations %t12 2>&1 | FileCheck %s -DFILE=%t12 --check-prefix=GNU-INVALID-DYNSYM +# RUN: llvm-readobj --dyn-relocations %t12 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=LLVM-INVALID-DYNSYM +# RUN: llvm-readelf --dyn-relocations %t12 2>&1 | \ +# RUN: FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=GNU-INVALID-DYNSYM # LLVM-INVALID-DYNSYM: Dynamic Relocations { # LLVM-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: index is greater than or equal to the number of dynamic symbols (2) # LLVM-INVALID-DYNSYM-NEXT: 0x0 R_X86_64_NONE 0x0 +# LLVM-INVALID-DYNSYM-NEXT: 0x0 R_X86_64_NONE 0x0 # LLVM-INVALID-DYNSYM-NEXT: } -# GNU-INVALID-DYNSYM: 'RELA' relocation section at offset 0x78 contains 24 bytes: +# GNU-INVALID-DYNSYM: 'RELA' relocation section at offset 0x78 contains 48 bytes: # GNU-INVALID-DYNSYM-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend # GNU-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: index is greater than or equal to the number of dynamic symbols (2) # GNU-INVALID-DYNSYM-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE + 0 +# GNU-INVALID-DYNSYM-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE + 0 --- !ELF FileHeader: @@ -285,13 +289,15 @@ Relocations: - Type: R_X86_64_NONE Symbol: 0x2 + - Type: R_X86_64_NONE + Symbol: 0x2 - Name: .dynamic Type: SHT_DYNAMIC Entries: - Tag: DT_RELA Value: 0x0 - Tag: DT_RELASZ - Value: 0x18 + Value: 0x30 - Tag: DT_RELAENT Value: 0x18 - Tag: DT_NULL 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 @@ -4554,16 +4554,14 @@ namespace { template -RelSymbol getSymbolForReloc(const ELFFile &Obj, StringRef FileName, - const ELFDumper &Dumper, +RelSymbol getSymbolForReloc(const ELFDumper &Dumper, const Relocation &Reloc) { using Elf_Sym = typename ELFT::Sym; auto WarnAndReturn = [&](const Elf_Sym *Sym, const Twine &Reason) -> RelSymbol { - reportWarning( - createError("unable to get name of the dynamic symbol with index " + - Twine(Reloc.Symbol) + ": " + Reason), - FileName); + Dumper.reportUniqueWarning( + "unable to get name of the dynamic symbol with index " + + Twine(Reloc.Symbol) + ": " + Reason); return {Sym, ""}; }; @@ -4581,6 +4579,7 @@ "index is greater than or equal to the number of dynamic symbols (" + Twine(Symbols.size()) + ")"); + const ELFFile &Obj = *Dumper.getElfObject().getELFFile(); const uint64_t FileSize = Obj.getBufSize(); const uint64_t SymOffset = ((const uint8_t *)FirstSym - Obj.base()) + (uint64_t)Reloc.Symbol * sizeof(Elf_Sym); @@ -4600,8 +4599,7 @@ template void GNUStyle::printDynamicReloc(const Relocation &R) { - printRelRelaReloc( - R, getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R)); + printRelRelaReloc(R, getSymbolForReloc(this->dumper(), R)); } template @@ -6604,8 +6602,7 @@ template void LLVMStyle::printDynamicReloc(const Relocation &R) { - RelSymbol S = - getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R); + RelSymbol S = getSymbolForReloc(this->dumper(), R); printRelRelaReloc(R, S.Name); }