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 #ifndef LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H 10 #define LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H 11 12 #include "MachOObject.h" 13 #include "llvm/BinaryFormat/MachO.h" 14 #include "llvm/ObjCopy/MachO/MachOObjcopy.h" 15 #include "llvm/Object/MachO.h" 16 #include <memory> 17 18 namespace llvm { 19 namespace objcopy { 20 namespace macho { 21 22 // The hierarchy of readers is responsible for parsing different inputs: 23 // raw binaries and regular MachO object files. 24 class Reader { 25 public: ~Reader()26 virtual ~Reader(){}; 27 virtual Expected<std::unique_ptr<Object>> create() const = 0; 28 }; 29 30 class MachOReader : public Reader { 31 const object::MachOObjectFile &MachOObj; 32 33 void readHeader(Object &O) const; 34 Error readLoadCommands(Object &O) const; 35 void readSymbolTable(Object &O) const; 36 void setSymbolInRelocationInfo(Object &O) const; 37 void readRebaseInfo(Object &O) const; 38 void readBindInfo(Object &O) const; 39 void readWeakBindInfo(Object &O) const; 40 void readLazyBindInfo(Object &O) const; 41 void readExportInfo(Object &O) const; 42 void readLinkData(Object &O, std::optional<size_t> LCIndex, 43 LinkData &LD) const; 44 void readCodeSignature(Object &O) const; 45 void readDataInCodeData(Object &O) const; 46 void readLinkerOptimizationHint(Object &O) const; 47 void readFunctionStartsData(Object &O) const; 48 void readDylibCodeSignDRs(Object &O) const; 49 void readExportsTrie(Object &O) const; 50 void readChainedFixups(Object &O) const; 51 void readIndirectSymbolTable(Object &O) const; 52 void readSwiftVersion(Object &O) const; 53 54 public: MachOReader(const object::MachOObjectFile & Obj)55 explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {} 56 57 Expected<std::unique_ptr<Object>> create() const override; 58 }; 59 60 } // end namespace macho 61 } // end namespace objcopy 62 } // end namespace llvm 63 64 #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H 65