[llvm] r289785 - Allow ELF section flags to be specified numerically

Prakhar Bahuguna via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 23:59:15 PST 2016


Author: prakhar
Date: Thu Dec 15 01:59:15 2016
New Revision: 289785

URL: http://llvm.org/viewvc/llvm-project?rev=289785&view=rev
Log:
Allow ELF section flags to be specified numerically

Summary:
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.

Reviewers: grosbach, rafael, t.p.northover, rengolin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27451

Added:
    llvm/trunk/test/MC/ELF/section-numeric-flag.s
Modified:
    llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=289785&r1=289784&r2=289785&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Thu Dec 15 01:59:15 2016
@@ -264,6 +264,10 @@ bool ELFAsmParser::ParseSectionName(Stri
 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':

Added: llvm/trunk/test/MC/ELF/section-numeric-flag.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/section-numeric-flag.s?rev=289785&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/section-numeric-flag.s (added)
+++ llvm/trunk/test/MC/ELF/section-numeric-flag.s Thu Dec 15 01:59:15 2016
@@ -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:      }




More information about the llvm-commits mailing list