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