ObjectFile: Add a method to check whether a section contains a symbol.

- No ELF or COFF implementation yet, I don't have a way to test that.
  Should be straightforward to add though.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135288 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2011-07-15 18:39:21 +00:00
parent 893818347e
commit 07ea23aa2d
5 changed files with 50 additions and 0 deletions

View File

@ -60,6 +60,8 @@ protected:
virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
bool &Result) const;
private:
MachOObject *MachOObj;
@ -383,6 +385,21 @@ error_code MachOObjectFile::isSectionText(DataRefImpl DRI,
return object_error::success;
}
error_code MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
DataRefImpl Symb,
bool &Result) const {
if (MachOObj->is64Bit()) {
InMemoryStruct<macho::Symbol64TableEntry> Entry;
getSymbol64TableEntry(Symb, Entry);
Result = Entry->SectionIndex == 1 + Sec.d.a + Sec.d.b;
} else {
InMemoryStruct<macho::SymbolTableEntry> Entry;
getSymbolTableEntry(Symb, Entry);
Result = Entry->SectionIndex == 1 + Sec.d.a + Sec.d.b;
}
return object_error::success;
}
ObjectFile::section_iterator MachOObjectFile::begin_sections() const {
DataRefImpl DRI;
DRI.d.a = DRI.d.b = 0;