xref: /freebsd/contrib/llvm-project/llvm/lib/ObjCopy/MachO/MachOReader.h (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
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:
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, Optional<size_t> LCIndex, LinkData &LD) const;
43   void readCodeSignature(Object &O) const;
44   void readDataInCodeData(Object &O) const;
45   void readLinkerOptimizationHint(Object &O) const;
46   void readFunctionStartsData(Object &O) const;
47   void readExportsTrie(Object &O) const;
48   void readChainedFixups(Object &O) const;
49   void readIndirectSymbolTable(Object &O) const;
50   void readSwiftVersion(Object &O) const;
51 
52 public:
53   explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {}
54 
55   Expected<std::unique_ptr<Object>> create() const override;
56 };
57 
58 } // end namespace macho
59 } // end namespace objcopy
60 } // end namespace llvm
61 
62 #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
63