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
const T *getEntry(uint32_t Section, uint32_t Entry) const;
template <typename T>
const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
const T *getEntry(uint32_t Section, uint32_t Entry) const;
template <typename T>
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;
const char *getDynamicString(uintX_t Offset) const;
ErrorOr<StringRef> getSymbolVersion(const Elf_Shdr *section,
ErrorOr<StringRef> getStringTable(const Elf_Shdr *Section) const;
const char *getDynamicString(uintX_t Offset) const;
ErrorOr<StringRef> getSymbolVersion(const Elf_Shdr *section,
}
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 {
- DRI.p =
- reinterpret_cast<uintptr_t>(Sym) | static_cast<uintptr_t>(IsDynamic);
+ if (!SymTable) {
+ 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;
template <class ELFT>
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
template <class ELFT>
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Sym) const {
- const Elf_Sym *S = toELFSymIter(Sym);
- Sym = toDRI(++S, Sym.p & 1);
}
template <class ELFT>
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
const Elf_Sym *ESym = toELFSymIter(Sym);
}
template <class ELFT>
ErrorOr<StringRef> ELFObjectFile<ELFT>::getSymbolName(DataRefImpl Sym) const {
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);
Result |= SymbolRef::SF_FormatSpecific;
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
Result |= SymbolRef::SF_FormatSpecific;
if (EF.getHeader()->e_machine == ELF::EM_ARM) {
- ErrorOr<StringRef> NameOrErr = EF.getSymbolName(ESym, Sym.p & 1);
- if (NameOrErr) {
+ if (ErrorOr<StringRef> NameOrErr = getSymbolName(Sym)) {
StringRef Name = *NameOrErr;
if (Name.startswith("$d") || Name.startswith("$t") ||
Name.startswith("$a"))
StringRef Name = *NameOrErr;
if (Name.startswith("$d") || Name.startswith("$t") ||
Name.startswith("$a"))
bool IsDyn = Rel.d.b & 1;
DataRefImpl SymbolData;
if (IsDyn)
bool IsDyn = Rel.d.b & 1;
DataRefImpl SymbolData;
if (IsDyn)
- SymbolData = toDRI(EF.dynamic_symbol_begin() + symbolIdx, true);
+ SymbolData = toDRI(EF.getDotDynSymSec(), symbolIdx);
- SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false);
+ SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx);
return symbol_iterator(SymbolRef(SymbolData, this));
}
return symbol_iterator(SymbolRef(SymbolData, this));
}
template <class ELFT>
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin_impl() const {
template <class ELFT>
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));
}
template <class ELFT>
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_end_impl() const {
return basic_symbol_iterator(SymbolRef(Sym, this));
}
template <class ELFT>
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));
}
template <class ELFT>
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_begin() const {
return basic_symbol_iterator(SymbolRef(Sym, this));
}
template <class ELFT>
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));
}
template <class ELFT>
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_end() const {
return symbol_iterator(SymbolRef(Sym, this));
}
template <class ELFT>
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_end() const {
- DataRefImpl Sym = toDRI(EF.dynamic_symbol_end(), true);
- return symbol_iterator(SymbolRef(Sym, this));
+ const Elf_Shdr *SymTab = EF.getDotDynSymSec();
+ DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
+ return basic_symbol_iterator(SymbolRef(Sym, this));