mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:50:30 +00:00
Refactor duplicated code and check for invalid symbol table size.
llvm-svn: 242981
This commit is contained in:
parent
18045e8fbf
commit
8c9308a255
@ -179,30 +179,34 @@ public:
|
||||
return make_range(section_begin(), section_end());
|
||||
}
|
||||
|
||||
const Elf_Sym *symbol_begin() const;
|
||||
const Elf_Sym *symbol_end() const;
|
||||
Elf_Sym_Range symbols() const {
|
||||
return make_range(symbol_begin(), symbol_end());
|
||||
const Elf_Sym *symbol_begin(const Elf_Shdr *Sec) const {
|
||||
if (!Sec)
|
||||
return nullptr;
|
||||
if (Sec->sh_entsize != sizeof(Elf_Sym))
|
||||
report_fatal_error("Invalid symbol size");
|
||||
return reinterpret_cast<const Elf_Sym *>(base() + Sec->sh_offset);
|
||||
}
|
||||
const Elf_Sym *symbol_end(const Elf_Shdr *Sec) const {
|
||||
if (!Sec)
|
||||
return nullptr;
|
||||
uint64_t Size = Sec->sh_size;
|
||||
if (Size % sizeof(Elf_Sym))
|
||||
report_fatal_error("Invalid symbol table size");
|
||||
return symbol_begin(Sec) + Size / sizeof(Elf_Sym);
|
||||
}
|
||||
Elf_Sym_Range symbols(const Elf_Shdr *Sec) const {
|
||||
return make_range(symbol_begin(Sec), symbol_end(Sec));
|
||||
}
|
||||
|
||||
const Elf_Sym *symbol_begin() const { return symbol_begin(dot_symtab_sec); }
|
||||
const Elf_Sym *symbol_end() const { return symbol_end(dot_symtab_sec); }
|
||||
Elf_Sym_Range symbols() const { return symbols(dot_symtab_sec); }
|
||||
|
||||
const Elf_Sym *dynamic_symbol_begin() const {
|
||||
if (!DotDynSymSec)
|
||||
return nullptr;
|
||||
if (DotDynSymSec->sh_entsize != sizeof(Elf_Sym))
|
||||
report_fatal_error("Invalid symbol size");
|
||||
return reinterpret_cast<const Elf_Sym *>(base() + DotDynSymSec->sh_offset);
|
||||
}
|
||||
|
||||
const Elf_Sym *dynamic_symbol_end() const {
|
||||
if (!DotDynSymSec)
|
||||
return nullptr;
|
||||
return reinterpret_cast<const Elf_Sym *>(base() + DotDynSymSec->sh_offset +
|
||||
DotDynSymSec->sh_size);
|
||||
}
|
||||
|
||||
Elf_Sym_Range dynamic_symbols() const {
|
||||
return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
|
||||
return symbol_begin(DotDynSymSec);
|
||||
}
|
||||
const Elf_Sym *dynamic_symbol_end() const { return symbol_end(DotDynSymSec); }
|
||||
Elf_Sym_Range dynamic_symbols() const { return symbols(DotDynSymSec); }
|
||||
|
||||
typedef iterator_range<const Elf_Rela *> Elf_Rela_Range;
|
||||
|
||||
@ -602,23 +606,6 @@ const typename ELFFile<ELFT>::Elf_Shdr *ELFFile<ELFT>::section_end() const {
|
||||
return section_begin() + getNumSections();
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
const typename ELFFile<ELFT>::Elf_Sym *ELFFile<ELFT>::symbol_begin() const {
|
||||
if (!dot_symtab_sec)
|
||||
return nullptr;
|
||||
if (dot_symtab_sec->sh_entsize != sizeof(Elf_Sym))
|
||||
report_fatal_error("Invalid symbol size");
|
||||
return reinterpret_cast<const Elf_Sym *>(base() + dot_symtab_sec->sh_offset);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
const typename ELFFile<ELFT>::Elf_Sym *ELFFile<ELFT>::symbol_end() const {
|
||||
if (!dot_symtab_sec)
|
||||
return nullptr;
|
||||
return reinterpret_cast<const Elf_Sym *>(base() + dot_symtab_sec->sh_offset +
|
||||
dot_symtab_sec->sh_size);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
template <typename T>
|
||||
const T *ELFFile<ELFT>::getEntry(uint32_t Section, uint32_t Entry) const {
|
||||
|
BIN
test/Object/Inputs/invalid-symbol-table-size.elf
Executable file
BIN
test/Object/Inputs/invalid-symbol-table-size.elf
Executable file
Binary file not shown.
@ -44,3 +44,7 @@ INVALID-SECTION-INDEX: Invalid section index
|
||||
|
||||
RUN: not llvm-readobj -s %p/Inputs/invalid-section-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SECTION-SIZE %s
|
||||
INVALID-SECTION-SIZE: Invalid section header entry size (e_shentsize) in ELF header
|
||||
|
||||
|
||||
RUN: not llvm-readobj -t %p/Inputs/invalid-symbol-table-size.elf 2>&1 | FileCheck --check-prefix=INVALID-SYMTAB-SIZE %s
|
||||
INVALID-SYMTAB-SIZE: Invalid symbol table size
|
||||
|
Loading…
Reference in New Issue
Block a user