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 @@ -278,6 +278,23 @@ return false; } +static std::string getSectionFlagString(unsigned flags) { + return (Twine(((flags & ELF::SHF_ALLOC) != 0) ? "a" : "") + + Twine(((flags & ELF::SHF_EXCLUDE) != 0) ? "e" : "") + + Twine(((flags & ELF::SHF_EXECINSTR) != 0) ? "x" : "") + + Twine(((flags & ELF::SHF_WRITE) != 0) ? "w" : "") + + Twine(((flags & ELF::SHF_LINK_ORDER) != 0) ? "o" : "") + + Twine(((flags & ELF::SHF_MERGE) != 0) ? "M" : "") + + Twine(((flags & ELF::SHF_STRINGS) != 0) ? "S" : "") + + Twine(((flags & ELF::SHF_TLS) != 0) ? "T" : "") + + Twine(((flags & ELF::XCORE_SHF_CP_SECTION) != 0) ? "c" : "") + + Twine(((flags & ELF::XCORE_SHF_DP_SECTION) != 0) ? "d" : "") + + Twine(((flags & ELF::SHF_ARM_PURECODE) != 0) ? "y" : "") + + Twine(((flags & ELF::SHF_HEX_GPREL) != 0) ? "s" : "") + + Twine(((flags & ELF::SHF_GROUP) != 0) ? "G" : "")) + .str(); +} + static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) { unsigned flags = 0; @@ -640,9 +657,12 @@ 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 = getSectionFlagString(ExpectedFlags); + 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