Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 1 | //===- MachOReader.h --------------------------------------------*- 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 | #include "MachOObjcopy.h" |
| 11 | #include "Object.h" |
| 12 | #include "llvm/BinaryFormat/MachO.h" |
| 13 | #include "llvm/Object/MachO.h" |
| 14 | #include <memory> |
| 15 | |
| 16 | namespace llvm { |
| 17 | namespace objcopy { |
| 18 | namespace macho { |
| 19 | |
| 20 | // The hierarchy of readers is responsible for parsing different inputs: |
| 21 | // raw binaries and regular MachO object files. |
| 22 | class Reader { |
| 23 | public: |
| 24 | virtual ~Reader(){}; |
| 25 | virtual std::unique_ptr<Object> create() const = 0; |
| 26 | }; |
| 27 | |
| 28 | class MachOReader : public Reader { |
| 29 | const object::MachOObjectFile &MachOObj; |
| 30 | |
| 31 | void readHeader(Object &O) const; |
| 32 | void readLoadCommands(Object &O) const; |
| 33 | void readSymbolTable(Object &O) const; |
| 34 | void readStringTable(Object &O) const; |
| 35 | void readRebaseInfo(Object &O) const; |
| 36 | void readBindInfo(Object &O) const; |
| 37 | void readWeakBindInfo(Object &O) const; |
| 38 | void readLazyBindInfo(Object &O) const; |
| 39 | void readExportInfo(Object &O) const; |
| 40 | |
| 41 | public: |
| 42 | explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {} |
| 43 | |
| 44 | std::unique_ptr<Object> create() const override; |
| 45 | }; |
| 46 | |
| 47 | } // end namespace macho |
| 48 | } // end namespace objcopy |
| 49 | } // end namespace llvm |