Changeset View
Changeset View
Standalone View
Standalone View
lib/MC/MCParser/ELFAsmParser.cpp
Show First 20 Lines • Show All 151 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 parseMetadataSym(MCSymbolELF *&Associated); | ||||
bool maybeParseUniqueID(int64_t &UniqueID); | bool maybeParseUniqueID(int64_t &UniqueID); | ||||
}; | }; | ||||
} // end anonymous namespace | } // end anonymous namespace | ||||
/// 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 255 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) { | bool ELFAsmParser::parseMetadataSym(MCSymbolELF *&Associated) { | ||||
MCAsmLexer &L = getLexer(); | MCAsmLexer &L = getLexer(); | ||||
if (L.isNot(AsmToken::Comma)) | if (L.isNot(AsmToken::Comma)) | ||||
return TokError("expected metadata symbol"); | return TokError("expected metadata symbol"); | ||||
Lex(); | Lex(); | ||||
StringRef Name; | StringRef Name; | ||||
if (getParser().parseIdentifier(Name)) | if (getParser().parseIdentifier(Name)) | ||||
return true; | return true; | ||||
MCSymbol *Sym = getContext().lookupSymbol(Name); | Associated = dyn_cast_or_null<MCSymbolELF>(getContext().lookupSymbol(Name)); | ||||
if (!Sym || !Sym->isInSection()) | if (!Associated || !Associated->isInSection()) | ||||
return TokError("symbol is not in a section: " + Name); | return TokError("symbol is not in a section: " + Name); | ||||
Associated = cast<MCSectionELF>(&Sym->getSection()); | |||||
return false; | 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(); | ||||
Show All 22 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; | MCSymbolELF *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 98 Lines • ▼ Show 20 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( | MCSection *ELFSection = | ||||
SectionName, Type, Flags, Size, GroupName, UniqueID, Associated); | getContext().getELFSection(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 |