[PATCH] D27451: Allow ELF section flags to be specified numerically

Prakhar Bahuguna via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 03:19:44 PST 2016


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

GAS already allows flags for sections to be specified directly as a
numeric value. This functionality is particularly useful for setting
processor or application-specific values that may not be directly
supported or understood by LLVM. This patch allows LLVM to use numeric
section flag values verbatim if specified by the assembly file.


https://reviews.llvm.org/D27451

Files:
  lib/MC/MCParser/ELFAsmParser.cpp
  test/MC/ELF/section-numeric-flag.s


Index: test/MC/ELF/section-numeric-flag.s
===================================================================
--- /dev/null
+++ test/MC/ELF/section-numeric-flag.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj %s -o - \
+// RUN: | llvm-readobj -s -t | FileCheck %s
+
+        .section .text,    "0x806", %progbits, unique, 0
+        .section .comment, "0x21"
+
+
+// CHECK:      Section {
+// CHECK:        Name: .text (1)
+// CHECK-NEXT:   Type: SHT_PROGBITS (0x1)
+// CHECK-NEXT:   Flags [ (0x6)
+// CHECK-NEXT:     SHF_ALLOC (0x2)
+// CHECK-NEXT:     SHF_EXECINSTR (0x4)
+// CHECK-NEXT:   ]
+// CHECK:        Size: 0
+// CHECK:      }
+
+// CHECK:      Section {
+// CHECK:        Name: .text (1)
+// CHECK-NEXT:   Type: SHT_PROGBITS (0x1)
+// CHECK-NEXT:   Flags [ (0x806)
+// CHECK-NEXT:     SHF_ALLOC (0x2)
+// CHECK-NEXT:     SHF_COMPRESSED (0x800)
+// CHECK-NEXT:     SHF_EXECINSTR (0x4)
+// CHECK-NEXT:   ]
+// CHECK:        Size: 0
+// CHECK:      }
+
+// CHECK:      Section {
+// CHECK:        Name: .comment (7)
+// CHECK-NEXT:   Type: SHT_PROGBITS (0x1)
+// CHECK-NEXT:   Flags [ (0x21)
+// CHECK-NEXT:     SHF_STRINGS (0x20)
+// CHECK-NEXT:     SHF_WRITE (0x1)
+// CHECK-NEXT:   ]
+// CHECK:        Size: 0
+// CHECK:      }
Index: lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- lib/MC/MCParser/ELFAsmParser.cpp
+++ lib/MC/MCParser/ELFAsmParser.cpp
@@ -264,6 +264,10 @@
 static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
   unsigned flags = 0;
 
+  // If a valid numerical value is set for the section flag, use it verbatim
+  if (!flagsStr.getAsInteger(0, flags))
+    return flags;
+
   for (char i : flagsStr) {
     switch (i) {
     case 'a':


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27451.80400.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161206/9d8c52c6/attachment.bin>


More information about the llvm-commits mailing list