From e5330f77cf420d71cfd46c960387eb06edeccbf8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 25 Apr 2013 12:45:46 +0000 Subject: [PATCH] Use a pointer as the relocation iterator. Since the relocation iterator walks only the relocations in one section, we can just use a pointer and avoid fetching information about the section at every reference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180262 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 14bca2bf901..38198b17938 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -758,31 +758,47 @@ MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, } relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const { - DataRefImpl ret; - ret.d.b = Sec.d.a; - return relocation_iterator(RelocationRef(ret, this)); + uint32_t Offset; + if (is64Bit()) { + macho::Section64 Sect = getSection64(Sec); + Offset = Sect.RelocationTableOffset; + } else { + macho::Section Sect = getSection(Sec); + Offset = Sect.RelocationTableOffset; + } + + DataRefImpl Ret; + Ret.p = reinterpret_cast(getPtr(this, Offset)); + return relocation_iterator(RelocationRef(Ret, this)); } relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const { - uint32_t LastReloc; + uint32_t Offset; + uint32_t Num; if (is64Bit()) { macho::Section64 Sect = getSection64(Sec); - LastReloc = Sect.NumRelocationTableEntries; + Offset = Sect.RelocationTableOffset; + Num = Sect.NumRelocationTableEntries; } else { macho::Section Sect = getSection(Sec); - LastReloc = Sect.NumRelocationTableEntries; + Offset = Sect.RelocationTableOffset; + Num = Sect.NumRelocationTableEntries; } + const macho::RelocationEntry *P = + reinterpret_cast(getPtr(this, Offset)); + DataRefImpl Ret; - Ret.d.a = LastReloc; - Ret.d.b = Sec.d.a; + Ret.p = reinterpret_cast(P + Num); return relocation_iterator(RelocationRef(Ret, this)); } - error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const { - ++Rel.d.a; +error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel, + RelocationRef &Res) const { + const macho::RelocationEntry *P = + reinterpret_cast(Rel.p); + Rel.p = reinterpret_cast(P + 1); Res = RelocationRef(Rel, this); return object_error::success; } @@ -1378,19 +1394,8 @@ MachOObjectFile::getLinkeditDataLoadCommand(const MachOObjectFile::LoadCommandIn macho::RelocationEntry MachOObjectFile::getRelocation(DataRefImpl Rel) const { - uint32_t RelOffset; - DataRefImpl Sec; - Sec.d.a = Rel.d.b; - if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - RelOffset = Sect.RelocationTableOffset; - } else { - macho::Section Sect = getSection(Sec); - RelOffset = Sect.RelocationTableOffset; - } - - uint64_t Offset = RelOffset + Rel.d.a * sizeof(macho::RelocationEntry); - return getStruct(this, getPtr(this, Offset)); + const char *P = reinterpret_cast(Rel.p); + return getStruct(this, P); } macho::Header MachOObjectFile::getHeader() const { -- 2.34.1