1 //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MachOObjectFile class, which binds the MachOObject
11 // class to the generic ObjectFile wrapper.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECT_MACHO_H
16 #define LLVM_OBJECT_MACHO_H
18 #include "llvm/Object/ObjectFile.h"
19 #include "llvm/Object/MachOObject.h"
20 #include "llvm/Support/MachO.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/ADT/SmallVector.h"
27 typedef MachOObject::LoadCommandInfo LoadCommandInfo;
29 class MachOObjectFile : public ObjectFile {
31 MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO, error_code &ec);
33 virtual symbol_iterator begin_symbols() const;
34 virtual symbol_iterator end_symbols() const;
35 virtual symbol_iterator begin_dynamic_symbols() const;
36 virtual symbol_iterator end_dynamic_symbols() const;
37 virtual section_iterator begin_sections() const;
38 virtual section_iterator end_sections() const;
40 virtual uint8_t getBytesInAddress() const;
41 virtual StringRef getFileFormatName() const;
42 virtual unsigned getArch() const;
44 MachOObject *getObject() { return MachOObj; }
46 static inline bool classof(const Binary *v) {
47 return v->getType() == isMachO;
49 static inline bool classof(const MachOObjectFile *v) { return true; }
52 virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
53 virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
54 virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
55 virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
56 virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
57 virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
58 virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
59 virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
60 virtual error_code getSymbolSection(DataRefImpl Symb,
61 section_iterator &Res) const;
63 virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
64 virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
65 virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
66 virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
67 virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
68 virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const;
69 virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
70 virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const;
71 virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
72 virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
74 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
75 virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
77 virtual error_code getRelocationNext(DataRefImpl Rel,
78 RelocationRef &Res) const;
79 virtual error_code getRelocationAddress(DataRefImpl Rel,
81 virtual error_code getRelocationOffset(DataRefImpl Rel,
83 virtual error_code getRelocationSymbol(DataRefImpl Rel,
84 SymbolRef &Res) const;
85 virtual error_code getRelocationType(DataRefImpl Rel,
87 virtual error_code getRelocationTypeName(DataRefImpl Rel,
88 SmallVectorImpl<char> &Result) const;
89 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
91 virtual error_code getRelocationValueString(DataRefImpl Rel,
92 SmallVectorImpl<char> &Result) const;
93 virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const;
96 MachOObject *MachOObj;
97 mutable uint32_t RegisteredStringTable;
98 typedef SmallVector<DataRefImpl, 1> SectionList;
102 void moveToNextSection(DataRefImpl &DRI) const;
103 void getSymbolTableEntry(DataRefImpl DRI,
104 InMemoryStruct<macho::SymbolTableEntry> &Res) const;
105 void getSymbol64TableEntry(DataRefImpl DRI,
106 InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
107 void moveToNextSymbol(DataRefImpl &DRI) const;
108 void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
109 void getSection64(DataRefImpl DRI,
110 InMemoryStruct<macho::Section64> &Res) const;
111 void getRelocation(DataRefImpl Rel,
112 InMemoryStruct<macho::RelocationEntry> &Res) const;
113 std::size_t getSectionIndex(DataRefImpl Sec) const;
115 void printRelocationTargetName(InMemoryStruct<macho::RelocationEntry>& RE,
116 raw_string_ostream &fmt) const;