1 //===- ELFAsmParser.cpp - ELF Assembly Parser -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
11 #include "llvm/ADT/StringSwitch.h"
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/MC/MCAsmInfo.h"
14 #include "llvm/MC/MCContext.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCParser/MCAsmLexer.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCSymbolELF.h"
20 #include "llvm/Support/ELF.h"
25 class ELFAsmParser : public MCAsmParserExtension {
26 template<bool (ELFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
27 void addDirectiveHandler(StringRef Directive) {
28 MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
29 this, HandleDirective<ELFAsmParser, HandlerMethod>);
31 getParser().addDirectiveHandler(Directive, Handler);
34 bool ParseSectionSwitch(StringRef Section, unsigned Type, unsigned Flags,
38 ELFAsmParser() { BracketExpressionsSupported = true; }
40 void Initialize(MCAsmParser &Parser) override {
41 // Call the base implementation.
42 this->MCAsmParserExtension::Initialize(Parser);
44 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");
51 &ELFAsmParser::ParseSectionDirectiveDataRel>(".data.rel");
53 &ELFAsmParser::ParseSectionDirectiveDataRelRo>(".data.rel.ro");
55 &ELFAsmParser::ParseSectionDirectiveEhFrame>(".eh_frame");
56 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(".section");
58 &ELFAsmParser::ParseDirectivePushSection>(".pushsection");
59 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");
70 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".protected");
72 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".internal");
74 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
75 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSubsection>(".subsection");
78 // FIXME: Part of this logic is duplicated in the MCELFStreamer. What is
79 // the best way for us to get access to it?
80 bool ParseSectionDirectiveData(StringRef, SMLoc) {
81 return ParseSectionSwitch(".data", ELF::SHT_PROGBITS,
82 ELF::SHF_WRITE | ELF::SHF_ALLOC,
83 SectionKind::getData());
85 bool ParseSectionDirectiveText(StringRef, SMLoc) {
86 return ParseSectionSwitch(".text", ELF::SHT_PROGBITS,
88 ELF::SHF_ALLOC, SectionKind::getText());
90 bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
91 return ParseSectionSwitch(".bss", ELF::SHT_NOBITS,
93 ELF::SHF_ALLOC, SectionKind::getBSS());
95 bool ParseSectionDirectiveRoData(StringRef, SMLoc) {
96 return ParseSectionSwitch(".rodata", ELF::SHT_PROGBITS,
98 SectionKind::getReadOnly());
100 bool ParseSectionDirectiveTData(StringRef, SMLoc) {
101 return ParseSectionSwitch(".tdata", ELF::SHT_PROGBITS,
103 ELF::SHF_TLS | ELF::SHF_WRITE,
104 SectionKind::getThreadData());
106 bool ParseSectionDirectiveTBSS(StringRef, SMLoc) {
107 return ParseSectionSwitch(".tbss", ELF::SHT_NOBITS,
109 ELF::SHF_TLS | ELF::SHF_WRITE,
110 SectionKind::getThreadBSS());
112 bool ParseSectionDirectiveDataRel(StringRef, SMLoc) {
113 return ParseSectionSwitch(".data.rel", ELF::SHT_PROGBITS,
114 ELF::SHF_ALLOC | ELF::SHF_WRITE,
115 SectionKind::getData());
117 bool ParseSectionDirectiveDataRelRo(StringRef, SMLoc) {
118 return ParseSectionSwitch(".data.rel.ro", ELF::SHT_PROGBITS,
121 SectionKind::getReadOnlyWithRel());
123 bool ParseSectionDirectiveEhFrame(StringRef, SMLoc) {
124 return ParseSectionSwitch(".eh_frame", ELF::SHT_PROGBITS,
125 ELF::SHF_ALLOC | ELF::SHF_WRITE,
126 SectionKind::getData());
128 bool ParseDirectivePushSection(StringRef, SMLoc);
129 bool ParseDirectivePopSection(StringRef, SMLoc);
130 bool ParseDirectiveSection(StringRef, SMLoc);
131 bool ParseDirectiveSize(StringRef, SMLoc);
132 bool ParseDirectivePrevious(StringRef, SMLoc);
133 bool ParseDirectiveType(StringRef, SMLoc);
134 bool ParseDirectiveIdent(StringRef, SMLoc);
135 bool ParseDirectiveSymver(StringRef, SMLoc);
136 bool ParseDirectiveVersion(StringRef, SMLoc);
137 bool ParseDirectiveWeakref(StringRef, SMLoc);
138 bool ParseDirectiveSymbolAttribute(StringRef, SMLoc);
139 bool ParseDirectiveSubsection(StringRef, SMLoc);
142 bool ParseSectionName(StringRef &SectionName);
143 bool ParseSectionArguments(bool IsPush, SMLoc loc);
144 unsigned parseSunStyleSectionFlags();
149 /// ParseDirectiveSymbolAttribute
150 /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
151 bool 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)) {
164 if (getParser().parseIdentifier(Name))
165 return TokError("expected identifier in directive");
167 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
169 getStreamer().EmitSymbolAttribute(Sym, Attr);
171 if (getLexer().is(AsmToken::EndOfStatement))
174 if (getLexer().isNot(AsmToken::Comma))
175 return TokError("unexpected token in directive");
184 bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
185 unsigned Flags, SectionKind Kind) {
186 const MCExpr *Subsection = nullptr;
187 if (getLexer().isNot(AsmToken::EndOfStatement)) {
188 if (getParser().parseExpression(Subsection))
193 getStreamer().SwitchSection(getContext().getELFSection(Section, Type, Flags),
199 bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
201 if (getParser().parseIdentifier(Name))
202 return TokError("expected identifier in directive");
203 MCSymbolELF *Sym = cast<MCSymbolELF>(getContext().getOrCreateSymbol(Name));
205 if (getLexer().isNot(AsmToken::Comma))
206 return TokError("unexpected token in directive");
210 if (getParser().parseExpression(Expr))
213 if (getLexer().isNot(AsmToken::EndOfStatement))
214 return TokError("unexpected token in directive");
217 getStreamer().emitELFSize(Sym, Expr);
221 bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
222 // A section name can contain -, so we cannot just use
224 SMLoc FirstLoc = getLexer().getLoc();
227 if (getLexer().is(AsmToken::String)) {
228 SectionName = getTok().getIdentifier();
235 SMLoc PrevLoc = getLexer().getLoc();
236 if (getLexer().is(AsmToken::Comma) ||
237 getLexer().is(AsmToken::EndOfStatement))
241 if (getLexer().is(AsmToken::String)) {
242 CurSize = getTok().getIdentifier().size() + 2;
244 } else if (getLexer().is(AsmToken::Identifier)) {
245 CurSize = getTok().getIdentifier().size();
248 CurSize = getTok().getString().size();
252 SectionName = StringRef(FirstLoc.getPointer(), Size);
254 // Make sure the following token is adjacent.
255 if (PrevLoc.getPointer() + CurSize != getTok().getLoc().getPointer())
264 static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
267 // If a valid numerical value is set for the section flag, use it verbatim
268 if (!flagsStr.getAsInteger(0, flags))
271 for (char i : flagsStr) {
274 flags |= ELF::SHF_ALLOC;
277 flags |= ELF::SHF_EXCLUDE;
280 flags |= ELF::SHF_EXECINSTR;
283 flags |= ELF::SHF_WRITE;
286 flags |= ELF::SHF_MERGE;
289 flags |= ELF::SHF_STRINGS;
292 flags |= ELF::SHF_TLS;
295 flags |= ELF::XCORE_SHF_CP_SECTION;
298 flags |= ELF::XCORE_SHF_DP_SECTION;
301 flags |= ELF::SHF_ARM_PURECODE;
304 flags |= ELF::SHF_GROUP;
307 *UseLastGroup = true;
317 unsigned ELFAsmParser::parseSunStyleSectionFlags() {
319 while (getLexer().is(AsmToken::Hash)) {
322 if (!getLexer().is(AsmToken::Identifier))
325 StringRef flagId = getTok().getIdentifier();
326 if (flagId == "alloc")
327 flags |= ELF::SHF_ALLOC;
328 else if (flagId == "execinstr")
329 flags |= ELF::SHF_EXECINSTR;
330 else if (flagId == "write")
331 flags |= ELF::SHF_WRITE;
332 else if (flagId == "tls")
333 flags |= ELF::SHF_TLS;
337 Lex(); // Eat the flag.
339 if (!getLexer().is(AsmToken::Comma))
341 Lex(); // Eat the comma.
347 bool ELFAsmParser::ParseDirectivePushSection(StringRef s, SMLoc loc) {
348 getStreamer().PushSection();
350 if (ParseSectionArguments(/*IsPush=*/true, loc)) {
351 getStreamer().PopSection();
358 bool ELFAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
359 if (!getStreamer().PopSection())
360 return TokError(".popsection without corresponding .pushsection");
364 // FIXME: This is a work in progress.
365 bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc loc) {
366 return ParseSectionArguments(/*IsPush=*/false, loc);
369 bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
370 StringRef SectionName;
372 if (ParseSectionName(SectionName))
373 return TokError("expected identifier in directive");
379 const MCExpr *Subsection = nullptr;
380 bool UseLastGroup = false;
382 int64_t UniqueID = ~0;
384 // Set the defaults first.
385 if (SectionName == ".fini" || SectionName == ".init" ||
386 SectionName == ".rodata")
387 Flags |= ELF::SHF_ALLOC;
388 if (SectionName == ".fini" || SectionName == ".init")
389 Flags |= ELF::SHF_EXECINSTR;
391 if (getLexer().is(AsmToken::Comma)) {
394 if (IsPush && getLexer().isNot(AsmToken::String)) {
395 if (getParser().parseExpression(Subsection))
397 if (getLexer().isNot(AsmToken::Comma))
404 if (getLexer().isNot(AsmToken::String)) {
405 if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
406 || getLexer().isNot(AsmToken::Hash))
407 return TokError("expected string in directive");
408 extraFlags = parseSunStyleSectionFlags();
410 StringRef FlagsStr = getTok().getStringContents();
412 extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
415 if (extraFlags == -1U)
416 return TokError("unknown flag");
419 bool Mergeable = Flags & ELF::SHF_MERGE;
420 bool Group = Flags & ELF::SHF_GROUP;
421 if (Group && UseLastGroup)
422 return TokError("Section cannot specifiy a group name while also acting "
423 "as a member of the last group");
425 if (getLexer().isNot(AsmToken::Comma)) {
427 return TokError("Mergeable section must specify the type");
429 return TokError("Group section must specify the type");
432 if (getLexer().is(AsmToken::At) || getLexer().is(AsmToken::Percent) ||
433 getLexer().is(AsmToken::String)) {
434 if (!getLexer().is(AsmToken::String))
437 return TokError("expected '@<type>', '%<type>' or \"<type>\"");
439 if (getParser().parseIdentifier(TypeName))
440 return TokError("expected identifier in directive");
443 if (getLexer().isNot(AsmToken::Comma))
444 return TokError("expected the entry size");
446 if (getParser().parseAbsoluteExpression(Size))
449 return TokError("entry size must be positive");
453 if (getLexer().isNot(AsmToken::Comma))
454 return TokError("expected group name");
456 if (getParser().parseIdentifier(GroupName))
458 if (getLexer().is(AsmToken::Comma)) {
461 if (getParser().parseIdentifier(Linkage))
463 if (Linkage != "comdat")
464 return TokError("Linkage must be 'comdat'");
467 if (getLexer().is(AsmToken::Comma)) {
469 if (getParser().parseIdentifier(UniqueStr))
470 return TokError("expected identifier in directive");
471 if (UniqueStr != "unique")
472 return TokError("expected 'unique'");
473 if (getLexer().isNot(AsmToken::Comma))
474 return TokError("expected commma");
476 if (getParser().parseAbsoluteExpression(UniqueID))
479 return TokError("unique id must be positive");
480 if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
481 return TokError("unique id is too large");
487 if (getLexer().isNot(AsmToken::EndOfStatement))
488 return TokError("unexpected token in directive");
491 unsigned Type = ELF::SHT_PROGBITS;
493 if (TypeName.empty()) {
494 if (SectionName.startswith(".note"))
495 Type = ELF::SHT_NOTE;
496 else if (SectionName == ".init_array")
497 Type = ELF::SHT_INIT_ARRAY;
498 else if (SectionName == ".fini_array")
499 Type = ELF::SHT_FINI_ARRAY;
500 else if (SectionName == ".preinit_array")
501 Type = ELF::SHT_PREINIT_ARRAY;
503 if (TypeName == "init_array")
504 Type = ELF::SHT_INIT_ARRAY;
505 else if (TypeName == "fini_array")
506 Type = ELF::SHT_FINI_ARRAY;
507 else if (TypeName == "preinit_array")
508 Type = ELF::SHT_PREINIT_ARRAY;
509 else if (TypeName == "nobits")
510 Type = ELF::SHT_NOBITS;
511 else if (TypeName == "progbits")
512 Type = ELF::SHT_PROGBITS;
513 else if (TypeName == "note")
514 Type = ELF::SHT_NOTE;
515 else if (TypeName == "unwind")
516 Type = ELF::SHT_X86_64_UNWIND;
518 return TokError("unknown section type");
522 MCSectionSubPair CurrentSection = getStreamer().getCurrentSection();
523 if (const MCSectionELF *Section =
524 cast_or_null<MCSectionELF>(CurrentSection.first))
525 if (const MCSymbol *Group = Section->getGroup()) {
526 GroupName = Group->getName();
527 Flags |= ELF::SHF_GROUP;
531 MCSection *ELFSection = getContext().getELFSection(SectionName, Type, Flags,
532 Size, GroupName, UniqueID);
533 getStreamer().SwitchSection(ELFSection, Subsection);
535 if (getContext().getGenDwarfForAssembly()) {
536 bool InsertResult = getContext().addGenDwarfSection(ELFSection);
538 if (getContext().getDwarfVersion() <= 2)
539 Warning(loc, "DWARF2 only supports one section per compilation unit");
541 if (!ELFSection->getBeginSymbol()) {
542 MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
543 getStreamer().EmitLabel(SectionStartSymbol);
544 ELFSection->setBeginSymbol(SectionStartSymbol);
552 bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
553 MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
554 if (PreviousSection.first == nullptr)
555 return TokError(".previous without corresponding .section");
556 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
561 static MCSymbolAttr MCAttrForString(StringRef Type) {
562 return StringSwitch<MCSymbolAttr>(Type)
563 .Cases("STT_FUNC", "function", MCSA_ELF_TypeFunction)
564 .Cases("STT_OBJECT", "object", MCSA_ELF_TypeObject)
565 .Cases("STT_TLS", "tls_object", MCSA_ELF_TypeTLS)
566 .Cases("STT_COMMON", "common", MCSA_ELF_TypeCommon)
567 .Cases("STT_NOTYPE", "notype", MCSA_ELF_TypeNoType)
568 .Cases("STT_GNU_IFUNC", "gnu_indirect_function",
569 MCSA_ELF_TypeIndFunction)
570 .Case("gnu_unique_object", MCSA_ELF_TypeGnuUniqueObject)
571 .Default(MCSA_Invalid);
574 /// ParseDirectiveELFType
575 /// ::= .type identifier , STT_<TYPE_IN_UPPER_CASE>
576 /// ::= .type identifier , #attribute
577 /// ::= .type identifier , @attribute
578 /// ::= .type identifier , %attribute
579 /// ::= .type identifier , "attribute"
580 bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
582 if (getParser().parseIdentifier(Name))
583 return TokError("expected identifier in directive");
585 // Handle the identifier as the key symbol.
586 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
588 // NOTE the comma is optional in all cases. It is only documented as being
589 // optional in the first case, however, GAS will silently treat the comma as
590 // optional in all cases. Furthermore, although the documentation states that
591 // the first form only accepts STT_<TYPE_IN_UPPER_CASE>, in reality, GAS
592 // accepts both the upper case name as well as the lower case aliases.
593 if (getLexer().is(AsmToken::Comma))
596 if (getLexer().isNot(AsmToken::Identifier) &&
597 getLexer().isNot(AsmToken::Hash) &&
598 getLexer().isNot(AsmToken::Percent) &&
599 getLexer().isNot(AsmToken::String)) {
600 if (!getLexer().getAllowAtInIdentifier())
601 return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', "
602 "'%<type>' or \"<type>\"");
603 else if (getLexer().isNot(AsmToken::At))
604 return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
605 "'%<type>' or \"<type>\"");
608 if (getLexer().isNot(AsmToken::String) &&
609 getLexer().isNot(AsmToken::Identifier))
612 SMLoc TypeLoc = getLexer().getLoc();
615 if (getParser().parseIdentifier(Type))
616 return TokError("expected symbol type in directive");
618 MCSymbolAttr Attr = MCAttrForString(Type);
619 if (Attr == MCSA_Invalid)
620 return Error(TypeLoc, "unsupported attribute in '.type' directive");
622 if (getLexer().isNot(AsmToken::EndOfStatement))
623 return TokError("unexpected token in '.type' directive");
626 getStreamer().EmitSymbolAttribute(Sym, Attr);
631 /// ParseDirectiveIdent
632 /// ::= .ident string
633 bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
634 if (getLexer().isNot(AsmToken::String))
635 return TokError("unexpected token in '.ident' directive");
637 StringRef Data = getTok().getIdentifier();
641 if (getLexer().isNot(AsmToken::EndOfStatement))
642 return TokError("unexpected token in '.ident' directive");
645 getStreamer().EmitIdent(Data);
649 /// ParseDirectiveSymver
650 /// ::= .symver foo, bar2@zed
651 bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
653 if (getParser().parseIdentifier(Name))
654 return TokError("expected identifier in directive");
656 if (getLexer().isNot(AsmToken::Comma))
657 return TokError("expected a comma");
659 // ARM assembly uses @ for a comment...
660 // except when parsing the second parameter of the .symver directive.
661 // Force the next symbol to allow @ in the identifier, which is
662 // required for this directive and then reset it to its initial state.
663 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
664 getLexer().setAllowAtInIdentifier(true);
666 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
669 if (getParser().parseIdentifier(AliasName))
670 return TokError("expected identifier in directive");
672 if (AliasName.find('@') == StringRef::npos)
673 return TokError("expected a '@' in the name");
675 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
676 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
677 const MCExpr *Value = MCSymbolRefExpr::create(Sym, getContext());
679 getStreamer().EmitAssignment(Alias, Value);
683 /// ParseDirectiveVersion
684 /// ::= .version string
685 bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
686 if (getLexer().isNot(AsmToken::String))
687 return TokError("unexpected token in '.version' directive");
689 StringRef Data = getTok().getIdentifier();
693 MCSection *Note = getContext().getELFSection(".note", ELF::SHT_NOTE, 0);
695 getStreamer().PushSection();
696 getStreamer().SwitchSection(Note);
697 getStreamer().EmitIntValue(Data.size()+1, 4); // namesz.
698 getStreamer().EmitIntValue(0, 4); // descsz = 0 (no description).
699 getStreamer().EmitIntValue(1, 4); // type = NT_VERSION.
700 getStreamer().EmitBytes(Data); // name.
701 getStreamer().EmitIntValue(0, 1); // terminate the string.
702 getStreamer().EmitValueToAlignment(4); // ensure 4 byte alignment.
703 getStreamer().PopSection();
707 /// ParseDirectiveWeakref
708 /// ::= .weakref foo, bar
709 bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
710 // FIXME: Share code with the other alias building directives.
713 if (getParser().parseIdentifier(AliasName))
714 return TokError("expected identifier in directive");
716 if (getLexer().isNot(AsmToken::Comma))
717 return TokError("expected a comma");
722 if (getParser().parseIdentifier(Name))
723 return TokError("expected identifier in directive");
725 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
727 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
729 getStreamer().EmitWeakReference(Alias, Sym);
733 bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
734 const MCExpr *Subsection = nullptr;
735 if (getLexer().isNot(AsmToken::EndOfStatement)) {
736 if (getParser().parseExpression(Subsection))
740 if (getLexer().isNot(AsmToken::EndOfStatement))
741 return TokError("unexpected token in directive");
745 getStreamer().SubSection(Subsection);
751 MCAsmParserExtension *createELFAsmParser() {
752 return new ELFAsmParser;