Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/MC/MCParser/ELFAsmParser.cpp
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
bool ParseSectionName(StringRef &SectionName); | bool ParseSectionName(StringRef &SectionName); | ||||
bool ParseSectionArguments(bool IsPush, SMLoc loc); | bool ParseSectionArguments(bool IsPush, SMLoc loc); | ||||
unsigned parseSunStyleSectionFlags(); | unsigned parseSunStyleSectionFlags(); | ||||
bool maybeParseSectionType(StringRef &TypeName); | bool maybeParseSectionType(StringRef &TypeName); | ||||
bool parseMergeSize(int64_t &Size); | bool parseMergeSize(int64_t &Size); | ||||
bool parseGroup(StringRef &GroupName); | bool parseGroup(StringRef &GroupName); | ||||
bool parseMetadataSym(MCSectionELF *&Associated); | |||||
bool maybeParseUniqueID(int64_t &UniqueID); | bool maybeParseUniqueID(int64_t &UniqueID); | ||||
}; | }; | ||||
} | } | ||||
/// ParseDirectiveSymbolAttribute | /// ParseDirectiveSymbolAttribute | ||||
/// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ] | /// ::= { ".local", ".weak", ... } [ identifier ( , identifier )* ] | ||||
bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) { | bool ELFAsmParser::ParseDirectiveSymbolAttribute(StringRef Directive, SMLoc) { | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | case 'e': | ||||
flags |= ELF::SHF_EXCLUDE; | flags |= ELF::SHF_EXCLUDE; | ||||
break; | break; | ||||
case 'x': | case 'x': | ||||
flags |= ELF::SHF_EXECINSTR; | flags |= ELF::SHF_EXECINSTR; | ||||
break; | break; | ||||
case 'w': | case 'w': | ||||
flags |= ELF::SHF_WRITE; | flags |= ELF::SHF_WRITE; | ||||
break; | break; | ||||
case 'm': | |||||
flags |= ELF::SHF_LINK_ORDER; | |||||
break; | |||||
case 'M': | case 'M': | ||||
flags |= ELF::SHF_MERGE; | flags |= ELF::SHF_MERGE; | ||||
break; | break; | ||||
case 'S': | case 'S': | ||||
flags |= ELF::SHF_STRINGS; | flags |= ELF::SHF_STRINGS; | ||||
break; | break; | ||||
case 'T': | case 'T': | ||||
flags |= ELF::SHF_TLS; | flags |= ELF::SHF_TLS; | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | if (L.is(AsmToken::Comma)) { | ||||
if (getParser().parseIdentifier(Linkage)) | if (getParser().parseIdentifier(Linkage)) | ||||
return true; | return true; | ||||
if (Linkage != "comdat") | if (Linkage != "comdat") | ||||
return TokError("Linkage must be 'comdat'"); | return TokError("Linkage must be 'comdat'"); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool ELFAsmParser::parseMetadataSym(MCSectionELF *&Associated) { | |||||
MCAsmLexer &L = getLexer(); | |||||
if (L.isNot(AsmToken::Comma)) | |||||
return TokError("expected metadata symbol"); | |||||
Lex(); | |||||
StringRef Name; | |||||
if (getParser().parseIdentifier(Name)) | |||||
return true; | |||||
MCSymbol *Sym = getContext().lookupSymbol(Name); | |||||
if (!Sym || !Sym->isInSection()) | |||||
return TokError("symbol is not in a section: " + Name); | |||||
Associated = cast<MCSectionELF>(&Sym->getSection()); | |||||
return false; | |||||
} | |||||
bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) { | bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) { | ||||
MCAsmLexer &L = getLexer(); | MCAsmLexer &L = getLexer(); | ||||
if (L.isNot(AsmToken::Comma)) | if (L.isNot(AsmToken::Comma)) | ||||
return false; | return false; | ||||
Lex(); | Lex(); | ||||
StringRef UniqueStr; | StringRef UniqueStr; | ||||
if (getParser().parseIdentifier(UniqueStr)) | if (getParser().parseIdentifier(UniqueStr)) | ||||
return TokError("expected identifier in directive"); | return TokError("expected identifier in directive"); | ||||
Show All 19 Lines | bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) { | ||||
StringRef TypeName; | StringRef TypeName; | ||||
int64_t Size = 0; | int64_t Size = 0; | ||||
StringRef GroupName; | StringRef GroupName; | ||||
unsigned Flags = 0; | unsigned Flags = 0; | ||||
const MCExpr *Subsection = nullptr; | const MCExpr *Subsection = nullptr; | ||||
bool UseLastGroup = false; | bool UseLastGroup = false; | ||||
StringRef UniqueStr; | StringRef UniqueStr; | ||||
MCSectionELF *Associated = nullptr; | |||||
int64_t UniqueID = ~0; | int64_t UniqueID = ~0; | ||||
// Set the defaults first. | // Set the defaults first. | ||||
if (SectionName == ".fini" || SectionName == ".init" || | if (SectionName == ".fini" || SectionName == ".init" || | ||||
SectionName == ".rodata") | SectionName == ".rodata") | ||||
Flags |= ELF::SHF_ALLOC; | Flags |= ELF::SHF_ALLOC; | ||||
if (SectionName == ".fini" || SectionName == ".init") | if (SectionName == ".fini" || SectionName == ".init") | ||||
Flags |= ELF::SHF_EXECINSTR; | Flags |= ELF::SHF_EXECINSTR; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (getLexer().is(AsmToken::Comma)) { | ||||
} | } | ||||
if (Mergeable) | if (Mergeable) | ||||
if (parseMergeSize(Size)) | if (parseMergeSize(Size)) | ||||
return true; | return true; | ||||
if (Group) | if (Group) | ||||
if (parseGroup(GroupName)) | if (parseGroup(GroupName)) | ||||
return true; | return true; | ||||
if (Flags & ELF::SHF_LINK_ORDER) | |||||
if (parseMetadataSym(Associated)) | |||||
return true; | |||||
if (maybeParseUniqueID(UniqueID)) | if (maybeParseUniqueID(UniqueID)) | ||||
return true; | return true; | ||||
} | } | ||||
EndStmt: | EndStmt: | ||||
if (getLexer().isNot(AsmToken::EndOfStatement)) | if (getLexer().isNot(AsmToken::EndOfStatement)) | ||||
return TokError("unexpected token in directive"); | return TokError("unexpected token in directive"); | ||||
Lex(); | Lex(); | ||||
Show All 33 Lines | if (UseLastGroup) { | ||||
if (const MCSectionELF *Section = | if (const MCSectionELF *Section = | ||||
cast_or_null<MCSectionELF>(CurrentSection.first)) | cast_or_null<MCSectionELF>(CurrentSection.first)) | ||||
if (const MCSymbol *Group = Section->getGroup()) { | if (const MCSymbol *Group = Section->getGroup()) { | ||||
GroupName = Group->getName(); | GroupName = Group->getName(); | ||||
Flags |= ELF::SHF_GROUP; | Flags |= ELF::SHF_GROUP; | ||||
} | } | ||||
} | } | ||||
MCSection *ELFSection = getContext().getELFSection(SectionName, Type, Flags, | MCSection *ELFSection = getContext().getELFSection( | ||||
Size, GroupName, UniqueID); | SectionName, Type, Flags, Size, GroupName, UniqueID, Associated); | ||||
getStreamer().SwitchSection(ELFSection, Subsection); | getStreamer().SwitchSection(ELFSection, Subsection); | ||||
if (getContext().getGenDwarfForAssembly()) { | if (getContext().getGenDwarfForAssembly()) { | ||||
bool InsertResult = getContext().addGenDwarfSection(ELFSection); | bool InsertResult = getContext().addGenDwarfSection(ELFSection); | ||||
if (InsertResult) { | if (InsertResult) { | ||||
if (getContext().getDwarfVersion() <= 2) | if (getContext().getDwarfVersion() <= 2) | ||||
Warning(loc, "DWARF2 only supports one section per compilation unit"); | Warning(loc, "DWARF2 only supports one section per compilation unit"); | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |