annotate lld/MachO/SyntheticSections.h @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===- SyntheticSections.h -------------------------------------*- C++ -*-===//
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #ifndef LLD_MACHO_SYNTHETIC_SECTIONS_H
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define LLD_MACHO_SYNTHETIC_SECTIONS_H
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
12 #include "Config.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "ExportTrie.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "InputSection.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include "OutputSection.h"
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
16 #include "OutputSegment.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include "Target.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
19 #include "llvm/ADT/Hashing.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "llvm/ADT/SetVector.h"
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21 #include "llvm/Support/MathExtras.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "llvm/Support/raw_ostream.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
24 namespace llvm {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
25 class DWARFUnit;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
26 } // namespace llvm
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
27
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 namespace lld {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 namespace macho {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
31 class Defined;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 class DylibSymbol;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 class LoadCommand;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
34 class ObjFile;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
35 class UnwindInfoSection;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 class SyntheticSection : public OutputSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 SyntheticSection(const char *segname, const char *name);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 virtual ~SyntheticSection() = default;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 static bool classof(const OutputSection *sec) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 return sec->kind() == SyntheticKind;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
45
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
46 const StringRef segname;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
47 // This fake InputSection makes it easier for us to write code that applies
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
48 // generically to both user inputs and synthetics.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
49 InputSection *isec;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
50 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
52 // All sections in __LINKEDIT should inherit from this.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
53 class LinkEditSection : public SyntheticSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
54 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
55 LinkEditSection(const char *segname, const char *name)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
56 : SyntheticSection(segname, name) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
57 align = target->wordSize;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
58 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
60 virtual void finalizeContents() {}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
61
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
62 // Sections in __LINKEDIT are special: their offsets are recorded in the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
63 // load commands like LC_DYLD_INFO_ONLY and LC_SYMTAB, instead of in section
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
64 // headers.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
65 bool isHidden() const override final { return true; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
66
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
67 virtual uint64_t getRawSize() const = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
68
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
69 // codesign (or more specifically libstuff) checks that each section in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
70 // __LINKEDIT ends where the next one starts -- no gaps are permitted. We
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
71 // therefore align every section's start and end points to WordSize.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
72 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
73 // NOTE: This assumes that the extra bytes required for alignment can be
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
74 // zero-valued bytes.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
75 uint64_t getSize() const override final {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
76 return llvm::alignTo(getRawSize(), align);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
77 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 // The header of the Mach-O file, which must have a file offset of zero.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 class MachHeaderSection : public SyntheticSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 MachHeaderSection();
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 bool isHidden() const override { return true; }
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
85 uint64_t getSize() const override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
88 void addLoadCommand(LoadCommand *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
89
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
90 protected:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 std::vector<LoadCommand *> loadCommands;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 uint32_t sizeOfCmds = 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 // A hidden section that exists solely for the purpose of creating the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 // __PAGEZERO segment, which is used to catch null pointer dereferences.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 class PageZeroSection : public SyntheticSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 PageZeroSection();
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 bool isHidden() const override { return true; }
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
101 uint64_t getSize() const override { return target->pageZeroSize; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 uint64_t getFileSize() const override { return 0; }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 void writeTo(uint8_t *buf) const override {}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
106 // This is the base class for the GOT and TLVPointer sections, which are nearly
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
107 // functionally identical -- they will both be populated by dyld with addresses
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
108 // to non-lazily-loaded dylib symbols. The main difference is that the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
109 // TLVPointerSection stores references to thread-local variables.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
110 class NonLazyPointerSectionBase : public SyntheticSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 public:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
112 NonLazyPointerSectionBase(const char *segname, const char *name);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
114 const llvm::SetVector<const Symbol *> &getEntries() const { return entries; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 bool isNeeded() const override { return !entries.empty(); }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
118 uint64_t getSize() const override {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
119 return entries.size() * target->wordSize;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
120 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
122 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
123
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
124 void addEntry(Symbol *sym);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
125
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
126 uint64_t getVA(uint32_t gotIndex) const {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
127 return addr + gotIndex * target->wordSize;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
130 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
131 llvm::SetVector<const Symbol *> entries;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
132 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
133
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
134 class GotSection : public NonLazyPointerSectionBase {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
135 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
136 GotSection()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
137 : NonLazyPointerSectionBase(segment_names::dataConst,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
138 section_names::got) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
139 // TODO: section_64::reserved1 should be an index into the indirect symbol
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
140 // table, which we do not currently emit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
141 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
142 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
143
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
144 class TlvPointerSection : public NonLazyPointerSectionBase {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
145 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
146 TlvPointerSection()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
147 : NonLazyPointerSectionBase(segment_names::data,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
148 section_names::threadPtrs) {}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
149 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
150
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
151 struct Location {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
152 const InputSection *isec;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
153 uint64_t offset;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
154
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
155 Location(const InputSection *isec, uint64_t offset)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
156 : isec(isec), offset(offset) {}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
157 uint64_t getVA() const { return isec->getVA() + offset; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
158 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
160 // Stores rebase opcodes, which tell dyld where absolute addresses have been
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
161 // encoded in the binary. If the binary is not loaded at its preferred address,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
162 // dyld has to rebase these addresses by adding an offset to them.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
163 class RebaseSection : public LinkEditSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
164 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
165 RebaseSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
166 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
167 uint64_t getRawSize() const override { return contents.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
168 bool isNeeded() const override { return !locations.empty(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
169 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
170
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
171 void addEntry(const InputSection *isec, uint64_t offset) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
172 if (config->isPic)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
173 locations.push_back({isec, offset});
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
174 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 private:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
177 std::vector<Location> locations;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
178 SmallVector<char, 128> contents;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
179 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
180
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
181 struct BindingEntry {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
182 const DylibSymbol *dysym;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
183 int64_t addend;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
184 Location target;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
185 BindingEntry(const DylibSymbol *dysym, int64_t addend, Location target)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
186 : dysym(dysym), addend(addend), target(std::move(target)) {}
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 // Stores bind opcodes for telling dyld which symbols to load non-lazily.
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
190 class BindingSection : public LinkEditSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 BindingSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
193 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
194 uint64_t getRawSize() const override { return contents.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
195 bool isNeeded() const override { return !bindings.empty(); }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
198 void addEntry(const DylibSymbol *dysym, const InputSection *isec,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
199 uint64_t offset, int64_t addend = 0) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
200 bindings.emplace_back(dysym, addend, Location(isec, offset));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
201 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
202
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
203 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
204 std::vector<BindingEntry> bindings;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
205 SmallVector<char, 128> contents;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
206 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
208 struct WeakBindingEntry {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
209 const Symbol *symbol;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
210 int64_t addend;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
211 Location target;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
212 WeakBindingEntry(const Symbol *symbol, int64_t addend, Location target)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
213 : symbol(symbol), addend(addend), target(std::move(target)) {}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
214 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
215
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
216 // Stores bind opcodes for telling dyld which weak symbols need coalescing.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
217 // There are two types of entries in this section:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
218 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
219 // 1) Non-weak definitions: This is a symbol definition that weak symbols in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
220 // other dylibs should coalesce to.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
221 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
222 // 2) Weak bindings: These tell dyld that a given symbol reference should
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
223 // coalesce to a non-weak definition if one is found. Note that unlike the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
224 // entries in the BindingSection, the bindings here only refer to these
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
225 // symbols by name, but do not specify which dylib to load them from.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
226 class WeakBindingSection : public LinkEditSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
227 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
228 WeakBindingSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
229 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
230 uint64_t getRawSize() const override { return contents.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
231 bool isNeeded() const override {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
232 return !bindings.empty() || !definitions.empty();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
233 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
234
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
235 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
236
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
237 void addEntry(const Symbol *symbol, const InputSection *isec, uint64_t offset,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
238 int64_t addend = 0) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
239 bindings.emplace_back(symbol, addend, Location(isec, offset));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
240 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
241
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
242 bool hasEntry() const { return !bindings.empty(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
243
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
244 void addNonWeakDefinition(const Defined *defined) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
245 definitions.emplace_back(defined);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
246 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
247
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
248 bool hasNonWeakDefinition() const { return !definitions.empty(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
249
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
250 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
251 std::vector<WeakBindingEntry> bindings;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
252 std::vector<const Defined *> definitions;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 SmallVector<char, 128> contents;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 // The following sections implement lazy symbol binding -- very similar to the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 // PLT mechanism in ELF.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 //
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
259 // ELF's .plt section is broken up into two sections in Mach-O: StubsSection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
260 // and StubHelperSection. Calls to functions in dylibs will end up calling into
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 // StubsSection, which contains indirect jumps to addresses stored in the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 // LazyPointerSection (the counterpart to ELF's .plt.got).
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 //
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
264 // We will first describe how non-weak symbols are handled.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
265 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
266 // At program start, the LazyPointerSection contains addresses that point into
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
267 // one of the entry points in the middle of the StubHelperSection. The code in
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 // StubHelperSection will push on the stack an offset into the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 // LazyBindingSection. The push is followed by a jump to the beginning of the
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 // StubHelperSection (similar to PLT0), which then calls into dyld_stub_binder.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 // dyld_stub_binder is a non-lazily-bound symbol, so this call looks it up in
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 // the GOT.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 //
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 // The stub binder will look up the bind opcodes in the LazyBindingSection at
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
275 // the given offset. The bind opcodes will tell the binder to update the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
276 // address in the LazyPointerSection to point to the symbol, so that subsequent
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
277 // calls don't have to redo the symbol resolution. The binder will then jump to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
278 // the resolved symbol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
279 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
280 // With weak symbols, the situation is slightly different. Since there is no
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
281 // "weak lazy" lookup, function calls to weak symbols are always non-lazily
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
282 // bound. We emit both regular non-lazy bindings as well as weak bindings, in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
283 // order that the weak bindings may overwrite the non-lazy bindings if an
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
284 // appropriate symbol is found at runtime. However, the bound addresses will
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
285 // still be written (non-lazily) into the LazyPointerSection.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 class StubsSection : public SyntheticSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 StubsSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
290 uint64_t getSize() const override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 bool isNeeded() const override { return !entries.empty(); }
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
292 void finalize() override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 void writeTo(uint8_t *buf) const override;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
294 const llvm::SetVector<Symbol *> &getEntries() const { return entries; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
295 // Returns whether the symbol was added. Note that every stubs entry will
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
296 // have a corresponding entry in the LazyPointerSection.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
297 bool addEntry(Symbol *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
298 uint64_t getVA(uint32_t stubsIndex) const {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
299 // ConcatOutputSection::finalize() can seek the address of a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
300 // stub before its address is assigned. Before __stubs is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
301 // finalized, return a contrived out-of-range address.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
302 return isFinal ? addr + stubsIndex * target->stubSize
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
303 : TargetInfo::outOfRangeVA;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
304 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
306 bool isFinal = false; // is address assigned?
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 private:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
309 llvm::SetVector<Symbol *> entries;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 class StubHelperSection : public SyntheticSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 StubHelperSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
315 uint64_t getSize() const override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 bool isNeeded() const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 void setup();
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 DylibSymbol *stubBinder = nullptr;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
322 Defined *dyldPrivate = nullptr;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 // This section contains space for just a single word, and will be used by dyld
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 // to cache an address to the image loader it uses. Note that unlike the other
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 // synthetic sections, which are OutputSections, the ImageLoaderCacheSection is
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 // an InputSection that gets merged into the __data OutputSection.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 class ImageLoaderCacheSection : public InputSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 ImageLoaderCacheSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
332 uint64_t getSize() const override { return target->wordSize; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
335 // Note that this section may also be targeted by non-lazy bindings. In
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
336 // particular, this happens when branch relocations target weak symbols.
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 class LazyPointerSection : public SyntheticSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 LazyPointerSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
340 uint64_t getSize() const override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 bool isNeeded() const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
345 class LazyBindingSection : public LinkEditSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 LazyBindingSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
348 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
349 uint64_t getRawSize() const override { return contents.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
350 bool isNeeded() const override { return !entries.empty(); }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 void writeTo(uint8_t *buf) const override;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
352 // Note that every entry here will by referenced by a corresponding entry in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
353 // the StubHelperSection.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
354 void addEntry(DylibSymbol *dysym);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
355 const llvm::SetVector<DylibSymbol *> &getEntries() const { return entries; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 private:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
358 uint32_t encode(const DylibSymbol &);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
359
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
360 llvm::SetVector<DylibSymbol *> entries;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 SmallVector<char, 128> contents;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 llvm::raw_svector_ostream os{contents};
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 // Stores a trie that describes the set of exported symbols.
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
366 class ExportSection : public LinkEditSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 ExportSection();
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
369 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
370 uint64_t getRawSize() const override { return size; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
373 bool hasWeakSymbol = false;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
374
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 private:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 TrieBuilder trieBuilder;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 size_t size = 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
380 class FunctionStartsSection : public LinkEditSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
381 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
382 FunctionStartsSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
383 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
384 uint64_t getRawSize() const override { return contents.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
385 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
386
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
387 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
388 SmallVector<char, 128> contents;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
389 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
390
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 // Stores the strings referenced by the symbol table.
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
392 class StringTableSection : public LinkEditSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 StringTableSection();
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 // Returns the start offset of the added string.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 uint32_t addString(StringRef);
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
397 uint64_t getRawSize() const override { return size; }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
400 static constexpr size_t emptyStringIndex = 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
401
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 private:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
403 // ld64 emits string tables which start with a space and a zero byte. We
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
404 // match its behavior here since some tools depend on it.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
405 // Consequently, the empty string will be at index 1, not zero.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
406 std::vector<StringRef> strings{" "};
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
407 size_t size = 2;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 struct SymtabEntry {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 Symbol *sym;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 size_t strx;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
415 struct StabsEntry {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
416 uint8_t type = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
417 uint32_t strx = StringTableSection::emptyStringIndex;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
418 uint8_t sect = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
419 uint16_t desc = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
420 uint64_t value = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
421
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
422 StabsEntry() = default;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
423 explicit StabsEntry(uint8_t type) : type(type) {}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
424 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
425
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
426 // Symbols of the same type must be laid out contiguously: we choose to emit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
427 // all local symbols first, then external symbols, and finally undefined
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
428 // symbols. For each symbol type, the LC_DYSYMTAB load command will record the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
429 // range (start index and total number) of those symbols in the symbol table.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
430 class SymtabSection : public LinkEditSection {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 public:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
432 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
433 uint32_t getNumSymbols() const;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
434 uint32_t getNumLocalSymbols() const {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
435 return stabs.size() + localSymbols.size();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
436 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
437 uint32_t getNumExternalSymbols() const { return externalSymbols.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
438 uint32_t getNumUndefinedSymbols() const { return undefinedSymbols.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
439
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
440 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
441 void emitBeginSourceStab(llvm::DWARFUnit *compileUnit);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
442 void emitEndSourceStab();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
443 void emitObjectFileStab(ObjFile *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
444 void emitEndFunStab(Defined *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
445 void emitStabs();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
446
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
447 protected:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 SymtabSection(StringTableSection &);
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
449
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
450 StringTableSection &stringTableSection;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
451 // STABS symbols are always local symbols, but we represent them with special
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
452 // entries because they may use fields like n_sect and n_desc differently.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
453 std::vector<StabsEntry> stabs;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
454 std::vector<SymtabEntry> localSymbols;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
455 std::vector<SymtabEntry> externalSymbols;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
456 std::vector<SymtabEntry> undefinedSymbols;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
457 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
458
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
459 template <class LP> SymtabSection *makeSymtabSection(StringTableSection &);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
460
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
461 // The indirect symbol table is a list of 32-bit integers that serve as indices
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
462 // into the (actual) symbol table. The indirect symbol table is a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
463 // concatenation of several sub-arrays of indices, each sub-array belonging to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
464 // a separate section. The starting offset of each sub-array is stored in the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
465 // reserved1 header field of the respective section.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
466 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
467 // These sub-arrays provide symbol information for sections that store
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
468 // contiguous sequences of symbol references. These references can be pointers
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
469 // (e.g. those in the GOT and TLVP sections) or assembly sequences (e.g.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
470 // function stubs).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
471 class IndirectSymtabSection : public LinkEditSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
472 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
473 IndirectSymtabSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
474 void finalizeContents() override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
475 uint32_t getNumSymbols() const;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
476 uint64_t getRawSize() const override {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
477 return getNumSymbols() * sizeof(uint32_t);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
478 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
479 bool isNeeded() const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
480 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
481 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
482
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
483 // The code signature comes at the very end of the linked output file.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
484 class CodeSignatureSection : public LinkEditSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
485 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
486 static constexpr uint8_t blockSizeShift = 12;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
487 static constexpr size_t blockSize = (1 << blockSizeShift); // 4 KiB
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
488 static constexpr size_t hashSize = 256 / 8;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
489 static constexpr size_t blobHeadersSize = llvm::alignTo<8>(
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
490 sizeof(llvm::MachO::CS_SuperBlob) + sizeof(llvm::MachO::CS_BlobIndex));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
491 static constexpr uint32_t fixedHeadersSize =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
492 blobHeadersSize + sizeof(llvm::MachO::CS_CodeDirectory);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
493
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
494 uint32_t fileNamePad = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
495 uint32_t allHeadersSize = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
496 StringRef fileName;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
497
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
498 CodeSignatureSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
499 uint64_t getRawSize() const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
500 bool isNeeded() const override { return true; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
501 void writeTo(uint8_t *buf) const override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
502 uint32_t getBlockCount() const;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
503 void writeHashes(uint8_t *buf) const;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
504 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
505
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
506 class BitcodeBundleSection : public SyntheticSection {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
507 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
508 BitcodeBundleSection();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
509 uint64_t getSize() const override { return xarSize; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
510 void finalize() override;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 void writeTo(uint8_t *buf) const override;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 private:
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
514 llvm::SmallString<261> xarPath;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
515 uint64_t xarSize;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 struct InStruct {
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
519 MachHeaderSection *header = nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
520 RebaseSection *rebase = nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
521 BindingSection *binding = nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
522 WeakBindingSection *weakBinding = nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
523 LazyBindingSection *lazyBinding = nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
524 ExportSection *exports = nullptr;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 GotSection *got = nullptr;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
526 TlvPointerSection *tlvPointers = nullptr;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 LazyPointerSection *lazyPointers = nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 StubsSection *stubs = nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 StubHelperSection *stubHelper = nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 ImageLoaderCacheSection *imageLoaderCache = nullptr;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
531 UnwindInfoSection *unwindInfo = nullptr;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 extern InStruct in;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
535 extern std::vector<SyntheticSection *> syntheticSections;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
536
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
537 void createSyntheticSymbols();
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 } // namespace macho
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 } // namespace lld
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 #endif