[llvm] r178947 - Don't use InMemoryStruct<macho::SymtabLoadCommand>.
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 5 20:31:08 PDT 2013
Author: rafael
Date: Fri Apr 5 22:31:08 2013
New Revision: 178947
URL: http://llvm.org/viewvc/llvm-project?rev=178947&view=rev
Log:
Don't use InMemoryStruct<macho::SymtabLoadCommand>.
This also required not using the RegisterStringTable API, which is also a
good thing.
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=178947&r1=178946&r2=178947&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Fri Apr 5 22:31:08 2013
@@ -76,6 +76,15 @@ namespace MachOFormat {
support::ulittle16_t Flags;
support::ulittle64_t Value;
};
+
+ struct SymtabLoadCommand {
+ support::ulittle32_t Type;
+ support::ulittle32_t Size;
+ support::ulittle32_t SymbolTableOffset;
+ support::ulittle32_t NumSymbolTableEntries;
+ support::ulittle32_t StringTableOffset;
+ support::ulittle32_t StringTableSize;
+ };
}
typedef MachOObject::LoadCommandInfo LoadCommandInfo;
@@ -169,20 +178,32 @@ protected:
private:
OwningPtr<MachOObject> MachOObj;
- mutable uint32_t RegisteredStringTable;
typedef SmallVector<DataRefImpl, 1> SectionList;
SectionList Sections;
void moveToNextSection(DataRefImpl &DRI) const;
+
const MachOFormat::SymbolTableEntry *
getSymbolTableEntry(DataRefImpl DRI) const;
+
+ const MachOFormat::SymbolTableEntry *
+ getSymbolTableEntry(DataRefImpl DRI,
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
+
const MachOFormat::Symbol64TableEntry *
getSymbol64TableEntry(DataRefImpl DRI) const;
+
+ const MachOFormat::Symbol64TableEntry *
+ getSymbol64TableEntry(DataRefImpl DRI,
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const;
+
void moveToNextSymbol(DataRefImpl &DRI) const;
const MachOFormat::Section *getSection(DataRefImpl DRI) const;
const MachOFormat::Section64 *getSection64(DataRefImpl DRI) const;
const MachOFormat::RelocationEntry *getRelocation(DataRefImpl Rel) const;
+ const MachOFormat::SymtabLoadCommand *
+ getSymtabLoadCommand(LoadCommandInfo LCI) const;
std::size_t getSectionIndex(DataRefImpl Sec) const;
void printRelocationTargetName(const MachOFormat::RelocationEntry *RE,
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=178947&r1=178946&r2=178947&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Apr 5 22:31:08 2013
@@ -30,8 +30,7 @@ namespace object {
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO,
error_code &ec)
: ObjectFile(Binary::ID_MachO, Object, ec),
- MachOObj(MOO),
- RegisteredStringTable(std::numeric_limits<uint32_t>::max()) {
+ MachOObj(MOO) {
DataRefImpl DRI;
moveToNextSection(DRI);
uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
@@ -62,13 +61,20 @@ ObjectFile *ObjectFile::createMachOObjec
/*===-- Symbols -----------------------------------------------------------===*/
+const MachOFormat::SymtabLoadCommand *
+MachOObjectFile::getSymtabLoadCommand(LoadCommandInfo LCI) const {
+ StringRef Data = MachOObj->getData(LCI.Offset,
+ sizeof(MachOFormat::SymtabLoadCommand));
+ return reinterpret_cast<const MachOFormat::SymtabLoadCommand*>(Data.data());
+}
+
void MachOObjectFile::moveToNextSymbol(DataRefImpl &DRI) const {
uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
while (DRI.d.a < LoadCommandCount) {
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
if (LCI.Command.Type == macho::LCT_Symtab) {
- InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
- MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
+ getSymtabLoadCommand(LCI);
if (DRI.d.b < SymtabLoadCmd->NumSymbolTableEntries)
return;
}
@@ -80,15 +86,16 @@ void MachOObjectFile::moveToNextSymbol(D
const MachOFormat::SymbolTableEntry *
MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const {
- InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
- MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
+ getSymtabLoadCommand(LCI);
- if (RegisteredStringTable != DRI.d.a) {
- MachOObj->RegisterStringTable(*SymtabLoadCmd);
- RegisteredStringTable = DRI.d.a;
- }
+ return getSymbolTableEntry(DRI, SymtabLoadCmd);
+}
+const MachOFormat::SymbolTableEntry *
+MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI,
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
@@ -100,15 +107,16 @@ MachOObjectFile::getSymbolTableEntry(Dat
const MachOFormat::Symbol64TableEntry*
MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const {
- InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
- MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
+ getSymtabLoadCommand(LCI);
- if (RegisteredStringTable != DRI.d.a) {
- MachOObj->RegisterStringTable(*SymtabLoadCmd);
- RegisteredStringTable = DRI.d.a;
- }
+ return getSymbol64TableEntry(DRI, SymtabLoadCmd);
+}
+const MachOFormat::Symbol64TableEntry*
+MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd) const {
uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
unsigned Index = DRI.d.b;
uint64_t Offset = (SymbolTableOffset +
@@ -128,13 +136,28 @@ error_code MachOObjectFile::getSymbolNex
error_code MachOObjectFile::getSymbolName(DataRefImpl DRI,
StringRef &Result) const {
+ LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
+ const MachOFormat::SymtabLoadCommand *SymtabLoadCmd =
+ getSymtabLoadCommand(LCI);
+
+ StringRef StringTable =
+ MachOObj->getData(SymtabLoadCmd->StringTableOffset,
+ SymtabLoadCmd->StringTableSize);
+
+ uint32_t StringIndex;
if (MachOObj->is64Bit()) {
- const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
- Result = MachOObj->getStringAtIndex(Entry->StringIndex);
+ const MachOFormat::Symbol64TableEntry *Entry =
+ getSymbol64TableEntry(DRI, SymtabLoadCmd);
+ StringIndex = Entry->StringIndex;
} else {
- const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
- Result = MachOObj->getStringAtIndex(Entry->StringIndex);
+ const MachOFormat::SymbolTableEntry *Entry =
+ getSymbolTableEntry(DRI, SymtabLoadCmd);
+ StringIndex = Entry->StringIndex;
}
+
+ const char *Start = &StringTable.data()[StringIndex];
+ Result = StringRef(Start);
+
return object_error::success;
}
More information about the llvm-commits
mailing list