Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 1 | //===- MachOReader.h --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 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 |
| 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(){}; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 24 | virtual Expected<std::unique_ptr<Object>> create() const = 0; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | class MachOReader : public Reader { |
| 28 | const object::MachOObjectFile &MachOObj; |
| 29 | |
| 30 | void readHeader(Object &O) const; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 31 | Error readLoadCommands(Object &O) const; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 32 | void readSymbolTable(Object &O) const; |
| 33 | void setSymbolInRelocationInfo(Object &O) const; |
| 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; |
ThiƩbaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 39 | void readLinkData(Object &O, Optional<size_t> LCIndex, LinkData &LD) const; |
| 40 | void readCodeSignature(Object &O) const; |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 41 | void readDataInCodeData(Object &O) const; |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame^] | 42 | void readLinkerOptimizationHint(Object &O) const; |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 43 | void readFunctionStartsData(Object &O) const; |
| 44 | void readIndirectSymbolTable(Object &O) const; |
ThiƩbaud Weksteen | e40e736 | 2020-10-28 15:03:00 +0100 | [diff] [blame] | 45 | void readSwiftVersion(Object &O) const; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 46 | |
| 47 | public: |
| 48 | explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {} |
| 49 | |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 50 | Expected<std::unique_ptr<Object>> create() const override; |
Chih-Hung Hsieh | 0860053 | 2019-12-19 15:55:38 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // end namespace macho |
| 54 | } // end namespace objcopy |
| 55 | } // end namespace llvm |