X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FObject%2FELFObjectFile.h;h=d345c96a404a68231851a19b3e90c17f5e8348fb;hb=4d79d2fcbfe2eb8110a118bc88dc06660f169cb1;hp=633211e056f6b5c45239747627d7c39b450b2225;hpb=e32110a5590ec3ea8ed4e18a35acdd2fdba9f638;p=oota-llvm.git diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 633211e056f..d345c96a404 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -193,6 +193,7 @@ protected: ELFFile EF; const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section. + const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section. void moveSymbolNext(DataRefImpl &Symb) const override; ErrorOr getSymbolName(DataRefImpl Symb) const override; @@ -239,10 +240,6 @@ protected: return *EF.getSection(Rel.d.a); } - const Elf_Sym *toELFSymIter(DataRefImpl Sym) const { - return EF.template getEntry(Sym.d.a, Sym.d.b); - } - DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const { DataRefImpl DRI; if (!SymTable) { @@ -303,7 +300,13 @@ public: const Elf_Rel *getRel(DataRefImpl Rel) const; const Elf_Rela *getRela(DataRefImpl Rela) const; - const Elf_Sym *getSymbol(DataRefImpl Symb) const; + const Elf_Sym *getSymbol(DataRefImpl Sym) const { + return EF.template getEntry(Sym.d.a, Sym.d.b); + } + + const Elf_Shdr *getSection(DataRefImpl Sec) const { + return reinterpret_cast(Sec.p); + } basic_symbol_iterator symbol_begin_impl() const override; basic_symbol_iterator symbol_end_impl() const override; @@ -350,7 +353,7 @@ void ELFObjectFile::moveSymbolNext(DataRefImpl &Sym) const { template ErrorOr ELFObjectFile::getSymbolName(DataRefImpl Sym) const { - const Elf_Sym *ESym = toELFSymIter(Sym); + const Elf_Sym *ESym = getSymbol(Sym); const Elf_Shdr *SymTableSec = *EF.getSection(Sym.d.a); const Elf_Shdr *StringTableSec = *EF.getSection(SymTableSec->sh_link); StringRef SymTable = *EF.getStringTable(StringTableSec); @@ -359,12 +362,12 @@ ErrorOr ELFObjectFile::getSymbolName(DataRefImpl Sym) const { template uint64_t ELFObjectFile::getSectionFlags(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_flags; + return getSection(Sec)->sh_flags; } template uint32_t ELFObjectFile::getSectionType(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_type; + return getSection(Sec)->sh_type; } template @@ -411,7 +414,7 @@ ELFObjectFile::getSymbolAddress(DataRefImpl Symb) const { template uint32_t ELFObjectFile::getSymbolAlignment(DataRefImpl Symb) const { - const Elf_Sym *Sym = toELFSymIter(Symb); + const Elf_Sym *Sym = getSymbol(Symb); if (Sym->st_shndx == ELF::SHN_COMMON) return Sym->st_value; return 0; @@ -419,22 +422,22 @@ uint32_t ELFObjectFile::getSymbolAlignment(DataRefImpl Symb) const { template uint64_t ELFObjectFile::getSymbolSize(DataRefImpl Sym) const { - return toELFSymIter(Sym)->st_size; + return getSymbol(Sym)->st_size; } template uint64_t ELFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const { - return toELFSymIter(Symb)->st_size; + return getSymbol(Symb)->st_size; } template uint8_t ELFObjectFile::getSymbolOther(DataRefImpl Symb) const { - return toELFSymIter(Symb)->st_other; + return getSymbol(Symb)->st_other; } template uint8_t ELFObjectFile::getSymbolELFType(DataRefImpl Symb) const { - return toELFSymIter(Symb)->getType(); + return getSymbol(Symb)->getType(); } template @@ -461,7 +464,7 @@ SymbolRef::Type ELFObjectFile::getSymbolType(DataRefImpl Symb) const { template uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const { - const Elf_Sym *ESym = toELFSymIter(Sym); + const Elf_Sym *ESym = getSymbol(Sym); uint32_t Result = SymbolRef::SF_None; @@ -475,7 +478,7 @@ uint32_t ELFObjectFile::getSymbolFlags(DataRefImpl Sym) const { Result |= SymbolRef::SF_Absolute; if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION || - ESym == EF.symbol_begin(EF.getDotSymtabSec()) || + ESym == EF.symbol_begin(DotSymtabSec) || ESym == EF.symbol_begin(DotDynSymSec)) Result |= SymbolRef::SF_FormatSpecific; @@ -527,14 +530,14 @@ ELFObjectFile::getSymbolSection(DataRefImpl Symb) const { template void ELFObjectFile::moveSectionNext(DataRefImpl &Sec) const { - const Elf_Shdr *ESec = toELFShdrIter(Sec); + const Elf_Shdr *ESec = getSection(Sec); Sec = toDRI(++ESec); } template std::error_code ELFObjectFile::getSectionName(DataRefImpl Sec, StringRef &Result) const { - ErrorOr Name = EF.getSectionName(&*toELFShdrIter(Sec)); + ErrorOr Name = EF.getSectionName(&*getSection(Sec)); if (!Name) return Name.getError(); Result = *Name; @@ -543,50 +546,50 @@ std::error_code ELFObjectFile::getSectionName(DataRefImpl Sec, template uint64_t ELFObjectFile::getSectionAddress(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_addr; + return getSection(Sec)->sh_addr; } template uint64_t ELFObjectFile::getSectionSize(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_size; + return getSection(Sec)->sh_size; } template std::error_code ELFObjectFile::getSectionContents(DataRefImpl Sec, StringRef &Result) const { - const Elf_Shdr *EShdr = toELFShdrIter(Sec); + const Elf_Shdr *EShdr = getSection(Sec); Result = StringRef((const char *)base() + EShdr->sh_offset, EShdr->sh_size); return std::error_code(); } template uint64_t ELFObjectFile::getSectionAlignment(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_addralign; + return getSection(Sec)->sh_addralign; } template bool ELFObjectFile::isSectionText(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_flags & ELF::SHF_EXECINSTR; + return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR; } template bool ELFObjectFile::isSectionData(DataRefImpl Sec) const { - const Elf_Shdr *EShdr = toELFShdrIter(Sec); + const Elf_Shdr *EShdr = getSection(Sec); return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) && EShdr->sh_type == ELF::SHT_PROGBITS; } template bool ELFObjectFile::isSectionBSS(DataRefImpl Sec) const { - const Elf_Shdr *EShdr = toELFShdrIter(Sec); + const Elf_Shdr *EShdr = getSection(Sec); return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) && EShdr->sh_type == ELF::SHT_NOBITS; } template bool ELFObjectFile::isSectionVirtual(DataRefImpl Sec) const { - return toELFShdrIter(Sec)->sh_type == ELF::SHT_NOBITS; + return getSection(Sec)->sh_type == ELF::SHT_NOBITS; } template @@ -633,7 +636,7 @@ ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const { if (EF.getHeader()->e_type != ELF::ET_REL) return section_end(); - const Elf_Shdr *EShdr = toELFShdrIter(Sec); + const Elf_Shdr *EShdr = getSection(Sec); uintX_t Type = EShdr->sh_type; if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA) return section_end(); @@ -667,7 +670,7 @@ ELFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { if (IsDyn) SymbolData = toDRI(DotDynSymSec, symbolIdx); else - SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx); + SymbolData = toDRI(DotSymtabSec, symbolIdx); return symbol_iterator(SymbolRef(SymbolData, this)); } @@ -711,12 +714,6 @@ ELFObjectFile::getRelocationAddend(DataRefImpl Rel) const { return (int64_t)getRela(Rel)->r_addend; } -template -const typename ELFFile::Elf_Sym * -ELFObjectFile::getSymbol(DataRefImpl Symb) const { - return &*toELFSymIter(Symb); -} - template const typename ELFObjectFile::Elf_Rel * ELFObjectFile::getRel(DataRefImpl Rel) const { @@ -750,19 +747,28 @@ ELFObjectFile::ELFObjectFile(MemoryBufferRef Object, std::error_code &EC) DotDynSymSec = &Sec; break; } + case ELF::SHT_SYMTAB: { + if (DotSymtabSec) { + // More than one .dynsym! + EC = object_error::parse_failed; + return; + } + DotSymtabSec = &Sec; + break; + } } } } template basic_symbol_iterator ELFObjectFile::symbol_begin_impl() const { - DataRefImpl Sym = toDRI(EF.getDotSymtabSec(), 0); + DataRefImpl Sym = toDRI(DotSymtabSec, 0); return basic_symbol_iterator(SymbolRef(Sym, this)); } template basic_symbol_iterator ELFObjectFile::symbol_end_impl() const { - const Elf_Shdr *SymTab = EF.getDotSymtabSec(); + const Elf_Shdr *SymTab = DotSymtabSec; if (!SymTab) return symbol_begin_impl(); DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));