summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-24 15:02:03 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-24 15:02:03 +0000
commitec4e350f122ad3a4a31ef2d47bcae904502babd1 (patch)
tree79d5c2723d62b69dde20234b6956ebc5a4b09066 /llvm/lib/Object/MachOObjectFile.cpp
parent9f1438108f39fd5bb04314182ab3ec2e45455094 (diff)
downloadbcm5719-llvm-ec4e350f122ad3a4a31ef2d47bcae904502babd1.tar.gz
bcm5719-llvm-ec4e350f122ad3a4a31ef2d47bcae904502babd1.zip
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. llvm-svn: 180189
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp51
1 files changed, 28 insertions, 23 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 2f5048688c0..08570f1314c 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -777,31 +777,47 @@ MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
}
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<uintptr_t>(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<const macho::RelocationEntry*>(getPtr(this, Offset));
+
DataRefImpl Ret;
- Ret.d.a = LastReloc;
- Ret.d.b = Sec.d.a;
+ Ret.p = reinterpret_cast<uintptr_t>(P + Num);
return relocation_iterator(RelocationRef(Ret, this));
}
error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
- RelocationRef &Res) const {
- ++Rel.d.a;
+ RelocationRef &Res) const {
+ const macho::RelocationEntry *P =
+ reinterpret_cast<const macho::RelocationEntry *>(Rel.p);
+ Rel.p = reinterpret_cast<uintptr_t>(P + 1);
Res = RelocationRef(Rel, this);
return object_error::success;
}
@@ -1397,19 +1413,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<macho::RelocationEntry>(this, getPtr(this, Offset));
+ const char *P = reinterpret_cast<const char *>(Rel.p);
+ return getStruct<macho::RelocationEntry>(this, P);
}
macho::Header MachOObjectFile::getHeader() const {
OpenPOWER on IntegriCloud