Mercurial > hg > CbC > CbC_llvm
comparison 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 |
comparison
equal
deleted
inserted
replaced
173:0572611fdcc8 | 207:2e18cbf3894f |
---|---|
7 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
8 | 8 |
9 #ifndef LLD_MACHO_INPUT_SECTION_H | 9 #ifndef LLD_MACHO_INPUT_SECTION_H |
10 #define LLD_MACHO_INPUT_SECTION_H | 10 #define LLD_MACHO_INPUT_SECTION_H |
11 | 11 |
12 #include "Config.h" | |
13 #include "Relocations.h" | |
14 | |
12 #include "lld/Common/LLVM.h" | 15 #include "lld/Common/LLVM.h" |
13 #include "llvm/ADT/ArrayRef.h" | 16 #include "llvm/ADT/ArrayRef.h" |
14 #include "llvm/ADT/PointerUnion.h" | |
15 #include "llvm/BinaryFormat/MachO.h" | 17 #include "llvm/BinaryFormat/MachO.h" |
16 | 18 |
17 namespace lld { | 19 namespace lld { |
18 namespace macho { | 20 namespace macho { |
19 | 21 |
20 class InputFile; | 22 class InputFile; |
21 class InputSection; | |
22 class OutputSection; | 23 class OutputSection; |
23 class Symbol; | |
24 | |
25 struct Reloc { | |
26 uint8_t type; | |
27 bool pcrel; | |
28 // The offset from the start of the subsection that this relocation belongs | |
29 // to. | |
30 uint32_t offset; | |
31 // Adding this offset to the address of the target symbol or subsection gives | |
32 // the destination that this relocation refers to. | |
33 uint64_t addend; | |
34 llvm::PointerUnion<Symbol *, InputSection *> target; | |
35 }; | |
36 | 24 |
37 class InputSection { | 25 class InputSection { |
38 public: | 26 public: |
39 virtual ~InputSection() = default; | 27 virtual ~InputSection() = default; |
40 virtual size_t getSize() const { return data.size(); } | 28 virtual uint64_t getSize() const { return data.size(); } |
41 virtual uint64_t getFileSize() const { return getSize(); } | 29 uint64_t getFileSize() const; |
42 uint64_t getFileOffset() const; | 30 uint64_t getFileOffset() const; |
43 uint64_t getVA() const; | 31 uint64_t getVA() const; |
44 | 32 |
45 virtual void writeTo(uint8_t *buf); | 33 void writeTo(uint8_t *buf); |
46 | 34 |
47 InputFile *file = nullptr; | 35 InputFile *file = nullptr; |
48 StringRef name; | 36 StringRef name; |
49 StringRef segname; | 37 StringRef segname; |
50 | 38 |
52 uint64_t outSecOff = 0; | 40 uint64_t outSecOff = 0; |
53 uint64_t outSecFileOff = 0; | 41 uint64_t outSecFileOff = 0; |
54 | 42 |
55 uint32_t align = 1; | 43 uint32_t align = 1; |
56 uint32_t flags = 0; | 44 uint32_t flags = 0; |
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; | |
57 | 62 |
58 ArrayRef<uint8_t> data; | 63 ArrayRef<uint8_t> data; |
59 std::vector<Reloc> relocs; | 64 std::vector<Reloc> relocs; |
60 }; | 65 }; |
61 | 66 |
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 | |
62 extern std::vector<InputSection *> inputSections; | 92 extern std::vector<InputSection *> inputSections; |
63 | 93 |
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 | |
64 } // namespace macho | 146 } // namespace macho |
147 | |
148 std::string toString(const macho::InputSection *); | |
149 | |
65 } // namespace lld | 150 } // namespace lld |
66 | 151 |
67 #endif | 152 #endif |