diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -500,6 +500,7 @@ int64_t Size = 0; StringRef GroupName; unsigned Flags = 0; + unsigned extraFlags = 0; const MCExpr *Subsection = nullptr; bool UseLastGroup = false; MCSymbolELF *LinkedToSym = nullptr; @@ -532,8 +533,6 @@ Lex(); } - unsigned extraFlags; - if (getLexer().isNot(AsmToken::String)) { if (!getContext().getAsmInfo()->usesSunStyleELFSectionSwitchSyntax() || getLexer().isNot(AsmToken::Hash)) @@ -655,10 +654,11 @@ // Check that flags are used consistently. However, the GNU assembler permits // to leave out in subsequent uses of the same sections; for compatibility, // do likewise. - if ((Flags || Size || !TypeName.empty()) && Section->getFlags() != Flags) + if ((extraFlags || Size || !TypeName.empty()) && Section->getFlags() != Flags) Error(loc, "changed section flags for " + SectionName + ", expected: 0x" + utohexstr(Section->getFlags())); - if ((Flags || Size || !TypeName.empty()) && Section->getEntrySize() != Size) + if ((extraFlags || Size || !TypeName.empty()) && + Section->getEntrySize() != Size) Error(loc, "changed section entsize for " + SectionName + ", expected: " + Twine(Section->getEntrySize())); diff --git a/llvm/test/MC/ELF/section-omitted-attributes.s b/llvm/test/MC/ELF/section-omitted-attributes.s --- a/llvm/test/MC/ELF/section-omitted-attributes.s +++ b/llvm/test/MC/ELF/section-omitted-attributes.s @@ -3,9 +3,15 @@ # If section flags and other attributes are omitted, don't error. # CHECK: .section .foo,"aM",@progbits,1 +# CHECK: .section .rodata.cst8,"aM",@progbits,8 .section .foo,"aM",@progbits,1 .section .foo .pushsection .foo + +# Likewise, except that the '.rodata' prefix implies SHF_ALLOC. +.section .rodata.cst8,"aM",@progbits,8 + +.section .rodata.cst8