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/MCSymbol.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::ParseSectionDirectiveDataRelRoLocal>(".data.rel.ro.local");
57 &ELFAsmParser::ParseSectionDirectiveEhFrame>(".eh_frame");
58 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(".section");
60 &ELFAsmParser::ParseDirectivePushSection>(".pushsection");
61 addDirectiveHandler<&ELFAsmParser::ParseDirectivePopSection>(".popsection");
62 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
63 addDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
64 addDirectiveHandler<&ELFAsmParser::ParseDirectiveType>(".type");
65 addDirectiveHandler<&ELFAsmParser::ParseDirectiveIdent>(".ident");
66 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymver>(".symver");
67 addDirectiveHandler<&ELFAsmParser::ParseDirectiveVersion>(".version");
68 addDirectiveHandler<&ELFAsmParser::ParseDirectiveWeakref>(".weakref");
69 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
70 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(".local");
72 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".protected");
74 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".internal");
76 &ELFAsmParser::ParseDirectiveSymbolAttribute>(".hidden");
77 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSubsection>(".subsection");
80 // FIXME: Part of this logic is duplicated in the MCELFStreamer. What is
81 // the best way for us to get access to it?
82 bool ParseSectionDirectiveData(StringRef, SMLoc) {
83 return ParseSectionSwitch(".data", ELF::SHT_PROGBITS,
84 ELF::SHF_WRITE |ELF::SHF_ALLOC,
85 SectionKind::getDataRel());
87 bool ParseSectionDirectiveText(StringRef, SMLoc) {
88 return ParseSectionSwitch(".text", ELF::SHT_PROGBITS,
90 ELF::SHF_ALLOC, SectionKind::getText());
92 bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
93 return ParseSectionSwitch(".bss", ELF::SHT_NOBITS,
95 ELF::SHF_ALLOC, SectionKind::getBSS());
97 bool ParseSectionDirectiveRoData(StringRef, SMLoc) {
98 return ParseSectionSwitch(".rodata", ELF::SHT_PROGBITS,
100 SectionKind::getReadOnly());
102 bool ParseSectionDirectiveTData(StringRef, SMLoc) {
103 return ParseSectionSwitch(".tdata", ELF::SHT_PROGBITS,
105 ELF::SHF_TLS | ELF::SHF_WRITE,
106 SectionKind::getThreadData());
108 bool ParseSectionDirectiveTBSS(StringRef, SMLoc) {
109 return ParseSectionSwitch(".tbss", ELF::SHT_NOBITS,
111 ELF::SHF_TLS | ELF::SHF_WRITE,
112 SectionKind::getThreadBSS());
114 bool ParseSectionDirectiveDataRel(StringRef, SMLoc) {
115 return ParseSectionSwitch(".data.rel", ELF::SHT_PROGBITS,
118 SectionKind::getDataRel());
120 bool ParseSectionDirectiveDataRelRo(StringRef, SMLoc) {
121 return ParseSectionSwitch(".data.rel.ro", ELF::SHT_PROGBITS,
124 SectionKind::getReadOnlyWithRel());
126 bool ParseSectionDirectiveDataRelRoLocal(StringRef, SMLoc) {
127 return ParseSectionSwitch(".data.rel.ro.local", ELF::SHT_PROGBITS,
130 SectionKind::getReadOnlyWithRelLocal());
132 bool ParseSectionDirectiveEhFrame(StringRef, SMLoc) {
133 return ParseSectionSwitch(".eh_frame", ELF::SHT_PROGBITS,
136 SectionKind::getDataRel());
138 bool ParseDirectivePushSection(StringRef, SMLoc);
139 bool ParseDirectivePopSection(StringRef, SMLoc);
140 bool ParseDirectiveSection(StringRef, SMLoc);
141 bool ParseDirectiveSize(StringRef, SMLoc);
142 bool ParseDirectivePrevious(StringRef, SMLoc);
143 bool ParseDirectiveType(StringRef, SMLoc);
144 bool ParseDirectiveIdent(StringRef, SMLoc);
145 bool ParseDirectiveSymver(StringRef, SMLoc);
146 bool ParseDirectiveVersion(StringRef, SMLoc);
147 bool ParseDirectiveWeakref(StringRef, SMLoc);
148 bool ParseDirectiveSymbolAttribute(StringRef, SMLoc);
149 bool ParseDirectiveSubsection(StringRef, SMLoc);
152 bool ParseSectionName(StringRef &SectionName);
153 bool ParseSectionArguments(bool IsPush, SMLoc loc);
154 unsigned parseSunStyleSectionFlags();
159 /// ParseDirectiveSymbolAttribute
160 /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ]
161 bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) {
162 MCSymbolAttr Attr = StringSwitch<MCSymbolAttr>(Directive)
163 .Case(".weak", MCSA_Weak)
164 .Case(".local", MCSA_Local)
165 .Case(".hidden", MCSA_Hidden)
166 .Case(".internal", MCSA_Internal)
167 .Case(".protected", MCSA_Protected)
168 .Default(MCSA_Invalid);
169 assert(Attr != MCSA_Invalid && "unexpected symbol attribute directive!");
170 if (getLexer().isNot(AsmToken::EndOfStatement)) {
174 if (getParser().parseIdentifier(Name))
175 return TokError("expected identifier in directive");
177 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
179 getStreamer().EmitSymbolAttribute(Sym, Attr);
181 if (getLexer().is(AsmToken::EndOfStatement))
184 if (getLexer().isNot(AsmToken::Comma))
185 return TokError("unexpected token in directive");
194 bool ELFAsmParser::ParseSectionSwitch(StringRef Section, unsigned Type,
195 unsigned Flags, SectionKind Kind) {
196 const MCExpr *Subsection = nullptr;
197 if (getLexer().isNot(AsmToken::EndOfStatement)) {
198 if (getParser().parseExpression(Subsection))
202 getStreamer().SwitchSection(getContext().getELFSection(
203 Section, Type, Flags, Kind),
209 bool ELFAsmParser::ParseDirectiveSize(StringRef, SMLoc) {
211 if (getParser().parseIdentifier(Name))
212 return TokError("expected identifier in directive");
213 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
215 if (getLexer().isNot(AsmToken::Comma))
216 return TokError("unexpected token in directive");
220 if (getParser().parseExpression(Expr))
223 if (getLexer().isNot(AsmToken::EndOfStatement))
224 return TokError("unexpected token in directive");
226 getStreamer().EmitELFSize(Sym, Expr);
230 bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
231 // A section name can contain -, so we cannot just use
233 SMLoc FirstLoc = getLexer().getLoc();
236 if (getLexer().is(AsmToken::String)) {
237 SectionName = getTok().getIdentifier();
245 SMLoc PrevLoc = getLexer().getLoc();
246 if (getLexer().is(AsmToken::Minus)) {
248 Lex(); // Consume the "-".
249 } else if (getLexer().is(AsmToken::String)) {
250 CurSize = getTok().getIdentifier().size() + 2;
252 } else if (getLexer().is(AsmToken::Identifier)) {
253 CurSize = getTok().getIdentifier().size();
260 SectionName = StringRef(FirstLoc.getPointer(), Size);
262 // Make sure the following token is adjacent.
263 if (PrevLoc.getPointer() + CurSize != getTok().getLoc().getPointer())
272 static SectionKind computeSectionKind(unsigned Flags, unsigned ElemSize) {
273 if (Flags & ELF::SHF_EXECINSTR)
274 return SectionKind::getText();
275 if (Flags & ELF::SHF_TLS)
276 return SectionKind::getThreadData();
277 if (Flags & ELF::SHF_MERGE) {
278 if (Flags & ELF::SHF_STRINGS) {
283 return SectionKind::getMergeable1ByteCString();
285 return SectionKind::getMergeable2ByteCString();
287 return SectionKind::getMergeable4ByteCString();
294 return SectionKind::getMergeableConst4();
296 return SectionKind::getMergeableConst8();
298 return SectionKind::getMergeableConst16();
303 return SectionKind::getDataRel();
306 static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
309 for (unsigned i = 0; i < flagsStr.size(); i++) {
310 switch (flagsStr[i]) {
312 flags |= ELF::SHF_ALLOC;
315 flags |= ELF::SHF_EXCLUDE;
318 flags |= ELF::SHF_EXECINSTR;
321 flags |= ELF::SHF_WRITE;
324 flags |= ELF::SHF_MERGE;
327 flags |= ELF::SHF_STRINGS;
330 flags |= ELF::SHF_TLS;
333 flags |= ELF::XCORE_SHF_CP_SECTION;
336 flags |= ELF::XCORE_SHF_DP_SECTION;
339 flags |= ELF::SHF_GROUP;
342 *UseLastGroup = true;
352 unsigned ELFAsmParser::parseSunStyleSectionFlags() {
354 while (getLexer().is(AsmToken::Hash)) {
357 if (!getLexer().is(AsmToken::Identifier))
360 StringRef flagId = getTok().getIdentifier();
361 if (flagId == "alloc")
362 flags |= ELF::SHF_ALLOC;
363 else if (flagId == "execinstr")
364 flags |= ELF::SHF_EXECINSTR;
365 else if (flagId == "write")
366 flags |= ELF::SHF_WRITE;
367 else if (flagId == "tls")
368 flags |= ELF::SHF_TLS;
372 Lex(); // Eat the flag.
374 if (!getLexer().is(AsmToken::Comma))
376 Lex(); // Eat the comma.
382 bool ELFAsmParser::ParseDirectivePushSection(StringRef s, SMLoc loc) {
383 getStreamer().PushSection();
385 if (ParseSectionArguments(/*IsPush=*/true, loc)) {
386 getStreamer().PopSection();
393 bool ELFAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
394 if (!getStreamer().PopSection())
395 return TokError(".popsection without corresponding .pushsection");
399 // FIXME: This is a work in progress.
400 bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc loc) {
401 return ParseSectionArguments(/*IsPush=*/false, loc);
404 bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
405 StringRef SectionName;
407 if (ParseSectionName(SectionName))
408 return TokError("expected identifier in directive");
414 const MCExpr *Subsection = nullptr;
415 bool UseLastGroup = false;
417 // Set the defaults first.
418 if (SectionName == ".fini" || SectionName == ".init" ||
419 SectionName == ".rodata")
420 Flags |= ELF::SHF_ALLOC;
421 if (SectionName == ".fini" || SectionName == ".init")
422 Flags |= ELF::SHF_EXECINSTR;
424 if (getLexer().is(AsmToken::Comma)) {
427 if (IsPush && getLexer().isNot(AsmToken::String)) {
428 if (getParser().parseExpression(Subsection))
430 if (getLexer().isNot(AsmToken::Comma))
437 if (getLexer().isNot(AsmToken::String)) {
438 if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax()
439 || getLexer().isNot(AsmToken::Hash))
440 return TokError("expected string in directive");
441 extraFlags = parseSunStyleSectionFlags();
443 StringRef FlagsStr = getTok().getStringContents();
445 extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup);
448 if (extraFlags == -1U)
449 return TokError("unknown flag");
452 bool Mergeable = Flags & ELF::SHF_MERGE;
453 bool Group = Flags & ELF::SHF_GROUP;
454 if (Group && UseLastGroup)
455 return TokError("Section cannot specifiy a group name while also acting "
456 "as a member of the last group");
458 if (getLexer().isNot(AsmToken::Comma)) {
460 return TokError("Mergeable section must specify the type");
462 return TokError("Group section must specify the type");
465 if (getLexer().is(AsmToken::At) || getLexer().is(AsmToken::Percent) ||
466 getLexer().is(AsmToken::String)) {
467 if (!getLexer().is(AsmToken::String))
470 return TokError("expected '@<type>', '%<type>' or \"<type>\"");
472 if (getParser().parseIdentifier(TypeName))
473 return TokError("expected identifier in directive");
476 if (getLexer().isNot(AsmToken::Comma))
477 return TokError("expected the entry size");
479 if (getParser().parseAbsoluteExpression(Size))
482 return TokError("entry size must be positive");
486 if (getLexer().isNot(AsmToken::Comma))
487 return TokError("expected group name");
489 if (getParser().parseIdentifier(GroupName))
491 if (getLexer().is(AsmToken::Comma)) {
494 if (getParser().parseIdentifier(Linkage))
496 if (Linkage != "comdat")
497 return TokError("Linkage must be 'comdat'");
504 if (getLexer().isNot(AsmToken::EndOfStatement))
505 return TokError("unexpected token in directive");
507 unsigned Type = ELF::SHT_PROGBITS;
509 if (TypeName.empty()) {
510 if (SectionName.startswith(".note"))
511 Type = ELF::SHT_NOTE;
512 else if (SectionName == ".init_array")
513 Type = ELF::SHT_INIT_ARRAY;
514 else if (SectionName == ".fini_array")
515 Type = ELF::SHT_FINI_ARRAY;
516 else if (SectionName == ".preinit_array")
517 Type = ELF::SHT_PREINIT_ARRAY;
519 if (TypeName == "init_array")
520 Type = ELF::SHT_INIT_ARRAY;
521 else if (TypeName == "fini_array")
522 Type = ELF::SHT_FINI_ARRAY;
523 else if (TypeName == "preinit_array")
524 Type = ELF::SHT_PREINIT_ARRAY;
525 else if (TypeName == "nobits")
526 Type = ELF::SHT_NOBITS;
527 else if (TypeName == "progbits")
528 Type = ELF::SHT_PROGBITS;
529 else if (TypeName == "note")
530 Type = ELF::SHT_NOTE;
531 else if (TypeName == "unwind")
532 Type = ELF::SHT_X86_64_UNWIND;
534 return TokError("unknown section type");
538 MCSectionSubPair CurrentSection = getStreamer().getCurrentSection();
539 if (const MCSectionELF *Section =
540 cast_or_null<MCSectionELF>(CurrentSection.first))
541 if (const MCSymbol *Group = Section->getGroup()) {
542 GroupName = Group->getName();
543 Flags |= ELF::SHF_GROUP;
547 SectionKind Kind = computeSectionKind(Flags, Size);
548 const MCSection *ELFSection = getContext().getELFSection(
549 SectionName, Type, Flags, Kind, Size, GroupName);
550 getStreamer().SwitchSection(ELFSection, Subsection);
552 if (getContext().getGenDwarfForAssembly()) {
553 auto &Sections = getContext().getGenDwarfSectionSyms();
554 auto InsertResult = Sections.insert(
555 std::make_pair(ELFSection, std::make_pair(nullptr, nullptr)));
556 if (InsertResult.second) {
557 if (getContext().getDwarfVersion() <= 2)
558 Error(loc, "DWARF2 only supports one section per compilation unit");
560 MCSymbol *SectionStartSymbol = getContext().CreateTempSymbol();
561 getStreamer().EmitLabel(SectionStartSymbol);
562 InsertResult.first->second.first = SectionStartSymbol;
569 bool ELFAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
570 MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
571 if (PreviousSection.first == nullptr)
572 return TokError(".previous without corresponding .section");
573 getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
578 static MCSymbolAttr MCAttrForString(StringRef Type) {
579 return StringSwitch<MCSymbolAttr>(Type)
580 .Cases("STT_FUNC", "function", MCSA_ELF_TypeFunction)
581 .Cases("STT_OBJECT", "object", MCSA_ELF_TypeObject)
582 .Cases("STT_TLS", "tls_object", MCSA_ELF_TypeTLS)
583 .Cases("STT_COMMON", "common", MCSA_ELF_TypeCommon)
584 .Cases("STT_NOTYPE", "notype", MCSA_ELF_TypeNoType)
585 .Cases("STT_GNU_IFUNC", "gnu_indirect_function",
586 MCSA_ELF_TypeIndFunction)
587 .Case("gnu_unique_object", MCSA_ELF_TypeGnuUniqueObject)
588 .Default(MCSA_Invalid);
591 /// ParseDirectiveELFType
592 /// ::= .type identifier , STT_<TYPE_IN_UPPER_CASE>
593 /// ::= .type identifier , #attribute
594 /// ::= .type identifier , @attribute
595 /// ::= .type identifier , %attribute
596 /// ::= .type identifier , "attribute"
597 bool ELFAsmParser::ParseDirectiveType(StringRef, SMLoc) {
599 if (getParser().parseIdentifier(Name))
600 return TokError("expected identifier in directive");
602 // Handle the identifier as the key symbol.
603 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
605 // NOTE the comma is optional in all cases. It is only documented as being
606 // optional in the first case, however, GAS will silently treat the comma as
607 // optional in all cases. Furthermore, although the documentation states that
608 // the first form only accepts STT_<TYPE_IN_UPPER_CASE>, in reality, GAS
609 // accepts both the upper case name as well as the lower case aliases.
610 if (getLexer().is(AsmToken::Comma))
613 if (getLexer().isNot(AsmToken::Identifier) &&
614 getLexer().isNot(AsmToken::Hash) && getLexer().isNot(AsmToken::At) &&
615 getLexer().isNot(AsmToken::Percent) && getLexer().isNot(AsmToken::String))
616 return TokError("expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
617 "'%<type>' or \"<type>\"");
619 if (getLexer().isNot(AsmToken::String) &&
620 getLexer().isNot(AsmToken::Identifier))
623 SMLoc TypeLoc = getLexer().getLoc();
626 if (getParser().parseIdentifier(Type))
627 return TokError("expected symbol type in directive");
629 MCSymbolAttr Attr = MCAttrForString(Type);
630 if (Attr == MCSA_Invalid)
631 return Error(TypeLoc, "unsupported attribute in '.type' directive");
633 if (getLexer().isNot(AsmToken::EndOfStatement))
634 return TokError("unexpected token in '.type' directive");
637 getStreamer().EmitSymbolAttribute(Sym, Attr);
642 /// ParseDirectiveIdent
643 /// ::= .ident string
644 bool ELFAsmParser::ParseDirectiveIdent(StringRef, SMLoc) {
645 if (getLexer().isNot(AsmToken::String))
646 return TokError("unexpected token in '.ident' directive");
648 StringRef Data = getTok().getIdentifier();
652 getStreamer().EmitIdent(Data);
656 /// ParseDirectiveSymver
657 /// ::= .symver foo, bar2@zed
658 bool ELFAsmParser::ParseDirectiveSymver(StringRef, SMLoc) {
660 if (getParser().parseIdentifier(Name))
661 return TokError("expected identifier in directive");
663 if (getLexer().isNot(AsmToken::Comma))
664 return TokError("expected a comma");
666 // ARM assembly uses @ for a comment...
667 // except when parsing the second parameter of the .symver directive.
668 // Force the next symbol to allow @ in the identifier, which is
669 // required for this directive and then reset it to its initial state.
670 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
671 getLexer().setAllowAtInIdentifier(true);
673 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
676 if (getParser().parseIdentifier(AliasName))
677 return TokError("expected identifier in directive");
679 if (AliasName.find('@') == StringRef::npos)
680 return TokError("expected a '@' in the name");
682 MCSymbol *Alias = getContext().GetOrCreateSymbol(AliasName);
683 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
684 const MCExpr *Value = MCSymbolRefExpr::Create(Sym, getContext());
686 getStreamer().EmitAssignment(Alias, Value);
690 /// ParseDirectiveVersion
691 /// ::= .version string
692 bool ELFAsmParser::ParseDirectiveVersion(StringRef, SMLoc) {
693 if (getLexer().isNot(AsmToken::String))
694 return TokError("unexpected token in '.version' directive");
696 StringRef Data = getTok().getIdentifier();
700 const MCSection *Note =
701 getContext().getELFSection(".note", ELF::SHT_NOTE, 0,
702 SectionKind::getReadOnly());
704 getStreamer().PushSection();
705 getStreamer().SwitchSection(Note);
706 getStreamer().EmitIntValue(Data.size()+1, 4); // namesz.
707 getStreamer().EmitIntValue(0, 4); // descsz = 0 (no description).
708 getStreamer().EmitIntValue(1, 4); // type = NT_VERSION.
709 getStreamer().EmitBytes(Data); // name.
710 getStreamer().EmitIntValue(0, 1); // terminate the string.
711 getStreamer().EmitValueToAlignment(4); // ensure 4 byte alignment.
712 getStreamer().PopSection();
716 /// ParseDirectiveWeakref
717 /// ::= .weakref foo, bar
718 bool ELFAsmParser::ParseDirectiveWeakref(StringRef, SMLoc) {
719 // FIXME: Share code with the other alias building directives.
722 if (getParser().parseIdentifier(AliasName))
723 return TokError("expected identifier in directive");
725 if (getLexer().isNot(AsmToken::Comma))
726 return TokError("expected a comma");
731 if (getParser().parseIdentifier(Name))
732 return TokError("expected identifier in directive");
734 MCSymbol *Alias = getContext().GetOrCreateSymbol(AliasName);
736 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
738 getStreamer().EmitWeakReference(Alias, Sym);
742 bool ELFAsmParser::ParseDirectiveSubsection(StringRef, SMLoc) {
743 const MCExpr *Subsection = nullptr;
744 if (getLexer().isNot(AsmToken::EndOfStatement)) {
745 if (getParser().parseExpression(Subsection))
749 if (getLexer().isNot(AsmToken::EndOfStatement))
750 return TokError("unexpected token in directive");
752 getStreamer().SubSection(Subsection);
758 MCAsmParserExtension *createELFAsmParser() {
759 return new ELFAsmParser;