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 (parseLinkedToSym(LinkedToSym))
623 if (parseGroup(GroupName, IsComdat))
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")
680 else if (TypeName ==
"llvm_jt_sizes")
683 return TokError(
"unknown section type");
688 cast_or_null<MCSectionELF>(getStreamer().getCurrentSectionOnly()))
690 GroupName = Group->getName();
691 IsComdat =
Section->isComdat();
698 IsComdat, UniqueID, LinkedToSym);
699 getStreamer().switchSection(Section, Subsection);
707 utohexstr(
Section->getType()));
710 utohexstr(
Section->getFlags()));
716 if (getContext().getGenDwarfForAssembly() &&
719 bool InsertResult = getContext().addGenDwarfSection(Section);
721 Warning(loc,
"DWARF2 only supports one section per compilation unit");
727bool ELFAsmParser::parseDirectivePrevious(
StringRef DirName,
SMLoc) {
729 if (PreviousSection.first ==
nullptr)
730 return TokError(
".previous without corresponding .section");
731 getStreamer().switchSection(PreviousSection.first, PreviousSection.second);
743 .
Cases(
"STT_GNU_IFUNC",
"gnu_indirect_function",
757 if (getParser().parseIdentifier(
Name))
758 return TokError(
"expected identifier");
775 if (!getLexer().getAllowAtInIdentifier())
776 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', "
777 "'%<type>' or \"<type>\"");
779 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
780 "'%<type>' or \"<type>\"");
787 SMLoc TypeLoc = getLexer().getLoc();
790 if (getParser().parseIdentifier(
Type))
791 return TokError(
"expected symbol type");
795 return Error(TypeLoc,
"unsupported attribute");
798 return TokError(
"expected end of directive");
801 getStreamer().emitSymbolAttribute(
Sym, Attr);
810 return TokError(
"expected string");
812 StringRef Data = getTok().getIdentifier();
817 return TokError(
"expected end of directive");
820 getStreamer().emitIdent(Data);
828 if (getParser().parseIdentifier(OriginalName))
829 return TokError(
"expected identifier");
832 return TokError(
"expected a comma");
838 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
839 getLexer().setAllowAtInIdentifier(
true);
841 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
843 if (getParser().parseIdentifier(
Name))
844 return TokError(
"expected identifier");
846 if (!
Name.contains(
'@'))
847 return TokError(
"expected a '@' in the name");
848 bool KeepOriginalSym = !
Name.contains(
"@@@");
850 if (getParser().parseIdentifier(Action) || Action !=
"remove")
851 return TokError(
"expected 'remove'");
852 KeepOriginalSym =
false;
856 getStreamer().emitELFSymverDirective(
857 getContext().getOrCreateSymbol(OriginalName),
Name, KeepOriginalSym);
865 return TokError(
"expected string");
867 StringRef Data = getTok().getIdentifier();
873 getStreamer().pushSection();
874 getStreamer().switchSection(
Note);
875 getStreamer().emitInt32(Data.size() + 1);
876 getStreamer().emitInt32(0);
877 getStreamer().emitInt32(1);
878 getStreamer().emitBytes(Data);
879 getStreamer().emitInt8(0);
880 getStreamer().emitValueToAlignment(
Align(4));
881 getStreamer().popSection();
891 if (getParser().parseIdentifier(AliasName))
892 return TokError(
"expected identifier");
895 return TokError(
"expected a comma");
900 if (getParser().parseIdentifier(
Name))
901 return TokError(
"expected identifier");
903 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
907 getStreamer().emitWeakReference(Alias,
Sym);
914 if (getParser().parseExpression(Subsection))
919 return TokError(
"expected end of directive");
923 return getStreamer().switchSection(getStreamer().getCurrentSectionOnly(),
927bool ELFAsmParser::parseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
934 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
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=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...
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 *, uint32_t > 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.