blob: ca3a0214cb6d3bc9840dcb3d09f7d4e8676b3e9d [file] [log] [blame]
Chih-Hung Hsieh08600532019-12-19 15:55:38 -08001//===- 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
15namespace llvm {
16namespace objcopy {
17namespace macho {
18
19// The hierarchy of readers is responsible for parsing different inputs:
20// raw binaries and regular MachO object files.
21class Reader {
22public:
23 virtual ~Reader(){};
Chris Wailese3116c42021-07-13 14:40:48 -070024 virtual Expected<std::unique_ptr<Object>> create() const = 0;
Chih-Hung Hsieh08600532019-12-19 15:55:38 -080025};
26
27class MachOReader : public Reader {
28 const object::MachOObjectFile &MachOObj;
29
30 void readHeader(Object &O) const;
Chris Wailese3116c42021-07-13 14:40:48 -070031 Error readLoadCommands(Object &O) const;
Chih-Hung Hsieh08600532019-12-19 15:55:38 -080032 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 Weksteene40e7362020-10-28 15:03:00 +010039 void readLinkData(Object &O, Optional<size_t> LCIndex, LinkData &LD) const;
40 void readCodeSignature(Object &O) const;
Jeff Vander Stoep247d86b2020-08-11 14:27:44 +020041 void readDataInCodeData(Object &O) const;
Chris Wailesbcf972c2021-10-21 11:03:28 -070042 void readLinkerOptimizationHint(Object &O) const;
Jeff Vander Stoep247d86b2020-08-11 14:27:44 +020043 void readFunctionStartsData(Object &O) const;
44 void readIndirectSymbolTable(Object &O) const;
ThiƩbaud Weksteene40e7362020-10-28 15:03:00 +010045 void readSwiftVersion(Object &O) const;
Chih-Hung Hsieh08600532019-12-19 15:55:38 -080046
47public:
48 explicit MachOReader(const object::MachOObjectFile &Obj) : MachOObj(Obj) {}
49
Chris Wailese3116c42021-07-13 14:40:48 -070050 Expected<std::unique_ptr<Object>> create() const override;
Chih-Hung Hsieh08600532019-12-19 15:55:38 -080051};
52
53} // end namespace macho
54} // end namespace objcopy
55} // end namespace llvm