LLVM 24.0.0git
DarwinAsmParser.cpp
Go to the documentation of this file.
1//===- DarwinAsmParser.cpp - Darwin (Mach-O) Assembly Parser --------------===//
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
10#include "llvm/ADT/StringRef.h"
12#include "llvm/ADT/Twine.h"
14#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCStreamer.h"
21#include "llvm/MC/MCSymbol.h"
22#include "llvm/MC/SectionKind.h"
23#include "llvm/Support/Error.h"
26#include "llvm/Support/SMLoc.h"
30#include <cstddef>
31#include <cstdint>
32#include <string>
33#include <system_error>
34#include <utility>
35
36using namespace llvm;
37
38namespace {
39
40/// Implementation of directive handling which is shared across all
41/// Darwin targets.
42class DarwinAsmParser : public MCAsmParserExtension {
43 template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
44 void addDirectiveHandler(StringRef Directive) {
45 MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
46 this, HandleDirective<DarwinAsmParser, HandlerMethod>);
47 getParser().addDirectiveHandler(Directive, Handler);
48 }
49
50 bool parseSectionSwitch(StringRef Segment, StringRef Section,
51 unsigned TAA = 0, unsigned ImplicitAlign = 0,
52 unsigned StubSize = 0);
53
54 SMLoc LastVersionDirective;
55
56public:
57 DarwinAsmParser() = default;
58
59 void Initialize(MCAsmParser &Parser) override {
60 // Call the base implementation.
62
63 addDirectiveHandler<&DarwinAsmParser::parseDirectiveAltEntry>(".alt_entry");
64 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(".desc");
65 addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>(
66 ".indirect_symbol");
67 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(".lsym");
68 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>(
69 ".subsections_via_symbols");
70 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".dump");
71 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".load");
72 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(".section");
73 addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>(
74 ".pushsection");
75 addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>(
76 ".popsection");
77 addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(".previous");
78 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>(
79 ".secure_log_unique");
80 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>(
81 ".secure_log_reset");
82 addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(".tbss");
83 addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(".zerofill");
84
85 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>(
86 ".data_region");
87 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>(
88 ".end_data_region");
89
90 // Special section directives.
91 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(".bss");
92 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(".const");
93 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>(
94 ".const_data");
95 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>(
96 ".constructor");
97 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>(
98 ".cstring");
99 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(".data");
100 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>(
101 ".destructor");
102 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(".dyld");
103 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>(
104 ".fvmlib_init0");
105 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>(
106 ".fvmlib_init1");
107 addDirectiveHandler<
108 &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>(
109 ".lazy_symbol_pointer");
110 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>(
111 ".linker_option");
112 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>(
113 ".literal16");
114 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>(
115 ".literal4");
116 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>(
117 ".literal8");
118 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>(
119 ".mod_init_func");
120 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>(
121 ".mod_term_func");
122 addDirectiveHandler<
123 &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>(
124 ".non_lazy_symbol_pointer");
125 addDirectiveHandler<
126 &DarwinAsmParser::parseSectionDirectiveThreadLocalVariablePointers>(
127 ".thread_local_variable_pointer");
128 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>(
129 ".objc_cat_cls_meth");
130 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>(
131 ".objc_cat_inst_meth");
132 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>(
133 ".objc_category");
134 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>(
135 ".objc_class");
136 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>(
137 ".objc_class_names");
138 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>(
139 ".objc_class_vars");
140 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>(
141 ".objc_cls_meth");
142 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>(
143 ".objc_cls_refs");
144 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>(
145 ".objc_inst_meth");
146 addDirectiveHandler<
147 &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>(
148 ".objc_instance_vars");
149 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>(
150 ".objc_message_refs");
151 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>(
152 ".objc_meta_class");
153 addDirectiveHandler<
154 &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>(
155 ".objc_meth_var_names");
156 addDirectiveHandler<
157 &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>(
158 ".objc_meth_var_types");
159 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>(
160 ".objc_module_info");
161 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>(
162 ".objc_protocol");
163 addDirectiveHandler<
164 &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>(
165 ".objc_selector_strs");
166 addDirectiveHandler<
167 &DarwinAsmParser::parseSectionDirectiveObjCStringObject>(
168 ".objc_string_object");
169 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>(
170 ".objc_symbols");
171 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>(
172 ".picsymbol_stub");
173 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>(
174 ".static_const");
175 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>(
176 ".static_data");
177 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>(
178 ".symbol_stub");
179 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(".tdata");
180 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(".text");
181 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>(
182 ".thread_init_func");
183 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv");
184
185 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident");
186 addDirectiveHandler<&DarwinAsmParser::parseWatchOSVersionMin>(
187 ".watchos_version_min");
188 addDirectiveHandler<&DarwinAsmParser::parseTvOSVersionMin>(
189 ".tvos_version_min");
190 addDirectiveHandler<&DarwinAsmParser::parseIOSVersionMin>(
191 ".ios_version_min");
192 addDirectiveHandler<&DarwinAsmParser::parseMacOSXVersionMin>(
193 ".macosx_version_min");
194 addDirectiveHandler<&DarwinAsmParser::parseBuildVersion>(".build_version");
195 addDirectiveHandler<&DarwinAsmParser::parseTargetTripleDirective>(
196 ".target_triple");
197 addDirectiveHandler<&DarwinAsmParser::parseDirectiveCGProfile>(
198 ".cg_profile");
199
200 LastVersionDirective = SMLoc();
201 }
202
203 bool parseDirectiveAltEntry(StringRef, SMLoc);
204 bool parseDirectiveDesc(StringRef, SMLoc);
205 bool parseDirectiveIndirectSymbol(StringRef, SMLoc);
206 bool parseDirectiveDumpOrLoad(StringRef, SMLoc);
207 bool parseDirectiveLsym(StringRef, SMLoc);
208 bool parseDirectiveLinkerOption(StringRef, SMLoc);
209 bool parseDirectiveSection(StringRef, SMLoc);
210 bool parseDirectivePushSection(StringRef, SMLoc);
211 bool parseDirectivePopSection(StringRef, SMLoc);
212 bool parseDirectivePrevious(StringRef, SMLoc);
213 bool parseDirectiveSecureLogReset(StringRef, SMLoc);
214 bool parseDirectiveSecureLogUnique(StringRef, SMLoc);
215 bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
216 bool parseDirectiveTBSS(StringRef, SMLoc);
217 bool parseDirectiveZerofill(StringRef, SMLoc);
218 bool parseDirectiveDataRegion(StringRef, SMLoc);
219 bool parseDirectiveDataRegionEnd(StringRef, SMLoc);
220
221 // Named Section Directive
222 bool parseSectionDirectiveBss(StringRef, SMLoc) {
223 return parseSectionSwitch("__DATA", "__bss");
224 }
225
226 bool parseSectionDirectiveConst(StringRef, SMLoc) {
227 return parseSectionSwitch("__TEXT", "__const");
228 }
229
230 bool parseSectionDirectiveStaticConst(StringRef, SMLoc) {
231 return parseSectionSwitch("__TEXT", "__static_const");
232 }
233
234 bool parseSectionDirectiveCString(StringRef, SMLoc) {
235 return parseSectionSwitch("__TEXT","__cstring",
237 }
238
239 bool parseSectionDirectiveLiteral4(StringRef, SMLoc) {
240 return parseSectionSwitch("__TEXT", "__literal4",
242 }
243
244 bool parseSectionDirectiveLiteral8(StringRef, SMLoc) {
245 return parseSectionSwitch("__TEXT", "__literal8",
247 }
248
249 bool parseSectionDirectiveLiteral16(StringRef, SMLoc) {
250 return parseSectionSwitch("__TEXT","__literal16",
252 }
253
254 bool parseSectionDirectiveConstructor(StringRef, SMLoc) {
255 return parseSectionSwitch("__TEXT","__constructor");
256 }
257
258 bool parseSectionDirectiveDestructor(StringRef, SMLoc) {
259 return parseSectionSwitch("__TEXT","__destructor");
260 }
261
262 bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) {
263 return parseSectionSwitch("__TEXT","__fvmlib_init0");
264 }
265
266 bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) {
267 return parseSectionSwitch("__TEXT","__fvmlib_init1");
268 }
269
270 bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
271 return parseSectionSwitch("__TEXT","__symbol_stub",
274 // FIXME: Different on PPC and ARM.
275 0, 16);
276 }
277
278 bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
279 return parseSectionSwitch("__TEXT","__picsymbol_stub",
282 }
283
284 bool parseSectionDirectiveData(StringRef, SMLoc) {
285 return parseSectionSwitch("__DATA", "__data");
286 }
287
288 bool parseSectionDirectiveStaticData(StringRef, SMLoc) {
289 return parseSectionSwitch("__DATA", "__static_data");
290 }
291
292 bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) {
293 return parseSectionSwitch("__DATA", "__nl_symbol_ptr",
295 }
296
297 bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) {
298 return parseSectionSwitch("__DATA", "__la_symbol_ptr",
300 }
301
302 bool parseSectionDirectiveThreadLocalVariablePointers(StringRef, SMLoc) {
303 return parseSectionSwitch("__DATA", "__thread_ptr",
305 }
306
307 bool parseSectionDirectiveDyld(StringRef, SMLoc) {
308 return parseSectionSwitch("__DATA", "__dyld");
309 }
310
311 bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) {
312 return parseSectionSwitch("__DATA", "__mod_init_func",
314 }
315
316 bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) {
317 return parseSectionSwitch("__DATA", "__mod_term_func",
319 }
320
321 bool parseSectionDirectiveConstData(StringRef, SMLoc) {
322 return parseSectionSwitch("__DATA", "__const");
323 }
324
325 bool parseSectionDirectiveObjCClass(StringRef, SMLoc) {
326 return parseSectionSwitch("__OBJC", "__class",
328 }
329
330 bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) {
331 return parseSectionSwitch("__OBJC", "__meta_class",
333 }
334
335 bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) {
336 return parseSectionSwitch("__OBJC", "__cat_cls_meth",
338 }
339
340 bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) {
341 return parseSectionSwitch("__OBJC", "__cat_inst_meth",
343 }
344
345 bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) {
346 return parseSectionSwitch("__OBJC", "__protocol",
348 }
349
350 bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) {
351 return parseSectionSwitch("__OBJC", "__string_object",
353 }
354
355 bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) {
356 return parseSectionSwitch("__OBJC", "__cls_meth",
358 }
359
360 bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) {
361 return parseSectionSwitch("__OBJC", "__inst_meth",
363 }
364
365 bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
366 return parseSectionSwitch("__OBJC", "__cls_refs",
369 }
370
371 bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
372 return parseSectionSwitch("__OBJC", "__message_refs",
375 }
376
377 bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
378 return parseSectionSwitch("__OBJC", "__symbols",
380 }
381
382 bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) {
383 return parseSectionSwitch("__OBJC", "__category",
385 }
386
387 bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) {
388 return parseSectionSwitch("__OBJC", "__class_vars",
390 }
391
392 bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) {
393 return parseSectionSwitch("__OBJC", "__instance_vars",
395 }
396
397 bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) {
398 return parseSectionSwitch("__OBJC", "__module_info",
400 }
401
402 bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) {
403 return parseSectionSwitch("__TEXT", "__cstring",
405 }
406
407 bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) {
408 return parseSectionSwitch("__TEXT", "__cstring",
410 }
411
412 bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) {
413 return parseSectionSwitch("__TEXT", "__cstring",
415 }
416
417 bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) {
418 return parseSectionSwitch("__OBJC", "__selector_strs",
420 }
421
422 bool parseSectionDirectiveTData(StringRef, SMLoc) {
423 return parseSectionSwitch("__DATA", "__thread_data",
425 }
426
427 bool parseSectionDirectiveText(StringRef, SMLoc) {
428 return parseSectionSwitch("__TEXT", "__text",
430 }
431
432 bool parseSectionDirectiveTLV(StringRef, SMLoc) {
433 return parseSectionSwitch("__DATA", "__thread_vars",
435 }
436
437 bool parseSectionDirectiveIdent(StringRef, SMLoc) {
438 // Darwin silently ignores the .ident directive.
439 getParser().eatToEndOfStatement();
440 return false;
441 }
442
443 bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
444 return parseSectionSwitch("__DATA", "__thread_init",
446 }
447
448 bool parseWatchOSVersionMin(StringRef Directive, SMLoc Loc) {
449 return parseVersionMin(Directive, Loc, MCVM_WatchOSVersionMin);
450 }
451 bool parseTvOSVersionMin(StringRef Directive, SMLoc Loc) {
452 return parseVersionMin(Directive, Loc, MCVM_TvOSVersionMin);
453 }
454 bool parseIOSVersionMin(StringRef Directive, SMLoc Loc) {
455 return parseVersionMin(Directive, Loc, MCVM_IOSVersionMin);
456 }
457 bool parseMacOSXVersionMin(StringRef Directive, SMLoc Loc) {
458 return parseVersionMin(Directive, Loc, MCVM_OSXVersionMin);
459 }
460
461 bool parseBuildVersion(StringRef Directive, SMLoc Loc);
462 bool parseTargetTripleDirective(StringRef Directive, SMLoc Loc);
463 bool parseVersionMin(StringRef Directive, SMLoc Loc, MCVersionMinType Type);
464 bool parseMajorMinorVersionComponent(unsigned *Major, unsigned *Minor,
465 const char *VersionName);
466 bool parseOptionalTrailingVersionComponent(unsigned *Component,
467 const char *ComponentName);
468 bool parseVersion(unsigned *Major, unsigned *Minor, unsigned *Update);
469 bool parseSDKVersion(VersionTuple &SDKVersion);
470 void checkVersion(StringRef Directive, StringRef Arg, SMLoc Loc,
471 Triple::OSType ExpectedOS);
472 bool parseDirectiveCGProfile(StringRef Directive, SMLoc Loc);
473};
474
475} // end anonymous namespace
476
477bool DarwinAsmParser::parseSectionSwitch(StringRef Segment, StringRef Section,
478 unsigned TAA, unsigned Alignment,
479 unsigned StubSize) {
480 if (getLexer().isNot(AsmToken::EndOfStatement))
481 return TokError("unexpected token in section switching directive");
482 Lex();
483
484 // FIXME: Arch specific.
485 bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS;
486 getStreamer().switchSection(getContext().getMachOSection(
487 Segment, Section, TAA, StubSize,
489
490 // Set the implicit alignment, if any.
491 //
492 // FIXME: This isn't really what 'as' does; I think it just uses the implicit
493 // alignment on the section (e.g., if one manually inserts bytes into the
494 // section, then just issuing the section switch directive will not realign
495 // the section. However, this is arguably more reasonable behavior, and there
496 // is no good reason for someone to intentionally emit incorrectly sized
497 // values into the implicitly aligned sections.
498 if (Alignment)
499 getStreamer().emitValueToAlignment(Align(Alignment));
500
501 return false;
502}
503
504/// parseDirectiveAltEntry
505/// ::= .alt_entry identifier
506bool DarwinAsmParser::parseDirectiveAltEntry(StringRef, SMLoc) {
507 MCSymbol *Sym;
508 if (getParser().parseSymbol(Sym))
509 return TokError("expected identifier in directive");
510
511 if (Sym->isDefined())
512 return TokError(".alt_entry must preceed symbol definition");
513
514 if (!getStreamer().emitSymbolAttribute(Sym, MCSA_AltEntry))
515 return TokError("unable to emit symbol attribute");
516
517 Lex();
518 return false;
519}
520
521/// parseDirectiveDesc
522/// ::= .desc identifier , expression
523bool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) {
524 MCSymbol *Sym;
525 if (getParser().parseSymbol(Sym))
526 return TokError("expected identifier in directive");
527
528 if (getLexer().isNot(AsmToken::Comma))
529 return TokError("unexpected token in '.desc' directive");
530 Lex();
531
532 int64_t DescValue;
533 if (getParser().parseAbsoluteExpression(DescValue))
534 return true;
535
536 if (getLexer().isNot(AsmToken::EndOfStatement))
537 return TokError("unexpected token in '.desc' directive");
538
539 Lex();
540
541 // Set the n_desc field of this Symbol to this DescValue
542 getStreamer().emitSymbolDesc(Sym, DescValue);
543
544 return false;
545}
546
547/// parseDirectiveIndirectSymbol
548/// ::= .indirect_symbol identifier
549bool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) {
550 const MCSectionMachO *Current = static_cast<const MCSectionMachO *>(
551 getStreamer().getCurrentSectionOnly());
553 if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
554 SectionType != MachO::S_LAZY_SYMBOL_POINTERS &&
556 SectionType != MachO::S_SYMBOL_STUBS)
557 return Error(Loc, "indirect symbol not in a symbol pointer or stub "
558 "section");
559
560 MCSymbol *Sym;
561 if (getParser().parseSymbol(Sym))
562 return TokError("expected identifier in .indirect_symbol directive");
563
564 // Assembler local symbols don't make any sense here. Complain loudly.
565 if (Sym->isTemporary())
566 return TokError("non-local symbol required in directive");
567
568 if (!getStreamer().emitSymbolAttribute(Sym, MCSA_IndirectSymbol))
569 return TokError("unable to emit indirect symbol attribute for: " +
570 Sym->getName());
571
572 if (getLexer().isNot(AsmToken::EndOfStatement))
573 return TokError("unexpected token in '.indirect_symbol' directive");
574
575 Lex();
576
577 return false;
578}
579
580/// parseDirectiveDumpOrLoad
581/// ::= ( .dump | .load ) "filename"
582bool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive,
583 SMLoc IDLoc) {
584 bool IsDump = Directive == ".dump";
585 if (getLexer().isNot(AsmToken::String))
586 return TokError("expected string in '.dump' or '.load' directive");
587
588 Lex();
589
590 if (getLexer().isNot(AsmToken::EndOfStatement))
591 return TokError("unexpected token in '.dump' or '.load' directive");
592
593 Lex();
594
595 // FIXME: If/when .dump and .load are implemented they will be done in the
596 // the assembly parser and not have any need for an MCStreamer API.
597 if (IsDump)
598 return Warning(IDLoc, "ignoring directive .dump for now");
599 else
600 return Warning(IDLoc, "ignoring directive .load for now");
601}
602
603/// ParseDirectiveLinkerOption
604/// ::= .linker_option "string" ( , "string" )*
605bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
606 SmallVector<std::string, 4> Args;
607 while (true) {
608 if (getLexer().isNot(AsmToken::String))
609 return TokError("expected string in '" + Twine(IDVal) + "' directive");
610
611 std::string Data;
612 if (getParser().parseEscapedString(Data))
613 return true;
614
615 Args.push_back(Data);
616
617 if (getLexer().is(AsmToken::EndOfStatement))
618 break;
619
620 if (getLexer().isNot(AsmToken::Comma))
621 return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
622 Lex();
623 }
624
625 getStreamer().emitLinkerOptions(Args);
626 return false;
627}
628
629/// parseDirectiveLsym
630/// ::= .lsym identifier , expression
631bool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) {
632 MCSymbol *Sym;
633 if (getParser().parseSymbol(Sym))
634 return TokError("expected identifier in directive");
635
636 if (getLexer().isNot(AsmToken::Comma))
637 return TokError("unexpected token in '.lsym' directive");
638 Lex();
639
640 const MCExpr *Value;
641 if (getParser().parseExpression(Value))
642 return true;
643
644 if (getLexer().isNot(AsmToken::EndOfStatement))
645 return TokError("unexpected token in '.lsym' directive");
646
647 Lex();
648
649 // We don't currently support this directive.
650 //
651 // FIXME: Diagnostic location!
652 (void) Sym;
653 return TokError("directive '.lsym' is unsupported");
654}
655
656/// parseDirectiveSection:
657/// ::= .section identifier (',' identifier)*
658bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
659 SMLoc Loc = getLexer().getLoc();
660
661 StringRef SectionName;
662 if (getParser().parseIdentifier(SectionName))
663 return Error(Loc, "expected identifier after '.section' directive");
664
665 // Verify there is a following comma.
666 if (!getLexer().is(AsmToken::Comma))
667 return TokError("unexpected token in '.section' directive");
668
669 std::string SectionSpec = std::string(SectionName);
670 SectionSpec += ",";
671
672 // Add all the tokens until the end of the line, ParseSectionSpecifier will
673 // handle this.
674 StringRef EOL = getLexer().LexUntilEndOfStatement();
675 SectionSpec.append(EOL.begin(), EOL.end());
676
677 Lex();
678 if (getLexer().isNot(AsmToken::EndOfStatement))
679 return TokError("unexpected token in '.section' directive");
680 Lex();
681
682 StringRef Segment, Section;
683 unsigned StubSize;
684 unsigned TAA;
685 bool TAAParsed;
687 SectionSpec, Segment, Section, TAA, TAAParsed, StubSize))
688 return Error(Loc, toString(std::move(E)));
689
690 // Issue a warning if the target is not powerpc and Section is a *coal* section.
691 Triple TT = getParser().getContext().getTargetTriple();
692 Triple::ArchType ArchTy = TT.getArch();
693
694 if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
695 StringRef NonCoalSection = StringSwitch<StringRef>(Section)
696 .Case("__textcoal_nt", "__text")
697 .Case("__const_coal", "__const")
698 .Case("__datacoal_nt", "__data")
699 .Default(Section);
700
701 if (Section != NonCoalSection) {
702 StringRef SectionVal(Loc.getPointer());
703 size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
704 SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
705 SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
706 getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
707 SMRange(BLoc, ELoc));
708 getParser().Note(Loc, "change section name to \"" + NonCoalSection +
709 "\"", SMRange(BLoc, ELoc));
710 }
711 }
712
713 // FIXME: Arch specific.
714 bool isText = Segment == "__TEXT"; // FIXME: Hack.
715 getStreamer().switchSection(getContext().getMachOSection(
716 Segment, Section, TAA, StubSize,
718 return false;
719}
720
721/// ParseDirectivePushSection:
722/// ::= .pushsection identifier (',' identifier)*
723bool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) {
724 getStreamer().pushSection();
725
726 if (parseDirectiveSection(S, Loc)) {
727 getStreamer().popSection();
728 return true;
729 }
730
731 return false;
732}
733
734/// ParseDirectivePopSection:
735/// ::= .popsection
736bool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
737 if (!getStreamer().popSection())
738 return TokError(".popsection without corresponding .pushsection");
739 return false;
740}
741
742/// ParseDirectivePrevious:
743/// ::= .previous
744bool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) {
745 MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
746 if (!PreviousSection.first)
747 return TokError(".previous without corresponding .section");
748 getStreamer().switchSection(PreviousSection.first, PreviousSection.second);
749 return false;
750}
751
752/// ParseDirectiveSecureLogUnique
753/// ::= .secure_log_unique ... message ...
754bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
755 StringRef LogMessage = getParser().parseStringToEndOfStatement();
756 if (getLexer().isNot(AsmToken::EndOfStatement))
757 return TokError("unexpected token in '.secure_log_unique' directive");
758
759 if (getContext().getSecureLogUsed())
760 return Error(IDLoc, ".secure_log_unique specified multiple times");
761
762 // Get the secure log path.
763 StringRef SecureLogFile = getContext().getSecureLogFile();
764 if (SecureLogFile.empty())
765 return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE "
766 "environment variable unset.");
767
768 // Open the secure log file if we haven't already.
769 raw_fd_ostream *OS = getContext().getSecureLog();
770 if (!OS) {
771 std::error_code EC;
772 auto NewOS = std::make_unique<raw_fd_ostream>(
773 SecureLogFile, EC, sys::fs::OF_Append | sys::fs::OF_TextWithCRLF);
774 if (EC)
775 return Error(IDLoc, Twine("can't open secure log file: ") +
776 SecureLogFile + " (" + EC.message() + ")");
777 OS = NewOS.get();
778 getContext().setSecureLog(std::move(NewOS));
779 }
780
781 // Write the message.
782 unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
783 *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
784 << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":"
785 << LogMessage + "\n";
786
787 getContext().setSecureLogUsed(true);
788
789 return false;
790}
791
792/// ParseDirectiveSecureLogReset
793/// ::= .secure_log_reset
794bool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
795 if (getLexer().isNot(AsmToken::EndOfStatement))
796 return TokError("unexpected token in '.secure_log_reset' directive");
797
798 Lex();
799
800 getContext().setSecureLogUsed(false);
801
802 return false;
803}
804
805/// parseDirectiveSubsectionsViaSymbols
806/// ::= .subsections_via_symbols
807bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
808 if (getLexer().isNot(AsmToken::EndOfStatement))
809 return TokError("unexpected token in '.subsections_via_symbols' directive");
810
811 Lex();
812
813 getStreamer().emitSubsectionsViaSymbols();
814
815 return false;
816}
817
818/// ParseDirectiveTBSS
819/// ::= .tbss identifier, size, align
820bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) {
821 SMLoc IDLoc = getLexer().getLoc();
822 MCSymbol *Sym;
823 if (getParser().parseSymbol(Sym))
824 return TokError("expected identifier in directive");
825
826 if (getLexer().isNot(AsmToken::Comma))
827 return TokError("unexpected token in directive");
828 Lex();
829
830 int64_t Size;
831 SMLoc SizeLoc = getLexer().getLoc();
832 if (getParser().parseAbsoluteExpression(Size))
833 return true;
834
835 int64_t Pow2Alignment = 0;
836 SMLoc Pow2AlignmentLoc;
837 if (getLexer().is(AsmToken::Comma)) {
838 Lex();
839 Pow2AlignmentLoc = getLexer().getLoc();
840 if (getParser().parseAbsoluteExpression(Pow2Alignment))
841 return true;
842 }
843
844 if (getLexer().isNot(AsmToken::EndOfStatement))
845 return TokError("unexpected token in '.tbss' directive");
846
847 Lex();
848
849 if (Size < 0)
850 return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than"
851 "zero");
852
853 // FIXME: Diagnose overflow.
854 if (Pow2Alignment < 0)
855 return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less"
856 "than zero");
857
858 if (!Sym->isUndefined())
859 return Error(IDLoc, "invalid symbol redefinition");
860
861 getStreamer().emitTBSSSymbol(
862 getContext().getMachOSection("__DATA", "__thread_bss",
865 Sym, Size, Align(1ULL << Pow2Alignment));
866
867 return false;
868}
869
870/// ParseDirectiveZerofill
871/// ::= .zerofill segname , sectname [, identifier , size_expression [
872/// , align_expression ]]
873bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) {
874 StringRef Segment;
875 if (getParser().parseIdentifier(Segment))
876 return TokError("expected segment name after '.zerofill' directive");
877
878 if (getLexer().isNot(AsmToken::Comma))
879 return TokError("unexpected token in directive");
880 Lex();
881
882 StringRef Section;
883 SMLoc SectionLoc = getLexer().getLoc();
884 if (getParser().parseIdentifier(Section))
885 return TokError("expected section name after comma in '.zerofill' "
886 "directive");
887
888 // If this is the end of the line all that was wanted was to create the
889 // the section but with no symbol.
890 if (getLexer().is(AsmToken::EndOfStatement)) {
891 // Create the zerofill section but no symbol
892 getStreamer().emitZerofill(
893 getContext().getMachOSection(Segment, Section, MachO::S_ZEROFILL, 0,
895 /*Symbol=*/nullptr, /*Size=*/0, Align(1), SectionLoc);
896 return false;
897 }
898
899 if (getLexer().isNot(AsmToken::Comma))
900 return TokError("unexpected token in directive");
901 Lex();
902
903 SMLoc IDLoc = getLexer().getLoc();
904 MCSymbol *Sym;
905 if (getParser().parseSymbol(Sym))
906 return TokError("expected identifier in directive");
907
908 if (getLexer().isNot(AsmToken::Comma))
909 return TokError("unexpected token in directive");
910 Lex();
911
912 int64_t Size;
913 SMLoc SizeLoc = getLexer().getLoc();
914 if (getParser().parseAbsoluteExpression(Size))
915 return true;
916
917 int64_t Pow2Alignment = 0;
918 SMLoc Pow2AlignmentLoc;
919 if (getLexer().is(AsmToken::Comma)) {
920 Lex();
921 Pow2AlignmentLoc = getLexer().getLoc();
922 if (getParser().parseAbsoluteExpression(Pow2Alignment))
923 return true;
924 }
925
926 if (getLexer().isNot(AsmToken::EndOfStatement))
927 return TokError("unexpected token in '.zerofill' directive");
928
929 Lex();
930
931 if (Size < 0)
932 return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less "
933 "than zero");
934
935 // NOTE: The alignment in the directive is a power of 2 value, the assembler
936 // may internally end up wanting an alignment in bytes.
937 // FIXME: Diagnose overflow.
938 if (Pow2Alignment < 0)
939 return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, "
940 "can't be less than zero");
941
942 if (!Sym->isUndefined())
943 return Error(IDLoc, "invalid symbol redefinition");
944
945 // Create the zerofill Symbol with Size and Pow2Alignment
946 //
947 // FIXME: Arch specific.
948 getStreamer().emitZerofill(
949 getContext().getMachOSection(Segment, Section, MachO::S_ZEROFILL, 0,
951 Sym, Size, Align(1ULL << Pow2Alignment), SectionLoc);
952
953 return false;
954}
955
956/// ParseDirectiveDataRegion
957/// ::= .data_region [ ( jt8 | jt16 | jt32 ) ]
958bool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) {
959 if (getLexer().is(AsmToken::EndOfStatement)) {
960 Lex();
961 getStreamer().emitDataRegion(MCDR_DataRegion);
962 return false;
963 }
964 StringRef RegionType;
965 SMLoc Loc = getParser().getTok().getLoc();
966 if (getParser().parseIdentifier(RegionType))
967 return TokError("expected region type after '.data_region' directive");
968 int Kind = StringSwitch<int>(RegionType)
969 .Case("jt8", MCDR_DataRegionJT8)
970 .Case("jt16", MCDR_DataRegionJT16)
971 .Case("jt32", MCDR_DataRegionJT32)
972 .Default(-1);
973 if (Kind == -1)
974 return Error(Loc, "unknown region type in '.data_region' directive");
975 Lex();
976
977 getStreamer().emitDataRegion((MCDataRegionType)Kind);
978 return false;
979}
980
981/// ParseDirectiveDataRegionEnd
982/// ::= .end_data_region
983bool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) {
984 if (getLexer().isNot(AsmToken::EndOfStatement))
985 return TokError("unexpected token in '.end_data_region' directive");
986
987 Lex();
988 getStreamer().emitDataRegion(MCDR_DataRegionEnd);
989 return false;
990}
991
992static bool isSDKVersionToken(const AsmToken &Tok) {
993 return Tok.is(AsmToken::Identifier) && Tok.getIdentifier() == "sdk_version";
994}
995
996/// parseMajorMinorVersionComponent ::= major, minor
997bool DarwinAsmParser::parseMajorMinorVersionComponent(unsigned *Major,
998 unsigned *Minor,
999 const char *VersionName) {
1000 // Get the major version number.
1001 if (getLexer().isNot(AsmToken::Integer))
1002 return TokError(Twine("invalid ") + VersionName +
1003 " major version number, integer expected");
1004 int64_t MajorVal = getLexer().getTok().getIntVal();
1005 if (MajorVal > 65535 || MajorVal <= 0)
1006 return TokError(Twine("invalid ") + VersionName + " major version number");
1007 *Major = (unsigned)MajorVal;
1008 Lex();
1009 if (getLexer().isNot(AsmToken::Comma))
1010 return TokError(Twine(VersionName) +
1011 " minor version number required, comma expected");
1012 Lex();
1013 // Get the minor version number.
1014 if (getLexer().isNot(AsmToken::Integer))
1015 return TokError(Twine("invalid ") + VersionName +
1016 " minor version number, integer expected");
1017 int64_t MinorVal = getLexer().getTok().getIntVal();
1018 if (MinorVal > 255 || MinorVal < 0)
1019 return TokError(Twine("invalid ") + VersionName + " minor version number");
1020 *Minor = MinorVal;
1021 Lex();
1022 return false;
1023}
1024
1025/// parseOptionalTrailingVersionComponent ::= , version_number
1026bool DarwinAsmParser::parseOptionalTrailingVersionComponent(
1027 unsigned *Component, const char *ComponentName) {
1028 assert(getLexer().is(AsmToken::Comma) && "comma expected");
1029 Lex();
1030 if (getLexer().isNot(AsmToken::Integer))
1031 return TokError(Twine("invalid ") + ComponentName +
1032 " version number, integer expected");
1033 int64_t Val = getLexer().getTok().getIntVal();
1034 if (Val > 255 || Val < 0)
1035 return TokError(Twine("invalid ") + ComponentName + " version number");
1036 *Component = Val;
1037 Lex();
1038 return false;
1039}
1040
1041/// parseVersion ::= parseMajorMinorVersionComponent
1042/// parseOptionalTrailingVersionComponent
1043bool DarwinAsmParser::parseVersion(unsigned *Major, unsigned *Minor,
1044 unsigned *Update) {
1045 if (parseMajorMinorVersionComponent(Major, Minor, "OS"))
1046 return true;
1047
1048 // Get the update level, if specified
1049 *Update = 0;
1050 if (getLexer().is(AsmToken::EndOfStatement) ||
1051 isSDKVersionToken(getLexer().getTok()))
1052 return false;
1053 if (getLexer().isNot(AsmToken::Comma))
1054 return TokError("invalid OS update specifier, comma expected");
1055 if (parseOptionalTrailingVersionComponent(Update, "OS update"))
1056 return true;
1057 return false;
1058}
1059
1060bool DarwinAsmParser::parseSDKVersion(VersionTuple &SDKVersion) {
1061 assert(isSDKVersionToken(getLexer().getTok()) && "expected sdk_version");
1062 Lex();
1063 unsigned Major, Minor;
1064 if (parseMajorMinorVersionComponent(&Major, &Minor, "SDK"))
1065 return true;
1066 SDKVersion = VersionTuple(Major, Minor);
1067
1068 // Get the subminor version, if specified.
1069 if (getLexer().is(AsmToken::Comma)) {
1070 unsigned Subminor;
1071 if (parseOptionalTrailingVersionComponent(&Subminor, "SDK subminor"))
1072 return true;
1073 SDKVersion = VersionTuple(Major, Minor, Subminor);
1074 }
1075 return false;
1076}
1077
1078void DarwinAsmParser::checkVersion(StringRef Directive, StringRef Arg,
1079 SMLoc Loc, Triple::OSType ExpectedOS) {
1080 const Triple &Target = getContext().getTargetTriple();
1081 if (Target.getOS() != ExpectedOS)
1082 Warning(Loc, Twine(Directive) +
1083 (Arg.empty() ? Twine() : Twine(' ') + Arg) +
1084 " used while targeting " + Target.getOSName());
1085
1086 if (LastVersionDirective.isValid()) {
1087 Warning(Loc, "overriding previous version directive");
1088 Note(LastVersionDirective, "previous definition is here");
1089 }
1090 LastVersionDirective = Loc;
1091}
1092
1094 switch (Type) {
1096 case MCVM_TvOSVersionMin: return Triple::TvOS;
1097 case MCVM_IOSVersionMin: return Triple::IOS;
1099 }
1100 llvm_unreachable("Invalid mc version min type");
1101}
1102
1103/// parseVersionMin
1104/// ::= .ios_version_min parseVersion parseSDKVersion
1105/// | .macosx_version_min parseVersion parseSDKVersion
1106/// | .tvos_version_min parseVersion parseSDKVersion
1107/// | .watchos_version_min parseVersion parseSDKVersion
1108bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc,
1110 unsigned Major;
1111 unsigned Minor;
1112 unsigned Update;
1113 if (parseVersion(&Major, &Minor, &Update))
1114 return true;
1115
1116 VersionTuple SDKVersion;
1117 if (isSDKVersionToken(getLexer().getTok()) && parseSDKVersion(SDKVersion))
1118 return true;
1119
1120 if (parseEOL())
1121 return addErrorSuffix(Twine(" in '") + Directive + "' directive");
1122
1124 checkVersion(Directive, StringRef(), Loc, ExpectedOS);
1125 getStreamer().emitVersionMin(Type, Major, Minor, Update, SDKVersion);
1126 return false;
1127}
1128
1130 switch (Type) {
1131 case MachO::PLATFORM_UNKNOWN: /* silence warning */
1132 break;
1133 case MachO::PLATFORM_MACOS: return Triple::MacOSX;
1134 case MachO::PLATFORM_IOS: return Triple::IOS;
1135 case MachO::PLATFORM_TVOS: return Triple::TvOS;
1136 case MachO::PLATFORM_WATCHOS: return Triple::WatchOS;
1137 case MachO::PLATFORM_XROS: return Triple::XROS;
1138 case MachO::PLATFORM_BRIDGEOS: /* silence warning */ break;
1139 case MachO::PLATFORM_DRIVERKIT:
1140 return Triple::DriverKit;
1141 case MachO::PLATFORM_MACCATALYST: return Triple::IOS;
1142 case MachO::PLATFORM_IOSSIMULATOR: /* silence warning */ break;
1143 case MachO::PLATFORM_TVOSSIMULATOR: /* silence warning */ break;
1144 case MachO::PLATFORM_WATCHOSSIMULATOR: /* silence warning */ break;
1145 case MachO::PLATFORM_XROS_SIMULATOR: /* silence warning */ break;
1146 }
1147 llvm_unreachable("Invalid mach-o platform type");
1148}
1149
1150/// parseBuildVersion
1151/// ::= .build_version (macos|ios|tvos|watchos), parseVersion parseSDKVersion
1152bool DarwinAsmParser::parseBuildVersion(StringRef Directive, SMLoc Loc) {
1153 StringRef PlatformName;
1154 SMLoc PlatformLoc = getTok().getLoc();
1155 if (getParser().parseIdentifier(PlatformName))
1156 return TokError("platform name expected");
1157
1158 unsigned Platform = StringSwitch<unsigned>(PlatformName)
1159#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
1160 marketing) \
1161 .Case(#build_name, MachO::PLATFORM_##platform)
1162#include "llvm/BinaryFormat/MachO.def"
1163 .Default(MachO::PLATFORM_UNKNOWN);
1164
1165 if (Platform == MachO::PLATFORM_UNKNOWN)
1166 return Error(PlatformLoc, "unknown platform name");
1167
1168 if (getLexer().isNot(AsmToken::Comma))
1169 return TokError("version number required, comma expected");
1170 Lex();
1171
1172 unsigned Major;
1173 unsigned Minor;
1174 unsigned Update;
1175 if (parseVersion(&Major, &Minor, &Update))
1176 return true;
1177
1178 VersionTuple SDKVersion;
1179 if (isSDKVersionToken(getLexer().getTok()) && parseSDKVersion(SDKVersion))
1180 return true;
1181
1182 if (parseEOL())
1183 return addErrorSuffix(" in '.build_version' directive");
1184
1185 Triple::OSType ExpectedOS
1187 checkVersion(Directive, PlatformName, Loc, ExpectedOS);
1188 getStreamer().emitBuildVersion(Platform, Major, Minor, Update, SDKVersion);
1189 return false;
1190}
1191
1192/// parseTargetTripleDirective
1193/// ::= .target_triple parseTargetTriple
1194bool DarwinAsmParser::parseTargetTripleDirective(StringRef Directive,
1195 SMLoc Loc) {
1196 StringRef TargetTriple;
1197 SMLoc TargetTripleLoc = getTok().getLoc();
1198 if (getParser().parseIdentifier(TargetTriple))
1199 return TokError("target triple expected");
1200 std::string NormalizedTriple = Triple::normalize(TargetTriple);
1201 if (!Triple(NormalizedTriple).isOSDarwin())
1202 return Error(TargetTripleLoc, "non-Darwin target triple");
1203
1204 if (parseEOL())
1205 return addErrorSuffix(" in '.target_triple' directive");
1206
1207 getStreamer().emitTargetTriple(NormalizedTriple);
1208 return false;
1209}
1210
1211/// parseDirectiveCGProfile
1212/// ::= .cg_profile from, to, count
1213bool DarwinAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
1215}
1216
1218 return new DarwinAsmParser;
1219}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Version parseVersion(StringRef Name)
static bool isSDKVersionToken(const AsmToken &Tok)
static Triple::OSType getOSTypeFromMCVM(MCVersionMinType Type)
static Triple::OSType getOSTypeFromPlatform(MachO::PlatformType Type)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Target independent representation for an assembler token.
Definition MCAsmMacro.h:22
bool is(TokenKind K) const
Definition MCAsmMacro.h:75
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition MCAsmMacro.h:92
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool parseDirectiveCGProfile(StringRef, SMLoc)
parseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
MachO::SectionType getType() const
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition MCSymbol.h:233
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition MCSymbol.h:243
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition MCSymbol.h:205
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
constexpr const char * getPointer() const
Definition SMLoc.h:33
constexpr bool isValid() const
Definition SMLoc.h:28
static SectionKind getText()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getThreadBSS()
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
iterator begin() const
Definition StringRef.h:114
iterator end() const
Definition StringRef.h:116
static LLVM_ABI std::string normalize(StringRef Str, CanonicalForm Form=CanonicalForm::ANY)
Turn an arbitrary machine specification into the canonical triple form (or something sensible that th...
Definition Triple.cpp:1185
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const char SectionName[]
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
SectionType
These are the section type and attributes fields.
Definition MachO.h:122
@ S_THREAD_LOCAL_VARIABLE_POINTERS
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition MachO.h:175
@ S_16BYTE_LITERALS
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition MachO.h:160
@ S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition MachO.h:178
@ S_THREAD_LOCAL_ZEROFILL
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition MachO.h:169
@ S_LAZY_SYMBOL_POINTERS
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition MachO.h:141
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition MachO.h:150
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition MachO.h:147
@ S_CSTRING_LITERALS
S_CSTRING_LITERALS - Section with literal C strings.
Definition MachO.h:131
@ S_THREAD_LOCAL_REGULAR
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition MachO.h:167
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
Definition MachO.h:129
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition MachO.h:139
@ S_4BYTE_LITERALS
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition MachO.h:133
@ S_LITERAL_POINTERS
S_LITERAL_POINTERS - Section with pointers to literals.
Definition MachO.h:137
@ S_8BYTE_LITERALS
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition MachO.h:135
@ S_THREAD_LOCAL_VARIABLES
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition MachO.h:172
@ S_SYMBOL_STUBS
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
Definition MachO.h:144
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
Definition Symbol.cpp:75
@ S_ATTR_NO_DEAD_STRIP
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition MachO.h:200
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition MachO.h:192
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition FileSystem.h:804
@ OF_Append
The file should be opened in append mode.
Definition FileSystem.h:807
This is an optimization pass for GlobalISel generic memory operations.
MCDataRegionType
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
@ MCDR_DataRegionJT8
.data_region jt8
@ MCDR_DataRegionJT32
.data_region jt32
@ MCDR_DataRegionJT16
.data_region jt16
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
MCVersionMinType
@ MCVM_WatchOSVersionMin
.watchos_version_min
@ MCVM_OSXVersionMin
.macosx_version_min
@ MCVM_TvOSVersionMin
.tvos_version_min
@ MCVM_IOSVersionMin
.ios_version_min
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition MCStreamer.h:68
LLVM_ABI MCAsmParserExtension * createDarwinAsmParser()
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)