1 //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares the MachOObjectFile class, which binds the MachOObject 11 // class to the generic ObjectFile wrapper. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_OBJECT_MACHO_H 16 #define LLVM_OBJECT_MACHO_H 17 18 #include "llvm/Object/ObjectFile.h" 19 #include "llvm/Object/MachOObject.h" 20 #include "llvm/Support/MachO.h" 21 #include "llvm/ADT/SmallVector.h" 22 23 namespace llvm { 24 namespace object { 25 26 typedef MachOObject::LoadCommandInfo LoadCommandInfo; 27 28 class MachOObjectFile : public ObjectFile { 29 public: 30 MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO, error_code &ec); 31 32 virtual symbol_iterator begin_symbols() const; 33 virtual symbol_iterator end_symbols() const; 34 virtual section_iterator begin_sections() const; 35 virtual section_iterator end_sections() const; 36 37 virtual uint8_t getBytesInAddress() const; 38 virtual StringRef getFileFormatName() const; 39 virtual unsigned getArch() const; 40 41 protected: 42 virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const; 43 virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const; 44 virtual error_code getSymbolOffset(DataRefImpl Symb, uint64_t &Res) const; 45 virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const; 46 virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const; 47 virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const; 48 virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const; 49 virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const; 50 virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::SymbolType &Res) const; 51 52 virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const; 53 virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const; 54 virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const; 55 virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const; 56 virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const; 57 virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const; 58 virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const; 59 virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const; 60 virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const; 61 virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S, 62 bool &Result) const; 63 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const; 64 virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const; 65 66 virtual error_code getRelocationNext(DataRefImpl Rel, 67 RelocationRef &Res) const; 68 virtual error_code getRelocationAddress(DataRefImpl Rel, 69 uint64_t &Res) const; 70 virtual error_code getRelocationSymbol(DataRefImpl Rel, 71 SymbolRef &Res) const; 72 virtual error_code getRelocationType(DataRefImpl Rel, 73 uint32_t &Res) const; 74 virtual error_code getRelocationTypeName(DataRefImpl Rel, 75 SmallVectorImpl<char> &Result) const; 76 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel, 77 int64_t &Res) const; 78 virtual error_code getRelocationValueString(DataRefImpl Rel, 79 SmallVectorImpl<char> &Result) const; 80 81 private: 82 MachOObject *MachOObj; 83 mutable uint32_t RegisteredStringTable; 84 typedef SmallVector<DataRefImpl, 1> SectionList; 85 SectionList Sections; 86 87 88 void moveToNextSection(DataRefImpl &DRI) const; 89 void getSymbolTableEntry(DataRefImpl DRI, 90 InMemoryStruct<macho::SymbolTableEntry> &Res) const; 91 void getSymbol64TableEntry(DataRefImpl DRI, 92 InMemoryStruct<macho::Symbol64TableEntry> &Res) const; 93 void moveToNextSymbol(DataRefImpl &DRI) const; 94 void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const; 95 void getSection64(DataRefImpl DRI, 96 InMemoryStruct<macho::Section64> &Res) const; 97 void getRelocation(DataRefImpl Rel, 98 InMemoryStruct<macho::RelocationEntry> &Res) const; 99 std::size_t getSectionIndex(DataRefImpl Sec) const; 100 }; 101 102 } 103 } 104 105 #endif 106 107