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 | |
12 | #include "Relocations.h" |
13 | |
14 | #include "lld/Common/LLVM.h" |
15 | #include "llvm/ADT/ArrayRef.h" |
16 | #include "llvm/BinaryFormat/MachO.h" |
17 | |
18 | namespace lld { |
19 | namespace macho { |
20 | |
21 | class InputFile; |
22 | class InputSection; |
23 | class OutputSection; |
24 | class Symbol; |
25 | class Defined; |
26 | |
27 | class InputSection { |
28 | public: |
29 | virtual ~InputSection() = default; |
30 | virtual uint64_t getSize() const { return data.size(); } |
31 | virtual uint64_t getFileSize() const; |
32 | uint64_t getFileOffset() const; |
33 | uint64_t getVA() const; |
34 | |
35 | virtual void writeTo(uint8_t *buf); |
36 | |
37 | InputFile *file = nullptr; |
38 | StringRef name; |
39 | StringRef segname; |
40 | |
41 | OutputSection *parent = nullptr; |
42 | uint64_t outSecOff = 0; |
43 | uint64_t outSecFileOff = 0; |
44 | |
45 | uint32_t align = 1; |
46 | uint32_t flags = 0; |
47 | |
48 | ArrayRef<uint8_t> data; |
49 | std::vector<Reloc> relocs; |
50 | }; |
51 | |
52 | inline uint8_t sectionType(uint32_t flags) { |
53 | return flags & llvm::MachO::SECTION_TYPE; |
54 | } |
55 | |
56 | inline bool isZeroFill(uint32_t flags) { |
57 | return llvm::MachO::isVirtualSection(sectionType(flags)); |
58 | } |
59 | |
60 | inline bool isThreadLocalVariables(uint32_t flags) { |
61 | return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_VARIABLES; |
62 | } |
63 | |
64 | // These sections contain the data for initializing thread-local variables. |
65 | inline bool isThreadLocalData(uint32_t flags) { |
66 | return sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_REGULAR || |
67 | sectionType(flags) == llvm::MachO::S_THREAD_LOCAL_ZEROFILL; |
68 | } |
69 | |
70 | inline bool isDebugSection(uint32_t flags) { |
71 | return (flags & llvm::MachO::SECTION_ATTRIBUTES_USR) == |
72 | llvm::MachO::S_ATTR_DEBUG; |
73 | } |
74 | |
75 | bool isCodeSection(InputSection *); |
76 | |
77 | extern std::vector<InputSection *> inputSections; |
78 | |
79 | namespace section_names { |
80 | |
81 | constexpr const char authGot[] = "__auth_got" ; |
82 | constexpr const char authPtr[] = "__auth_ptr" ; |
83 | constexpr const char binding[] = "__binding" ; |
84 | constexpr const char bitcodeBundle[] = "__bundle" ; |
85 | constexpr const char cfString[] = "__cfstring" ; |
86 | constexpr const char codeSignature[] = "__code_signature" ; |
87 | constexpr const char common[] = "__common" ; |
88 | constexpr const char compactUnwind[] = "__compact_unwind" ; |
89 | constexpr const char data[] = "__data" ; |
90 | constexpr const char debugAbbrev[] = "__debug_abbrev" ; |
91 | constexpr const char debugInfo[] = "__debug_info" ; |
92 | constexpr const char debugStr[] = "__debug_str" ; |
93 | constexpr const char ehFrame[] = "__eh_frame" ; |
94 | constexpr const char export_[] = "__export" ; |
95 | constexpr const char functionStarts[] = "__func_starts" ; |
96 | constexpr const char got[] = "__got" ; |
97 | constexpr const char [] = "__mach_header" ; |
98 | constexpr const char indirectSymbolTable[] = "__ind_sym_tab" ; |
99 | constexpr const char const_[] = "__const" ; |
100 | constexpr const char lazySymbolPtr[] = "__la_symbol_ptr" ; |
101 | constexpr const char lazyBinding[] = "__lazy_binding" ; |
102 | constexpr const char moduleInitFunc[] = "__mod_init_func" ; |
103 | constexpr const char moduleTermFunc[] = "__mod_term_func" ; |
104 | constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr" ; |
105 | constexpr const char objcCatList[] = "__objc_catlist" ; |
106 | constexpr const char objcClassList[] = "__objc_classlist" ; |
107 | constexpr const char objcConst[] = "__objc_const" ; |
108 | constexpr const char objcImageInfo[] = "__objc_imageinfo" ; |
109 | constexpr const char objcNonLazyCatList[] = "__objc_nlcatlist" ; |
110 | constexpr const char objcNonLazyClassList[] = "__objc_nlclslist" ; |
111 | constexpr const char objcProtoList[] = "__objc_protolist" ; |
112 | constexpr const char pageZero[] = "__pagezero" ; |
113 | constexpr const char pointers[] = "__pointers" ; |
114 | constexpr const char rebase[] = "__rebase" ; |
115 | constexpr const char staticInit[] = "__StaticInit" ; |
116 | constexpr const char stringTable[] = "__string_table" ; |
117 | constexpr const char stubHelper[] = "__stub_helper" ; |
118 | constexpr const char stubs[] = "__stubs" ; |
119 | constexpr const char swift[] = "__swift" ; |
120 | constexpr const char symbolTable[] = "__symbol_table" ; |
121 | constexpr const char textCoalNt[] = "__textcoal_nt" ; |
122 | constexpr const char text[] = "__text" ; |
123 | constexpr const char threadPtrs[] = "__thread_ptrs" ; |
124 | constexpr const char threadVars[] = "__thread_vars" ; |
125 | constexpr const char unwindInfo[] = "__unwind_info" ; |
126 | constexpr const char weakBinding[] = "__weak_binding" ; |
127 | constexpr const char zeroFill[] = "__zerofill" ; |
128 | |
129 | } // namespace section_names |
130 | |
131 | } // namespace macho |
132 | |
133 | std::string toString(const macho::InputSection *); |
134 | |
135 | } // namespace lld |
136 | |
137 | #endif |
138 | |