mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Refactor duplicated code and check for invalid symbol table size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242981 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -179,30 +179,34 @@ public:
|
|||||||
return make_range(section_begin(), section_end());
|
return make_range(section_begin(), section_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Elf_Sym *symbol_begin() const;
|
const Elf_Sym *symbol_begin(const Elf_Shdr *Sec) const {
|
||||||
const Elf_Sym *symbol_end() const;
|
if (!Sec)
|
||||||
Elf_Sym_Range symbols() const {
|
return nullptr;
|
||||||
return make_range(symbol_begin(), symbol_end());
|
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 {
|
const Elf_Sym *dynamic_symbol_begin() const {
|
||||||
if (!DotDynSymSec)
|
return symbol_begin(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());
|
|
||||||
}
|
}
|
||||||
|
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;
|
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();
|
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 <class ELFT>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T *ELFFile<ELFT>::getEntry(uint32_t Section, uint32_t Entry) const {
|
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
|
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
|
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
|
||||||
|
Reference in New Issue
Block a user