From bf70566a450a28e24bd1eb5539af8d407fb9959b Mon Sep 17 00:00:00 2001 From: Venkatraman Govindaraju Date: Sat, 1 Mar 2014 06:21:00 +0000 Subject: [PATCH] Add support for parsing sun-style section flags in ELFAsmParser. llvm-svn: 202573 --- llvm/lib/MC/MCParser/ELFAsmParser.cpp | 49 +++++++++++++++++++++++---- llvm/test/MC/Sparc/sparc-pic.s | 2 +- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index ca5532d4851e..0505a93a4873 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -151,6 +151,7 @@ public: private: bool ParseSectionName(StringRef &SectionName); bool ParseSectionArguments(bool IsPush); + unsigned parseSunStyleSectionFlags(); }; } @@ -322,6 +323,36 @@ static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) { return flags; } +unsigned ELFAsmParser::parseSunStyleSectionFlags() { + unsigned flags = 0; + while (getLexer().is(AsmToken::Hash)) { + Lex(); // Eat the #. + + if (!getLexer().is(AsmToken::Identifier)) + return -1U; + + StringRef flagId = getTok().getIdentifier(); + if (flagId == "alloc") + flags |= ELF::SHF_ALLOC; + else if (flagId == "execinstr") + flags |= ELF::SHF_EXECINSTR; + else if (flagId == "write") + flags |= ELF::SHF_WRITE; + else if (flagId == "tls") + flags |= ELF::SHF_TLS; + else + return -1U; + + Lex(); // Eat the flag. + + if (!getLexer().is(AsmToken::Comma)) + break; + Lex(); // Eat the comma. + } + return flags; +} + + bool ELFAsmParser::ParseDirectivePushSection(StringRef s, SMLoc loc) { getStreamer().PushSection(); @@ -374,14 +405,20 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush) { goto EndStmt; Lex(); } - - if (getLexer().isNot(AsmToken::String)) - return TokError("expected string in directive"); - StringRef FlagsStr = getTok().getStringContents(); - Lex(); + unsigned extraFlags; + + if (getLexer().isNot(AsmToken::String)) { + if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax() + || getLexer().isNot(AsmToken::Hash)) + return TokError("expected string in directive"); + extraFlags = parseSunStyleSectionFlags(); + } else { + StringRef FlagsStr = getTok().getStringContents(); + Lex(); + extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup); + } - unsigned extraFlags = parseSectionFlags(FlagsStr, &UseLastGroup); if (extraFlags == -1U) return TokError("unknown flag"); Flags |= extraFlags; diff --git a/llvm/test/MC/Sparc/sparc-pic.s b/llvm/test/MC/Sparc/sparc-pic.s index 83c2966e597c..5a34d309899e 100644 --- a/llvm/test/MC/Sparc/sparc-pic.s +++ b/llvm/test/MC/Sparc/sparc-pic.s @@ -40,7 +40,7 @@ foo: .cfi_endproc .type AGlobalVar,@object ! @AGlobalVar - .section .bss + .section .bss,#alloc,#write .globl AGlobalVar .align 8 AGlobalVar: