[PATCH] D77919: [MC][ELF] Add section flags to diagnostic

Brian Cain via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 19:30:07 PDT 2020


bcain updated this revision to Diff 258222.
bcain added a comment.

Fixed the expressions in getSectionFlagString() - strings instead of chars, the nulls were the wrong choice.

Test passes now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77919/new/

https://reviews.llvm.org/D77919

Files:
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/test/MC/ELF/section-flags-changed.s


Index: llvm/test/MC/ELF/section-flags-changed.s
===================================================================
--- llvm/test/MC/ELF/section-flags-changed.s
+++ llvm/test/MC/ELF/section-flags-changed.s
@@ -3,10 +3,10 @@
 foo:
 .section .foo,"ax", at 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", at 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", at progbits
 
 .pushsection .foo,"ax", at progbits
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ 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()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77919.258222.patch
Type: text/x-patch
Size: 2849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200417/188333fb/attachment.bin>


More information about the llvm-commits mailing list