blob: 8bfb475635cb02ce48a90c94741a48e56b27e467 [file] [log] [blame]
Daniel Dunbarab058b82010-07-12 21:23:32 +00001//===- ELFAsmParser.cpp - ELF 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"
Michael J. Spencer3d898232010-10-09 03:47:55 +000011#include "llvm/ADT/StringSwitch.h"
Eli Friedman9de59672010-07-17 06:27:28 +000012#include "llvm/ADT/Twine.h"
Eli Friedman9e36dd02010-07-17 04:29:04 +000013#include "llvm/MC/MCAsmInfo.h"
Daniel Dunbarab058b82010-07-12 21:23:32 +000014#include "llvm/MC/MCContext.h"
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +000015#include "llvm/MC/MCExpr.h"
Daniel Dunbarab058b82010-07-12 21:23:32 +000016#include "llvm/MC/MCParser/MCAsmLexer.h"
Eli Friedman9e36dd02010-07-17 04:29:04 +000017#include "llvm/MC/MCSectionELF.h"
18#include "llvm/MC/MCStreamer.h"
Rafael Espindolaa8695762015-06-02 00:25:12 +000019#include "llvm/MC/MCSymbolELF.h"
Rafael Espindolaaea49582011-01-23 04:28:49 +000020#include "llvm/Support/ELF.h"
Daniel Dunbarab058b82010-07-12 21:23:32 +000021using namespace llvm;
22
23namespace {
24
25class ELFAsmParser : public MCAsmParserExtension {
Eli Bendersky29b9f472013-01-16 00:50:52 +000026 template<bool (ELFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
Jim Grosbachd2037eb2013-02-20 22:21:35 +000027 void addDirectiveHandler(StringRef Directive) {
Eli Bendersky29b9f472013-01-16 00:50:52 +000028 MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
29 this, HandleDirective<ELFAsmParser, HandlerMethod>);
30
Jim Grosbachd2037eb2013-02-20 22:21:35 +000031 getParser().addDirectiveHandler(Directive, Handler);
Daniel Dunbar8897d472010-07-18 22:22:07 +000032 }
33
Rafael Espindola5645bad2013-10-16 01:05:45 +000034 bool ParseSectionSwitch(StringRef Section, unsigned Type, unsigned Flags,
35 SectionKind Kind);
Daniel Dunbarab058b82010-07-12 21:23:32 +000036
37public:
Rafael Espindola5645bad2013-10-16 01:05:45 +000038 ELFAsmParser() { BracketExpressionsSupported = true; }
Daniel Dunbarab058b82010-07-12 21:23:32 +000039
Craig Topper59be68f2014-03-08 07:14:16 +000040 void Initialize(MCAsmParser &Parser) override {
Daniel Dunbarab058b82010-07-12 21:23:32 +000041 // Call the base implementation.
42 this->MCAsmParserExtension::Initialize(Parser);
43
Jim Grosbachd2037eb2013-02-20 22:21:35 +000044 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveData>(".data");
45 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveText>(".text");
46 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveBSS>(".bss");
47 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveRoData>(".rodata");
48 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTData>(".tdata");
49 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTBSS>(".tbss");
50 addDirectiveHandler<
Jim Grosbach1a55fa62011-07-25 17:11:29 +000051 &ELFAsmParser::ParseSectionDirectiveDataRel>(".data.rel");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000052 addDirectiveHandler<
Jim Grosbach1a55fa62011-07-25 17:11:29 +000053 &ELFAsmParser::ParseSectionDirectiveDataRelRo>(".data.rel.ro");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000054 addDirectiveHandler<
Jim Grosbach1a55fa62011-07-25 17:11:29 +000055 &ELFAsmParser::ParseSectionDirectiveEhFrame>(".eh_frame");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000056 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(".section");
57 addDirectiveHandler<
Jim Grosbach1a55fa62011-07-25 17:11:29 +000058 &ELFAsmParser::ParseDirectivePushSection>(".pushsection");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000059 addDirectiveHandler<&ELFAsmParser::ParseDirectivePopSection>(".popsection");
60 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
61 addDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
62 addDirectiveHandler<&ELFAsmParser::ParseDirectiveType>(".type");
63 addDirectiveHandler<&ELFAsmParser::ParseDirectiveIdent>(".ident");
64 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymver>(".symver");
65 addDirectiveHandler<&ELFAsmParser::ParseDirectiveVersion>(".version");
66 addDirectiveHandler<&ELFAsmParser::ParseDirectiveWeakref>(".weakref");
67 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
68 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".local");
69 addDirectiveHandler<
Jim Grosbach38b1ed82011-07-25 17:55:35 +000070 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".protected");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000071 addDirectiveHandler<
Jim Grosbach38b1ed82011-07-25 17:55:35 +000072 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".internal");
Jim Grosbachd2037eb2013-02-20 22:21:35 +000073 addDirectiveHandler<
Jim Grosbach38b1ed82011-07-25 17:55:35 +000074 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
Peter Collingbourne2f495b92013-04-17 21:18:16 +000075 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSubsection>(".subsection");
Daniel Dunbarab058b82010-07-12 21:23:32 +000076 }
77
Rafael Espindolaf667d922010-09-15 21:48:40 +000078 // FIXME: Part of this logic is duplicated in the MCELFStreamer. What is
79 // the best way for us to get access to it?
Daniel Dunbarab058b82010-07-12 21:23:32 +000080 bool ParseSectionDirectiveData(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +000081 return ParseSectionSwitch(".data", ELF::SHT_PROGBITS,
Rafael Espindola449711c2015-11-18 06:02:15 +000082 ELF::SHF_WRITE | ELF::SHF_ALLOC,
83 SectionKind::getData());
Daniel Dunbarab058b82010-07-12 21:23:32 +000084 }
85 bool ParseSectionDirectiveText(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +000086 return ParseSectionSwitch(".text", ELF::SHT_PROGBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +000087 ELF::SHF_EXECINSTR |
88 ELF::SHF_ALLOC, SectionKind::getText());
Daniel Dunbarab058b82010-07-12 21:23:32 +000089 }
Matt Fleminga8f6c1c2010-07-20 21:12:46 +000090 bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +000091 return ParseSectionSwitch(".bss", ELF::SHT_NOBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +000092 ELF::SHF_WRITE |
93 ELF::SHF_ALLOC, SectionKind::getBSS());
Matt Fleminga8f6c1c2010-07-20 21:12:46 +000094 }
95 bool ParseSectionDirectiveRoData(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +000096 return ParseSectionSwitch(".rodata", ELF::SHT_PROGBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +000097 ELF::SHF_ALLOC,
Matt Fleminga8f6c1c2010-07-20 21:12:46 +000098 SectionKind::getReadOnly());
99 }
100 bool ParseSectionDirectiveTData(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000101 return ParseSectionSwitch(".tdata", ELF::SHT_PROGBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000102 ELF::SHF_ALLOC |
103 ELF::SHF_TLS | ELF::SHF_WRITE,
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000104 SectionKind::getThreadData());
105 }
106 bool ParseSectionDirectiveTBSS(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000107 return ParseSectionSwitch(".tbss", ELF::SHT_NOBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000108 ELF::SHF_ALLOC |
109 ELF::SHF_TLS | ELF::SHF_WRITE,
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000110 SectionKind::getThreadBSS());
111 }
112 bool ParseSectionDirectiveDataRel(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000113 return ParseSectionSwitch(".data.rel", ELF::SHT_PROGBITS,
Rafael Espindola449711c2015-11-18 06:02:15 +0000114 ELF::SHF_ALLOC | ELF::SHF_WRITE,
115 SectionKind::getData());
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000116 }
117 bool ParseSectionDirectiveDataRelRo(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000118 return ParseSectionSwitch(".data.rel.ro", ELF::SHT_PROGBITS,
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000119 ELF::SHF_ALLOC |
120 ELF::SHF_WRITE,
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000121 SectionKind::getReadOnlyWithRel());
122 }
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000123 bool ParseSectionDirectiveEhFrame(StringRef, SMLoc) {
Rafael Espindolaaea49582011-01-23 04:28:49 +0000124 return ParseSectionSwitch(".eh_frame", ELF::SHT_PROGBITS,
Rafael Espindola449711c2015-11-18 06:02:15 +0000125 ELF::SHF_ALLOC | ELF::SHF_WRITE,
126 SectionKind::getData());
Matt Fleminga8f6c1c2010-07-20 21:12:46 +0000127 }
Rafael Espindola58ac6e12011-02-16 01:08:29 +0000128 bool ParseDirectivePushSection(StringRef, SMLoc);
129 bool ParseDirectivePopSection(StringRef, SMLoc);
Eli Friedman9e36dd02010-07-17 04:29:04 +0000130 bool ParseDirectiveSection(StringRef, SMLoc);
131 bool ParseDirectiveSize(StringRef, SMLoc);
Benjamin Kramere39017c2010-09-02 18:53:37 +0000132 bool ParseDirectivePrevious(StringRef, SMLoc);
Michael J. Spencer3d898232010-10-09 03:47:55 +0000133 bool ParseDirectiveType(StringRef, SMLoc);
Rafael Espindolac9fb35e2010-10-26 19:35:47 +0000134 bool ParseDirectiveIdent(StringRef, SMLoc);
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000135 bool ParseDirectiveSymver(StringRef, SMLoc);
Benjamin Kramer6bee7f72012-05-12 14:30:47 +0000136 bool ParseDirectiveVersion(StringRef, SMLoc);
Rafael Espindola16145972010-11-01 14:28:48 +0000137 bool ParseDirectiveWeakref(StringRef, SMLoc);
Jim Grosbach38b1ed82011-07-25 17:55:35 +0000138 bool ParseDirectiveSymbolAttribute(StringRef, SMLoc);
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000139 bool ParseDirectiveSubsection(StringRef, SMLoc);
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000140
141private:
142 bool ParseSectionName(StringRef &SectionName);
Oliver Stannard8b273082014-06-19 15:52:37 +0000143 bool ParseSectionArguments(bool IsPush, SMLoc loc);
Venkatraman Govindarajubf705662014-03-01 06:21:00 +0000144 unsigned parseSunStyleSectionFlags();
Daniel Dunbarab058b82010-07-12 21:23:32 +0000145};
146
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000147}
Daniel Dunbarab058b82010-07-12 21:23:32 +0000148
Jim Grosbach38b1ed82011-07-25 17:55:35 +0000149/// ParseDirectiveSymbolAttribute
150/// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
151bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
152 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
153 .Case(".weak", MCSA_Weak)
154 .Case(".local", MCSA_Local)
155 .Case(".hidden", MCSA_Hidden)
156 .Case(".internal", MCSA_Internal)
157 .Case(".protected", MCSA_Protected)
158 .Default(MCSA_Invalid);
159 assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
160 if (getLexer().isNot(AsmToken::EndOfStatement)) {
161 for (;;) {
162 StringRef Name;
163
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000164 if (getParser().parseIdentifier(Name))
Jim Grosbach38b1ed82011-07-25 17:55:35 +0000165 return TokError("expected identifier in directive");
166
Jim Grosbach6f482002015-05-18 18:43:14 +0000167 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Jim Grosbach38b1ed82011-07-25 17:55:35 +0000168
169 getStreamer().EmitSymbolAttribute(Sym, Attr);
170
171 if (getLexer().is(AsmToken::EndOfStatement))
172 break;
173
174 if (getLexer().isNot(AsmToken::Comma))
175 return TokError("unexpected token in directive");
176 Lex();
177 }
178 }
179
180 Lex();
181 return false;
182}
183
Daniel Dunbarab058b82010-07-12 21:23:32 +0000184bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
185 unsigned Flags, SectionKind Kind) {
Craig Topper353eda42014-04-24 06:44:33 +0000186 const MCExpr *Subsection = nullptr;
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000187 if (getLexer().isNot(AsmToken::EndOfStatement)) {
188 if (getParser().parseExpression(Subsection))
189 return true;
190 }
Nirav Dave53a72f42016-07-11 12:42:14 +0000191 Lex();
Daniel Dunbarab058b82010-07-12 21:23:32 +0000192
Rafael Espindolaba31e272015-01-29 17:33:21 +0000193 getStreamer().SwitchSection(getContext().getELFSection(Section, Type, Flags),
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000194 Subsection);
Daniel Dunbarab058b82010-07-12 21:23:32 +0000195
196 return false;
197}
198
Eli Friedman9e36dd02010-07-17 04:29:04 +0000199bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
Eli Friedman56178a02010-07-17 03:09:18 +0000200 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000201 if (getParser().parseIdentifier(Name))
Eli Friedman56178a02010-07-17 03:09:18 +0000202 return TokError("expected identifier in directive");
Rafael Espindolaa8695762015-06-02 00:25:12 +0000203 MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
Eli Friedman56178a02010-07-17 03:09:18 +0000204
205 if (getLexer().isNot(AsmToken::Comma))
206 return TokError("unexpected token in directive");
207 Lex();
208
209 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000210 if (getParser().parseExpression(Expr))
Eli Friedman56178a02010-07-17 03:09:18 +0000211 return true;
212
213 if (getLexer().isNot(AsmToken::EndOfStatement))
214 return TokError("unexpected token in directive");
Nirav Davea645433c2016-07-18 15:24:03 +0000215 Lex();
Eli Friedman56178a02010-07-17 03:09:18 +0000216
Rafael Espindolaa8695762015-06-02 00:25:12 +0000217 getStreamer().emitELFSize(Sym, Expr);
Eli Friedman56178a02010-07-17 03:09:18 +0000218 return false;
219}
220
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000221bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
222 // A section name can contain -, so we cannot just use
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000223 // parseIdentifier.
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000224 SMLoc FirstLoc = getLexer().getLoc();
225 unsigned Size = 0;
226
Rafael Espindola689939e2011-01-24 18:02:54 +0000227 if (getLexer().is(AsmToken::String)) {
228 SectionName = getTok().getIdentifier();
229 Lex();
230 return false;
231 }
232
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000233 for (;;) {
Marina Yatsina33ef7da2016-03-22 11:23:15 +0000234
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000235 SMLoc PrevLoc = getLexer().getLoc();
Marina Yatsina33ef7da2016-03-22 11:23:15 +0000236 if (getLexer().is(AsmToken::Comma) ||
237 getLexer().is(AsmToken::EndOfStatement))
238 break;
239
240 unsigned CurSize;
241 if (getLexer().is(AsmToken::String)) {
Rafael Espindola689939e2011-01-24 18:02:54 +0000242 CurSize = getTok().getIdentifier().size() + 2;
243 Lex();
244 } else if (getLexer().is(AsmToken::Identifier)) {
245 CurSize = getTok().getIdentifier().size();
246 Lex();
247 } else {
Marina Yatsina33ef7da2016-03-22 11:23:15 +0000248 CurSize = getTok().getString().size();
249 Lex();
Rafael Espindola689939e2011-01-24 18:02:54 +0000250 }
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000251 Size += CurSize;
252 SectionName = StringRef(FirstLoc.getPointer(), Size);
253
254 // Make sure the following token is adjacent.
255 if (PrevLoc.getPointer() + CurSize != getTok().getLoc().getPointer())
256 break;
257 }
258 if (Size == 0)
259 return true;
260
261 return false;
262}
263
Benjamin Kramerac511ca2013-09-15 19:53:20 +0000264static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
265 unsigned flags = 0;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000266
Benjamin Kramer7b4658f2016-06-26 14:49:00 +0000267 for (char i : flagsStr) {
268 switch (i) {
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000269 case 'a':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000270 flags |= ELF::SHF_ALLOC;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000271 break;
Benjamin Kramerac511ca2013-09-15 19:53:20 +0000272 case 'e':
273 flags |= ELF::SHF_EXCLUDE;
274 break;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000275 case 'x':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000276 flags |= ELF::SHF_EXECINSTR;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000277 break;
278 case 'w':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000279 flags |= ELF::SHF_WRITE;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000280 break;
281 case 'M':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000282 flags |= ELF::SHF_MERGE;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000283 break;
284 case 'S':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000285 flags |= ELF::SHF_STRINGS;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000286 break;
287 case 'T':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000288 flags |= ELF::SHF_TLS;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000289 break;
290 case 'c':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000291 flags |= ELF::XCORE_SHF_CP_SECTION;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000292 break;
293 case 'd':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000294 flags |= ELF::XCORE_SHF_DP_SECTION;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000295 break;
Prakhar Bahuguna52a7dd72016-12-15 07:59:08 +0000296 case 'y':
297 flags |= ELF::SHF_ARM_PURECODE;
298 break;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000299 case 'G':
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000300 flags |= ELF::SHF_GROUP;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000301 break;
David Majnemera4b521b2013-09-15 19:24:16 +0000302 case '?':
303 *UseLastGroup = true;
304 break;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000305 default:
Benjamin Kramerac511ca2013-09-15 19:53:20 +0000306 return -1U;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000307 }
308 }
309
310 return flags;
311}
312
Venkatraman Govindarajubf705662014-03-01 06:21:00 +0000313unsigned ELFAsmParser::parseSunStyleSectionFlags() {
314 unsigned flags = 0;
315 while (getLexer().is(AsmToken::Hash)) {
316 Lex(); // Eat the #.
317
318 if (!getLexer().is(AsmToken::Identifier))
319 return -1U;
320
321 StringRef flagId = getTok().getIdentifier();
322 if (flagId == "alloc")
323 flags |= ELF::SHF_ALLOC;
324 else if (flagId == "execinstr")
325 flags |= ELF::SHF_EXECINSTR;
326 else if (flagId == "write")
327 flags |= ELF::SHF_WRITE;
328 else if (flagId == "tls")
329 flags |= ELF::SHF_TLS;
330 else
331 return -1U;
332
333 Lex(); // Eat the flag.
334
335 if (!getLexer().is(AsmToken::Comma))
336 break;
337 Lex(); // Eat the comma.
338 }
339 return flags;
340}
341
342
Rafael Espindola58ac6e12011-02-16 01:08:29 +0000343bool ELFAsmParser::ParseDirectivePushSection(StringRef s, SMLoc loc) {
344 getStreamer().PushSection();
345
Oliver Stannard8b273082014-06-19 15:52:37 +0000346 if (ParseSectionArguments(/*IsPush=*/true, loc)) {
Rafael Espindola58ac6e12011-02-16 01:08:29 +0000347 getStreamer().PopSection();
348 return true;
349 }
350
351 return false;
352}
353
354bool ELFAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
355 if (!getStreamer().PopSection())
356 return TokError(".popsection without corresponding .pushsection");
357 return false;
358}
359
Eli Friedman9e36dd02010-07-17 04:29:04 +0000360// FIXME: This is a work in progress.
Oliver Stannard8b273082014-06-19 15:52:37 +0000361bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc loc) {
362 return ParseSectionArguments(/*IsPush=*/false, loc);
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000363}
364
Oliver Stannard8b273082014-06-19 15:52:37 +0000365bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
Eli Friedman9e36dd02010-07-17 04:29:04 +0000366 StringRef SectionName;
Rafael Espindolaf7f43322010-09-16 17:05:55 +0000367
368 if (ParseSectionName(SectionName))
Eli Friedman9e36dd02010-07-17 04:29:04 +0000369 return TokError("expected identifier in directive");
370
Eli Friedman9e36dd02010-07-17 04:29:04 +0000371 StringRef TypeName;
372 int64_t Size = 0;
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000373 StringRef GroupName;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000374 unsigned Flags = 0;
Craig Topper353eda42014-04-24 06:44:33 +0000375 const MCExpr *Subsection = nullptr;
David Majnemera4b521b2013-09-15 19:24:16 +0000376 bool UseLastGroup = false;
Rafael Espindola68fa2492015-02-17 20:48:01 +0000377 StringRef UniqueStr;
Rafael Espindola8ca44f02015-04-04 18:02:01 +0000378 int64_t UniqueID = ~0;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000379
380 // Set the defaults first.
381 if (SectionName == ".fini" || SectionName == ".init" ||
382 SectionName == ".rodata")
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000383 Flags |= ELF::SHF_ALLOC;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000384 if (SectionName == ".fini" || SectionName == ".init")
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000385 Flags |= ELF::SHF_EXECINSTR;
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000386
Eli Friedman9e36dd02010-07-17 04:29:04 +0000387 if (getLexer().is(AsmToken::Comma)) {
388 Lex();
389
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000390 if (IsPush && getLexer().isNot(AsmToken::String)) {
391 if (getParser().parseExpression(Subsection))
392 return true;
393 if (getLexer().isNot(AsmToken::Comma))
394 goto EndStmt;
395 Lex();
396 }
Eli Friedman9e36dd02010-07-17 04:29:04 +0000397
Venkatraman Govindarajubf705662014-03-01 06:21:00 +0000398 unsigned extraFlags;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000399
Venkatraman Govindarajubf705662014-03-01 06:21:00 +0000400 if (getLexer().isNot(AsmToken::String)) {
401 if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
402 || getLexer().isNot(AsmToken::Hash))
403 return TokError("expected string in directive");
404 extraFlags = parseSunStyleSectionFlags();
405 } else {
406 StringRef FlagsStr = getTok().getStringContents();
407 Lex();
408 extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
409 }
410
Benjamin Kramerac511ca2013-09-15 19:53:20 +0000411 if (extraFlags == -1U)
Rafael Espindolaf8e127e2010-11-25 15:32:56 +0000412 return TokError("unknown flag");
413 Flags |= extraFlags;
414
Rafael Espindola0e7e34e2011-01-23 04:43:11 +0000415 bool Mergeable = Flags & ELF::SHF_MERGE;
416 bool Group = Flags & ELF::SHF_GROUP;
David Majnemera4b521b2013-09-15 19:24:16 +0000417 if (Group && UseLastGroup)
418 return TokError("Section cannot specifiy a group name while also acting "
419 "as a member of the last group");
Eli Friedman9e36dd02010-07-17 04:29:04 +0000420
Rafael Espindola8aefb662010-10-28 21:33:33 +0000421 if (getLexer().isNot(AsmToken::Comma)) {
422 if (Mergeable)
423 return TokError("Mergeable section must specify the type");
424 if (Group)
425 return TokError("Group section must specify the type");
426 } else {
427 Lex();
David Majnemerf90c3b52013-09-21 05:25:12 +0000428 if (getLexer().is(AsmToken::At) || getLexer().is(AsmToken::Percent) ||
429 getLexer().is(AsmToken::String)) {
430 if (!getLexer().is(AsmToken::String))
431 Lex();
432 } else
433 return TokError("expected '@<type>', '%<type>' or \"<type>\"");
Rafael Espindola8aefb662010-10-28 21:33:33 +0000434
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000435 if (getParser().parseIdentifier(TypeName))
Rafael Espindola8aefb662010-10-28 21:33:33 +0000436 return TokError("expected identifier in directive");
437
438 if (Mergeable) {
439 if (getLexer().isNot(AsmToken::Comma))
440 return TokError("expected the entry size");
441 Lex();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000442 if (getParser().parseAbsoluteExpression(Size))
Rafael Espindola8aefb662010-10-28 21:33:33 +0000443 return true;
444 if (Size <= 0)
445 return TokError("entry size must be positive");
446 }
447
448 if (Group) {
449 if (getLexer().isNot(AsmToken::Comma))
450 return TokError("expected group name");
451 Lex();
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000452 if (getParser().parseIdentifier(GroupName))
Rafael Espindola8aefb662010-10-28 21:33:33 +0000453 return true;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000454 if (getLexer().is(AsmToken::Comma)) {
455 Lex();
Rafael Espindola8aefb662010-10-28 21:33:33 +0000456 StringRef Linkage;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000457 if (getParser().parseIdentifier(Linkage))
Eli Friedman9e36dd02010-07-17 04:29:04 +0000458 return true;
Rafael Espindolaa3e9a222010-11-11 18:13:52 +0000459 if (Linkage != "comdat")
460 return TokError("Linkage must be 'comdat'");
Eli Friedman9e36dd02010-07-17 04:29:04 +0000461 }
462 }
Rafael Espindola68fa2492015-02-17 20:48:01 +0000463 if (getLexer().is(AsmToken::Comma)) {
464 Lex();
465 if (getParser().parseIdentifier(UniqueStr))
466 return TokError("expected identifier in directive");
467 if (UniqueStr != "unique")
468 return TokError("expected 'unique'");
Rafael Espindola41e2b5c2015-04-06 16:34:41 +0000469 if (getLexer().isNot(AsmToken::Comma))
470 return TokError("expected commma");
471 Lex();
Rafael Espindola8ca44f02015-04-04 18:02:01 +0000472 if (getParser().parseAbsoluteExpression(UniqueID))
473 return true;
474 if (UniqueID < 0)
475 return TokError("unique id must be positive");
476 if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
477 return TokError("unique id is too large");
Rafael Espindola68fa2492015-02-17 20:48:01 +0000478 }
Eli Friedman9e36dd02010-07-17 04:29:04 +0000479 }
480 }
481
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000482EndStmt:
Eli Friedman9e36dd02010-07-17 04:29:04 +0000483 if (getLexer().isNot(AsmToken::EndOfStatement))
484 return TokError("unexpected token in directive");
Nirav Davea645433c2016-07-18 15:24:03 +0000485 Lex();
Eli Friedman9e36dd02010-07-17 04:29:04 +0000486
Rafael Espindolaaea49582011-01-23 04:28:49 +0000487 unsigned Type = ELF::SHT_PROGBITS;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000488
Joerg Sonnenbergere2bb3142013-02-16 00:32:53 +0000489 if (TypeName.empty()) {
490 if (SectionName.startswith(".note"))
491 Type = ELF::SHT_NOTE;
492 else if (SectionName == ".init_array")
493 Type = ELF::SHT_INIT_ARRAY;
494 else if (SectionName == ".fini_array")
495 Type = ELF::SHT_FINI_ARRAY;
496 else if (SectionName == ".preinit_array")
497 Type = ELF::SHT_PREINIT_ARRAY;
498 } else {
Eli Friedman9e36dd02010-07-17 04:29:04 +0000499 if (TypeName == "init_array")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000500 Type = ELF::SHT_INIT_ARRAY;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000501 else if (TypeName == "fini_array")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000502 Type = ELF::SHT_FINI_ARRAY;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000503 else if (TypeName == "preinit_array")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000504 Type = ELF::SHT_PREINIT_ARRAY;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000505 else if (TypeName == "nobits")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000506 Type = ELF::SHT_NOBITS;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000507 else if (TypeName == "progbits")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000508 Type = ELF::SHT_PROGBITS;
Rafael Espindola9ae2d052010-12-26 21:30:59 +0000509 else if (TypeName == "note")
Rafael Espindolaaea49582011-01-23 04:28:49 +0000510 Type = ELF::SHT_NOTE;
Rafael Espindola4b7b7fb2011-01-23 05:43:40 +0000511 else if (TypeName == "unwind")
512 Type = ELF::SHT_X86_64_UNWIND;
Eli Friedman9e36dd02010-07-17 04:29:04 +0000513 else
514 return TokError("unknown section type");
515 }
516
David Majnemera4b521b2013-09-15 19:24:16 +0000517 if (UseLastGroup) {
518 MCSectionSubPair CurrentSection = getStreamer().getCurrentSection();
519 if (const MCSectionELF *Section =
520 cast_or_null<MCSectionELF>(CurrentSection.first))
521 if (const MCSymbol *Group = Section->getGroup()) {
522 GroupName = Group->getName();
523 Flags |= ELF::SHF_GROUP;
524 }
525 }
526
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000527 MCSection *ELFSection = getContext().getELFSection(SectionName, Type, Flags,
528 Size, GroupName, UniqueID);
Oliver Stannard8b273082014-06-19 15:52:37 +0000529 getStreamer().SwitchSection(ELFSection, Subsection);
530
531 if (getContext().getGenDwarfForAssembly()) {
Rafael Espindolae0746792015-05-21 16:52:32 +0000532 bool InsertResult = getContext().addGenDwarfSection(ELFSection);
533 if (InsertResult) {
Oliver Stannard8b273082014-06-19 15:52:37 +0000534 if (getContext().getDwarfVersion() <= 2)
Oliver Stannard14f97d02014-09-22 10:45:16 +0000535 Warning(loc, "DWARF2 only supports one section per compilation unit");
Oliver Stannard8b273082014-06-19 15:52:37 +0000536
Rafael Espindola2f9bdd82015-05-27 20:52:32 +0000537 if (!ELFSection->getBeginSymbol()) {
538 MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
539 getStreamer().EmitLabel(SectionStartSymbol);
540 ELFSection->setBeginSymbol(SectionStartSymbol);
541 }
Oliver Stannard8b273082014-06-19 15:52:37 +0000542 }
543 }
544
Eli Friedman9e36dd02010-07-17 04:29:04 +0000545 return false;
546}
547
Benjamin Kramere39017c2010-09-02 18:53:37 +0000548bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000549 MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
Craig Topper353eda42014-04-24 06:44:33 +0000550 if (PreviousSection.first == nullptr)
Rafael Espindola58ac6e12011-02-16 01:08:29 +0000551 return TokError(".previous without corresponding .section");
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000552 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
Benjamin Kramere39017c2010-09-02 18:53:37 +0000553
554 return false;
555}
556
Saleem Abdulrasool13b414a2014-06-08 00:34:34 +0000557static MCSymbolAttr MCAttrForString(StringRef Type) {
558 return StringSwitch<MCSymbolAttr>(Type)
559 .Cases("STT_FUNC", "function", MCSA_ELF_TypeFunction)
560 .Cases("STT_OBJECT", "object", MCSA_ELF_TypeObject)
561 .Cases("STT_TLS", "tls_object", MCSA_ELF_TypeTLS)
562 .Cases("STT_COMMON", "common", MCSA_ELF_TypeCommon)
563 .Cases("STT_NOTYPE", "notype", MCSA_ELF_TypeNoType)
564 .Cases("STT_GNU_IFUNC", "gnu_indirect_function",
565 MCSA_ELF_TypeIndFunction)
566 .Case("gnu_unique_object", MCSA_ELF_TypeGnuUniqueObject)
567 .Default(MCSA_Invalid);
568}
569
Michael J. Spencer3d898232010-10-09 03:47:55 +0000570/// ParseDirectiveELFType
David Majnemerf90c3b52013-09-21 05:25:12 +0000571/// ::= .type identifier , STT_<TYPE_IN_UPPER_CASE>
572/// ::= .type identifier , #attribute
Michael J. Spencer3d898232010-10-09 03:47:55 +0000573/// ::= .type identifier , @attribute
David Majnemerf90c3b52013-09-21 05:25:12 +0000574/// ::= .type identifier , %attribute
575/// ::= .type identifier , "attribute"
Michael J. Spencer3d898232010-10-09 03:47:55 +0000576bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
577 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000578 if (getParser().parseIdentifier(Name))
Michael J. Spencer3d898232010-10-09 03:47:55 +0000579 return TokError("expected identifier in directive");
580
581 // Handle the identifier as the key symbol.
Jim Grosbach6f482002015-05-18 18:43:14 +0000582 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Michael J. Spencer3d898232010-10-09 03:47:55 +0000583
Saleem Abdulrasool13b414a2014-06-08 00:34:34 +0000584 // NOTE the comma is optional in all cases. It is only documented as being
585 // optional in the first case, however, GAS will silently treat the comma as
586 // optional in all cases. Furthermore, although the documentation states that
587 // the first form only accepts STT_<TYPE_IN_UPPER_CASE>, in reality, GAS
588 // accepts both the upper case name as well as the lower case aliases.
589 if (getLexer().is(AsmToken::Comma))
590 Lex();
Michael J. Spencer3d898232010-10-09 03:47:55 +0000591
Saleem Abdulrasool13b414a2014-06-08 00:34:34 +0000592 if (getLexer().isNot(AsmToken::Identifier) &&
Gabor Ballabasaf06a882015-07-01 08:58:49 +0000593 getLexer().isNot(AsmToken::Hash) &&
594 getLexer().isNot(AsmToken::Percent) &&
595 getLexer().isNot(AsmToken::String)) {
596 if (!getLexer().getAllowAtInIdentifier())
597 return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', "
598 "'%<type>' or \"<type>\"");
599 else if (getLexer().isNot(AsmToken::At))
600 return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
601 "'%<type>' or \"<type>\"");
602 }
Michael J. Spencer3d898232010-10-09 03:47:55 +0000603
Saleem Abdulrasool13b414a2014-06-08 00:34:34 +0000604 if (getLexer().isNot(AsmToken::String) &&
605 getLexer().isNot(AsmToken::Identifier))
606 Lex();
607
608 SMLoc TypeLoc = getLexer().getLoc();
609
610 StringRef Type;
611 if (getParser().parseIdentifier(Type))
612 return TokError("expected symbol type in directive");
613
614 MCSymbolAttr Attr = MCAttrForString(Type);
Michael J. Spencer3d898232010-10-09 03:47:55 +0000615 if (Attr == MCSA_Invalid)
616 return Error(TypeLoc, "unsupported attribute in '.type' directive");
617
618 if (getLexer().isNot(AsmToken::EndOfStatement))
619 return TokError("unexpected token in '.type' directive");
Michael J. Spencer3d898232010-10-09 03:47:55 +0000620 Lex();
621
622 getStreamer().EmitSymbolAttribute(Sym, Attr);
623
624 return false;
625}
626
Rafael Espindolac9fb35e2010-10-26 19:35:47 +0000627/// ParseDirectiveIdent
628/// ::= .ident string
629bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
630 if (getLexer().isNot(AsmToken::String))
631 return TokError("unexpected token in '.ident' directive");
632
633 StringRef Data = getTok().getIdentifier();
634
635 Lex();
636
Nirav Davea645433c2016-07-18 15:24:03 +0000637 if (getLexer().isNot(AsmToken::EndOfStatement))
638 return TokError("unexpected token in '.ident' directive");
639 Lex();
640
Rafael Espindola5645bad2013-10-16 01:05:45 +0000641 getStreamer().EmitIdent(Data);
Rafael Espindolac9fb35e2010-10-26 19:35:47 +0000642 return false;
643}
644
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000645/// ParseDirectiveSymver
646/// ::= .symver foo, bar2@zed
647bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
648 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000649 if (getParser().parseIdentifier(Name))
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000650 return TokError("expected identifier in directive");
651
652 if (getLexer().isNot(AsmToken::Comma))
653 return TokError("expected a comma");
654
David Peixottoc0f92a22014-01-15 22:40:02 +0000655 // ARM assembly uses @ for a comment...
656 // except when parsing the second parameter of the .symver directive.
657 // Force the next symbol to allow @ in the identifier, which is
658 // required for this directive and then reset it to its initial state.
659 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
660 getLexer().setAllowAtInIdentifier(true);
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000661 Lex();
David Peixottoc0f92a22014-01-15 22:40:02 +0000662 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000663
664 StringRef AliasName;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000665 if (getParser().parseIdentifier(AliasName))
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000666 return TokError("expected identifier in directive");
667
668 if (AliasName.find('@') == StringRef::npos)
669 return TokError("expected a '@' in the name");
670
Jim Grosbach6f482002015-05-18 18:43:14 +0000671 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
672 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Jim Grosbach13760bd2015-05-30 01:25:56 +0000673 const MCExpr *Value = MCSymbolRefExpr::create(Sym, getContext());
Rafael Espindolaeb0c2c12010-10-27 15:18:17 +0000674
675 getStreamer().EmitAssignment(Alias, Value);
676 return false;
677}
678
Benjamin Kramer6bee7f72012-05-12 14:30:47 +0000679/// ParseDirectiveVersion
680/// ::= .version string
681bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
682 if (getLexer().isNot(AsmToken::String))
683 return TokError("unexpected token in '.version' directive");
684
685 StringRef Data = getTok().getIdentifier();
686
687 Lex();
688
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000689 MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
Benjamin Kramer6bee7f72012-05-12 14:30:47 +0000690
691 getStreamer().PushSection();
692 getStreamer().SwitchSection(Note);
693 getStreamer().EmitIntValue(Data.size()+1, 4); // namesz.
694 getStreamer().EmitIntValue(0, 4); // descsz = 0 (no description).
695 getStreamer().EmitIntValue(1, 4); // type = NT_VERSION.
Eric Christophere3ab3d02013-01-09 01:57:54 +0000696 getStreamer().EmitBytes(Data); // name.
Benjamin Kramer6bee7f72012-05-12 14:30:47 +0000697 getStreamer().EmitIntValue(0, 1); // terminate the string.
698 getStreamer().EmitValueToAlignment(4); // ensure 4 byte alignment.
699 getStreamer().PopSection();
700 return false;
701}
702
Rafael Espindola16145972010-11-01 14:28:48 +0000703/// ParseDirectiveWeakref
704/// ::= .weakref foo, bar
705bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
706 // FIXME: Share code with the other alias building directives.
707
708 StringRef AliasName;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000709 if (getParser().parseIdentifier(AliasName))
Rafael Espindola16145972010-11-01 14:28:48 +0000710 return TokError("expected identifier in directive");
711
712 if (getLexer().isNot(AsmToken::Comma))
713 return TokError("expected a comma");
714
715 Lex();
716
717 StringRef Name;
Jim Grosbachd2037eb2013-02-20 22:21:35 +0000718 if (getParser().parseIdentifier(Name))
Rafael Espindola16145972010-11-01 14:28:48 +0000719 return TokError("expected identifier in directive");
720
Jim Grosbach6f482002015-05-18 18:43:14 +0000721 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
Rafael Espindola16145972010-11-01 14:28:48 +0000722
Jim Grosbach6f482002015-05-18 18:43:14 +0000723 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Rafael Espindola16145972010-11-01 14:28:48 +0000724
725 getStreamer().EmitWeakReference(Alias, Sym);
726 return false;
727}
728
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000729bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
Craig Topper353eda42014-04-24 06:44:33 +0000730 const MCExpr *Subsection = nullptr;
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000731 if (getLexer().isNot(AsmToken::EndOfStatement)) {
732 if (getParser().parseExpression(Subsection))
733 return true;
734 }
735
736 if (getLexer().isNot(AsmToken::EndOfStatement))
737 return TokError("unexpected token in directive");
738
Nirav Davea645433c2016-07-18 15:24:03 +0000739 Lex();
740
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000741 getStreamer().SubSection(Subsection);
742 return false;
743}
744
Daniel Dunbarab058b82010-07-12 21:23:32 +0000745namespace llvm {
746
747MCAsmParserExtension *createELFAsmParser() {
748 return new ELFAsmParser;
749}
750
751}