From 05b5bdd024d07e7a62f1cdc39f465e10ce5dbc6d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 6 Apr 2013 02:15:44 +0000 Subject: [PATCH] Don't use InMemoryStruct in getSymbol64TableEntry. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178946 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 11 +++++++-- lib/Object/MachOObjectFile.cpp | 43 +++++++++++++++------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 70d7f6ee8a0..1da9a912d34 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -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 &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; diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index f82ed08250a..4d9186490fe 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -98,8 +98,8 @@ MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const { return reinterpret_cast(Data.data()); } -void MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI, - InMemoryStruct &Res) const { +const MachOFormat::Symbol64TableEntry* +MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const { InMemoryStruct SymtabLoadCmd; LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); MachOObj->ReadSymtabLoadCommand(LCI, SymtabLoadCmd); @@ -109,11 +109,15 @@ void MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI, 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(Data.data()); } - error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI, SymbolRef &Result) const { DRI.d.b++; @@ -125,8 +129,7 @@ error_code MachOObjectFile::getSymbolNext(DataRefImpl DRI, error_code MachOObjectFile::getSymbolName(DataRefImpl DRI, StringRef &Result) const { if (MachOObj->is64Bit()) { - InMemoryStruct 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::getSymbolName(DataRefImpl DRI, error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl DRI, uint64_t &Result) const { if (MachOObj->is64Bit()) { - InMemoryStruct 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::getSymbolFileOffset(DataRefImpl DRI, error_code MachOObjectFile::getSymbolAddress(DataRefImpl DRI, uint64_t &Result) const { if (MachOObj->is64Bit()) { - InMemoryStruct 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::getSymbolSize(DataRefImpl DRI, uint64_t EndOffset = 0; uint8_t SectionIndex; if (MachOObj->is64Bit()) { - InMemoryStruct 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::getSymbolSize(DataRefImpl DRI, 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::getSymbolNMTypeChar(DataRefImpl DRI, char &Result) const { uint8_t Type, Flags; if (MachOObj->is64Bit()) { - InMemoryStruct Entry; - getSymbol64TableEntry(DRI, Entry); + const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI); Type = Entry->Type; Flags = Entry->Flags; } else { @@ -283,8 +282,7 @@ error_code MachOObjectFile::getSymbolFlags(DataRefImpl DRI, uint16_t MachOFlags; uint8_t MachOType; if (MachOObj->is64Bit()) { - InMemoryStruct Entry; - getSymbol64TableEntry(DRI, Entry); + const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(DRI); MachOFlags = Entry->Flags; MachOType = Entry->Type; } else { @@ -321,8 +319,7 @@ error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb, section_iterator &Res) const { uint8_t index; if (MachOObj->is64Bit()) { - InMemoryStruct 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::getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const { uint8_t n_type; if (MachOObj->is64Bit()) { - InMemoryStruct 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::sectionContainsSymbol(DataRefImpl Sec, SectEnd += SectBegin; if (MachOObj->is64Bit()) { - InMemoryStruct Entry; - getSymbol64TableEntry(Symb, Entry); + const MachOFormat::Symbol64TableEntry *Entry = getSymbol64TableEntry(Symb); uint64_t SymAddr= Entry->Value; Result = (SymAddr >= SectBegin) && (SymAddr < SectEnd); } else {