[llvm] r178946 - Don't use InMemoryStruct in getSymbol64TableEntry.
Rafael Espindola
rafael.espindola at gmail.com
Fri Apr 5 19:15:44 PDT 2013
Author: rafael
Date: Fri Apr 5 21:15:44 2013
New Revision: 178946
URL: http://llvm.org/viewvc/llvm-project?rev=178946&view=rev
Log:
Don't use InMemoryStruct in getSymbol64TableEntry.
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=178946&r1=178945&r2=178946&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Fri Apr 5 21:15:44 2013
@@ -69,6 +69,13 @@ namespace MachOFormat {
support::ulittle32_t Value;
};
+ struct Symbol64TableEntry {
+ support::ulittle32_t StringIndex;
+ uint8_t Type;
+ uint8_t SectionIndex;
+ support::ulittle16_t Flags;
+ support::ulittle64_t Value;
+ };
}
typedef MachOObject::LoadCommandInfo LoadCommandInfo;
@@ -170,8 +177,8 @@ private:
void moveToNextSection(DataRefImpl &DRI) const;
const MachOFormat::SymbolTableEntry *
getSymbolTableEntry(DataRefImpl DRI) const;
- void getSymbol64TableEntry(DataRefImpl DRI,
- InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
+ const MachOFormat::Symbol64TableEntry *
+ getSymbol64TableEntry(DataRefImpl DRI) const;
void moveToNextSymbol(DataRefImpl &DRI) const;
const MachOFormat::Section *getSection(DataRefImpl DRI) const;
const MachOFormat::Section64 *getSection64(DataRefImpl DRI) const;
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=178946&r1=178945&r2=178946&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Apr 5 21:15:44 2013
@@ -98,8 +98,8 @@ MachOObjectFile::getSymbolTableEntry(Dat
return reinterpret_cast<const MachOFormat::SymbolTableEntry*>(Data.data());
}
-void MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI,
- InMemoryStruct<macho::Symbol64TableEntry> &Res) const {
+const MachOFormat::Symbol64TableEntry*
+MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const {
InMemoryStruct<macho::SymtabLoadCommand> SymtabLoadCmd;
LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a);
MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd);
@@ -109,11 +109,15 @@ void MachOObjectFile::getSymbol64TableEn
RegisteredStringTable = DRI.d.a;
}
- MachOObj->ReadSymbol64TableEntry(SymtabLoadCmd->SymbolTableOffset, DRI.d.b,
- Res);
+ uint64_t SymbolTableOffset = SymtabLoadCmd->SymbolTableOffset;
+ unsigned Index = DRI.d.b;
+ uint64_t Offset = (SymbolTableOffset +
+ Index * sizeof(macho::Symbol64TableEntry));
+ StringRef Data = MachOObj->getData(Offset,
+ sizeof(MachOFormat::Symbol64TableEntry));
+ return reinterpret_cast<const MachOFormat::Symbol64TableEntry*>(Data.data());
}
-
error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI,
SymbolRef &Result) const {
DRI.d.b++;
@@ -125,8 +129,7 @@ error_code MachOObjectFile::getSymbolNex
error_code MachOObjectFile::getSymbolName(DataRefImpl DRI,
StringRef &Result) const {
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
Result = MachOObj->getStringAtIndex(Entry->StringIndex);
} else {
const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
@@ -138,8 +141,7 @@ error_code MachOObjectFile::getSymbolNam
error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI,
uint64_t &Result) const {
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
Result = Entry->Value;
if (Entry->SectionIndex) {
const MachOFormat::Section64 *Section =
@@ -162,8 +164,7 @@ error_code MachOObjectFile::getSymbolFil
error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI,
uint64_t &Result) const {
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
Result = Entry->Value;
} else {
const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(DRI);
@@ -179,8 +180,7 @@ error_code MachOObjectFile::getSymbolSiz
uint64_t EndOffset = 0;
uint8_t SectionIndex;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
BeginOffset = Entry->Value;
SectionIndex = Entry->SectionIndex;
if (!SectionIndex) {
@@ -199,7 +199,7 @@ error_code MachOObjectFile::getSymbolSiz
while (Command == DRI.d.a) {
moveToNextSymbol(DRI);
if (DRI.d.a < LoadCommandCount) {
- getSymbol64TableEntry(DRI, Entry);
+ Entry = getSymbol64TableEntry(DRI);
if (Entry->SectionIndex == SectionIndex && Entry->Value > BeginOffset)
if (!EndOffset || Entry->Value < EndOffset)
EndOffset = Entry->Value;
@@ -248,8 +248,7 @@ error_code MachOObjectFile::getSymbolNMT
char &Result) const {
uint8_t Type, Flags;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
Type = Entry->Type;
Flags = Entry->Flags;
} else {
@@ -283,8 +282,7 @@ error_code MachOObjectFile::getSymbolFla
uint16_t MachOFlags;
uint8_t MachOType;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(DRI, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI);
MachOFlags = Entry->Flags;
MachOType = Entry->Type;
} else {
@@ -321,8 +319,7 @@ error_code MachOObjectFile::getSymbolSec
section_iterator &Res) const {
uint8_t index;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
index = Entry->SectionIndex;
} else {
const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
@@ -341,8 +338,7 @@ error_code MachOObjectFile::getSymbolTyp
SymbolRef::Type &Res) const {
uint8_t n_type;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
n_type = Entry->Type;
} else {
const MachOFormat::SymbolTableEntry *Entry = getSymbolTableEntry(Symb);
@@ -648,8 +644,7 @@ error_code MachOObjectFile::sectionConta
SectEnd += SectBegin;
if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Symbol64TableEntry> Entry;
- getSymbol64TableEntry(Symb, Entry);
+ const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb);
uint64_t SymAddr= Entry->Value;
Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd);
} else {
More information about the llvm-commits
mailing list