diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-09 00:22:58 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-09 00:22:58 +0000 |
commit | 7df9c57651574feccd53aec0aac469dea2b48bc6 (patch) | |
tree | d893f892d3b18986c22cb59859b3c77243129d99 /lib | |
parent | b3d25a940cfd44ffbac71adc6d8f3759ad8a8cb4 (diff) |
Add a SymbolTableEntryBase.
Use it when we don't need to know if we have a 32 or 64 bit SymbolTableEntry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179074 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 3931c53ac8..ae30105a93 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -116,47 +116,40 @@ void MachOObjectFile::moveToNextSymbol(DataRefImpl &DRI) const { } } -const MachOFormat::SymbolTableEntry<false> * -MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const { +const MachOFormat::SymbolTableEntryBase * +MachOObjectFile::getSymbolTableEntryBase(DataRefImpl DRI) const { const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a); const MachOFormat::SymtabLoadCommand *SymtabLoadCmd = reinterpret_cast<const MachOFormat::SymtabLoadCommand*>(Command); - - return getSymbolTableEntry(DRI, SymtabLoadCmd); + return getSymbolTableEntryBase(DRI, SymtabLoadCmd); } const MachOFormat::SymbolTableEntry<false> * -MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI, +MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const { + const MachOFormat::SymbolTableEntryBase *Base = getSymbolTableEntryBase(DRI); + return reinterpret_cast<const MachOFormat::SymbolTableEntry<false>*>(Base); +} + +const MachOFormat::SymbolTableEntryBase * +MachOObjectFile::getSymbolTableEntryBase(DataRefImpl DRI, const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const { uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset; unsigned Index = DRI.d.b; - uint64_t Offset = (SymbolTableOffset + - Index * sizeof(MachOFormat::SymbolTableEntry<false>)); - StringRef Data = - getData(Offset, sizeof(MachOFormat::SymbolTableEntry<false>)); - return - reinterpret_cast<const MachOFormat::SymbolTableEntry<false>*>(Data.data()); -} -const MachOFormat::SymbolTableEntry<true>* -MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const { - const MachOFormat::LoadCommand *Command = getLoadCommandInfo(DRI.d.a); - const MachOFormat::SymtabLoadCommand *SymtabLoadCmd = - reinterpret_cast<const MachOFormat::SymtabLoadCommand*>(Command); + unsigned SymbolTableEntrySize = is64Bit() ? + sizeof(MachOFormat::SymbolTableEntry<true>) : + sizeof(MachOFormat::SymbolTableEntry<false>); - return getSymbol64TableEntry(DRI, SymtabLoadCmd); + uint64_t Offset = SymbolTableOffset + Index * SymbolTableEntrySize; + StringRef Data = getData(Offset, SymbolTableEntrySize); + return + reinterpret_cast<const MachOFormat::SymbolTableEntryBase*>(Data.data()); } const MachOFormat::SymbolTableEntry<true>* -MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI, - const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const { - uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset; - unsigned Index = DRI.d.b; - uint64_t Offset = (SymbolTableOffset + - Index * sizeof(MachOFormat::SymbolTableEntry<true>)); - StringRef Data = getData(Offset, sizeof(MachOFormat::SymbolTableEntry<true>)); - return - reinterpret_cast<const MachOFormat::SymbolTableEntry<true>*>(Data.data()); +MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const { + const MachOFormat::SymbolTableEntryBase *Base = getSymbolTableEntryBase(DRI); + return reinterpret_cast<const MachOFormat::SymbolTableEntry<true>*>(Base); } error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI, @@ -176,16 +169,9 @@ error_code MachOObjectFile::getSymbolName(DataRefImpl DRI, StringRef StringTable = getData(SymtabLoadCmd->StringTableOffset, SymtabLoadCmd->StringTableSize); - uint32_t StringIndex; - if (is64Bit()) { - const MachOFormat::SymbolTableEntry<true> *Entry = - getSymbol64TableEntry(DRI, SymtabLoadCmd); - StringIndex = Entry->StringIndex; - } else { - const MachOFormat::SymbolTableEntry<false> *Entry = - getSymbolTableEntry(DRI, SymtabLoadCmd); - StringIndex = Entry->StringIndex; - } + const MachOFormat::SymbolTableEntryBase *Entry = + getSymbolTableEntryBase(DRI, SymtabLoadCmd); + uint32_t StringIndex = Entry->StringIndex; const char *Start = &StringTable.data()[StringIndex]; Result = StringRef(Start); @@ -403,16 +389,10 @@ error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb, error_code MachOObjectFile::getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const { - uint8_t n_type; - if (is64Bit()) { - const MachOFormat::SymbolTableEntry<true> *Entry = - getSymbol64TableEntry(Symb); - n_type = Entry->Type; - } else { - const MachOFormat::SymbolTableEntry<false> *Entry = - getSymbolTableEntry(Symb); - n_type = Entry->Type; - } + const MachOFormat::SymbolTableEntryBase *Entry = + getSymbolTableEntryBase(Symb); + uint8_t n_type = Entry->Type; + Res = SymbolRef::ST_Other; // If this is a STAB debugging symbol, we can do nothing more. |