[PATCH] D27986: Print numeric section flag for OS/processor specific bits

Prakhar Bahuguna via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 06:11:26 PST 2016


prakhar created this revision.
prakhar added reviewers: grosbach, rengolin.
prakhar added a subscriber: llvm-commits.

When outputting assembly, any OS or processor-specific flags cannot be
represented by symbolic letters, so these are lost in the generated
assembly. This patch therefore prints out the flags in numeric form if
any of these bits are set. This is compatible with how GAS handles
unknown flags, and allows the generation of assembly that can be read by
GAS.


https://reviews.llvm.org/D27986

Files:
  lib/MC/MCSectionELF.cpp
  test/CodeGen/ARM/execute-only-section.ll


Index: test/CodeGen/ARM/execute-only-section.ll
===================================================================
--- test/CodeGen/ARM/execute-only-section.ll
+++ test/CodeGen/ARM/execute-only-section.ll
@@ -2,7 +2,7 @@
 ; RUN: llc < %s -mtriple=thumbv8m.base -arm-execute-only %s -o - | FileCheck %s
 ; RUN: llc < %s -mtriple=thumbv8m.main -arm-execute-only %s -o - | FileCheck %s
 
-; CHECK:     .section .text,"axy",%progbits,unique,0
+; CHECK:     .section .text,"0x20000006",%progbits,unique,0
 ; CHECK-NOT: .section
 ; CHECK-NOT: .text
 ; CHECK:     .globl test_SectionForGlobal
@@ -12,7 +12,7 @@
   ret void
 }
 
-; CHECK:     .section .test,"axy",%progbits
+; CHECK:     .section .test,"0x20000006",%progbits
 ; CHECK-NOT: .section
 ; CHECK-NOT: .text
 ; CHECK:     .globl test_ExplicitSectionForGlobal
Index: lib/MC/MCSectionELF.cpp
===================================================================
--- lib/MC/MCSectionELF.cpp
+++ lib/MC/MCSectionELF.cpp
@@ -14,6 +14,7 @@
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Format.h"
 
 using namespace llvm;
 
@@ -88,30 +89,35 @@
   }
 
   OS << ",\"";
-  if (Flags & ELF::SHF_ALLOC)
-    OS << 'a';
-  if (Flags & ELF::SHF_EXCLUDE)
-    OS << 'e';
-  if (Flags & ELF::SHF_EXECINSTR)
-    OS << 'x';
-  if (Flags & ELF::SHF_GROUP)
-    OS << 'G';
-  if (Flags & ELF::SHF_WRITE)
-    OS << 'w';
-  if (Flags & ELF::SHF_MERGE)
-    OS << 'M';
-  if (Flags & ELF::SHF_STRINGS)
-    OS << 'S';
-  if (Flags & ELF::SHF_TLS)
-    OS << 'T';
-
-  // If there are target-specific flags, print them.
-  if (Flags & ELF::XCORE_SHF_CP_SECTION)
-    OS << 'c';
-  if (Flags & ELF::XCORE_SHF_DP_SECTION)
-    OS << 'd';
-  if (Flags & ELF::SHF_ARM_PURECODE)
-    OS << 'y';
+
+  // If the flag has OS or processor-specific bits set, print the whole numeric
+  // flag, otherwise use the symbolic representation
+  if (Flags & (ELF::SHF_MASKOS | ELF::SHF_MASKPROC))
+    OS << format_hex(Flags, 0);
+  else {
+    if (Flags & ELF::SHF_ALLOC)
+      OS << 'a';
+    if (Flags & ELF::SHF_EXCLUDE)
+      OS << 'e';
+    if (Flags & ELF::SHF_EXECINSTR)
+      OS << 'x';
+    if (Flags & ELF::SHF_GROUP)
+      OS << 'G';
+    if (Flags & ELF::SHF_WRITE)
+      OS << 'w';
+    if (Flags & ELF::SHF_MERGE)
+      OS << 'M';
+    if (Flags & ELF::SHF_STRINGS)
+      OS << 'S';
+    if (Flags & ELF::SHF_TLS)
+      OS << 'T';
+
+    // If there are target-specific flags, print them.
+    if (Flags & ELF::XCORE_SHF_CP_SECTION)
+      OS << 'c';
+    if (Flags & ELF::XCORE_SHF_DP_SECTION)
+      OS << 'd';
+  }
 
   OS << '"';
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27986.82103.patch
Type: text/x-patch
Size: 2652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161220/54d7ff3e/attachment.bin>


More information about the llvm-commits mailing list