Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 1 | //===- DarwinAsmParser.cpp - Darwin (Mach-O) Assembly Parser --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/MC/MCParser/MCAsmParserExtension.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/StringRef.h" |
| 12 | #include "llvm/ADT/StringSwitch.h" |
| 13 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCContext.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 16 | #include "llvm/MC/MCParser/MCAsmParser.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCSectionMachO.h" |
| 18 | #include "llvm/MC/MCStreamer.h" |
| 19 | #include "llvm/MC/MCSymbol.h" |
Benjamin Kramer | d59664f | 2014-04-29 23:26:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/FileSystem.h" |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 21 | #include "llvm/Support/MemoryBuffer.h" |
| 22 | #include "llvm/Support/SourceMgr.h" |
| 23 | using namespace llvm; |
| 24 | |
| 25 | namespace { |
| 26 | |
| 27 | /// \brief Implementation of directive handling which is shared across all |
| 28 | /// Darwin targets. |
| 29 | class DarwinAsmParser : public MCAsmParserExtension { |
Eli Bendersky | 29b9f47 | 2013-01-16 00:50:52 +0000 | [diff] [blame] | 30 | template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)> |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 31 | void addDirectiveHandler(StringRef Directive) { |
Eli Bendersky | 29b9f47 | 2013-01-16 00:50:52 +0000 | [diff] [blame] | 32 | MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair( |
| 33 | this, HandleDirective<DarwinAsmParser, HandlerMethod>); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 34 | getParser().addDirectiveHandler(Directive, Handler); |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 37 | bool parseSectionSwitch(const char *Segment, const char *Section, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 38 | unsigned TAA = 0, unsigned ImplicitAlign = 0, |
| 39 | unsigned StubSize = 0); |
| 40 | |
| 41 | public: |
| 42 | DarwinAsmParser() {} |
| 43 | |
Craig Topper | 59be68f | 2014-03-08 07:14:16 +0000 | [diff] [blame] | 44 | void Initialize(MCAsmParser &Parser) override { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 45 | // Call the base implementation. |
| 46 | this->MCAsmParserExtension::Initialize(Parser); |
| 47 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 48 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(".desc"); |
| 49 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>( |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 50 | ".indirect_symbol"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 51 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(".lsym"); |
| 52 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 53 | ".subsections_via_symbols"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 54 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".dump"); |
| 55 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".load"); |
| 56 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(".section"); |
| 57 | addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 58 | ".pushsection"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 59 | addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 60 | ".popsection"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 61 | addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(".previous"); |
| 62 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 63 | ".secure_log_unique"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 64 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>( |
Daniel Dunbar | 8897d47 | 2010-07-18 22:22:07 +0000 | [diff] [blame] | 65 | ".secure_log_reset"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 66 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(".tbss"); |
| 67 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(".zerofill"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 68 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 69 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 70 | ".data_region"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 71 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 72 | ".end_data_region"); |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 73 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 74 | // Special section directives. |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 75 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(".bss"); |
| 76 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(".const"); |
| 77 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 78 | ".const_data"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 79 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 80 | ".constructor"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 81 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 82 | ".cstring"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 83 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(".data"); |
| 84 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 85 | ".destructor"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 86 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(".dyld"); |
| 87 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 88 | ".fvmlib_init0"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 89 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 90 | ".fvmlib_init1"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 91 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 92 | &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 93 | ".lazy_symbol_pointer"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 94 | addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>( |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 95 | ".linker_option"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 96 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 97 | ".literal16"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 98 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 99 | ".literal4"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 100 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 101 | ".literal8"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 102 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 103 | ".mod_init_func"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 104 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 105 | ".mod_term_func"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 106 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 107 | &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 108 | ".non_lazy_symbol_pointer"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 109 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 110 | ".objc_cat_cls_meth"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 111 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 112 | ".objc_cat_inst_meth"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 113 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 114 | ".objc_category"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 115 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 116 | ".objc_class"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 117 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 118 | ".objc_class_names"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 119 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 120 | ".objc_class_vars"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 121 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 122 | ".objc_cls_meth"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 123 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 124 | ".objc_cls_refs"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 125 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 126 | ".objc_inst_meth"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 127 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 128 | &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 129 | ".objc_instance_vars"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 130 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 131 | ".objc_message_refs"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 132 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 133 | ".objc_meta_class"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 134 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 135 | &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 136 | ".objc_meth_var_names"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 137 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 138 | &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 139 | ".objc_meth_var_types"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 140 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 141 | ".objc_module_info"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 142 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 143 | ".objc_protocol"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 144 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 145 | &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 146 | ".objc_selector_strs"); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 147 | addDirectiveHandler< |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 148 | &DarwinAsmParser::parseSectionDirectiveObjCStringObject>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 149 | ".objc_string_object"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 150 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 151 | ".objc_symbols"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 152 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 153 | ".picsymbol_stub"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 154 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 155 | ".static_const"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 156 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 157 | ".static_data"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 158 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 159 | ".symbol_stub"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 160 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(".tdata"); |
| 161 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(".text"); |
| 162 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>( |
Daniel Dunbar | b94c578 | 2013-01-18 01:25:25 +0000 | [diff] [blame] | 163 | ".thread_init_func"); |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 164 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv"); |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 165 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 166 | addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident"); |
| 167 | addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".ios_version_min"); |
| 168 | addDirectiveHandler<&DarwinAsmParser::parseVersionMin>( |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame] | 169 | ".macosx_version_min"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 172 | bool parseDirectiveDesc(StringRef, SMLoc); |
| 173 | bool parseDirectiveIndirectSymbol(StringRef, SMLoc); |
| 174 | bool parseDirectiveDumpOrLoad(StringRef, SMLoc); |
| 175 | bool parseDirectiveLsym(StringRef, SMLoc); |
| 176 | bool parseDirectiveLinkerOption(StringRef, SMLoc); |
| 177 | bool parseDirectiveSection(StringRef, SMLoc); |
| 178 | bool parseDirectivePushSection(StringRef, SMLoc); |
| 179 | bool parseDirectivePopSection(StringRef, SMLoc); |
| 180 | bool parseDirectivePrevious(StringRef, SMLoc); |
| 181 | bool parseDirectiveSecureLogReset(StringRef, SMLoc); |
| 182 | bool parseDirectiveSecureLogUnique(StringRef, SMLoc); |
| 183 | bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc); |
| 184 | bool parseDirectiveTBSS(StringRef, SMLoc); |
| 185 | bool parseDirectiveZerofill(StringRef, SMLoc); |
| 186 | bool parseDirectiveDataRegion(StringRef, SMLoc); |
| 187 | bool parseDirectiveDataRegionEnd(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 188 | |
| 189 | // Named Section Directive |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 190 | bool parseSectionDirectiveBss(StringRef, SMLoc) { |
| 191 | return parseSectionSwitch("__DATA", "__bss"); |
Rafael Espindola | 3402c05 | 2013-10-02 14:09:29 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 194 | bool parseSectionDirectiveConst(StringRef, SMLoc) { |
| 195 | return parseSectionSwitch("__TEXT", "__const"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 196 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 197 | bool parseSectionDirectiveStaticConst(StringRef, SMLoc) { |
| 198 | return parseSectionSwitch("__TEXT", "__static_const"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 199 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 200 | bool parseSectionDirectiveCString(StringRef, SMLoc) { |
| 201 | return parseSectionSwitch("__TEXT","__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 202 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 203 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 204 | bool parseSectionDirectiveLiteral4(StringRef, SMLoc) { |
| 205 | return parseSectionSwitch("__TEXT", "__literal4", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 206 | MachO::S_4BYTE_LITERALS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 207 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 208 | bool parseSectionDirectiveLiteral8(StringRef, SMLoc) { |
| 209 | return parseSectionSwitch("__TEXT", "__literal8", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 210 | MachO::S_8BYTE_LITERALS, 8); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 211 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 212 | bool parseSectionDirectiveLiteral16(StringRef, SMLoc) { |
| 213 | return parseSectionSwitch("__TEXT","__literal16", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 214 | MachO::S_16BYTE_LITERALS, 16); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 215 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 216 | bool parseSectionDirectiveConstructor(StringRef, SMLoc) { |
| 217 | return parseSectionSwitch("__TEXT","__constructor"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 218 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 219 | bool parseSectionDirectiveDestructor(StringRef, SMLoc) { |
| 220 | return parseSectionSwitch("__TEXT","__destructor"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 221 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 222 | bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) { |
| 223 | return parseSectionSwitch("__TEXT","__fvmlib_init0"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 224 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 225 | bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) { |
| 226 | return parseSectionSwitch("__TEXT","__fvmlib_init1"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 227 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 228 | bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) { |
| 229 | return parseSectionSwitch("__TEXT","__symbol_stub", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 230 | MachO::S_SYMBOL_STUBS | |
| 231 | MachO::S_ATTR_PURE_INSTRUCTIONS, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 232 | // FIXME: Different on PPC and ARM. |
| 233 | 0, 16); |
| 234 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 235 | bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) { |
| 236 | return parseSectionSwitch("__TEXT","__picsymbol_stub", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 237 | MachO::S_SYMBOL_STUBS | |
| 238 | MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 239 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 240 | bool parseSectionDirectiveData(StringRef, SMLoc) { |
| 241 | return parseSectionSwitch("__DATA", "__data"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 242 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 243 | bool parseSectionDirectiveStaticData(StringRef, SMLoc) { |
| 244 | return parseSectionSwitch("__DATA", "__static_data"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 245 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 246 | bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) { |
| 247 | return parseSectionSwitch("__DATA", "__nl_symbol_ptr", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 248 | MachO::S_NON_LAZY_SYMBOL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 249 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 250 | bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) { |
| 251 | return parseSectionSwitch("__DATA", "__la_symbol_ptr", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 252 | MachO::S_LAZY_SYMBOL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 253 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 254 | bool parseSectionDirectiveDyld(StringRef, SMLoc) { |
| 255 | return parseSectionSwitch("__DATA", "__dyld"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 256 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 257 | bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) { |
| 258 | return parseSectionSwitch("__DATA", "__mod_init_func", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 259 | MachO::S_MOD_INIT_FUNC_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 260 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 261 | bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) { |
| 262 | return parseSectionSwitch("__DATA", "__mod_term_func", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 263 | MachO::S_MOD_TERM_FUNC_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 264 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 265 | bool parseSectionDirectiveConstData(StringRef, SMLoc) { |
| 266 | return parseSectionSwitch("__DATA", "__const"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 267 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 268 | bool parseSectionDirectiveObjCClass(StringRef, SMLoc) { |
| 269 | return parseSectionSwitch("__OBJC", "__class", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 270 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 271 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 272 | bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) { |
| 273 | return parseSectionSwitch("__OBJC", "__meta_class", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 274 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 275 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 276 | bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) { |
| 277 | return parseSectionSwitch("__OBJC", "__cat_cls_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 278 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 279 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 280 | bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) { |
| 281 | return parseSectionSwitch("__OBJC", "__cat_inst_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 282 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 283 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 284 | bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) { |
| 285 | return parseSectionSwitch("__OBJC", "__protocol", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 286 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 287 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 288 | bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) { |
| 289 | return parseSectionSwitch("__OBJC", "__string_object", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 290 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 291 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 292 | bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) { |
| 293 | return parseSectionSwitch("__OBJC", "__cls_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 294 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 295 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 296 | bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) { |
| 297 | return parseSectionSwitch("__OBJC", "__inst_meth", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 298 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 299 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 300 | bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) { |
| 301 | return parseSectionSwitch("__OBJC", "__cls_refs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 302 | MachO::S_ATTR_NO_DEAD_STRIP | |
| 303 | MachO::S_LITERAL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 304 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 305 | bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) { |
| 306 | return parseSectionSwitch("__OBJC", "__message_refs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 307 | MachO::S_ATTR_NO_DEAD_STRIP | |
| 308 | MachO::S_LITERAL_POINTERS, 4); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 309 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 310 | bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) { |
| 311 | return parseSectionSwitch("__OBJC", "__symbols", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 312 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 313 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 314 | bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) { |
| 315 | return parseSectionSwitch("__OBJC", "__category", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 316 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 317 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 318 | bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) { |
| 319 | return parseSectionSwitch("__OBJC", "__class_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 320 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 321 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 322 | bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) { |
| 323 | return parseSectionSwitch("__OBJC", "__instance_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 324 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 325 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 326 | bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) { |
| 327 | return parseSectionSwitch("__OBJC", "__module_info", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 328 | MachO::S_ATTR_NO_DEAD_STRIP); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 329 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 330 | bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) { |
| 331 | return parseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 332 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 333 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 334 | bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) { |
| 335 | return parseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 336 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 337 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 338 | bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) { |
| 339 | return parseSectionSwitch("__TEXT", "__cstring", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 340 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 341 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 342 | bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) { |
| 343 | return parseSectionSwitch("__OBJC", "__selector_strs", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 344 | MachO::S_CSTRING_LITERALS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 345 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 346 | bool parseSectionDirectiveTData(StringRef, SMLoc) { |
| 347 | return parseSectionSwitch("__DATA", "__thread_data", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 348 | MachO::S_THREAD_LOCAL_REGULAR); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 349 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 350 | bool parseSectionDirectiveText(StringRef, SMLoc) { |
| 351 | return parseSectionSwitch("__TEXT", "__text", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 352 | MachO::S_ATTR_PURE_INSTRUCTIONS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 353 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 354 | bool parseSectionDirectiveTLV(StringRef, SMLoc) { |
| 355 | return parseSectionSwitch("__DATA", "__thread_vars", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 356 | MachO::S_THREAD_LOCAL_VARIABLES); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 357 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 358 | bool parseSectionDirectiveIdent(StringRef, SMLoc) { |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 359 | // Darwin silently ignores the .ident directive. |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 360 | getParser().eatToEndOfStatement(); |
Jim Grosbach | 14be61a | 2011-03-08 19:17:19 +0000 | [diff] [blame] | 361 | return false; |
| 362 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 363 | bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) { |
| 364 | return parseSectionSwitch("__DATA", "__thread_init", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 365 | MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 366 | } |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 367 | bool parseVersionMin(StringRef, SMLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 368 | |
| 369 | }; |
| 370 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 371 | } // end anonymous namespace |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 372 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 373 | bool DarwinAsmParser::parseSectionSwitch(const char *Segment, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 374 | const char *Section, |
| 375 | unsigned TAA, unsigned Align, |
| 376 | unsigned StubSize) { |
| 377 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 378 | return TokError("unexpected token in section switching directive"); |
| 379 | Lex(); |
| 380 | |
| 381 | // FIXME: Arch specific. |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 382 | bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS; |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 383 | getStreamer().SwitchSection(getContext().getMachOSection( |
| 384 | Segment, Section, TAA, StubSize, |
| 385 | isText ? SectionKind::getText() |
| 386 | : SectionKind::getDataRel())); |
| 387 | |
| 388 | // Set the implicit alignment, if any. |
| 389 | // |
| 390 | // FIXME: This isn't really what 'as' does; I think it just uses the implicit |
| 391 | // alignment on the section (e.g., if one manually inserts bytes into the |
Bill Wendling | 5391eb6 | 2010-10-19 10:18:23 +0000 | [diff] [blame] | 392 | // section, then just issuing the section switch directive will not realign |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 393 | // the section. However, this is arguably more reasonable behavior, and there |
| 394 | // is no good reason for someone to intentionally emit incorrectly sized |
| 395 | // values into the implicitly aligned sections. |
| 396 | if (Align) |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 397 | getStreamer().EmitValueToAlignment(Align); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 398 | |
| 399 | return false; |
| 400 | } |
| 401 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 402 | /// parseDirectiveDesc |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 403 | /// ::= .desc identifier , expression |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 404 | bool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 405 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 406 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 407 | return TokError("expected identifier in directive"); |
| 408 | |
| 409 | // Handle the identifier as the key symbol. |
| 410 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 411 | |
| 412 | if (getLexer().isNot(AsmToken::Comma)) |
| 413 | return TokError("unexpected token in '.desc' directive"); |
| 414 | Lex(); |
| 415 | |
| 416 | int64_t DescValue; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 417 | if (getParser().parseAbsoluteExpression(DescValue)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 418 | return true; |
| 419 | |
| 420 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 421 | return TokError("unexpected token in '.desc' directive"); |
| 422 | |
| 423 | Lex(); |
| 424 | |
| 425 | // Set the n_desc field of this Symbol to this DescValue |
| 426 | getStreamer().EmitSymbolDesc(Sym, DescValue); |
| 427 | |
| 428 | return false; |
| 429 | } |
| 430 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 431 | /// parseDirectiveIndirectSymbol |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 432 | /// ::= .indirect_symbol identifier |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 433 | bool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) { |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 434 | const MCSectionMachO *Current = static_cast<const MCSectionMachO*>( |
| 435 | getStreamer().getCurrentSection().first); |
David Majnemer | cd481d3 | 2014-03-07 18:49:54 +0000 | [diff] [blame] | 436 | MachO::SectionType SectionType = Current->getType(); |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 437 | if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS && |
| 438 | SectionType != MachO::S_LAZY_SYMBOL_POINTERS && |
| 439 | SectionType != MachO::S_SYMBOL_STUBS) |
Kevin Enderby | 3aeada2 | 2013-08-28 17:50:59 +0000 | [diff] [blame] | 440 | return Error(Loc, "indirect symbol not in a symbol pointer or stub " |
| 441 | "section"); |
| 442 | |
| 443 | StringRef Name; |
| 444 | if (getParser().parseIdentifier(Name)) |
| 445 | return TokError("expected identifier in .indirect_symbol directive"); |
| 446 | |
| 447 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 448 | |
| 449 | // Assembler local symbols don't make any sense here. Complain loudly. |
| 450 | if (Sym->isTemporary()) |
| 451 | return TokError("non-local symbol required in directive"); |
| 452 | |
| 453 | if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_IndirectSymbol)) |
| 454 | return TokError("unable to emit indirect symbol attribute for: " + Name); |
| 455 | |
| 456 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 457 | return TokError("unexpected token in '.indirect_symbol' directive"); |
| 458 | |
| 459 | Lex(); |
| 460 | |
| 461 | return false; |
| 462 | } |
| 463 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 464 | /// parseDirectiveDumpOrLoad |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 465 | /// ::= ( .dump | .load ) "filename" |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 466 | bool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 467 | SMLoc IDLoc) { |
| 468 | bool IsDump = Directive == ".dump"; |
| 469 | if (getLexer().isNot(AsmToken::String)) |
| 470 | return TokError("expected string in '.dump' or '.load' directive"); |
| 471 | |
| 472 | Lex(); |
| 473 | |
| 474 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 475 | return TokError("unexpected token in '.dump' or '.load' directive"); |
| 476 | |
| 477 | Lex(); |
| 478 | |
| 479 | // FIXME: If/when .dump and .load are implemented they will be done in the |
| 480 | // the assembly parser and not have any need for an MCStreamer API. |
| 481 | if (IsDump) |
Joerg Sonnenberger | 74ba262 | 2011-05-19 18:00:13 +0000 | [diff] [blame] | 482 | return Warning(IDLoc, "ignoring directive .dump for now"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 483 | else |
Joerg Sonnenberger | 74ba262 | 2011-05-19 18:00:13 +0000 | [diff] [blame] | 484 | return Warning(IDLoc, "ignoring directive .load for now"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 487 | /// ParseDirectiveLinkerOption |
| 488 | /// ::= .linker_option "string" ( , "string" )* |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 489 | bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) { |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 490 | SmallVector<std::string, 4> Args; |
| 491 | for (;;) { |
| 492 | if (getLexer().isNot(AsmToken::String)) |
| 493 | return TokError("expected string in '" + Twine(IDVal) + "' directive"); |
| 494 | |
| 495 | std::string Data; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 496 | if (getParser().parseEscapedString(Data)) |
Daniel Dunbar | 16004b8 | 2013-01-18 01:25:48 +0000 | [diff] [blame] | 497 | return true; |
| 498 | |
| 499 | Args.push_back(Data); |
| 500 | |
| 501 | Lex(); |
| 502 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 503 | break; |
| 504 | |
| 505 | if (getLexer().isNot(AsmToken::Comma)) |
| 506 | return TokError("unexpected token in '" + Twine(IDVal) + "' directive"); |
| 507 | Lex(); |
| 508 | } |
| 509 | |
| 510 | getStreamer().EmitLinkerOptions(Args); |
| 511 | return false; |
| 512 | } |
| 513 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 514 | /// parseDirectiveLsym |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 515 | /// ::= .lsym identifier , expression |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 516 | bool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 517 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 518 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 519 | return TokError("expected identifier in directive"); |
| 520 | |
| 521 | // Handle the identifier as the key symbol. |
| 522 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 523 | |
| 524 | if (getLexer().isNot(AsmToken::Comma)) |
| 525 | return TokError("unexpected token in '.lsym' directive"); |
| 526 | Lex(); |
| 527 | |
| 528 | const MCExpr *Value; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 529 | if (getParser().parseExpression(Value)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 530 | return true; |
| 531 | |
| 532 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 533 | return TokError("unexpected token in '.lsym' directive"); |
| 534 | |
| 535 | Lex(); |
| 536 | |
| 537 | // We don't currently support this directive. |
| 538 | // |
| 539 | // FIXME: Diagnostic location! |
| 540 | (void) Sym; |
| 541 | return TokError("directive '.lsym' is unsupported"); |
| 542 | } |
| 543 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 544 | /// parseDirectiveSection: |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 545 | /// ::= .section identifier (',' identifier)* |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 546 | bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 547 | SMLoc Loc = getLexer().getLoc(); |
| 548 | |
| 549 | StringRef SectionName; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 550 | if (getParser().parseIdentifier(SectionName)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 551 | return Error(Loc, "expected identifier after '.section' directive"); |
| 552 | |
| 553 | // Verify there is a following comma. |
| 554 | if (!getLexer().is(AsmToken::Comma)) |
| 555 | return TokError("unexpected token in '.section' directive"); |
| 556 | |
| 557 | std::string SectionSpec = SectionName; |
| 558 | SectionSpec += ","; |
| 559 | |
| 560 | // Add all the tokens until the end of the line, ParseSectionSpecifier will |
| 561 | // handle this. |
| 562 | StringRef EOL = getLexer().LexUntilEndOfStatement(); |
| 563 | SectionSpec.append(EOL.begin(), EOL.end()); |
| 564 | |
| 565 | Lex(); |
| 566 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 567 | return TokError("unexpected token in '.section' directive"); |
| 568 | Lex(); |
| 569 | |
| 570 | |
| 571 | StringRef Segment, Section; |
Daniel Dunbar | f1d62cf | 2011-03-17 16:25:24 +0000 | [diff] [blame] | 572 | unsigned StubSize; |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 573 | unsigned TAA; |
| 574 | bool TAAParsed; |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 575 | std::string ErrorStr = |
| 576 | MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section, |
Stuart Hastings | 12d5312 | 2011-03-19 02:42:31 +0000 | [diff] [blame] | 577 | TAA, TAAParsed, StubSize); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 578 | |
| 579 | if (!ErrorStr.empty()) |
| 580 | return Error(Loc, ErrorStr.c_str()); |
| 581 | |
| 582 | // FIXME: Arch specific. |
| 583 | bool isText = Segment == "__TEXT"; // FIXME: Hack. |
| 584 | getStreamer().SwitchSection(getContext().getMachOSection( |
| 585 | Segment, Section, TAA, StubSize, |
| 586 | isText ? SectionKind::getText() |
| 587 | : SectionKind::getDataRel())); |
| 588 | return false; |
| 589 | } |
| 590 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 591 | /// ParseDirectivePushSection: |
| 592 | /// ::= .pushsection identifier (',' identifier)* |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 593 | bool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) { |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 594 | getStreamer().PushSection(); |
| 595 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 596 | if (parseDirectiveSection(S, Loc)) { |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 597 | getStreamer().PopSection(); |
| 598 | return true; |
| 599 | } |
| 600 | |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | /// ParseDirectivePopSection: |
| 605 | /// ::= .popsection |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 606 | bool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) { |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 607 | if (!getStreamer().PopSection()) |
| 608 | return TokError(".popsection without corresponding .pushsection"); |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | /// ParseDirectivePrevious: |
| 613 | /// ::= .previous |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 614 | bool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) { |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 615 | MCSectionSubPair PreviousSection = getStreamer().getPreviousSection(); |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 616 | if (!PreviousSection.first) |
| 617 | return TokError(".previous without corresponding .section"); |
Peter Collingbourne | 2f495b9 | 2013-04-17 21:18:16 +0000 | [diff] [blame] | 618 | getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second); |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 619 | return false; |
| 620 | } |
| 621 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 622 | /// ParseDirectiveSecureLogUnique |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 623 | /// ::= .secure_log_unique ... message ... |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 624 | bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 625 | StringRef LogMessage = getParser().parseStringToEndOfStatement(); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 626 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 627 | return TokError("unexpected token in '.secure_log_unique' directive"); |
| 628 | |
David Blaikie | dc3f01e | 2015-03-09 01:57:13 +0000 | [diff] [blame^] | 629 | if (getContext().getSecureLogUsed()) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 630 | return Error(IDLoc, ".secure_log_unique specified multiple times"); |
| 631 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 632 | // Get the secure log path. |
| 633 | const char *SecureLogFile = getContext().getSecureLogFile(); |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 634 | if (!SecureLogFile) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 635 | return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE " |
| 636 | "environment variable unset."); |
| 637 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 638 | // Open the secure log file if we haven't already. |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 639 | raw_ostream *OS = getContext().getSecureLog(); |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 640 | if (!OS) { |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 641 | std::error_code EC; |
| 642 | OS = new raw_fd_ostream(SecureLogFile, EC, |
Rafael Espindola | 90c7f1c | 2014-02-24 18:20:12 +0000 | [diff] [blame] | 643 | sys::fs::F_Append | sys::fs::F_Text); |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 644 | if (EC) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 645 | delete OS; |
| 646 | return Error(IDLoc, Twine("can't open secure log file: ") + |
Rafael Espindola | 3fd1e99 | 2014-08-25 18:16:47 +0000 | [diff] [blame] | 647 | SecureLogFile + " (" + EC.message() + ")"); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 648 | } |
| 649 | getContext().setSecureLog(OS); |
| 650 | } |
| 651 | |
Daniel Dunbar | 40a564f | 2010-07-18 20:15:59 +0000 | [diff] [blame] | 652 | // Write the message. |
Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 653 | unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc); |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 654 | *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier() |
| 655 | << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":" |
| 656 | << LogMessage + "\n"; |
| 657 | |
| 658 | getContext().setSecureLogUsed(true); |
| 659 | |
| 660 | return false; |
| 661 | } |
| 662 | |
| 663 | /// ParseDirectiveSecureLogReset |
| 664 | /// ::= .secure_log_reset |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 665 | bool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 666 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 667 | return TokError("unexpected token in '.secure_log_reset' directive"); |
| 668 | |
| 669 | Lex(); |
| 670 | |
| 671 | getContext().setSecureLogUsed(false); |
| 672 | |
| 673 | return false; |
| 674 | } |
| 675 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 676 | /// parseDirectiveSubsectionsViaSymbols |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 677 | /// ::= .subsections_via_symbols |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 678 | bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 679 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 680 | return TokError("unexpected token in '.subsections_via_symbols' directive"); |
| 681 | |
| 682 | Lex(); |
| 683 | |
| 684 | getStreamer().EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
| 685 | |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | /// ParseDirectiveTBSS |
| 690 | /// ::= .tbss identifier, size, align |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 691 | bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 692 | SMLoc IDLoc = getLexer().getLoc(); |
| 693 | StringRef Name; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 694 | if (getParser().parseIdentifier(Name)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 695 | return TokError("expected identifier in directive"); |
| 696 | |
| 697 | // Handle the identifier as the key symbol. |
| 698 | MCSymbol *Sym = getContext().GetOrCreateSymbol(Name); |
| 699 | |
| 700 | if (getLexer().isNot(AsmToken::Comma)) |
| 701 | return TokError("unexpected token in directive"); |
| 702 | Lex(); |
| 703 | |
| 704 | int64_t Size; |
| 705 | SMLoc SizeLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 706 | if (getParser().parseAbsoluteExpression(Size)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 707 | return true; |
| 708 | |
| 709 | int64_t Pow2Alignment = 0; |
| 710 | SMLoc Pow2AlignmentLoc; |
| 711 | if (getLexer().is(AsmToken::Comma)) { |
| 712 | Lex(); |
| 713 | Pow2AlignmentLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 714 | if (getParser().parseAbsoluteExpression(Pow2Alignment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 715 | return true; |
| 716 | } |
| 717 | |
| 718 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 719 | return TokError("unexpected token in '.tbss' directive"); |
| 720 | |
| 721 | Lex(); |
| 722 | |
| 723 | if (Size < 0) |
| 724 | return Error(SizeLoc, "invalid '.tbss' directive size, can't be less than" |
| 725 | "zero"); |
| 726 | |
| 727 | // FIXME: Diagnose overflow. |
| 728 | if (Pow2Alignment < 0) |
| 729 | return Error(Pow2AlignmentLoc, "invalid '.tbss' alignment, can't be less" |
| 730 | "than zero"); |
| 731 | |
| 732 | if (!Sym->isUndefined()) |
| 733 | return Error(IDLoc, "invalid symbol redefinition"); |
| 734 | |
| 735 | getStreamer().EmitTBSSSymbol(getContext().getMachOSection( |
| 736 | "__DATA", "__thread_bss", |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 737 | MachO::S_THREAD_LOCAL_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 738 | 0, SectionKind::getThreadBSS()), |
| 739 | Sym, Size, 1 << Pow2Alignment); |
| 740 | |
| 741 | return false; |
| 742 | } |
| 743 | |
| 744 | /// ParseDirectiveZerofill |
| 745 | /// ::= .zerofill segname , sectname [, identifier , size_expression [ |
| 746 | /// , align_expression ]] |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 747 | bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) { |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 748 | StringRef Segment; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 749 | if (getParser().parseIdentifier(Segment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 750 | return TokError("expected segment name after '.zerofill' directive"); |
| 751 | |
| 752 | if (getLexer().isNot(AsmToken::Comma)) |
| 753 | return TokError("unexpected token in directive"); |
| 754 | Lex(); |
| 755 | |
| 756 | StringRef Section; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 757 | if (getParser().parseIdentifier(Section)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 758 | return TokError("expected section name after comma in '.zerofill' " |
| 759 | "directive"); |
| 760 | |
| 761 | // If this is the end of the line all that was wanted was to create the |
| 762 | // the section but with no symbol. |
| 763 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 764 | // Create the zerofill section but no symbol |
| 765 | getStreamer().EmitZerofill(getContext().getMachOSection( |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 766 | Segment, Section, MachO::S_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 767 | 0, SectionKind::getBSS())); |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | if (getLexer().isNot(AsmToken::Comma)) |
| 772 | return TokError("unexpected token in directive"); |
| 773 | Lex(); |
| 774 | |
| 775 | SMLoc IDLoc = getLexer().getLoc(); |
| 776 | StringRef IDStr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 777 | if (getParser().parseIdentifier(IDStr)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 778 | return TokError("expected identifier in directive"); |
| 779 | |
| 780 | // handle the identifier as the key symbol. |
| 781 | MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr); |
| 782 | |
| 783 | if (getLexer().isNot(AsmToken::Comma)) |
| 784 | return TokError("unexpected token in directive"); |
| 785 | Lex(); |
| 786 | |
| 787 | int64_t Size; |
| 788 | SMLoc SizeLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 789 | if (getParser().parseAbsoluteExpression(Size)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 790 | return true; |
| 791 | |
| 792 | int64_t Pow2Alignment = 0; |
| 793 | SMLoc Pow2AlignmentLoc; |
| 794 | if (getLexer().is(AsmToken::Comma)) { |
| 795 | Lex(); |
| 796 | Pow2AlignmentLoc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 797 | if (getParser().parseAbsoluteExpression(Pow2Alignment)) |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 798 | return true; |
| 799 | } |
| 800 | |
| 801 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 802 | return TokError("unexpected token in '.zerofill' directive"); |
| 803 | |
| 804 | Lex(); |
| 805 | |
| 806 | if (Size < 0) |
| 807 | return Error(SizeLoc, "invalid '.zerofill' directive size, can't be less " |
| 808 | "than zero"); |
| 809 | |
| 810 | // NOTE: The alignment in the directive is a power of 2 value, the assembler |
| 811 | // may internally end up wanting an alignment in bytes. |
| 812 | // FIXME: Diagnose overflow. |
| 813 | if (Pow2Alignment < 0) |
| 814 | return Error(Pow2AlignmentLoc, "invalid '.zerofill' directive alignment, " |
| 815 | "can't be less than zero"); |
| 816 | |
| 817 | if (!Sym->isUndefined()) |
| 818 | return Error(IDLoc, "invalid symbol redefinition"); |
| 819 | |
| 820 | // Create the zerofill Symbol with Size and Pow2Alignment |
| 821 | // |
| 822 | // FIXME: Arch specific. |
| 823 | getStreamer().EmitZerofill(getContext().getMachOSection( |
David Majnemer | 7b58305 | 2014-03-07 07:36:05 +0000 | [diff] [blame] | 824 | Segment, Section, MachO::S_ZEROFILL, |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 825 | 0, SectionKind::getBSS()), |
| 826 | Sym, Size, 1 << Pow2Alignment); |
| 827 | |
| 828 | return false; |
| 829 | } |
| 830 | |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 831 | /// ParseDirectiveDataRegion |
| 832 | /// ::= .data_region [ ( jt8 | jt16 | jt32 ) ] |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 833 | bool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) { |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 834 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 835 | Lex(); |
| 836 | getStreamer().EmitDataRegion(MCDR_DataRegion); |
| 837 | return false; |
| 838 | } |
| 839 | StringRef RegionType; |
| 840 | SMLoc Loc = getParser().getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 841 | if (getParser().parseIdentifier(RegionType)) |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 842 | return TokError("expected region type after '.data_region' directive"); |
| 843 | int Kind = StringSwitch<int>(RegionType) |
| 844 | .Case("jt8", MCDR_DataRegionJT8) |
| 845 | .Case("jt16", MCDR_DataRegionJT16) |
| 846 | .Case("jt32", MCDR_DataRegionJT32) |
| 847 | .Default(-1); |
| 848 | if (Kind == -1) |
| 849 | return Error(Loc, "unknown region type in '.data_region' directive"); |
| 850 | Lex(); |
| 851 | |
| 852 | getStreamer().EmitDataRegion((MCDataRegionType)Kind); |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | /// ParseDirectiveDataRegionEnd |
| 857 | /// ::= .end_data_region |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 858 | bool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) { |
Jim Grosbach | 4b63d2a | 2012-05-18 19:12:01 +0000 | [diff] [blame] | 859 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 860 | return TokError("unexpected token in '.end_data_region' directive"); |
| 861 | |
| 862 | Lex(); |
| 863 | getStreamer().EmitDataRegion(MCDR_DataRegionEnd); |
| 864 | return false; |
| 865 | } |
| 866 | |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 867 | /// parseVersionMin |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame] | 868 | /// ::= .ios_version_min major,minor[,update] |
| 869 | /// ::= .macosx_version_min major,minor[,update] |
Jim Grosbach | 319026d | 2014-03-18 22:09:10 +0000 | [diff] [blame] | 870 | bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc) { |
Jim Grosbach | 448334a | 2014-03-18 22:09:05 +0000 | [diff] [blame] | 871 | int64_t Major = 0, Minor = 0, Update = 0; |
| 872 | int Kind = StringSwitch<int>(Directive) |
| 873 | .Case(".ios_version_min", MCVM_IOSVersionMin) |
| 874 | .Case(".macosx_version_min", MCVM_OSXVersionMin); |
| 875 | // Get the major version number. |
| 876 | if (getLexer().isNot(AsmToken::Integer)) |
| 877 | return TokError("invalid OS major version number"); |
| 878 | Major = getLexer().getTok().getIntVal(); |
| 879 | if (Major > 65535 || Major <= 0) |
| 880 | return TokError("invalid OS major version number"); |
| 881 | Lex(); |
| 882 | if (getLexer().isNot(AsmToken::Comma)) |
| 883 | return TokError("minor OS version number required, comma expected"); |
| 884 | Lex(); |
| 885 | // Get the minor version number. |
| 886 | if (getLexer().isNot(AsmToken::Integer)) |
| 887 | return TokError("invalid OS minor version number"); |
| 888 | Minor = getLexer().getTok().getIntVal(); |
| 889 | if (Minor > 255 || Minor < 0) |
| 890 | return TokError("invalid OS minor version number"); |
| 891 | Lex(); |
| 892 | // Get the update level, if specified |
| 893 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 894 | if (getLexer().isNot(AsmToken::Comma)) |
| 895 | return TokError("invalid update specifier, comma expected"); |
| 896 | Lex(); |
| 897 | if (getLexer().isNot(AsmToken::Integer)) |
| 898 | return TokError("invalid OS update number"); |
| 899 | Update = getLexer().getTok().getIntVal(); |
| 900 | if (Update > 255 || Update < 0) |
| 901 | return TokError("invalid OS update number"); |
| 902 | Lex(); |
| 903 | } |
| 904 | |
| 905 | // We've parsed a correct version specifier, so send it to the streamer. |
| 906 | getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update); |
| 907 | |
| 908 | return false; |
| 909 | } |
| 910 | |
Daniel Dunbar | 0cb91cf | 2010-07-12 20:51:51 +0000 | [diff] [blame] | 911 | namespace llvm { |
| 912 | |
| 913 | MCAsmParserExtension *createDarwinAsmParser() { |
| 914 | return new DarwinAsmParser; |
| 915 | } |
| 916 | |
Bill Wendling | ce4fe41 | 2012-08-08 06:30:30 +0000 | [diff] [blame] | 917 | } // end llvm namespace |