LLVM: lib/MC/MCSectionMachO.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
13
14namespace llvm {
19}
20
21using namespace llvm;
22
23
24
25
26static constexpr struct {
40 StringLiteral("S_NON_LAZY_SYMBOL_POINTERS")},
45 StringLiteral("S_MOD_INIT_FUNC_POINTERS")},
47 StringLiteral("S_MOD_TERM_FUNC_POINTERS")},
55 StringLiteral("S_LAZY_DYLIB_SYMBOL_POINTERS")},
59 StringLiteral("S_THREAD_LOCAL_ZEROFILL")},
61 StringLiteral("S_THREAD_LOCAL_VARIABLES")},
63 StringLiteral("S_THREAD_LOCAL_VARIABLE_POINTERS")},
64 {StringLiteral("thread_local_init_function_pointers"),
65 StringLiteral("S_THREAD_LOCAL_INIT_FUNCTION_POINTERS")},
69
70
71
72
73static constexpr struct {
77#define ENTRY(ASMNAME, ENUM) \
78 { MachO::ENUM, StringLiteral(ASMNAME), StringLiteral(#ENUM) },
89#undef ENTRY
90 { 0, StringLiteral("none"), StringLiteral("") },
92
94 unsigned TAA, unsigned reserved2, SectionKind K,
98 TypeAndAttributes(TAA), Reserved2(reserved2) {
100 "Segment or section string too long");
101 for (unsigned i = 0; i != 16; ++i) {
102 if (i < Segment.size())
103 SegmentName[i] = Segment[i];
104 else
105 SegmentName[i] = 0;
106 }
107}
108
112 auto &Sec = static_cast<const MCSectionMachO &>(Section);
113 OS << "\t.section\t" << Sec.getSegmentName() << ',' << Sec.getName();
114
115
116 unsigned TAA = Sec.getTypeAndAttributes();
117 if (TAA == 0) {
118 OS << '\n';
119 return;
120 }
121
124 "Invalid SectionType specified!");
125
127 OS << ',';
129 } else {
130
131 OS << '\n';
132 return;
133 }
134
135
137 if (SectionAttrs == 0) {
138
139
140 if (Sec.Reserved2 != 0)
141 OS << ",none," << Sec.Reserved2;
142 OS << '\n';
143 return;
144 }
145
146
147 char Separator = ',';
148 for (unsigned i = 0;
150 ++i) {
151
153 continue;
154
155
157
158 OS << Separator;
161 else
163 Separator = '+';
164 }
165
166 assert(SectionAttrs == 0 && "Unknown section attributes!");
167
168
169 if (Sec.Reserved2 != 0)
170 OS << ',' << Sec.Reserved2;
171 OS << '\n';
172}
173
174
175
176
177
178
182 unsigned &TAA,
183 bool &TAAParsed,
184 unsigned &StubSize) {
185 TAAParsed = false;
186
188 Spec.split(SplitSpec, ',');
189
190 auto GetEmptyOrTrim = [&SplitSpec](size_t Idx) -> StringRef {
191 return SplitSpec.size() > Idx ? SplitSpec[Idx].trim() : StringRef();
192 };
193 Segment = GetEmptyOrTrim(0);
194 Section = GetEmptyOrTrim(1);
195 StringRef SectionType = GetEmptyOrTrim(2);
196 StringRef Attrs = GetEmptyOrTrim(3);
197 StringRef StubSizeStr = GetEmptyOrTrim(4);
198
199
200 if (Section.empty())
202 "mach-o section specifier requires a segment "
203 "and section separated by a comma");
204
205
206 if (Section.size() > 16)
208 "mach-o section specifier requires a section "
209 "whose length is between 1 and 16 characters");
210
211
212 TAA = 0;
213 StubSize = 0;
214 if (SectionType.empty())
216
217
218 auto TypeDescriptor =
221 return SectionType == Descriptor.AssemblerName;
222 });
223
224
227 "mach-o section specifier uses an unknown "
228 "section type");
229
230
232 TAAParsed = true;
233
234
235 if (Attrs.empty()) {
236
239 "mach-o section specifier of type "
240 "'symbol_stubs' requires a size specifier");
242 }
243
244
246 Attrs.split(SectionAttrs, '+', -1, false);
247
248 for (StringRef &SectionAttr : SectionAttrs) {
249 auto AttrDescriptorI =
252 return SectionAttr.trim() == Descriptor.AssemblerName;
253 });
256 "mach-o section specifier has invalid "
257 "attribute");
258
259 TAA |= AttrDescriptorI->AttrFlag;
260 }
261
262
263 if (StubSizeStr.empty()) {
264
267 "mach-o section specifier of type "
268 "'symbol_stubs' requires a size specifier");
270 }
271
272
275 "mach-o section specifier cannot have a stub "
276 "size specified because it does not have type "
277 "'symbol_stubs'");
278
279
282 "mach-o section specifier has a malformed "
283 "stub size");
284
286}
287
290 if (L->Tail)
291 Atoms.resize(L->Tail->getLayoutOrder() + 1);
292}
293
295 return I < Atoms.size() ? Atoms[I] : nullptr;
296}
297
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned AttrFlag
Definition MCSectionMachO.cpp:74
static constexpr struct @232230120306032273124110341046323001201340257043 SectionTypeDescriptors[MachO::LAST_KNOWN_SECTION_TYPE+1]
SectionTypeDescriptors - These are strings that describe the various section types.
static constexpr struct @127225366024301302345121024312200357337344112313 SectionAttrDescriptors[]
SectionAttrDescriptors - This is an array of descriptors for section attributes.
#define ENTRY(ASMNAME, ENUM)
StringLiteral EnumName
Definition MCSectionMachO.cpp:27
StringLiteral AssemblerName
Definition MCSectionMachO.cpp:27
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
void printSwitchToSection(const MCSection &, uint32_t, const Triple &, raw_ostream &) const final
Definition MCSectionMachO.cpp:109
This class is intended to be used as a base class for asm properties and features specific to the tar...
Base class for the full range of assembler expressions which are needed for parsing.
This represents a section on a Mach-O system (used by Mac OS X).
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
Definition MCSectionMachO.cpp:179
void setAtom(size_t I, const MCSymbol *Sym)
Definition MCSectionMachO.cpp:298
const MCSymbol * getAtom(size_t I) const
Definition MCSectionMachO.cpp:294
void allocAtoms()
Definition MCSectionMachO.cpp:288
Instances of this class represent a uniqued identifier for a section in the current translation unit.
FragList * curFragList() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
SectionKind - This is a simple POD value that classifies the properties of a section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
Triple - Helper class for working with autoconf configuration names.
This class implements an extremely fast bulk output stream that can only output to a stream.
bool isVirtualSection(uint8_t type)
SectionType
These are the section type and attributes fields.
@ LAST_KNOWN_SECTION_TYPE
@ S_SYMBOL_STUBS
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
@ S_ATTR_SOME_INSTRUCTIONS
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
@ S_ATTR_EXT_RELOC
S_ATTR_EXT_RELOC - Section has external relocation entries.
@ S_ATTR_DEBUG
S_ATTR_DEBUG - A debug section.
@ S_ATTR_NO_DEAD_STRIP
S_ATTR_NO_DEAD_STRIP - No dead stripping.
@ S_ATTR_LOC_RELOC
S_ATTR_LOC_RELOC - Section has local relocation entries.
@ S_ATTR_NO_TOC
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents.
@ S_ATTR_LIVE_SUPPORT
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
@ S_ATTR_SELF_MODIFYING_CODE
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
@ S_ATTR_STRIP_STATIC_SYMS
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.