Sort the #include lines for the include/... tree with the script.
[oota-llvm.git] / include / llvm / Object / MachO.h
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/ADT/SmallVector.h"
19 #include "llvm/Object/MachOObject.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/MachO.h"
22 #include "llvm/Support/raw_ostream.h"
23
24 namespace llvm {
25 namespace object {
26
27 typedef MachOObject::LoadCommandInfo LoadCommandInfo;
28
29 class MachOObjectFile : public ObjectFile {
30 public:
31   MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO, error_code &ec);
32
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 library_iterator begin_libraries_needed() const;
38   virtual library_iterator end_libraries_needed() const;
39   virtual section_iterator begin_sections() const;
40   virtual section_iterator end_sections() const;
41
42   virtual uint8_t getBytesInAddress() const;
43   virtual StringRef getFileFormatName() const;
44   virtual unsigned getArch() const;
45   virtual StringRef getLoadName() const;
46
47   MachOObject *getObject() { return MachOObj.get(); }
48
49   static inline bool classof(const Binary *v) {
50     return v->isMachO();
51   }
52
53 protected:
54   virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
55   virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
56   virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
57   virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
58   virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
59   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
60   virtual error_code getSymbolFlags(DataRefImpl Symb, uint32_t &Res) const;
61   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
62   virtual error_code getSymbolSection(DataRefImpl Symb,
63                                       section_iterator &Res) const;
64   virtual error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const;
65
66   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
67   virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
68   virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
69   virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
70   virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
71   virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const;
72   virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
73   virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const;
74   virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
75   virtual error_code isSectionRequiredForExecution(DataRefImpl Sec,
76                                                    bool &Res) const;
77   virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const;
78   virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const;
79   virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const;
80   virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
81                                            bool &Result) const;
82   virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
83   virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
84
85   virtual error_code getRelocationNext(DataRefImpl Rel,
86                                        RelocationRef &Res) const;
87   virtual error_code getRelocationAddress(DataRefImpl Rel,
88                                           uint64_t &Res) const;
89   virtual error_code getRelocationOffset(DataRefImpl Rel,
90                                          uint64_t &Res) const;
91   virtual error_code getRelocationSymbol(DataRefImpl Rel,
92                                          SymbolRef &Res) const;
93   virtual error_code getRelocationType(DataRefImpl Rel,
94                                        uint64_t &Res) const;
95   virtual error_code getRelocationTypeName(DataRefImpl Rel,
96                                            SmallVectorImpl<char> &Result) const;
97   virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
98                                                  int64_t &Res) const;
99   virtual error_code getRelocationValueString(DataRefImpl Rel,
100                                            SmallVectorImpl<char> &Result) const;
101   virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const;
102
103   virtual error_code getLibraryNext(DataRefImpl LibData, LibraryRef &Res) const;
104   virtual error_code getLibraryPath(DataRefImpl LibData, StringRef &Res) const;
105
106 private:
107   OwningPtr<MachOObject> MachOObj;
108   mutable uint32_t RegisteredStringTable;
109   typedef SmallVector<DataRefImpl, 1> SectionList;
110   SectionList Sections;
111
112
113   void moveToNextSection(DataRefImpl &DRI) const;
114   void getSymbolTableEntry(DataRefImpl DRI,
115                            InMemoryStruct<macho::SymbolTableEntry> &Res) const;
116   void getSymbol64TableEntry(DataRefImpl DRI,
117                           InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
118   void moveToNextSymbol(DataRefImpl &DRI) const;
119   void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
120   void getSection64(DataRefImpl DRI,
121                     InMemoryStruct<macho::Section64> &Res) const;
122   void getRelocation(DataRefImpl Rel,
123                      InMemoryStruct<macho::RelocationEntry> &Res) const;
124   std::size_t getSectionIndex(DataRefImpl Sec) const;
125
126   void printRelocationTargetName(InMemoryStruct<macho::RelocationEntry>& RE,
127                                  raw_string_ostream &fmt) const;
128 };
129
130 }
131 }
132
133 #endif
134