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

Brian Cain via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 22:14:52 PDT 2020


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

Added a getSectionFlagString() function.
Changed section name delimiters in diagnostic to single-quotes


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' : '\0')
+      + Twine( ((flags & ELF::SHF_EXCLUDE) != 0) ? 'e' : '\0')
+      + Twine( ((flags & ELF::SHF_EXECINSTR) != 0) ? 'x' : '\0')
+      + Twine( ((flags & ELF::SHF_WRITE) != 0) ? 'w' : '\0')
+      + Twine( ((flags & ELF::SHF_LINK_ORDER) != 0) ? 'o' : '\0')
+      + Twine( ((flags & ELF::SHF_MERGE) != 0) ? 'M' : '\0')
+      + Twine( ((flags & ELF::SHF_STRINGS) != 0) ? 'S' : '\0')
+      + Twine( ((flags & ELF::SHF_TLS) != 0) ? 'T' : '\0')
+      + Twine( ((flags & ELF::XCORE_SHF_CP_SECTION) != 0) ? 'c' : '\0')
+      + Twine( ((flags & ELF::XCORE_SHF_DP_SECTION) != 0) ? 'd' : '\0')
+      + Twine( ((flags & ELF::SHF_ARM_PURECODE) != 0) ? 'y' : '\0')
+      + Twine( ((flags & ELF::SHF_HEX_GPREL) != 0) ? 's' : '\0')
+      + Twine( ((flags & ELF::SHF_GROUP) != 0) ? 'G' : '\0')
+	).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.257192.patch
Type: text/x-patch
Size: 2839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200414/f3942a3d/attachment-0001.bin>


More information about the llvm-commits mailing list