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")
681 return TokError(
"unknown section type");
686 cast_or_null<MCSectionELF>(getStreamer().getCurrentSectionOnly()))
688 GroupName = Group->getName();
689 IsComdat =
Section->isComdat();
696 IsComdat, UniqueID, LinkedToSym);
697 getStreamer().switchSection(Section, Subsection);
705 utohexstr(
Section->getType()));
708 utohexstr(
Section->getFlags()));
714 if (getContext().getGenDwarfForAssembly() &&
717 bool InsertResult = getContext().addGenDwarfSection(Section);
719 Warning(loc,
"DWARF2 only supports one section per compilation unit");
725bool ELFAsmParser::ParseDirectivePrevious(
StringRef DirName,
SMLoc) {
727 if (PreviousSection.first ==
nullptr)
728 return TokError(
".previous without corresponding .section");
729 getStreamer().switchSection(PreviousSection.first, PreviousSection.second);
741 .
Cases(
"STT_GNU_IFUNC",
"gnu_indirect_function",
755 if (getParser().parseIdentifier(
Name))
756 return TokError(
"expected identifier");
773 if (!getLexer().getAllowAtInIdentifier())
774 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', "
775 "'%<type>' or \"<type>\"");
777 return TokError(
"expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '@<type>', "
778 "'%<type>' or \"<type>\"");
785 SMLoc TypeLoc = getLexer().getLoc();
788 if (getParser().parseIdentifier(
Type))
789 return TokError(
"expected symbol type");
793 return Error(TypeLoc,
"unsupported attribute");
796 return TokError(
"expected end of directive");
799 getStreamer().emitSymbolAttribute(
Sym, Attr);
808 return TokError(
"expected string");
810 StringRef Data = getTok().getIdentifier();
815 return TokError(
"expected end of directive");
818 getStreamer().emitIdent(Data);
826 if (getParser().parseIdentifier(OriginalName))
827 return TokError(
"expected identifier");
830 return TokError(
"expected a comma");
836 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
837 getLexer().setAllowAtInIdentifier(
true);
839 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
841 if (getParser().parseIdentifier(
Name))
842 return TokError(
"expected identifier");
844 if (!
Name.contains(
'@'))
845 return TokError(
"expected a '@' in the name");
846 bool KeepOriginalSym = !
Name.contains(
"@@@");
848 if (getParser().parseIdentifier(Action) || Action !=
"remove")
849 return TokError(
"expected 'remove'");
850 KeepOriginalSym =
false;
854 getStreamer().emitELFSymverDirective(
855 getContext().getOrCreateSymbol(OriginalName),
Name, KeepOriginalSym);
863 return TokError(
"expected string");
865 StringRef Data = getTok().getIdentifier();
871 getStreamer().pushSection();
872 getStreamer().switchSection(
Note);
873 getStreamer().emitInt32(Data.size() + 1);
874 getStreamer().emitInt32(0);
875 getStreamer().emitInt32(1);
876 getStreamer().emitBytes(Data);
877 getStreamer().emitInt8(0);
878 getStreamer().emitValueToAlignment(
Align(4));
879 getStreamer().popSection();
889 if (getParser().parseIdentifier(AliasName))
890 return TokError(
"expected identifier");
893 return TokError(
"expected a comma");
898 if (getParser().parseIdentifier(
Name))
899 return TokError(
"expected identifier");
901 MCSymbol *Alias = getContext().getOrCreateSymbol(AliasName);
905 getStreamer().emitWeakReference(Alias,
Sym);
912 if (getParser().parseExpression(Subsection))
917 return TokError(
"expected end of directive");
921 return getStreamer().switchSection(getStreamer().getCurrentSectionOnly(),
925bool ELFAsmParser::ParseDirectiveCGProfile(
StringRef S,
SMLoc Loc) {
932 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...
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 *, 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.