33#include <system_error>
43 template<
bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
44 void addDirectiveHandler(StringRef Directive) {
46 this, HandleDirective<DarwinAsmParser, HandlerMethod>);
47 getParser().addDirectiveHandler(Directive, Handler);
50 bool parseSectionSwitch(StringRef Segment, StringRef Section,
51 unsigned TAA = 0,
unsigned ImplicitAlign = 0,
52 unsigned StubSize = 0);
54 SMLoc LastVersionDirective;
57 DarwinAsmParser() =
default;
59 void Initialize(MCAsmParser &Parser)
override {
63 addDirectiveHandler<&DarwinAsmParser::parseDirectiveAltEntry>(
".alt_entry");
64 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(
".desc");
65 addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>(
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>(
75 addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>(
77 addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(
".previous");
78 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>(
79 ".secure_log_unique");
80 addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>(
82 addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(
".tbss");
83 addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(
".zerofill");
85 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>(
87 addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>(
91 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(
".bss");
92 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(
".const");
93 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>(
95 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>(
97 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>(
99 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(
".data");
100 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>(
102 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(
".dyld");
103 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>(
105 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>(
108 &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>(
109 ".lazy_symbol_pointer");
110 addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>(
112 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>(
114 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>(
116 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>(
118 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>(
120 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>(
123 &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>(
124 ".non_lazy_symbol_pointer");
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>(
134 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>(
136 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>(
137 ".objc_class_names");
138 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>(
140 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>(
142 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>(
144 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>(
147 &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>(
148 ".objc_instance_vars");
149 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>(
150 ".objc_message_refs");
151 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>(
154 &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>(
155 ".objc_meth_var_names");
157 &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>(
158 ".objc_meth_var_types");
159 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>(
160 ".objc_module_info");
161 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>(
164 &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>(
165 ".objc_selector_strs");
167 &DarwinAsmParser::parseSectionDirectiveObjCStringObject>(
168 ".objc_string_object");
169 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>(
171 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>(
173 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>(
175 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>(
177 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>(
179 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(
".tdata");
180 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(
".text");
181 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>(
182 ".thread_init_func");
183 addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(
".tlv");
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>(
192 addDirectiveHandler<&DarwinAsmParser::parseMacOSXVersionMin>(
193 ".macosx_version_min");
194 addDirectiveHandler<&DarwinAsmParser::parseBuildVersion>(
".build_version");
195 addDirectiveHandler<&DarwinAsmParser::parseDirectiveCGProfile>(
198 LastVersionDirective = SMLoc();
201 bool parseDirectiveAltEntry(StringRef, SMLoc);
202 bool parseDirectiveDesc(StringRef, SMLoc);
203 bool parseDirectiveIndirectSymbol(StringRef, SMLoc);
204 bool parseDirectiveDumpOrLoad(StringRef, SMLoc);
205 bool parseDirectiveLsym(StringRef, SMLoc);
206 bool parseDirectiveLinkerOption(StringRef, SMLoc);
207 bool parseDirectiveSection(StringRef, SMLoc);
208 bool parseDirectivePushSection(StringRef, SMLoc);
209 bool parseDirectivePopSection(StringRef, SMLoc);
210 bool parseDirectivePrevious(StringRef, SMLoc);
211 bool parseDirectiveSecureLogReset(StringRef, SMLoc);
212 bool parseDirectiveSecureLogUnique(StringRef, SMLoc);
213 bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
214 bool parseDirectiveTBSS(StringRef, SMLoc);
215 bool parseDirectiveZerofill(StringRef, SMLoc);
216 bool parseDirectiveDataRegion(StringRef, SMLoc);
217 bool parseDirectiveDataRegionEnd(StringRef, SMLoc);
220 bool parseSectionDirectiveBss(StringRef, SMLoc) {
221 return parseSectionSwitch(
"__DATA",
"__bss");
224 bool parseSectionDirectiveConst(StringRef, SMLoc) {
225 return parseSectionSwitch(
"__TEXT",
"__const");
228 bool parseSectionDirectiveStaticConst(StringRef, SMLoc) {
229 return parseSectionSwitch(
"__TEXT",
"__static_const");
232 bool parseSectionDirectiveCString(StringRef, SMLoc) {
233 return parseSectionSwitch(
"__TEXT",
"__cstring",
237 bool parseSectionDirectiveLiteral4(StringRef, SMLoc) {
238 return parseSectionSwitch(
"__TEXT",
"__literal4",
242 bool parseSectionDirectiveLiteral8(StringRef, SMLoc) {
243 return parseSectionSwitch(
"__TEXT",
"__literal8",
247 bool parseSectionDirectiveLiteral16(StringRef, SMLoc) {
248 return parseSectionSwitch(
"__TEXT",
"__literal16",
252 bool parseSectionDirectiveConstructor(StringRef, SMLoc) {
253 return parseSectionSwitch(
"__TEXT",
"__constructor");
256 bool parseSectionDirectiveDestructor(StringRef, SMLoc) {
257 return parseSectionSwitch(
"__TEXT",
"__destructor");
260 bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) {
261 return parseSectionSwitch(
"__TEXT",
"__fvmlib_init0");
264 bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) {
265 return parseSectionSwitch(
"__TEXT",
"__fvmlib_init1");
268 bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
269 return parseSectionSwitch(
"__TEXT",
"__symbol_stub",
276 bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
277 return parseSectionSwitch(
"__TEXT",
"__picsymbol_stub",
282 bool parseSectionDirectiveData(StringRef, SMLoc) {
283 return parseSectionSwitch(
"__DATA",
"__data");
286 bool parseSectionDirectiveStaticData(StringRef, SMLoc) {
287 return parseSectionSwitch(
"__DATA",
"__static_data");
290 bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) {
291 return parseSectionSwitch(
"__DATA",
"__nl_symbol_ptr",
295 bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) {
296 return parseSectionSwitch(
"__DATA",
"__la_symbol_ptr",
300 bool parseSectionDirectiveThreadLocalVariablePointers(StringRef, SMLoc) {
301 return parseSectionSwitch(
"__DATA",
"__thread_ptr",
305 bool parseSectionDirectiveDyld(StringRef, SMLoc) {
306 return parseSectionSwitch(
"__DATA",
"__dyld");
309 bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) {
310 return parseSectionSwitch(
"__DATA",
"__mod_init_func",
314 bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) {
315 return parseSectionSwitch(
"__DATA",
"__mod_term_func",
319 bool parseSectionDirectiveConstData(StringRef, SMLoc) {
320 return parseSectionSwitch(
"__DATA",
"__const");
323 bool parseSectionDirectiveObjCClass(StringRef, SMLoc) {
324 return parseSectionSwitch(
"__OBJC",
"__class",
328 bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) {
329 return parseSectionSwitch(
"__OBJC",
"__meta_class",
333 bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) {
334 return parseSectionSwitch(
"__OBJC",
"__cat_cls_meth",
338 bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) {
339 return parseSectionSwitch(
"__OBJC",
"__cat_inst_meth",
343 bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) {
344 return parseSectionSwitch(
"__OBJC",
"__protocol",
348 bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) {
349 return parseSectionSwitch(
"__OBJC",
"__string_object",
353 bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) {
354 return parseSectionSwitch(
"__OBJC",
"__cls_meth",
358 bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) {
359 return parseSectionSwitch(
"__OBJC",
"__inst_meth",
363 bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
364 return parseSectionSwitch(
"__OBJC",
"__cls_refs",
369 bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
370 return parseSectionSwitch(
"__OBJC",
"__message_refs",
375 bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
376 return parseSectionSwitch(
"__OBJC",
"__symbols",
380 bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) {
381 return parseSectionSwitch(
"__OBJC",
"__category",
385 bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) {
386 return parseSectionSwitch(
"__OBJC",
"__class_vars",
390 bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) {
391 return parseSectionSwitch(
"__OBJC",
"__instance_vars",
395 bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) {
396 return parseSectionSwitch(
"__OBJC",
"__module_info",
400 bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) {
401 return parseSectionSwitch(
"__TEXT",
"__cstring",
405 bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) {
406 return parseSectionSwitch(
"__TEXT",
"__cstring",
410 bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) {
411 return parseSectionSwitch(
"__TEXT",
"__cstring",
415 bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) {
416 return parseSectionSwitch(
"__OBJC",
"__selector_strs",
420 bool parseSectionDirectiveTData(StringRef, SMLoc) {
421 return parseSectionSwitch(
"__DATA",
"__thread_data",
425 bool parseSectionDirectiveText(StringRef, SMLoc) {
426 return parseSectionSwitch(
"__TEXT",
"__text",
430 bool parseSectionDirectiveTLV(StringRef, SMLoc) {
431 return parseSectionSwitch(
"__DATA",
"__thread_vars",
435 bool parseSectionDirectiveIdent(StringRef, SMLoc) {
437 getParser().eatToEndOfStatement();
441 bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
442 return parseSectionSwitch(
"__DATA",
"__thread_init",
446 bool parseWatchOSVersionMin(StringRef Directive, SMLoc Loc) {
449 bool parseTvOSVersionMin(StringRef Directive, SMLoc Loc) {
452 bool parseIOSVersionMin(StringRef Directive, SMLoc Loc) {
455 bool parseMacOSXVersionMin(StringRef Directive, SMLoc Loc) {
459 bool parseBuildVersion(StringRef Directive, SMLoc Loc);
461 bool parseMajorMinorVersionComponent(
unsigned *Major,
unsigned *Minor,
462 const char *VersionName);
463 bool parseOptionalTrailingVersionComponent(
unsigned *Component,
464 const char *ComponentName);
465 bool parseVersion(
unsigned *Major,
unsigned *Minor,
unsigned *Update);
466 bool parseSDKVersion(VersionTuple &SDKVersion);
467 void checkVersion(StringRef Directive, StringRef Arg, SMLoc Loc,
469 bool parseDirectiveCGProfile(StringRef Directive, SMLoc Loc);
475 unsigned TAA,
unsigned Alignment,
478 return TokError(
"unexpected token in section switching directive");
483 getStreamer().switchSection(
getContext().getMachOSection(
484 Segment, Section, TAA, StubSize,
496 getStreamer().emitValueToAlignment(
Align(Alignment));
503bool DarwinAsmParser::parseDirectiveAltEntry(StringRef, SMLoc) {
506 return TokError(
"expected identifier in directive");
509 return TokError(
".alt_entry must preceed symbol definition");
512 return TokError(
"unable to emit symbol attribute");
520bool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) {
523 return TokError(
"expected identifier in directive");
526 return TokError(
"unexpected token in '.desc' directive");
530 if (getParser().parseAbsoluteExpression(DescValue))
534 return TokError(
"unexpected token in '.desc' directive");
539 getStreamer().emitSymbolDesc(Sym, DescValue);
546bool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) {
547 const MCSectionMachO *Current =
static_cast<const MCSectionMachO *
>(
548 getStreamer().getCurrentSectionOnly());
554 return Error(Loc,
"indirect symbol not in a symbol pointer or stub "
559 return TokError(
"expected identifier in .indirect_symbol directive");
563 return TokError(
"non-local symbol required in directive");
566 return TokError(
"unable to emit indirect symbol attribute for: " +
570 return TokError(
"unexpected token in '.indirect_symbol' directive");
579bool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive,
581 bool IsDump = Directive ==
".dump";
583 return TokError(
"expected string in '.dump' or '.load' directive");
588 return TokError(
"unexpected token in '.dump' or '.load' directive");
595 return Warning(IDLoc,
"ignoring directive .dump for now");
597 return Warning(IDLoc,
"ignoring directive .load for now");
602bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
603 SmallVector<std::string, 4>
Args;
606 return TokError(
"expected string in '" + Twine(IDVal) +
"' directive");
609 if (getParser().parseEscapedString(
Data))
618 return TokError(
"unexpected token in '" + Twine(IDVal) +
"' directive");
622 getStreamer().emitLinkerOptions(Args);
628bool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) {
631 return TokError(
"expected identifier in directive");
634 return TokError(
"unexpected token in '.lsym' directive");
638 if (getParser().parseExpression(
Value))
642 return TokError(
"unexpected token in '.lsym' directive");
650 return TokError(
"directive '.lsym' is unsupported");
655bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
656 SMLoc Loc = getLexer().getLoc();
659 if (getParser().parseIdentifier(SectionName))
660 return Error(Loc,
"expected identifier after '.section' directive");
664 return TokError(
"unexpected token in '.section' directive");
666 std::string SectionSpec = std::string(SectionName);
671 StringRef EOL = getLexer().LexUntilEndOfStatement();
672 SectionSpec.append(EOL.
begin(), EOL.
end());
676 return TokError(
"unexpected token in '.section' directive");
684 SectionSpec, Segment, Section, TAA, TAAParsed, StubSize))
688 Triple
TT = getParser().getContext().getTargetTriple();
692 StringRef NonCoalSection = StringSwitch<StringRef>(Section)
693 .Case(
"__textcoal_nt",
"__text")
694 .Case(
"__const_coal",
"__const")
695 .Case(
"__datacoal_nt",
"__data")
698 if (Section != NonCoalSection) {
700 size_t B = SectionVal.find(
',') + 1,
E = SectionVal.find(
',',
B);
703 getParser().Warning(Loc,
"section \"" + Section +
"\" is deprecated",
704 SMRange(BLoc, ELoc));
705 getParser().Note(Loc,
"change section name to \"" + NonCoalSection +
706 "\"", SMRange(BLoc, ELoc));
711 bool isText = Segment ==
"__TEXT";
712 getStreamer().switchSection(
getContext().getMachOSection(
713 Segment, Section, TAA, StubSize,
720bool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) {
721 getStreamer().pushSection();
723 if (parseDirectiveSection(S, Loc)) {
724 getStreamer().popSection();
733bool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
734 if (!getStreamer().popSection())
735 return TokError(
".popsection without corresponding .pushsection");
741bool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) {
743 if (!PreviousSection.first)
744 return TokError(
".previous without corresponding .section");
745 getStreamer().switchSection(PreviousSection.first, PreviousSection.second);
751bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
752 StringRef LogMessage = getParser().parseStringToEndOfStatement();
754 return TokError(
"unexpected token in '.secure_log_unique' directive");
757 return Error(IDLoc,
".secure_log_unique specified multiple times");
760 StringRef SecureLogFile =
getContext().getSecureLogFile();
761 if (SecureLogFile.
empty())
762 return Error(IDLoc,
".secure_log_unique used but AS_SECURE_LOG_FILE "
763 "environment variable unset.");
766 raw_fd_ostream *OS =
getContext().getSecureLog();
769 auto NewOS = std::make_unique<raw_fd_ostream>(
772 return Error(IDLoc, Twine(
"can't open secure log file: ") +
773 SecureLogFile +
" (" +
EC.message() +
")");
779 unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
780 *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
781 <<
":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) <<
":"
782 << LogMessage +
"\n";
791bool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
793 return TokError(
"unexpected token in '.secure_log_reset' directive");
804bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
806 return TokError(
"unexpected token in '.subsections_via_symbols' directive");
810 getStreamer().emitSubsectionsViaSymbols();
817bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) {
818 SMLoc IDLoc = getLexer().getLoc();
821 return TokError(
"expected identifier in directive");
824 return TokError(
"unexpected token in directive");
828 SMLoc SizeLoc = getLexer().getLoc();
829 if (getParser().parseAbsoluteExpression(
Size))
832 int64_t Pow2Alignment = 0;
833 SMLoc Pow2AlignmentLoc;
836 Pow2AlignmentLoc = getLexer().getLoc();
837 if (getParser().parseAbsoluteExpression(Pow2Alignment))
842 return TokError(
"unexpected token in '.tbss' directive");
847 return Error(SizeLoc,
"invalid '.tbss' directive size, can't be less than"
851 if (Pow2Alignment < 0)
852 return Error(Pow2AlignmentLoc,
"invalid '.tbss' alignment, can't be less"
856 return Error(IDLoc,
"invalid symbol redefinition");
858 getStreamer().emitTBSSSymbol(
859 getContext().getMachOSection(
"__DATA",
"__thread_bss",
862 Sym,
Size,
Align(1ULL << Pow2Alignment));
870bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) {
872 if (getParser().parseIdentifier(Segment))
873 return TokError(
"expected segment name after '.zerofill' directive");
876 return TokError(
"unexpected token in directive");
880 SMLoc SectionLoc = getLexer().getLoc();
881 if (getParser().parseIdentifier(Section))
882 return TokError(
"expected section name after comma in '.zerofill' "
889 getStreamer().emitZerofill(
892 nullptr, 0,
Align(1), SectionLoc);
897 return TokError(
"unexpected token in directive");
900 SMLoc IDLoc = getLexer().getLoc();
903 return TokError(
"expected identifier in directive");
906 return TokError(
"unexpected token in directive");
910 SMLoc SizeLoc = getLexer().getLoc();
911 if (getParser().parseAbsoluteExpression(
Size))
914 int64_t Pow2Alignment = 0;
915 SMLoc Pow2AlignmentLoc;
918 Pow2AlignmentLoc = getLexer().getLoc();
919 if (getParser().parseAbsoluteExpression(Pow2Alignment))
924 return TokError(
"unexpected token in '.zerofill' directive");
929 return Error(SizeLoc,
"invalid '.zerofill' directive size, can't be less "
935 if (Pow2Alignment < 0)
936 return Error(Pow2AlignmentLoc,
"invalid '.zerofill' directive alignment, "
937 "can't be less than zero");
940 return Error(IDLoc,
"invalid symbol redefinition");
945 getStreamer().emitZerofill(
948 Sym,
Size,
Align(1ULL << Pow2Alignment), SectionLoc);
955bool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) {
961 StringRef RegionType;
962 SMLoc Loc = getParser().getTok().getLoc();
963 if (getParser().parseIdentifier(RegionType))
964 return TokError(
"expected region type after '.data_region' directive");
965 int Kind = StringSwitch<int>(RegionType)
971 return Error(Loc,
"unknown region type in '.data_region' directive");
980bool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) {
982 return TokError(
"unexpected token in '.end_data_region' directive");
994bool DarwinAsmParser::parseMajorMinorVersionComponent(
unsigned *Major,
996 const char *VersionName) {
999 return TokError(Twine(
"invalid ") + VersionName +
1000 " major version number, integer expected");
1001 int64_t MajorVal = getLexer().getTok().getIntVal();
1002 if (MajorVal > 65535 || MajorVal <= 0)
1003 return TokError(Twine(
"invalid ") + VersionName +
" major version number");
1004 *Major = (unsigned)MajorVal;
1007 return TokError(Twine(VersionName) +
1008 " minor version number required, comma expected");
1012 return TokError(Twine(
"invalid ") + VersionName +
1013 " minor version number, integer expected");
1014 int64_t MinorVal = getLexer().getTok().getIntVal();
1015 if (MinorVal > 255 || MinorVal < 0)
1016 return TokError(Twine(
"invalid ") + VersionName +
" minor version number");
1023bool DarwinAsmParser::parseOptionalTrailingVersionComponent(
1024 unsigned *Component,
const char *ComponentName) {
1028 return TokError(Twine(
"invalid ") + ComponentName +
1029 " version number, integer expected");
1030 int64_t Val = getLexer().getTok().getIntVal();
1031 if (Val > 255 || Val < 0)
1032 return TokError(Twine(
"invalid ") + ComponentName +
" version number");
1040bool DarwinAsmParser::parseVersion(
unsigned *Major,
unsigned *Minor,
1042 if (parseMajorMinorVersionComponent(Major, Minor,
"OS"))
1051 return TokError(
"invalid OS update specifier, comma expected");
1052 if (parseOptionalTrailingVersionComponent(Update,
"OS update"))
1057bool DarwinAsmParser::parseSDKVersion(VersionTuple &SDKVersion) {
1060 unsigned Major, Minor;
1061 if (parseMajorMinorVersionComponent(&Major, &Minor,
"SDK"))
1063 SDKVersion = VersionTuple(Major, Minor);
1068 if (parseOptionalTrailingVersionComponent(&Subminor,
"SDK subminor"))
1070 SDKVersion = VersionTuple(Major, Minor, Subminor);
1075void DarwinAsmParser::checkVersion(StringRef Directive, StringRef Arg,
1078 if (
Target.getOS() != ExpectedOS)
1079 Warning(Loc, Twine(Directive) +
1080 (Arg.
empty() ? Twine() : Twine(
' ') + Arg) +
1081 " used while targeting " +
Target.getOSName());
1083 if (LastVersionDirective.
isValid()) {
1084 Warning(Loc,
"overriding previous version directive");
1085 Note(LastVersionDirective,
"previous definition is here");
1087 LastVersionDirective = Loc;
1105bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc,
1113 VersionTuple SDKVersion;
1118 return addErrorSuffix(Twine(
" in '") + Directive +
"' directive");
1121 checkVersion(Directive, StringRef(), Loc, ExpectedOS);
1122 getStreamer().emitVersionMin(
Type, Major, Minor, Update, SDKVersion);
1128 case MachO::PLATFORM_UNKNOWN:
1135 case MachO::PLATFORM_BRIDGEOS:
break;
1136 case MachO::PLATFORM_DRIVERKIT:
1138 case MachO::PLATFORM_MACCATALYST:
return Triple::IOS;
1139 case MachO::PLATFORM_IOSSIMULATOR:
break;
1140 case MachO::PLATFORM_TVOSSIMULATOR:
break;
1141 case MachO::PLATFORM_WATCHOSSIMULATOR:
break;
1142 case MachO::PLATFORM_XROS_SIMULATOR:
break;
1149bool DarwinAsmParser::parseBuildVersion(StringRef Directive, SMLoc Loc) {
1150 StringRef PlatformName;
1151 SMLoc PlatformLoc = getTok().getLoc();
1152 if (getParser().parseIdentifier(PlatformName))
1153 return TokError(
"platform name expected");
1155 unsigned Platform = StringSwitch<unsigned>(PlatformName)
1156#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
1158 .Case(#build_name, MachO::PLATFORM_##platform)
1159#include "llvm/BinaryFormat/MachO.def"
1160 .Default(MachO::PLATFORM_UNKNOWN);
1162 if (Platform == MachO::PLATFORM_UNKNOWN)
1163 return Error(PlatformLoc,
"unknown platform name");
1166 return TokError(
"version number required, comma expected");
1175 VersionTuple SDKVersion;
1180 return addErrorSuffix(
" in '.build_version' directive");
1184 checkVersion(Directive, PlatformName, Loc, ExpectedOS);
1185 getStreamer().emitBuildVersion(Platform, Major, Minor, Update, SDKVersion);
1191bool DarwinAsmParser::parseDirectiveCGProfile(StringRef S, SMLoc Loc) {
1198 return new DarwinAsmParser;
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)
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.
bool is(TokenKind K) const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
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).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
constexpr bool isValid() const
static SectionKind getText()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getThreadBSS()
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
@ S_THREAD_LOCAL_VARIABLE_POINTERS
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
@ S_16BYTE_LITERALS
S_16BYTE_LITERALS - Section with only 16 byte literals.
@ S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
@ S_THREAD_LOCAL_ZEROFILL
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
@ S_LAZY_SYMBOL_POINTERS
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
@ S_MOD_TERM_FUNC_POINTERS
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
@ S_CSTRING_LITERALS
S_CSTRING_LITERALS - Section with literal C strings.
@ S_THREAD_LOCAL_REGULAR
S_THREAD_LOCAL_REGULAR - Thread local data section.
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
@ S_4BYTE_LITERALS
S_4BYTE_LITERALS - Section with 4 byte literals.
@ S_LITERAL_POINTERS
S_LITERAL_POINTERS - Section with pointers to literals.
@ S_8BYTE_LITERALS
S_8BYTE_LITERALS - Section with 8 byte literals.
@ S_THREAD_LOCAL_VARIABLES
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
@ S_SYMBOL_STUBS
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
LLVM_ABI SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
@ S_ATTR_NO_DEAD_STRIP
S_ATTR_NO_DEAD_STRIP - No dead stripping.
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Context & getContext() const
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
@ OF_Append
The file should be opened in append mode.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
@ MCDR_DataRegionJT8
.data_region jt8
@ MCDR_DataRegionJT32
.data_region jt32
@ MCDR_DataRegionJT16
.data_region jt16
@ MCVM_WatchOSVersionMin
.watchos_version_min
@ MCVM_OSXVersionMin
.macosx_version_min
@ MCVM_TvOSVersionMin
.tvos_version_min
@ MCVM_IOSVersionMin
.ios_version_min
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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
MCAsmParserExtension * createDarwinAsmParser()
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)