forked from OSchip/llvm-project
[llvm-readelf/obj] - Report unique warnings in getSymbolForReloc() helper.
Use `reportUniqueWarning` instead of `reportWarning` and refine the interface of the helper. Differential revision: https://reviews.llvm.org/D92556
This commit is contained in:
parent
152df3add1
commit
50de7d5504
|
@ -260,18 +260,22 @@ ProgramHeaders:
|
|||
## 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 <corrupt> 0x0
|
||||
# LLVM-INVALID-DYNSYM-NEXT: 0x0 R_X86_64_NONE <corrupt> 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 <corrupt> + 0
|
||||
# GNU-INVALID-DYNSYM-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE <corrupt> + 0
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
|
@ -285,13 +289,15 @@ Sections:
|
|||
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
|
||||
|
|
|
@ -4554,16 +4554,14 @@ template <class ELFT> void GNUStyle<ELFT>::printSectionMapping() {
|
|||
namespace {
|
||||
|
||||
template <class ELFT>
|
||||
RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
|
||||
const ELFDumper<ELFT> &Dumper,
|
||||
RelSymbol<ELFT> getSymbolForReloc(const ELFDumper<ELFT> &Dumper,
|
||||
const Relocation<ELFT> &Reloc) {
|
||||
using Elf_Sym = typename ELFT::Sym;
|
||||
auto WarnAndReturn = [&](const Elf_Sym *Sym,
|
||||
const Twine &Reason) -> RelSymbol<ELFT> {
|
||||
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, "<corrupt>"};
|
||||
};
|
||||
|
||||
|
@ -4581,6 +4579,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
|
|||
"index is greater than or equal to the number of dynamic symbols (" +
|
||||
Twine(Symbols.size()) + ")");
|
||||
|
||||
const ELFFile<ELFT> &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 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> &Obj, StringRef FileName,
|
|||
|
||||
template <class ELFT>
|
||||
void GNUStyle<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
|
||||
printRelRelaReloc(
|
||||
R, getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R));
|
||||
printRelRelaReloc(R, getSymbolForReloc(this->dumper(), R));
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
@ -6604,8 +6602,7 @@ template <class ELFT> void LLVMStyle<ELFT>::printDynamicRelocations() {
|
|||
|
||||
template <class ELFT>
|
||||
void LLVMStyle<ELFT>::printDynamicReloc(const Relocation<ELFT> &R) {
|
||||
RelSymbol<ELFT> S =
|
||||
getSymbolForReloc(this->Obj, this->FileName, this->dumper(), R);
|
||||
RelSymbol<ELFT> S = getSymbolForReloc(this->dumper(), R);
|
||||
printRelRelaReloc(R, S.Name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue