36 template<
bool (ELFAsmParser::*HandlerMethod)(StringRef, SMLoc)>
39 this, HandleDirective<ELFAsmParser, HandlerMethod>);
44 bool ParseSectionSwitch(
StringRef Section,
unsigned Type,
unsigned Flags,
48 ELFAsmParser() { BracketExpressionsSupported =
true; }
54 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveData>(
".data");
55 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveText>(
".text");
56 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveBSS>(
".bss");
57 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveRoData>(
".rodata");
58 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTData>(
".tdata");
59 addDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveTBSS>(
".tbss");
61 &ELFAsmParser::ParseSectionDirectiveDataRel>(
".data.rel");
63 &ELFAsmParser::ParseSectionDirectiveDataRelRo>(
".data.rel.ro");
65 &ELFAsmParser::ParseSectionDirectiveEhFrame>(
".eh_frame");
66 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(
".section");
68 &ELFAsmParser::ParseDirectivePushSection>(
".pushsection");
69 addDirectiveHandler<&ELFAsmParser::ParseDirectivePopSection>(
".popsection");
70 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(
".size");
71 addDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(
".previous");
72 addDirectiveHandler<&ELFAsmParser::ParseDirectiveType>(
".type");
73 addDirectiveHandler<&ELFAsmParser::ParseDirectiveIdent>(
".ident");
74 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymver>(
".symver");
75 addDirectiveHandler<&ELFAsmParser::ParseDirectiveVersion>(
".version");
76 addDirectiveHandler<&ELFAsmParser::ParseDirectiveWeakref>(
".weakref");
77 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(
".weak");
78 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSymbolAttribute>(
".local");
80 &ELFAsmParser::ParseDirectiveSymbolAttribute>(
".protected");
82 &ELFAsmParser::ParseDirectiveSymbolAttribute>(
".internal");
84 &ELFAsmParser::ParseDirectiveSymbolAttribute>(
".hidden");
85 addDirectiveHandler<&ELFAsmParser::ParseDirectiveSubsection>(
".subsection");
86 addDirectiveHandler<&ELFAsmParser::ParseDirectiveCGProfile>(
".cg_profile");
155 bool ParseSectionArguments(
bool IsPush,
SMLoc loc);
156 unsigned parseSunStyleSectionFlags();
157 bool maybeParseSectionType(
StringRef &TypeName);
158 bool parseMergeSize(int64_t &
Size);
159 bool parseGroup(
StringRef &GroupName,
bool &IsComdat);
161 bool maybeParseUniqueID(int64_t &UniqueID);
181 if (getParser().parseIdentifier(
Name))
182 return TokError(
"expected identifier");
184 if (getParser().discardLTOSymbol(
Name)) {
192 getStreamer().emitSymbolAttribute(
Sym, Attr);
198 return TokError(
"expected comma");
207bool ELFAsmParser::ParseSectionSwitch(
StringRef Section,
unsigned Type,
209 const MCExpr *Subsection =
nullptr;
211 if (getParser().parseExpression(Subsection))
216 getStreamer().switchSection(getContext().getELFSection(Section,
Type, Flags),
224 if (getParser().parseIdentifier(
Name))
225 return TokError(
"expected identifier");
229 return TokError(
"expected comma");
233 if (getParser().parseExpression(Expr))
237 return TokError(
"unexpected token");
240 getStreamer().emitELFSize(
Sym, Expr);
247 SMLoc FirstLoc = getLexer().getLoc();
256 while (!getParser().hasPendingError()) {
257 SMLoc PrevLoc = getLexer().getLoc();
264 CurSize = getTok().getIdentifier().size() + 2;
267 CurSize = getTok().getIdentifier().size();
270 CurSize = getTok().getString().size();
277 if (PrevLoc.
getPointer() + CurSize != getTok().getLoc().getPointer())
287 bool *UseLastGroup) {
294 for (
char i : flagsStr) {
331 if (!(TT.isARM() || TT.isThumb()))
349 if (TT.isOSSolaris())
355 *UseLastGroup =
true;
365unsigned ELFAsmParser::parseSunStyleSectionFlags() {
373 StringRef flagId = getTok().getIdentifier();
374 if (flagId ==
"alloc")
376 else if (flagId ==
"execinstr")
378 else if (flagId ==
"write")
380 else if (flagId ==
"tls")
395bool ELFAsmParser::ParseDirectivePushSection(
StringRef s,
SMLoc loc) {
396 getStreamer().pushSection();
398 if (ParseSectionArguments(
true, loc)) {
399 getStreamer().popSection();
407 if (!getStreamer().popSection())
408 return TokError(
".popsection without corresponding .pushsection");
413 return ParseSectionArguments(
false, loc);
416bool ELFAsmParser::maybeParseSectionType(
StringRef &TypeName) {
423 if (
L.getAllowAtInIdentifier())
424 return TokError(
"expected '@<type>', '%<type>' or \"<type>\"");
426 return TokError(
"expected '%<type>' or \"<type>\"");
433 }
else if (getParser().parseIdentifier(TypeName))
434 return TokError(
"expected identifier");
438bool ELFAsmParser::parseMergeSize(int64_t &
Size) {
440 return TokError(
"expected the entry size");
442 if (getParser().parseAbsoluteExpression(
Size))
445 return TokError(
"entry size must be positive");
449bool ELFAsmParser::parseGroup(
StringRef &GroupName,
bool &IsComdat) {
452 return TokError(
"expected group name");
455 GroupName = getTok().getString();
457 }
else if (getParser().parseIdentifier(GroupName)) {
458 return TokError(
"invalid group name");
463 if (getParser().parseIdentifier(Linkage))
464 return TokError(
"invalid linkage");
465 if (Linkage !=
"comdat")
466 return TokError(
"Linkage must be 'comdat'");
474bool ELFAsmParser::parseLinkedToSym(
MCSymbolELF *&LinkedToSym) {
477 return TokError(
"expected linked-to symbol");
480 SMLoc StartLoc =
L.getLoc();
481 if (getParser().parseIdentifier(
Name)) {
482 if (getParser().getTok().getString() ==
"0") {
484 LinkedToSym =
nullptr;
487 return TokError(
"invalid linked-to symbol");
489 LinkedToSym = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(
Name));
491 return Error(StartLoc,
"linked-to symbol is not in a section: " +
Name);
495bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) {
501 if (getParser().parseIdentifier(UniqueStr))
502 return TokError(
"expected identifier");
503 if (UniqueStr !=
"unique")
504 return TokError(
"expected 'unique'");
506 return TokError(
"expected commma");
508 if (getParser().parseAbsoluteExpression(UniqueID))
511 return TokError(
"unique id must be positive");
512 if (!isUInt<32>(UniqueID) || UniqueID == ~0U)
513 return TokError(
"unique id is too large");
539bool ELFAsmParser::ParseSectionArguments(
bool IsPush,
SMLoc loc) {
543 return TokError(
"expected identifier");
548 bool IsComdat =
false;
550 unsigned extraFlags = 0;
551 const MCExpr *Subsection =
nullptr;
552 bool UseLastGroup =
false;
554 int64_t UniqueID = ~0;
575 if (getParser().parseExpression(Subsection))
584 return TokError(
"expected string");
585 extraFlags = parseSunStyleSectionFlags();
587 StringRef FlagsStr = getTok().getStringContents();
593 if (extraFlags == -1U)
594 return TokError(
"unknown flag");
599 if (Group && UseLastGroup)
600 return TokError(
"Section cannot specifiy a group name while also acting "
601 "as a member of the last group");
603 if (maybeParseSectionType(TypeName))
609 return TokError(
"Mergeable section must specify the type");
611 return TokError(
"Group section must specify the type");
613 return TokError(
"expected end of directive");
617 if (parseMergeSize(
Size))
620 if (parseGroup(GroupName, IsComdat))
623 if (parseLinkedToSym(LinkedToSym))
625 if (maybeParseUniqueID(UniqueID))
631 return TokError(
"expected end of directive");
650 if (TypeName ==
"init_array")
652 else if (TypeName ==
"fini_array")
654 else if (TypeName ==
"preinit_array")
656 else if (TypeName ==
"nobits")
658 else if (TypeName ==
"progbits")
660 else if (TypeName ==
"note")
662 else if (TypeName ==
"unwind")
664 else if (TypeName ==
"llvm_odrtab")
666 else if (TypeName ==
"llvm_linker_options")
668 else if (TypeName ==
"llvm_call_graph_profile")
670 else if (TypeName ==
"llvm_dependent_libraries")
672 else if (TypeName ==
"llvm_sympart")
674 else if (TypeName ==
"llvm_bb_addr_map")
676 else if (TypeName ==
"llvm_offloading")
678 else if (TypeName ==
"llvm_lto")
681 return TokError(
"unknown section type");
687 cast_or_null<MCSectionELF>(CurrentSection.first))
689 GroupName = Group->getName();
690 IsComdat =
Section->isComdat();
697 IsComdat, UniqueID, LinkedToSym);
698 getStreamer().switchSection(Section, Subsection);
706 utohexstr(
Section->getType()));
709 utohexstr(
Section->getFlags()));
715 if (getContext().getGenDwarfForAssembly() &&
718 bool InsertResult = getContext().addGenDwarfSection(Section);
721 Warning(loc,
"DWARF2 only supports one section per compilation unit");
723 if (!
Section->getBeginSymbol()) {
724 MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
725 getStreamer().emitLabel(SectionStartSymbol);
726 Section->setBeginSymbol(SectionStartSymbol);
734bool ELFAsmParser::ParseDirectivePrevious(
StringRef DirName,
SMLoc) {
736 if (PreviousSection.first ==
nullptr)
737 return TokError(
".previous without corresponding .section");
738 getStreamer().switchSection(PreviousSection.first, PreviousSection.second);
750 .
Cases(
"STT_GNU_IFUNC",
"gnu_indirect_function",
764 if (getParser().parseIdentifier(
Name))
765 return TokError(
"expected identifier");
782 if (!getLexer().getAllowAtInIdentifier())
783 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', "
784 "'%<type>' or \"<type>\"");
786 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
787 "'%<type>' or \"<type>\"");
794 SMLoc TypeLoc = getLexer().getLoc();
797 if (getParser().parseIdentifier(
Type))
798 return TokError(
"expected symbol type");
802 return Error(TypeLoc,
"unsupported attribute");
805 return TokError(
"expected end of directive");
808 getStreamer().emitSymbolAttribute(
Sym, Attr);
817 return TokError(
"expected string");
824 return TokError(
"expected end of directive");
827 getStreamer().emitIdent(
Data);
835 if (getParser().parseIdentifier(OriginalName))
836 return TokError(
"expected identifier");
839 return TokError(
"expected a comma");
845 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
846 getLexer().setAllowAtInIdentifier(
true);
848 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
850 if (getParser().parseIdentifier(
Name))
851 return TokError(
"expected identifier");
853 if (!
Name.contains(
'@'))
854 return TokError(
"expected a '@' in the name");
855 bool KeepOriginalSym = !
Name.contains(
"@@@");
857 if (getParser().parseIdentifier(Action) || Action !=
"remove")
858 return TokError(
"expected 'remove'");
859 KeepOriginalSym =
false;
863 getStreamer().emitELFSymverDirective(
864 getContext().getOrCreateSymbol(OriginalName),
Name, KeepOriginalSym);
872 return TokError(
"expected string");
880 getStreamer().pushSection();
881 getStreamer().switchSection(
Note);
882 getStreamer().emitInt32(
Data.size() + 1);
883 getStreamer().emitInt32(0);
884 getStreamer().emitInt32(1);
885 getStreamer().emitBytes(
Data);
886 getStreamer().emitInt8(0);
887 getStreamer().emitValueToAlignment(
Align(4));
888 getStreamer().popSection();
898 if (getParser().parseIdentifier(AliasName))
899 return TokError(
"expected identifier");
902 return TokError(
"expected a comma");
907 if (getParser().parseIdentifier(
Name))
908 return TokError(
"expected identifier");
910 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
914 getStreamer().emitWeakReference(Alias,
Sym);
919 const MCExpr *Subsection =
nullptr;
921 if (getParser().parseExpression(Subsection))
926 return TokError(
"expected end of directive");
930 getStreamer().subSection(Subsection);
934bool ELFAsmParser::ParseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
941 return new ELFAsmParser;
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static bool hasPrefix(StringRef SectionName, StringRef Prefix)
static bool allowSectionTypeMismatch(const Triple &TT, StringRef SectionName, unsigned Type)
static unsigned parseSectionFlags(const Triple &TT, StringRef flagsStr, bool *UseLastGroup)
static MCSymbolAttr MCAttrForString(StringRef Type)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Lightweight error class with error context and mandatory checking.
Generic assembler lexer interface, for use by target specific assembly lexers.
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool ParseDirectiveCGProfile(StringRef, SMLoc)
ParseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
MCAsmParser & getParser()
Generic assembler parser interface, for use by target specific assembly parsers.
std::pair< MCAsmParserExtension *, DirectiveHandler > ExtensionDirectiveHandler
virtual void addDirectiveHandler(StringRef Directive, ExtensionDirectiveHandler Handler)=0
Base class for the full range of assembler expressions which are needed for parsing.
This represents a section on linux, lots of unix variants and some bare metal systems.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Represents a location in source code.
constexpr const char * getPointer() const
SectionKind - This is a simple POD value that classifies the properties of a section.
static SectionKind getThreadData()
static SectionKind getText()
static SectionKind getReadOnlyWithRel()
static SectionKind getData()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getReadOnly()
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
@ SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_LINKER_OPTIONS
@ SHT_LLVM_CALL_GRAPH_PROFILE
@ XCORE_SHF_DP_SECTION
All sections with the "d" flag are grouped together by the linker to form the data section and the dp...
@ XCORE_SHF_CP_SECTION
All sections with the "c" flag are grouped together by the linker to form the constant pool and the c...
ManagedStatic< cl::opt< FnT >, OptCreatorT > Action
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
This is an optimization pass for GlobalISel generic memory operations.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
MCAsmParserExtension * createELFAsmParser()
@ MCSA_Protected
.protected (ELF)
@ MCSA_Internal
.internal (ELF)
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_Invalid
Not a valid directive.
This struct is a compact representation of a valid (non-zero power of two) alignment.