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 @@ -640,9 +640,16 @@ if (Section->getType() != Type) Error(loc, "changed section type for " + SectionName + ", expected: 0x" + utohexstr(Section->getType())); - if (Section->getFlags() != Flags) - Error(loc, "changed section flags for " + SectionName + ", expected: 0x" + - utohexstr(Section->getFlags())); + if (Section->getFlags() != Flags) { + const unsigned ExpectedFlags = Section->getFlags(); + const std::string ExpectedFlagsText = + Twine(StringRef((ExpectedFlags & ELF::SHF_ALLOC) ? "a" : "") + + StringRef((ExpectedFlags & ELF::SHF_WRITE) ? "w" : "") + + StringRef((ExpectedFlags & ELF::SHF_EXECINSTR) ? "x" : "")) + .str(); + Error(loc, "changed section flags for `" + SectionName + "', expected: \"" + + ExpectedFlagsText + "\""); + } if (Section->getEntrySize() != Size) Error(loc, "changed section entsize for " + SectionName + ", expected: " + Twine(Section->getEntrySize())); diff --git a/llvm/test/MC/ELF/section-flags-changed.s b/llvm/test/MC/ELF/section-flags-changed.s --- a/llvm/test/MC/ELF/section-flags-changed.s +++ b/llvm/test/MC/ELF/section-flags-changed.s @@ -3,10 +3,10 @@ foo: .section .foo,"ax",@progbits -# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6 +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for `.foo', expected: "ax" .section .foo,"awx",@progbits -# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo, expected: 0x6 +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for `.foo', expected: "ax" .pushsection .foo,"a",@progbits .pushsection .foo,"ax",@progbits