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/ADT/SmallVector.h"
26 typedef MachOObject::LoadCommandInfo LoadCommandInfo;
28 class MachOObjectFile : public ObjectFile {
30 MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO, error_code &ec);
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;
37 virtual uint8_t getBytesInAddress() const;
38 virtual StringRef getFileFormatName() const;
39 virtual unsigned getArch() const;
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;
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,
63 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
64 virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
66 virtual error_code getRelocationNext(DataRefImpl Rel,
67 RelocationRef &Res) const;
68 virtual error_code getRelocationAddress(DataRefImpl Rel,
70 virtual error_code getRelocationSymbol(DataRefImpl Rel,
71 SymbolRef &Res) const;
72 virtual error_code getRelocationType(DataRefImpl Rel,
74 virtual error_code getRelocationTypeName(DataRefImpl Rel,
75 SmallVectorImpl<char> &Result) const;
76 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
78 virtual error_code getRelocationValueString(DataRefImpl Rel,
79 SmallVectorImpl<char> &Result) const;
82 MachOObject *MachOObj;
83 mutable uint32_t RegisteredStringTable;
84 typedef SmallVector<DataRefImpl, 1> SectionList;
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;