llvm.org GIT mirror llvm / abdd9e7
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 Rafael Espindola 4 years ago
2 changed file(s) with 39 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
233233 const T *getEntry(uint32_t Section, uint32_t Entry) const;
234234 template
235235 const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
236
237 const Elf_Shdr *getDotSymtabSec() const { return dot_symtab_sec; }
238 const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
239
236240 ErrorOr getStringTable(const Elf_Shdr *Section) const;
237241 const char *getDynamicString(uintX_t Offset) const;
238242 ErrorOr getSymbolVersion(const Elf_Shdr *section,
243243 }
244244
245245 const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
246 return reinterpret_cast(Sym.p & ~uintptr_t(1));
247 }
248
249 DataRefImpl toDRI(const Elf_Sym *Sym, bool IsDynamic) const {
246 return EF.template getEntry(Sym.d.a, Sym.d.b);
247 }
248
249 DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
250250 DataRefImpl DRI;
251 DRI.p =
252 reinterpret_cast(Sym) | static_cast(IsDynamic);
251 if (!SymTable) {
252 DRI.d.a = 0;
253 DRI.d.b = 0;
254 return DRI;
255 }
256 uint32_t Type = SymTable->sh_type;
257 assert(Type == ELF::SHT_SYMTAB || Type == ELF::SHT_DYNSYM);
258
259 uintptr_t SHT = reinterpret_cast(EF.section_begin());
260 unsigned SymTableIndex =
261 (reinterpret_cast(SymTable) - SHT) / sizeof(Elf_Shdr);
262
263 DRI.d.a = SymTableIndex;
264 DRI.d.b = SymbolNum;
253265 return DRI;
254266 }
255267
342354
343355 template
344356 void ELFObjectFile::moveSymbolNext(DataRefImpl &Sym) const {
345 const Elf_Sym *S = toELFSymIter(Sym);
346 Sym = toDRI(++S, Sym.p & 1);
357 ++Sym.d.b;
347358 }
348359
349360 template
350361 ErrorOr ELFObjectFile::getSymbolName(DataRefImpl Sym) const {
351362 const Elf_Sym *ESym = toELFSymIter(Sym);
352 return EF.getSymbolName(ESym, Sym.p & 1);
363 const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a);
364 const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link);
365 StringRef SymTable = *EF.getStringTable(StringTableSec);
366 return ESym->getName(SymTable);
353367 }
354368
355369 template
480494 Result |= SymbolRef::SF_FormatSpecific;
481495
482496 if (EF.getHeader()->e_machine == ELF::EM_ARM) {
483 ErrorOr NameOrErr = EF.getSymbolName(ESym, Sym.p & 1);
484 if (NameOrErr) {
497 if (ErrorOr NameOrErr = getSymbolName(Sym)) {
485498 StringRef Name = *NameOrErr;
486499 if (Name.startswith("$d") || Name.startswith("$t") ||
487500 Name.startswith("$a"))
668681 bool IsDyn = Rel.d.b & 1;
669682 DataRefImpl SymbolData;
670683 if (IsDyn)
671 SymbolData = toDRI(EF.dynamic_symbol_begin() + symbolIdx, true);
684 SymbolData = toDRI(EF.getDotDynSymSec(), symbolIdx);
672685 else
673 SymbolData = toDRI(EF.symbol_begin() + symbolIdx, false);
686 SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx);
674687 return symbol_iterator(SymbolRef(SymbolData, this));
675688 }
676689
767780
768781 template
769782 basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const {
770 DataRefImpl Sym = toDRI(EF.symbol_begin(), false);
783 DataRefImpl Sym = toDRI(EF.getDotSymtabSec(), 0);
771784 return basic_symbol_iterator(SymbolRef(Sym, this));
772785 }
773786
774787 template
775788 basic_symbol_iterator ELFObjectFile::symbol_end_impl() const {
776 DataRefImpl Sym = toDRI(EF.symbol_end(), false);
789 const Elf_Shdr *SymTab = EF.getDotSymtabSec();
790 if (!SymTab)
791 return symbol_begin_impl();
792 DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
777793 return basic_symbol_iterator(SymbolRef(Sym, this));
778794 }
779795
780796 template
781797 elf_symbol_iterator ELFObjectFile::dynamic_symbol_begin() const {
782 DataRefImpl Sym = toDRI(EF.dynamic_symbol_begin(), true);
798 DataRefImpl Sym = toDRI(EF.getDotDynSymSec(), 0);
783799 return symbol_iterator(SymbolRef(Sym, this));
784800 }
785801
786802 template
787803 elf_symbol_iterator ELFObjectFile::dynamic_symbol_end() const {
788 DataRefImpl Sym = toDRI(EF.dynamic_symbol_end(), true);
789 return symbol_iterator(SymbolRef(Sym, this));
804 const Elf_Shdr *SymTab = EF.getDotDynSymSec();
805 DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
806 return basic_symbol_iterator(SymbolRef(Sym, this));
790807 }
791808
792809 template