1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//                     The LLVM Compiler Infrastructure
4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source
6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details.
7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file declares the MachOObjectFile class, which implement the ObjectFile
11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// interface for MachO files.
12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//
13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===//
14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_OBJECT_MACHO_H
16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_OBJECT_MACHO_H
17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/ArrayRef.h"
19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallString.h"
20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallVector.h"
21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/StringExtras.h"
22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/StringRef.h"
23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/Triple.h"
24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/iterator_range.h"
25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/BinaryFormat/MachO.h"
26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/MC/SubtargetFeature.h"
27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/Binary.h"
28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/ObjectFile.h"
29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Object/SymbolicFile.h"
30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Error.h"
31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/Format.h"
32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/MemoryBuffer.h"
33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/raw_ostream.h"
34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <cstdint>
35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <memory>
36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <string>
37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include <system_error>
38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace llvm {
40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace object {
41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// DiceRef - This is a value type class that represents a single
43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// data in code entry in the table in a Mach-O object file.
44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DiceRef {
45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DataRefImpl DicePimpl;
46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const ObjectFile *OwningObject = nullptr;
47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DiceRef() = default;
50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DiceRef(DataRefImpl DiceP, const ObjectFile *Owner);
51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const DiceRef &Other) const;
53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator<(const DiceRef &Other) const;
54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveNext();
56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getOffset(uint32_t &Result) const;
58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getLength(uint16_t &Result) const;
59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getKind(uint16_t &Result) const;
60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DataRefImpl getRawDataRefImpl() const;
62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const ObjectFile *getObjectFile() const;
63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing dice_iterator = content_iterator<DiceRef>;
65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// ExportEntry encapsulates the current-state-of-the-walk used when doing a
67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// non-recursive walk of the trie data structure.  This allows you to iterate
68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// across all exported symbols using:
69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///      Error Err;
70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///      for (const llvm::object::ExportEntry &AnExport : Obj->exports(&Err)) {
71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///      }
72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///      if (Err) { report error ...
73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass ExportEntry {
74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ExportEntry(Error *Err, const MachOObjectFile *O, ArrayRef<uint8_t> Trie);
76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef name() const;
78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t flags() const;
79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t address() const;
80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t other() const;
81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef otherName() const;
82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t nodeOffset() const;
83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const ExportEntry &) const;
85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveNext();
87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend class MachOObjectFile;
90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToFirst();
92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToEnd();
93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t readULEB128(const uint8_t *&p, const char **error);
94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void pushDownUntilBottom();
95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void pushNode(uint64_t Offset);
96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Represents a node in the mach-o exports trie.
98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct NodeState {
99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    NodeState(const uint8_t *Ptr);
100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    const uint8_t *Start;
102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    const uint8_t *Current;
103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t Flags = 0;
104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t Address = 0;
105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t Other = 0;
106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    const char *ImportName = nullptr;
107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned ChildCount = 0;
108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned NextChildIndex = 0;
109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    unsigned ParentStringLength = 0;
110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    bool IsExportNode = false;
111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using NodeList = SmallVector<NodeState, 16>;
113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using node_iterator = NodeList::const_iterator;
114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Error *E;
116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *O;
117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> Trie;
118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  SmallString<256> CumulativeString;
119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  NodeList Stack;
120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool Done = false;
121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<node_iterator> nodes() const {
123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return make_range(Stack.begin(), Stack.end());
124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing export_iterator = content_iterator<ExportEntry>;
127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// Segment info so SegIndex/SegOffset pairs in a Mach-O Bind or Rebase entry
129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// can be checked and translated.  Only the SegIndex/SegOffset pairs from
130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// checked entries are to be used with the segmentName(), sectionName() and
131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// address() methods below.
132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BindRebaseSegInfo {
133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  BindRebaseSegInfo(const MachOObjectFile *Obj);
135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Used to check a Mach-O Bind or Rebase entry for errors when iterating.
137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *checkSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                bool endInvalid);
139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *checkCountAndSkip(uint32_t Count, uint32_t Skip,
140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                uint8_t PointerSize, int32_t SegIndex,
141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                uint64_t SegOffset);
142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Used with valid SegIndex/SegOffset values from checked entries.
143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef segmentName(int32_t SegIndex);
144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef sectionName(int32_t SegIndex, uint64_t SegOffset);
145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t address(uint32_t SegIndex, uint64_t SegOffset);
146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct SectionInfo {
149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t Address;
150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t Size;
151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    StringRef SectionName;
152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    StringRef SegmentName;
153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t OffsetInSegment;
154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint64_t SegmentStartAddress;
155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    int32_t SegmentIndex;
156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const SectionInfo &findSection(int32_t SegIndex, uint64_t SegOffset);
158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  SmallVector<SectionInfo, 32> Sections;
160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int32_t MaxSegIndex;
161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// MachORebaseEntry encapsulates the current state in the decompression of
164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// rebasing opcodes. This allows you to iterate through the compressed table of
165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// rebasing using:
166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    Error Err;
167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    for (const llvm::object::MachORebaseEntry &Entry : Obj->rebaseTable(&Err)) {
168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    }
169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    if (Err) { report error ...
170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MachORebaseEntry {
171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachORebaseEntry(Error *Err, const MachOObjectFile *O,
173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                   ArrayRef<uint8_t> opcodes, bool is64Bit);
174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int32_t segmentIndex() const;
176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t segmentOffset() const;
177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef typeName() const;
178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef segmentName() const;
179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef sectionName() const;
180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t address() const;
181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const MachORebaseEntry &) const;
183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveNext();
185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend class MachOObjectFile;
188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToFirst();
190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToEnd();
191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t readULEB128(const char **error);
192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Error *E;
194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *O;
195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> Opcodes;
196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const uint8_t *Ptr;
197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t SegmentOffset = 0;
198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int32_t SegmentIndex = -1;
199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t RemainingLoopCount = 0;
200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t AdvanceAmount = 0;
201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t  RebaseType = 0;
202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t  PointerSize;
203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool     Done = false;
204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing rebase_iterator = content_iterator<MachORebaseEntry>;
206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// MachOBindEntry encapsulates the current state in the decompression of
208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// binding opcodes. This allows you to iterate through the compressed table of
209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// bindings using:
210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    Error Err;
211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    for (const llvm::object::MachOBindEntry &Entry : Obj->bindTable(&Err)) {
212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    }
213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot///    if (Err) { report error ...
214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MachOBindEntry {
215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  enum class Kind { Regular, Lazy, Weak };
217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachOBindEntry(Error *Err, const MachOObjectFile *O,
219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                 ArrayRef<uint8_t> Opcodes, bool is64Bit, MachOBindEntry::Kind);
220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int32_t segmentIndex() const;
222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t segmentOffset() const;
223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef typeName() const;
224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef symbolName() const;
225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t flags() const;
226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int64_t addend() const;
227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int ordinal() const;
228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef segmentName() const;
230c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef sectionName() const;
231c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t address() const;
232c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
233c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool operator==(const MachOBindEntry &) const;
234c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
235c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveNext();
236c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
237c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
238c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  friend class MachOObjectFile;
239c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
240c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToFirst();
241c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveToEnd();
242c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t readULEB128(const char **error);
243c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int64_t readSLEB128(const char **error);
244c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
245c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Error *E;
246c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *O;
247c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> Opcodes;
248c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const uint8_t *Ptr;
249c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t SegmentOffset = 0;
250c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int32_t  SegmentIndex = -1;
251c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef SymbolName;
252c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool     LibraryOrdinalSet = false;
253c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int      Ordinal = 0;
254c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t Flags = 0;
255c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  int64_t  Addend = 0;
256c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t RemainingLoopCount = 0;
257c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t AdvanceAmount = 0;
258c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t  BindType = 0;
259c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t  PointerSize;
260c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Kind     TableKind;
261c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool     Done = false;
262c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
263c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotusing bind_iterator = content_iterator<MachOBindEntry>;
264c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
265c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass MachOObjectFile : public ObjectFile {
266c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic:
267c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  struct LoadCommandInfo {
268c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    const char *Ptr;      // Where in memory the load command is.
269c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachO::load_command C; // The command itself.
270c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
271c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using LoadCommandList = SmallVector<LoadCommandInfo, 4>;
272c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using load_command_iterator = LoadCommandList::const_iterator;
273c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
274c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static Expected<std::unique_ptr<MachOObjectFile>>
275c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
276c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot         uint32_t UniversalCputype = 0, uint32_t UniversalIndex = 0);
277c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
278c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveSymbolNext(DataRefImpl &Symb) const override;
279c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
280c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getNValue(DataRefImpl Sym) const;
281c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
282c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
283c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // MachO specific.
284c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Error checkSymbolTable() const;
285c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
286c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
287c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getSectionType(SectionRef Sec) const;
288c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
289c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
290c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
291c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
292c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
293c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
294c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
295c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getSymbolSectionID(SymbolRef Symb) const;
296c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getSectionID(SectionRef Sec) const;
297c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
298c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveSectionNext(DataRefImpl &Sec) const override;
299c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getSectionName(DataRefImpl Sec,
300c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                 StringRef &Res) const override;
301c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSectionAddress(DataRefImpl Sec) const override;
302c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSectionIndex(DataRefImpl Sec) const override;
303c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSectionSize(DataRefImpl Sec) const override;
304c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getSectionContents(DataRefImpl Sec,
305c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                     StringRef &Res) const override;
306c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
307c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionCompressed(DataRefImpl Sec) const override;
308c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionText(DataRefImpl Sec) const override;
309c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionData(DataRefImpl Sec) const override;
310c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionBSS(DataRefImpl Sec) const override;
311c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionVirtual(DataRefImpl Sec) const override;
312c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionBitcode(DataRefImpl Sec) const override;
313c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
314c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// When dsymutil generates the companion file, it strips all unnecessary
315c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// sections (e.g. everything in the _TEXT segment) by omitting their body
316c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// and setting the offset in their corresponding load command to zero.
317c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ///
318c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// While the load command itself is valid, reading the section corresponds
319c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// to reading the number of bytes specified in the load command, starting
320c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// from offset 0 (i.e. the Mach-O header at the beginning of the file).
321c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isSectionStripped(DataRefImpl Sec) const override;
322c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
323c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
324c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
325c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
326c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator extrel_begin() const;
327c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator extrel_end() const;
328c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<relocation_iterator> external_relocations() const {
329c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return make_range(extrel_begin(), extrel_end());
330c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
331c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
332c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void moveRelocationNext(DataRefImpl &Rel) const override;
333c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
334c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
335c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  section_iterator getRelocationSection(DataRefImpl Rel) const;
336c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getRelocationType(DataRefImpl Rel) const override;
337c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void getRelocationTypeName(DataRefImpl Rel,
338c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                             SmallVectorImpl<char> &Result) const override;
339c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t getRelocationLength(DataRefImpl Rel) const;
340c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
341c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // MachO specific.
342c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
343c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t getLibraryCount() const;
344c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
345c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
346c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
347c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // TODO: Would be useful to have an iterator based version
348c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // of the load command interface too.
349c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
350c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  basic_symbol_iterator symbol_begin() const override;
351c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  basic_symbol_iterator symbol_end() const override;
352c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
353c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // MachO specific.
354c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
355c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSymbolIndex(DataRefImpl Symb) const;
356c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
357c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  section_iterator section_begin() const override;
358c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  section_iterator section_end() const override;
359c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
360c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint8_t getBytesInAddress() const override;
361c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
362c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef getFileFormatName() const override;
363c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getArch() const override;
364c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
365c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Triple getArchTriple(const char **McpuDefault = nullptr) const;
366c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
367c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator section_rel_begin(unsigned Index) const;
368c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  relocation_iterator section_rel_end(unsigned Index) const;
369c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
370c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  dice_iterator begin_dices() const;
371c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  dice_iterator end_dices() const;
372c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
373c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  load_command_iterator begin_load_commands() const;
374c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  load_command_iterator end_load_commands() const;
375c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<load_command_iterator> load_commands() const;
376c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
377c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use iterating over all exported symbols.
378c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<export_iterator> exports(Error &Err) const;
379c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
380c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use examining a trie not in a MachOObjectFile.
381c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static iterator_range<export_iterator> exports(Error &Err,
382c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 ArrayRef<uint8_t> Trie,
383c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 const MachOObjectFile *O =
384c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                                      nullptr);
385c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
386c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use iterating over all rebase table entries.
387c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<rebase_iterator> rebaseTable(Error &Err);
388c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
389c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use examining rebase opcodes in a MachOObjectFile.
390c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static iterator_range<rebase_iterator> rebaseTable(Error &Err,
391c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     MachOObjectFile *O,
392c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     ArrayRef<uint8_t> Opcodes,
393c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     bool is64);
394c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
395c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use iterating over all bind table entries.
396c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<bind_iterator> bindTable(Error &Err);
397c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
398c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use iterating over all lazy bind table entries.
399c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<bind_iterator> lazyBindTable(Error &Err);
400c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
401c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use iterating over all weak bind table entries.
402c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  iterator_range<bind_iterator> weakBindTable(Error &Err);
403c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
404c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use examining bind opcodes in a MachOObjectFile.
405c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static iterator_range<bind_iterator> bindTable(Error &Err,
406c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 MachOObjectFile *O,
407c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 ArrayRef<uint8_t> Opcodes,
408c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 bool is64,
409c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                 MachOBindEntry::Kind);
410c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
411c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use with a SegIndex,SegOffset pair in MachOBindEntry::moveNext() to
412c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// validate a MachOBindEntry.
413c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *BindEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
414c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         bool endInvalid) const {
415c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
416c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     endInvalid);
417c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
418c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for
419c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode.
420c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *BindEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
421c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         uint8_t PointerSize, int32_t SegIndex,
422c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         uint64_t SegOffset) const {
423c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
424c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     SegIndex, SegOffset);
425c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
426c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
427c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to
428c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// validate a MachORebaseEntry.
429c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
430c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                           bool endInvalid) const {
431c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
432c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     endInvalid);
433c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
434c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for
435c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// the REBASE_OPCODE_DO_*_TIMES* opcodes.
436c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
437c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         uint8_t PointerSize, int32_t SegIndex,
438c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         uint64_t SegOffset) const {
439c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
440c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                     SegIndex, SegOffset);
441c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
442c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
443c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use with the SegIndex of a checked Mach-O Bind or Rebase entry to
444c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// get the segment name.
445c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef BindRebaseSegmentName(int32_t SegIndex) const {
446c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->segmentName(SegIndex);
447c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
448c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
449c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
450c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Rebase entry to get the section name.
451c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef BindRebaseSectionName(uint32_t SegIndex, uint64_t SegOffset) const {
452c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
453c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
454c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
455c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
456c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  /// Rebase entry to get the address.
457c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t BindRebaseAddress(uint32_t SegIndex, uint64_t SegOffset) const {
458c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return BindRebaseSectionTable->address(SegIndex, SegOffset);
459c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
460c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
461c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // In a MachO file, sections have a segment name. This is used in the .o
462c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // files. They have a single segment, but this field specifies which segment
463c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // a section should be put in in the final object.
464c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef getSectionFinalSegmentName(DataRefImpl Sec) const;
465c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
466c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // Names are stored as 16 bytes. These returns the raw 16 bytes without
467c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // interpreting them as a C string.
468c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
469c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<char> getSectionRawFinalSegmentName(DataRefImpl Sec) const;
470c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
471c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // MachO specific Info about relocations.
472c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isRelocationScattered(const MachO::any_relocation_info &RE) const;
473c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getPlainRelocationSymbolNum(
474c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachO::any_relocation_info &RE) const;
475c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const;
476c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool getScatteredRelocationScattered(
477c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachO::any_relocation_info &RE) const;
478c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t getScatteredRelocationValue(
479c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachO::any_relocation_info &RE) const;
480c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t getScatteredRelocationType(
481c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                    const MachO::any_relocation_info &RE) const;
482c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const;
483c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const;
484c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const;
485c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const;
486c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const;
487c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
488c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  // MachO specific structures.
489c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::section getSection(DataRefImpl DRI) const;
490c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::section_64 getSection64(DataRefImpl DRI) const;
491c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::section getSection(const LoadCommandInfo &L, unsigned Index) const;
492c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::section_64 getSection64(const LoadCommandInfo &L,unsigned Index) const;
493c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const;
494c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const;
495c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
496c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::linkedit_data_command
497c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getLinkeditDataLoadCommand(const LoadCommandInfo &L) const;
498c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::segment_command
499c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSegmentLoadCommand(const LoadCommandInfo &L) const;
500c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::segment_command_64
501c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSegment64LoadCommand(const LoadCommandInfo &L) const;
502c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::linker_option_command
503c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
504c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::version_min_command
505c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getVersionMinLoadCommand(const LoadCommandInfo &L) const;
506c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::note_command
507c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getNoteLoadCommand(const LoadCommandInfo &L) const;
508c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::build_version_command
509c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getBuildVersionLoadCommand(const LoadCommandInfo &L) const;
510c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::build_tool_version
511c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getBuildToolVersion(unsigned index) const;
512c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::dylib_command
513c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getDylibIDLoadCommand(const LoadCommandInfo &L) const;
514c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::dyld_info_command
515c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getDyldInfoLoadCommand(const LoadCommandInfo &L) const;
516c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::dylinker_command
517c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getDylinkerCommand(const LoadCommandInfo &L) const;
518c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::uuid_command
519c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getUuidCommand(const LoadCommandInfo &L) const;
520c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::rpath_command
521c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getRpathCommand(const LoadCommandInfo &L) const;
522c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::source_version_command
523c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSourceVersionCommand(const LoadCommandInfo &L) const;
524c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::entry_point_command
525c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getEntryPointCommand(const LoadCommandInfo &L) const;
526c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::encryption_info_command
527c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getEncryptionInfoCommand(const LoadCommandInfo &L) const;
528c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::encryption_info_command_64
529c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
530c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::sub_framework_command
531c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSubFrameworkCommand(const LoadCommandInfo &L) const;
532c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::sub_umbrella_command
533c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSubUmbrellaCommand(const LoadCommandInfo &L) const;
534c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::sub_library_command
535c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSubLibraryCommand(const LoadCommandInfo &L) const;
536c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::sub_client_command
537c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getSubClientCommand(const LoadCommandInfo &L) const;
538c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::routines_command
539c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getRoutinesCommand(const LoadCommandInfo &L) const;
540c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::routines_command_64
541c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getRoutinesCommand64(const LoadCommandInfo &L) const;
542c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::thread_command
543c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getThreadCommand(const LoadCommandInfo &L) const;
544c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
545c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
546c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
547c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachO::mach_header &getHeader() const;
548c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachO::mach_header_64 &getHeader64() const;
549c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint32_t
550c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC,
551c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              unsigned Index) const;
552c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset,
553c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                                    unsigned Index) const;
554c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::symtab_command getSymtabLoadCommand() const;
555c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::dysymtab_command getDysymtabLoadCommand() const;
556c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::linkedit_data_command getDataInCodeLoadCommand() const;
557c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::linkedit_data_command getLinkOptHintsLoadCommand() const;
558c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getDyldInfoRebaseOpcodes() const;
559c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getDyldInfoBindOpcodes() const;
560c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getDyldInfoWeakBindOpcodes() const;
561c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getDyldInfoLazyBindOpcodes() const;
562c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getDyldInfoExportsTrie() const;
563c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  ArrayRef<uint8_t> getUuid() const;
564c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
565c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef getStringTableData() const;
566c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool is64Bit() const;
567c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
568c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
569c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
570c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                                         StringRef &Suffix);
571c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
572c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static Triple::ArchType getArch(uint32_t CPUType);
573c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static Triple getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
574c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              const char **McpuDefault = nullptr,
575c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                              const char **ArchFlag = nullptr);
576c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static bool isValidArch(StringRef ArchFlag);
577c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static Triple getHostArch();
578c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
579c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool isRelocatableObject() const override;
580c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
581c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  StringRef mapDebugSectionName(StringRef Name) const override;
582c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
583c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool hasPageZeroSegment() const { return HasPageZeroSegment; }
584c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
585c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static bool classof(const Binary *v) {
586c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return v->isMachO();
587c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
588c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
589c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static uint32_t
590c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getVersionMinMajor(MachO::version_min_command &C, bool SDK) {
591c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
592c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return (VersionOrSDK >> 16) & 0xffff;
593c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
594c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
595c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static uint32_t
596c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getVersionMinMinor(MachO::version_min_command &C, bool SDK) {
597c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
598c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return (VersionOrSDK >> 8) & 0xff;
599c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
600c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
601c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static uint32_t
602c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  getVersionMinUpdate(MachO::version_min_command &C, bool SDK) {
603c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
604c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return VersionOrSDK & 0xff;
605c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
606c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
607c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static std::string getBuildPlatform(uint32_t platform) {
608c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    switch (platform) {
609c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::PLATFORM_MACOS: return "macos";
610c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::PLATFORM_IOS: return "ios";
611c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::PLATFORM_TVOS: return "tvos";
612c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::PLATFORM_WATCHOS: return "watchos";
613c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
614c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    default:
615c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      std::string ret;
616c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      raw_string_ostream ss(ret);
617c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      ss << format_hex(platform, 8, true);
618c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return ss.str();
619c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
620c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
621c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
622c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static std::string getBuildTool(uint32_t tools) {
623c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    switch (tools) {
624c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::TOOL_CLANG: return "clang";
625c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::TOOL_SWIFT: return "swift";
626c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    case MachO::TOOL_LD: return "ld";
627c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    default:
628c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      std::string ret;
629c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      raw_string_ostream ss(ret);
630c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      ss << format_hex(tools, 8, true);
631c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      return ss.str();
632c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    }
633c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
634c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
635c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  static std::string getVersionString(uint32_t version) {
636c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t major = (version >> 16) & 0xffff;
637c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t minor = (version >> 8) & 0xff;
638c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    uint32_t update = version & 0xff;
639c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
640c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    SmallString<32> Version;
641c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    Version = utostr(major) + "." + utostr(minor);
642c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    if (update != 0)
643c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot      Version += "." + utostr(update);
644c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    return Version.str();
645c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  }
646c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
647c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate:
648c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
649c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                  Error &Err, uint32_t UniversalCputype = 0,
650c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot                  uint32_t UniversalIndex = 0);
651c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
652c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
653c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
654c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  union {
655c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachO::mach_header_64 Header64;
656c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    MachO::mach_header Header;
657c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  };
658c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using SectionList = SmallVector<const char*, 1>;
659c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  SectionList Sections;
660c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using LibraryList = SmallVector<const char*, 1>;
661c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  LibraryList Libraries;
662c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  LoadCommandList LoadCommands;
663c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using LibraryShortName = SmallVector<StringRef, 1>;
664c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  using BuildToolList = SmallVector<const char*, 1>;
665c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  BuildToolList BuildTools;
666c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  mutable LibraryShortName LibrariesShortNames;
667c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable;
668c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *SymtabLoadCmd = nullptr;
669c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *DysymtabLoadCmd = nullptr;
670c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *DataInCodeLoadCmd = nullptr;
671c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *LinkOptHintsLoadCmd = nullptr;
672c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *DyldInfoLoadCmd = nullptr;
673c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const char *UuidLoadCmd = nullptr;
674c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  bool HasPageZeroSegment = false;
675c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot};
676c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
677c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// DiceRef
678c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner)
679c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  : DicePimpl(DiceP) , OwningObject(Owner) {}
680c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
681c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline bool DiceRef::operator==(const DiceRef &Other) const {
682c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return DicePimpl == Other.DicePimpl;
683c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
684c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
685c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline bool DiceRef::operator<(const DiceRef &Other) const {
686c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return DicePimpl < Other.DicePimpl;
687c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
688c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
689c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline void DiceRef::moveNext() {
690c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachO::data_in_code_entry *P =
691c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
692c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  DicePimpl.p = reinterpret_cast<uintptr_t>(P + 1);
693c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
694c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
695c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// Since a Mach-O data in code reference, a DiceRef, can only be created when
696c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for
697c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// the methods that get the values of the fields of the reference.
698c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
699c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline std::error_code DiceRef::getOffset(uint32_t &Result) const {
700c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *MachOOF =
701c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    static_cast<const MachOObjectFile *>(OwningObject);
702c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
703c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Result = Dice.offset;
704c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return std::error_code();
705c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
706c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
707c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline std::error_code DiceRef::getLength(uint16_t &Result) const {
708c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *MachOOF =
709c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    static_cast<const MachOObjectFile *>(OwningObject);
710c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
711c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Result = Dice.length;
712c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return std::error_code();
713c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
714c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
715c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline std::error_code DiceRef::getKind(uint16_t &Result) const {
716c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  const MachOObjectFile *MachOOF =
717c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot    static_cast<const MachOObjectFile *>(OwningObject);
718c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
719c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  Result = Dice.kind;
720c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return std::error_code();
721c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
722c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
723c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline DataRefImpl DiceRef::getRawDataRefImpl() const {
724c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return DicePimpl;
725c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
726c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
727c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotinline const ObjectFile *DiceRef::getObjectFile() const {
728c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot  return OwningObject;
729c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}
730c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
731c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace object
732c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end namespace llvm
733c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot
734c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif // LLVM_OBJECT_MACHO_H
735