[llvm] r179074 - Add a SymbolTableEntryBase.
Rafael Espindola
rafael.espindola at gmail.com
Mon Apr 8 17:22:59 PDT 2013
Author: rafael
Date: Mon Apr 8 19:22:58 2013
New Revision: 179074
URL: http://llvm.org/viewvc/llvm-project?rev=179074&view=rev
Log:
Add a SymbolTableEntryBase.
Use it when we don't need to know if we have a 32 or 64 bit SymbolTableEntry.
Modified:
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/lib/Object/MachOObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=179074&r1=179073&r2=179074&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Mon Apr 8 19:22:58 2013
@@ -71,6 +71,13 @@ namespace MachOFormat {
support::ulittle32_t Word1;
};
+ struct SymbolTableEntryBase {
+ support::ulittle32_t StringIndex;
+ uint8_t Type;
+ uint8_t SectionIndex;
+ support::ulittle16_t Flags;
+ };
+
template<bool is64Bits>
struct SymbolTableEntry;
@@ -263,12 +270,11 @@ private:
void moveToNextSection(DataRefImpl &DRI) const;
- const MachOFormat::SymbolTableEntry<false> *
- getSymbolTableEntry(DataRefImpl DRI,
- const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
+ const MachOFormat::SymbolTableEntryBase *
+ getSymbolTableEntryBase(DataRefImpl DRI) const;
- const MachOFormat::SymbolTableEntry<true> *
- getSymbol64TableEntry(DataRefImpl DRI,
+ const MachOFormat::SymbolTableEntryBase *
+ getSymbolTableEntryBase(DataRefImpl DRI,
const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
void moveToNextSymbol(DataRefImpl &DRI) const;
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=179074&r1=179073&r2=179074&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Mon Apr 8 19:22:58 2013
@@ -116,47 +116,40 @@ void MachOObjectFile::moveToNextSymbol(D
}
}
-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::getSymbolNam
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::getSymbolSec
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.
More information about the llvm-commits
mailing list