Fixed ObjectFile functions:
[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/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"
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 section_iterator begin_sections() const;
36   virtual section_iterator end_sections() const;
37
38   virtual uint8_t getBytesInAddress() const;
39   virtual StringRef getFileFormatName() const;
40   virtual unsigned getArch() const;
41
42   MachOObject *getObject() { return MachOObj; }
43
44   static inline bool classof(const Binary *v) {
45     return v->getType() == isMachO;
46   }
47   static inline bool classof(const MachOObjectFile *v) { return true; }
48
49 protected:
50   virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
51   virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
52   virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const;
53   virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
54   virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
55   virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
56   virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
57   virtual error_code isSymbolGlobal(DataRefImpl Symb, bool &Res) const;
58   virtual error_code isSymbolWeak(DataRefImpl Symb, bool &Res) const;
59   virtual error_code getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const;
60   virtual error_code isSymbolAbsolute(DataRefImpl Symb, bool &Res) const;
61   virtual error_code getSymbolSection(DataRefImpl Symb,
62                                       section_iterator &Res) const;
63
64   virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
65   virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
66   virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
67   virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
68   virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
69   virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const;
70   virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
71   virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const;
72   virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
73   virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
74                                            bool &Result) const;
75   virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
76   virtual relocation_iterator getSectionRelEnd(DataRefImpl Sec) const;
77
78   virtual error_code getRelocationNext(DataRefImpl Rel,
79                                        RelocationRef &Res) const;
80   virtual error_code getRelocationAddress(DataRefImpl Rel,
81                                           uint64_t &Res) const;
82   virtual error_code getRelocationOffset(DataRefImpl Rel,
83                                          uint64_t &Res) const;
84   virtual error_code getRelocationSymbol(DataRefImpl Rel,
85                                          SymbolRef &Res) const;
86   virtual error_code getRelocationType(DataRefImpl Rel,
87                                        uint64_t &Res) const;
88   virtual error_code getRelocationTypeName(DataRefImpl Rel,
89                                            SmallVectorImpl<char> &Result) const;
90   virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
91                                                  int64_t &Res) const;
92   virtual error_code getRelocationValueString(DataRefImpl Rel,
93                                            SmallVectorImpl<char> &Result) const;
94   virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const;
95
96 private:
97   MachOObject *MachOObj;
98   mutable uint32_t RegisteredStringTable;
99   typedef SmallVector<DataRefImpl, 1> SectionList;
100   SectionList Sections;
101
102
103   void moveToNextSection(DataRefImpl &DRI) const;
104   void getSymbolTableEntry(DataRefImpl DRI,
105                            InMemoryStruct<macho::SymbolTableEntry> &Res) const;
106   void getSymbol64TableEntry(DataRefImpl DRI,
107                           InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
108   void moveToNextSymbol(DataRefImpl &DRI) const;
109   void getSection(DataRefImpl DRI, InMemoryStruct<macho::Section> &Res) const;
110   void getSection64(DataRefImpl DRI,
111                     InMemoryStruct<macho::Section64> &Res) const;
112   void getRelocation(DataRefImpl Rel,
113                      InMemoryStruct<macho::RelocationEntry> &Res) const;
114   std::size_t getSectionIndex(DataRefImpl Sec) const;
115
116   void printRelocationTargetName(InMemoryStruct<macho::RelocationEntry>& RE,
117                                  raw_string_ostream &fmt) const;
118 };
119
120 }
121 }
122
123 #endif
124