xref: /freebsd-src/contrib/llvm-project/llvm/lib/ObjCopy/MachO/MachOReader.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
181ad6265SDimitry Andric //===- MachOReader.h --------------------------------------------*- C++ -*-===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
1081ad6265SDimitry Andric #define LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
1181ad6265SDimitry Andric 
1281ad6265SDimitry Andric #include "MachOObject.h"
1381ad6265SDimitry Andric #include "llvm/BinaryFormat/MachO.h"
1481ad6265SDimitry Andric #include "llvm/ObjCopy/MachO/MachOObjcopy.h"
1581ad6265SDimitry Andric #include "llvm/Object/MachO.h"
1681ad6265SDimitry Andric #include <memory>
1781ad6265SDimitry Andric 
1881ad6265SDimitry Andric namespace llvm {
1981ad6265SDimitry Andric namespace objcopy {
2081ad6265SDimitry Andric namespace macho {
2181ad6265SDimitry Andric 
2281ad6265SDimitry Andric // The hierarchy of readers is responsible for parsing different inputs:
2381ad6265SDimitry Andric // raw binaries and regular MachO object files.
2481ad6265SDimitry Andric class Reader {
2581ad6265SDimitry Andric public:
~Reader()2681ad6265SDimitry Andric   virtual ~Reader(){};
2781ad6265SDimitry Andric   virtual Expected<std::unique_ptr<Object>> create() const = 0;
2881ad6265SDimitry Andric };
2981ad6265SDimitry Andric 
3081ad6265SDimitry Andric class MachOReader : public Reader {
3181ad6265SDimitry Andric   const object::MachOObjectFile &MachOObj;
3281ad6265SDimitry Andric 
3381ad6265SDimitry Andric   void readHeader(Object &O) const;
3481ad6265SDimitry Andric   Error readLoadCommands(Object &O) const;
3581ad6265SDimitry Andric   void readSymbolTable(Object &O) const;
3681ad6265SDimitry Andric   void setSymbolInRelocationInfo(Object &O) const;
3781ad6265SDimitry Andric   void readRebaseInfo(Object &O) const;
3881ad6265SDimitry Andric   void readBindInfo(Object &O) const;
3981ad6265SDimitry Andric   void readWeakBindInfo(Object &O) const;
4081ad6265SDimitry Andric   void readLazyBindInfo(Object &O) const;
4181ad6265SDimitry Andric   void readExportInfo(Object &O) const;
42*bdd1243dSDimitry Andric   void readLinkData(Object &O, std::optional<size_t> LCIndex,
43*bdd1243dSDimitry Andric                     LinkData &LD) const;
4481ad6265SDimitry Andric   void readCodeSignature(Object &O) const;
4581ad6265SDimitry Andric   void readDataInCodeData(Object &O) const;
4681ad6265SDimitry Andric   void readLinkerOptimizationHint(Object &O) const;
4781ad6265SDimitry Andric   void readFunctionStartsData(Object &O) const;
48*bdd1243dSDimitry Andric   void readDylibCodeSignDRs(Object &O) const;
4981ad6265SDimitry Andric   void readExportsTrie(Object &O) const;
5081ad6265SDimitry Andric   void readChainedFixups(Object &O) const;
5181ad6265SDimitry Andric   void readIndirectSymbolTable(Object &O) const;
5281ad6265SDimitry Andric   void readSwiftVersion(Object &O) const;
5381ad6265SDimitry Andric 
5481ad6265SDimitry Andric public:
MachOReader(const object::MachOObjectFile & Obj)5581ad6265SDimitry Andric   explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {}
5681ad6265SDimitry Andric 
5781ad6265SDimitry Andric   Expected<std::unique_ptr<Object>> create() const override;
5881ad6265SDimitry Andric };
5981ad6265SDimitry Andric 
6081ad6265SDimitry Andric } // end namespace macho
6181ad6265SDimitry Andric } // end namespace objcopy
6281ad6265SDimitry Andric } // end namespace llvm
6381ad6265SDimitry Andric 
6481ad6265SDimitry Andric #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOREADER_H
65