mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 17:24:48 +00:00
Continue to remove the notion that ELF has dynamic and static symbols.
The ELFObjectFile now just reasons about a section/index pair, removing one of the users that force ELF.h to maintain the difference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241344 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -234,6 +234,10 @@ public:
|
|||||||
const T *getEntry(uint32_t Section, uint32_t Entry) const;
|
const T *getEntry(uint32_t Section, uint32_t Entry) const;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
|
const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
|
||||||
|
|
||||||
|
const Elf_Shdr *getDotSymtabSec() const { return dot_symtab_sec; }
|
||||||
|
const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
|
||||||
|
|
||||||
ErrorOr<StringRef> getStringTable(const Elf_Shdr *Section) const;
|
ErrorOr<StringRef> getStringTable(const Elf_Shdr *Section) const;
|
||||||
const char *getDynamicString(uintX_t Offset) const;
|
const char *getDynamicString(uintX_t Offset) const;
|
||||||
ErrorOr<StringRef> getSymbolVersion(const Elf_Shdr *section,
|
ErrorOr<StringRef> getSymbolVersion(const Elf_Shdr *section,
|
||||||
|
@ -244,13 +244,25 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
|
const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
|
||||||
return reinterpret_cast<const Elf_Sym *>(Sym.p & ~uintptr_t(1));
|
return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataRefImpl toDRI(const Elf_Sym *Sym, bool IsDynamic) const {
|
DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
|
||||||
DataRefImpl DRI;
|
DataRefImpl DRI;
|
||||||
DRI.p =
|
if (!SymTable) {
|
||||||
reinterpret_cast<uintptr_t>(Sym) | static_cast<uintptr_t>(IsDynamic);
|
DRI.d.a = 0;
|
||||||
|
DRI.d.b = 0;
|
||||||
|
return DRI;
|
||||||
|
}
|
||||||
|
uint32_t Type = SymTable->sh_type;
|
||||||
|
assert(Type == ELF::SHT_SYMTAB || Type == ELF::SHT_DYNSYM);
|
||||||
|
|
||||||
|
uintptr_t SHT = reinterpret_cast<uintptr_t>(EF.section_begin());
|
||||||
|
unsigned SymTableIndex =
|
||||||
|
(reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr);
|
||||||
|
|
||||||
|
DRI.d.a = SymTableIndex;
|
||||||
|
DRI.d.b = SymbolNum;
|
||||||
return DRI;
|
return DRI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,14 +355,16 @@ typedef ELFObjectFile<ELFType<support::big, true>> ELF64BEObjectFile;
|
|||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
|
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
|
||||||
const Elf_Sym *S = toELFSymIter(Sym);
|
++Sym.d.b;
|
||||||
Sym = toDRI(++S, Sym.p & 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
|
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
|
||||||
const Elf_Sym *ESym = toELFSymIter(Sym);
|
const Elf_Sym *ESym = toELFSymIter(Sym);
|
||||||
return EF.getSymbolName(ESym, Sym.p & 1);
|
const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a);
|
||||||
|
const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link);
|
||||||
|
StringRef SymTable = *EF.getStringTable(StringTableSec);
|
||||||
|
return ESym->getName(SymTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
@ -481,8 +495,7 @@ uint32_t ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
|
|||||||
Result |= SymbolRef::SF_FormatSpecific;
|
Result |= SymbolRef::SF_FormatSpecific;
|
||||||
|
|
||||||
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
|
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
|
||||||
ErrorOr<StringRef> NameOrErr = EF.getSymbolName(ESym, Sym.p & 1);
|
if (ErrorOr<StringRef> NameOrErr = getSymbolName(Sym)) {
|
||||||
if (NameOrErr) {
|
|
||||||
StringRef Name = *NameOrErr;
|
StringRef Name = *NameOrErr;
|
||||||
if (Name.startswith("$d") || Name.startswith("$t") ||
|
if (Name.startswith("$d") || Name.startswith("$t") ||
|
||||||
Name.startswith("$a"))
|
Name.startswith("$a"))
|
||||||
@ -669,9 +682,9 @@ ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
|
|||||||
bool IsDyn = Rel.d.b & 1;
|
bool IsDyn = Rel.d.b & 1;
|
||||||
DataRefImpl SymbolData;
|
DataRefImpl SymbolData;
|
||||||
if (IsDyn)
|
if (IsDyn)
|
||||||
SymbolData = toDRI(EF.dynamic_symbol_begin() + symbolIdx, true);
|
SymbolData = toDRI(EF.getDotDynSymSec(), symbolIdx);
|
||||||
else
|
else
|
||||||
SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false);
|
SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx);
|
||||||
return symbol_iterator(SymbolRef(SymbolData, this));
|
return symbol_iterator(SymbolRef(SymbolData, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,26 +781,30 @@ ELFObjectFile<ELFT>::ELFObjectFile(MemoryBufferRef Object, std::error_code &EC)
|
|||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin_impl() const {
|
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin_impl() const {
|
||||||
DataRefImpl Sym = toDRI(EF.symbol_begin(), false);
|
DataRefImpl Sym = toDRI(EF.getDotSymtabSec(), 0);
|
||||||
return basic_symbol_iterator(SymbolRef(Sym, this));
|
return basic_symbol_iterator(SymbolRef(Sym, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_end_impl() const {
|
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_end_impl() const {
|
||||||
DataRefImpl Sym = toDRI(EF.symbol_end(), false);
|
const Elf_Shdr *SymTab = EF.getDotSymtabSec();
|
||||||
|
if (!SymTab)
|
||||||
|
return symbol_begin_impl();
|
||||||
|
DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
|
||||||
return basic_symbol_iterator(SymbolRef(Sym, this));
|
return basic_symbol_iterator(SymbolRef(Sym, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_begin() const {
|
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_begin() const {
|
||||||
DataRefImpl Sym = toDRI(EF.dynamic_symbol_begin(), true);
|
DataRefImpl Sym = toDRI(EF.getDotDynSymSec(), 0);
|
||||||
return symbol_iterator(SymbolRef(Sym, this));
|
return symbol_iterator(SymbolRef(Sym, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_end() const {
|
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_end() const {
|
||||||
DataRefImpl Sym = toDRI(EF.dynamic_symbol_end(), true);
|
const Elf_Shdr *SymTab = EF.getDotDynSymSec();
|
||||||
return symbol_iterator(SymbolRef(Sym, this));
|
DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
|
||||||
|
return basic_symbol_iterator(SymbolRef(Sym, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
Reference in New Issue
Block a user