Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 1 | //===- MachOReader.h --------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 127252b | 2019-02-11 08:25:19 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "MachOObjcopy.h" |
| 10 | #include "Object.h" |
| 11 | #include "llvm/BinaryFormat/MachO.h" |
| 12 | #include "llvm/Object/MachO.h" |
| 13 | #include <memory> |
| 14 | |
| 15 | namespace llvm { |
| 16 | namespace objcopy { |
| 17 | namespace macho { |
| 18 | |
| 19 | // The hierarchy of readers is responsible for parsing different inputs: |
| 20 | // raw binaries and regular MachO object files. |
| 21 | class Reader { |
| 22 | public: |
| 23 | virtual ~Reader(){}; |
| 24 | virtual std::unique_ptr<Object> create() const = 0; |
| 25 | }; |
| 26 | |
| 27 | class MachOReader : public Reader { |
| 28 | const object::MachOObjectFile &MachOObj; |
| 29 | |
| 30 | void readHeader(Object &O) const; |
| 31 | void readLoadCommands(Object &O) const; |
| 32 | void readSymbolTable(Object &O) const; |
Seiya Nuta | f923d9b | 2019-06-21 00:21:50 +0000 | [diff] [blame] | 33 | void setSymbolInRelocationInfo(Object &O) const; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 34 | void readRebaseInfo(Object &O) const; |
| 35 | void readBindInfo(Object &O) const; |
| 36 | void readWeakBindInfo(Object &O) const; |
| 37 | void readLazyBindInfo(Object &O) const; |
| 38 | void readExportInfo(Object &O) const; |
Alexander Shaposhnikov | 913bc31 | 2020-06-15 18:55:59 -0700 | [diff] [blame] | 39 | void readLinkData(Object &O, Optional<size_t> LCIndex, LinkData &LD) const; |
| 40 | void readCodeSignature(Object &O) const; |
Seiya Nuta | 552bcb8 | 2019-08-19 21:05:31 +0000 | [diff] [blame] | 41 | void readDataInCodeData(Object &O) const; |
| 42 | void readFunctionStartsData(Object &O) const; |
| 43 | void readIndirectSymbolTable(Object &O) const; |
Alexander Shaposhnikov | 842a8cc | 2020-05-26 16:49:56 -0700 | [diff] [blame] | 44 | void readSwiftVersion(Object &O) const; |
Alexander Shaposhnikov | d911ed1 | 2019-02-02 00:38:07 +0000 | [diff] [blame] | 45 | |
| 46 | public: |
| 47 | explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {} |
| 48 | |
| 49 | std::unique_ptr<Object> create() const override; |
| 50 | }; |
| 51 | |
| 52 | } // end namespace macho |
| 53 | } // end namespace objcopy |
| 54 | } // end namespace llvm |