[llvm] r178945 - Don't use InMemoryStruct in getSymbolTableEntry.
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 5 18:59:05 PDT 2013
Author: rafael
Date: Fri Apr 5 20:59:05 2013
New Revision: 178945
URL: http://llvm.org/viewvc/llvm-project?rev=178945&view=rev
Log:
Don't use InMemoryStruct in getSymbolTableEntry.
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=178945&r1=178944&r2=178945&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Fri Apr 5 20:59:05 2013
@@ -60,6 +60,15 @@ namespace MachOFormat {
support::ulittle32_t Word0;
support::ulittle32_t Word1;
};
+
+ struct SymbolTableEntry {
+ support::ulittle32_t StringIndex;
+ uint8_t Type;
+ uint8_t SectionIndex;
+ support::ulittle16_t Flags;
+ support::ulittle32_t Value;
+ };
+
}
typedef MachOObject::LoadCommandInfo LoadCommandInfo;
@@ -159,8 +168,8 @@ private:
void moveToNextSection(DataRefImpl &DRI) const;
- void getSymbolTableEntry(DataRefImpl DRI,
- InMemoryStruct<macho::SymbolTableEntry> &Res) const;
+ const MachOFormat::SymbolTableEntry *
+ getSymbolTableEntry(DataRefImpl DRI) const;
void getSymbol64TableEntry(DataRefImpl DRI,
InMemoryStruct<macho::Symbol64TableEntry> &Res) 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=178945&r1=178944&r2=178945&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Apr 5 20:59:05 2013
@@ -78,8 +78,8 @@ void MachOObjectFile::moveToNextSymbol(D
}
}
-void MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI,
- InMemoryStruct<macho::SymbolTableEntry> &Res) const {
+const MachOFormat::SymbolTableEntry *
+MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const {
InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
@@ -89,8 +89,13 @@ void MachOObjectFile::getSymbolTableEntr
RegisteredStringTable = DRI.d.a;
}
- MachOObj->ReadSymbolTableEntry(SymtabLoadCmd->SymbolTableOffset, DRI.d.b,
- Res);
+ uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
+ unsigned Index = DRI.d.b;
+ uint64_t Offset = (SymbolTableOffset +
+ Index * sizeof(macho::SymbolTableEntry));
+ StringRef Data = MachOObj->getData(Offset,
+ sizeof(MachOFormat::SymbolTableEntry));
+ return reinterpret_cast<const MachOFormat::SymbolTableEntry*>(Data.data());
}
void MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
@@ -124,8 +129,7 @@ error_code MachOObjectFile::getSymbolNam
getSymbol64TableEntry(DRI, Entry);
Result = MachOObj->getStringAtIndex(Entry->StringIndex);
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
Result = MachOObj->getStringAtIndex(Entry->StringIndex);
}
return object_error::success;
@@ -143,8 +147,7 @@ error_code MachOObjectFile::getSymbolFil
Result += Section->Offset - Section->Address;
}
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
Result = Entry->Value;
if (Entry->SectionIndex) {
const MachOFormat::Section *Section =
@@ -163,8 +166,7 @@ error_code MachOObjectFile::getSymbolAdd
getSymbol64TableEntry(DRI, Entry);
Result = Entry->Value;
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
Result = Entry->Value;
}
return object_error::success;
@@ -205,8 +207,7 @@ error_code MachOObjectFile::getSymbolSiz
DRI.d.b++;
}
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
@@ -225,7 +226,7 @@ error_code MachOObjectFile::getSymbolSiz
while (Command == DRI.d.a) {
moveToNextSymbol(DRI);
if (DRI.d.a < LoadCommandCount) {
- getSymbolTableEntry(DRI, Entry);
+ Entry = getSymbolTableEntry(DRI);
if (Entry->SectionIndex == SectionIndex && Entry->Value > BeginOffset)
if (!EndOffset || Entry->Value < EndOffset)
EndOffset = Entry->Value;
@@ -252,8 +253,7 @@ error_code MachOObjectFile::getSymbolNMT
Type = Entry->Type;
Flags = Entry->Flags;
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
Type = Entry->Type;
Flags = Entry->Flags;
}
@@ -288,8 +288,7 @@ error_code MachOObjectFile::getSymbolFla
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(DRI, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
}
@@ -326,8 +325,7 @@ error_code MachOObjectFile::getSymbolSec
getSymbol64TableEntry(Symb, Entry);
index = Entry->SectionIndex;
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
index = Entry->SectionIndex;
}
@@ -347,8 +345,7 @@ error_code MachOObjectFile::getSymbolTyp
getSymbol64TableEntry(Symb, Entry);
n_type = Entry->Type;
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
n_type = Entry->Type;
}
Res = SymbolRef::ST_Other;
@@ -656,8 +653,7 @@ error_code MachOObjectFile::sectionConta
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
} else {
- InMemoryStruct<macho::SymbolTableEntry> Entry;
- getSymbolTableEntry(Symb, Entry);
+ const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
}
More information about the llvm-commits
mailing list