annotate lld/MachO/InputSection.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 //===- InputSection.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_INPUT_SECTION_H
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define LLD_MACHO_INPUT_SECTION_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"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
13 #include "Relocations.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
14
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include "lld/Common/LLVM.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #include "llvm/ADT/ArrayRef.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include "llvm/BinaryFormat/MachO.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 namespace lld {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 namespace macho {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 class InputFile;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 class OutputSection;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 class InputSection {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 public:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 virtual ~InputSection() = default;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
28 virtual uint64_t getSize() const { return data.size(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
29 uint64_t getFileSize() const;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 uint64_t getFileOffset() const;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 uint64_t getVA() const;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
33 void writeTo(uint8_t *buf);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 InputFile *file = nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 StringRef name;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 StringRef segname;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 OutputSection *parent = nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 uint64_t outSecOff = 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 uint64_t outSecFileOff = 0;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 uint32_t align = 1;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 uint32_t flags = 0;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
45 uint32_t callSiteCount = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
46 bool isFinal = false; // is address assigned?
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
48 // How many symbols refer to this InputSection.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
49 uint32_t numRefs = 0;
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 // With subsections_via_symbols, most symbols have their own InputSection,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
52 // and for weak symbols (e.g. from inline functions), only the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
53 // InputSection from one translation unit will make it to the output,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
54 // while all copies in other translation units are coalesced into the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
55 // first and not copied to the output.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
56 bool wasCoalesced = false;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
57
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
58 bool isCoalescedWeak() const { return wasCoalesced && numRefs == 0; }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
59 bool shouldOmitFromOutput() const { return !live || isCoalescedWeak(); }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
60
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
61 bool live = !config->deadStrip;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 ArrayRef<uint8_t> data;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 std::vector<Reloc> relocs;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
67 inline uint8_t sectionType(uint32_t flags) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
68 return flags & llvm::MachO::SECTION_TYPE;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
69 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
71 inline bool isZeroFill(uint32_t flags) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
72 return llvm::MachO::isVirtualSection(sectionType(flags));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
73 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
75 inline bool isThreadLocalVariables(uint32_t flags) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
76 return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_VARIABLES;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
77 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
78
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
79 // These sections contain the data for initializing thread-local variables.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
80 inline bool isThreadLocalData(uint32_t flags) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
81 return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_REGULAR ||
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
82 sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_ZEROFILL;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
83 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
85 inline bool isDebugSection(uint32_t flags) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
86 return (flags & llvm::MachO::SECTION_ATTRIBUTES_USR) ==
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
87 llvm::MachO::S_ATTR_DEBUG;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
88 }
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 bool isCodeSection(const InputSection *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
91
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 extern std::vector<InputSection *> inputSections;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
94 namespace section_names {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
95
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
96 constexpr const char authGot[] = "__auth_got";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
97 constexpr const char authPtr[] = "__auth_ptr";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
98 constexpr const char binding[] = "__binding";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
99 constexpr const char bitcodeBundle[] = "__bundle";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
100 constexpr const char cfString[] = "__cfstring";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
101 constexpr const char codeSignature[] = "__code_signature";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
102 constexpr const char common[] = "__common";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
103 constexpr const char compactUnwind[] = "__compact_unwind";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
104 constexpr const char data[] = "__data";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
105 constexpr const char debugAbbrev[] = "__debug_abbrev";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
106 constexpr const char debugInfo[] = "__debug_info";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
107 constexpr const char debugStr[] = "__debug_str";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
108 constexpr const char ehFrame[] = "__eh_frame";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
109 constexpr const char export_[] = "__export";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
110 constexpr const char functionStarts[] = "__func_starts";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
111 constexpr const char got[] = "__got";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
112 constexpr const char header[] = "__mach_header";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
113 constexpr const char indirectSymbolTable[] = "__ind_sym_tab";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
114 constexpr const char const_[] = "__const";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
115 constexpr const char lazySymbolPtr[] = "__la_symbol_ptr";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
116 constexpr const char lazyBinding[] = "__lazy_binding";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
117 constexpr const char moduleInitFunc[] = "__mod_init_func";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
118 constexpr const char moduleTermFunc[] = "__mod_term_func";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
119 constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
120 constexpr const char objcCatList[] = "__objc_catlist";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
121 constexpr const char objcClassList[] = "__objc_classlist";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
122 constexpr const char objcConst[] = "__objc_const";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
123 constexpr const char objcImageInfo[] = "__objc_imageinfo";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
124 constexpr const char objcNonLazyCatList[] = "__objc_nlcatlist";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
125 constexpr const char objcNonLazyClassList[] = "__objc_nlclslist";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
126 constexpr const char objcProtoList[] = "__objc_protolist";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
127 constexpr const char pageZero[] = "__pagezero";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
128 constexpr const char pointers[] = "__pointers";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
129 constexpr const char rebase[] = "__rebase";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
130 constexpr const char staticInit[] = "__StaticInit";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
131 constexpr const char stringTable[] = "__string_table";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
132 constexpr const char stubHelper[] = "__stub_helper";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
133 constexpr const char stubs[] = "__stubs";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
134 constexpr const char swift[] = "__swift";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
135 constexpr const char symbolTable[] = "__symbol_table";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
136 constexpr const char textCoalNt[] = "__textcoal_nt";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
137 constexpr const char text[] = "__text";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
138 constexpr const char threadPtrs[] = "__thread_ptrs";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
139 constexpr const char threadVars[] = "__thread_vars";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
140 constexpr const char unwindInfo[] = "__unwind_info";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
141 constexpr const char weakBinding[] = "__weak_binding";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
142 constexpr const char zeroFill[] = "__zerofill";
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 } // namespace section_names
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
145
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 } // namespace macho
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
147
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
148 std::string toString(const macho::InputSection *);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
149
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 } // namespace lld
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 #endif