summaryrefslogtreecommitdiff
path: root/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-10-07 19:25:32 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-10-07 19:25:32 +0000
commit4344b1ef9b3721a5ebc2e024f753772a1e4ddd92 (patch)
tree4e940dd99f2b1745799c9f1544fc1a88b3e5594f /lib/Object/MachOObjectFile.cpp
parent186ffac4d35c9ea669b03ac75f5e21bff1f01a7f (diff)
downloadllvm-4344b1ef9b3721a5ebc2e024f753772a1e4ddd92.tar.gz
llvm-4344b1ef9b3721a5ebc2e024f753772a1e4ddd92.tar.bz2
llvm-4344b1ef9b3721a5ebc2e024f753772a1e4ddd92.tar.xz
Change relocation API to be per section. This time without breaking GCC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141385 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object/MachOObjectFile.cpp')
-rw-r--r--lib/Object/MachOObjectFile.cpp82
1 files changed, 49 insertions, 33 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp
index 33e0d2643b..73fa8275c3 100644
--- a/lib/Object/MachOObjectFile.cpp
+++ b/lib/Object/MachOObjectFile.cpp
@@ -39,8 +39,6 @@ public:
virtual symbol_iterator end_symbols() const;
virtual section_iterator begin_sections() const;
virtual section_iterator end_sections() const;
- virtual relocation_iterator begin_relocations() const;
- virtual relocation_iterator end_relocations() const;
virtual uint8_t getBytesInAddress() const;
virtual StringRef getFileFormatName() const;
@@ -67,6 +65,8 @@ protected:
virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
bool &Result) const;
+ virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
+ virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
virtual error_code getRelocationNext(DataRefImpl Rel,
RelocationRef &Res) const;
@@ -76,8 +76,13 @@ protected:
SymbolRef &Res) const;
virtual error_code getRelocationType(DataRefImpl Rel,
uint32_t &Res) const;
+ virtual error_code getRelocationTypeName(DataRefImpl Rel,
+ SmallVectorImpl<char> &Result) const;
virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
int64_t &Res) const;
+ virtual error_code getRelocationValueString(DataRefImpl Rel,
+ SmallVectorImpl<char> &Result) const;
+
private:
MachOObject *MachOObj;
mutable uint32_t RegisteredStringTable;
@@ -96,6 +101,7 @@ private:
InMemoryStruct<macho::Section64> &Res) const;
void getRelocation(DataRefImpl Rel,
InMemoryStruct<macho::RelocationEntry> &Res) const;
+ std::size_t getSectionIndex(DataRefImpl Sec) const;
};
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO,
@@ -324,7 +330,7 @@ error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
}
-ObjectFile::symbol_iterator MachOObjectFile::begin_symbols() const {
+symbol_iterator MachOObjectFile::begin_symbols() const {
// DRI.d.a = segment number; DRI.d.b = symbol index.
DataRefImpl DRI;
DRI.d.a = DRI.d.b = 0;
@@ -332,7 +338,7 @@ ObjectFile::symbol_iterator MachOObjectFile::begin_symbols() const {
return symbol_iterator(SymbolRef(DRI, this));
}
-ObjectFile::symbol_iterator MachOObjectFile::end_symbols() const {
+symbol_iterator MachOObjectFile::end_symbols() const {
DataRefImpl DRI;
DRI.d.a = MachOObj->getHeader().NumLoadCommands;
DRI.d.b = 0;
@@ -380,6 +386,13 @@ MachOObjectFile::getSection(DataRefImpl DRI,
MachOObj->ReadSection(LCI, DRI.d.b, Res);
}
+std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const {
+ SectionList::const_iterator loc =
+ std::find(Sections.begin(), Sections.end(), Sec);
+ assert(loc != Sections.end() && "Sec is not a valid section!");
+ return std::distance(Sections.begin(), loc);
+}
+
void
MachOObjectFile::getSection64(DataRefImpl DRI,
InMemoryStruct<macho::Section64> &Res) const {
@@ -511,14 +524,37 @@ error_code MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
return object_error::success;
}
-ObjectFile::section_iterator MachOObjectFile::begin_sections() const {
+relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
+ DataRefImpl ret;
+ ret.d.a = 0;
+ ret.d.b = getSectionIndex(Sec);
+ return relocation_iterator(RelocationRef(ret, this));
+}
+relocation_iterator MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
+ uint32_t last_reloc;
+ if (is64BitLoadCommand(MachOObj, Sec)) {
+ InMemoryStruct<macho::Section64> Sect;
+ getSection64(Sec, Sect);
+ last_reloc = Sect->NumRelocationTableEntries;
+ } else {
+ InMemoryStruct<macho::Section> Sect;
+ getSection(Sec, Sect);
+ last_reloc = Sect->NumRelocationTableEntries;
+ }
+ DataRefImpl ret;
+ ret.d.a = last_reloc;
+ ret.d.b = getSectionIndex(Sec);
+ return relocation_iterator(RelocationRef(ret, this));
+}
+
+section_iterator MachOObjectFile::begin_sections() const {
DataRefImpl DRI;
DRI.d.a = DRI.d.b = 0;
moveToNextSection(DRI);
return section_iterator(SectionRef(DRI, this));
}
-ObjectFile::section_iterator MachOObjectFile::end_sections() const {
+section_iterator MachOObjectFile::end_sections() const {
DataRefImpl DRI;
DRI.d.a = MachOObj->getHeader().NumLoadCommands;
DRI.d.b = 0;
@@ -545,23 +581,6 @@ getRelocation(DataRefImpl Rel,
error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
RelocationRef &Res) const {
++Rel.d.a;
- while (Rel.d.b < Sections.size()) {
- unsigned relocationCount;
- if (MachOObj->is64Bit()) {
- InMemoryStruct<macho::Section64> Sect;
- getSection64(Sections[Rel.d.b], Sect);
- relocationCount = Sect->NumRelocationTableEntries;
- } else {
- InMemoryStruct<macho::Section> Sect;
- getSection(Sections[Rel.d.b], Sect);
- relocationCount = Sect->NumRelocationTableEntries;
- }
- if (Rel.d.a < relocationCount)
- break;
-
- Rel.d.a = 0;
- ++Rel.d.b;
- }
Res = RelocationRef(Rel, this);
return object_error::success;
}
@@ -610,6 +629,10 @@ error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
Res = RE->Word1;
return object_error::success;
}
+error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
+ SmallVectorImpl<char> &Result) const {
+ return object_error::success;
+}
error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
int64_t &Res) const {
InMemoryStruct<macho::RelocationEntry> RE;
@@ -631,16 +654,9 @@ error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
}
return object_error::success;
}
-ObjectFile::relocation_iterator MachOObjectFile::begin_relocations() const {
- DataRefImpl ret;
- ret.d.a = ret.d.b = 0;
- return relocation_iterator(RelocationRef(ret, this));
-}
-ObjectFile::relocation_iterator MachOObjectFile::end_relocations() const {
- DataRefImpl ret;
- ret.d.a = 0;
- ret.d.b = Sections.size();
- return relocation_iterator(RelocationRef(ret, this));
+error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel,
+ SmallVectorImpl<char> &Result) const {
+ return object_error::success;
}
/*===-- Miscellaneous -----------------------------------------------------===*/