summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrakhar Bahuguna <prakhar.bahuguna@arm.com>2016-12-15 07:59:15 +0000
committerPrakhar Bahuguna <prakhar.bahuguna@arm.com>2016-12-15 07:59:15 +0000
commite640c6f765c82c0fefd3b231e0e7022d33cc82c9 (patch)
tree7a0b53f5a67b2c6786c189bac851dcb939240e0f
parent52a7dd7d7825b269ae569db0e2bcb193c7698666 (diff)
downloadbcm5719-llvm-e640c6f765c82c0fefd3b231e0e7022d33cc82c9.tar.gz
bcm5719-llvm-e640c6f765c82c0fefd3b231e0e7022d33cc82c9.zip
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 llvm-svn: 289785
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp4
-rw-r--r--llvm/test/MC/ELF/section-numeric-flag.s37
2 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 8bfb475635c..8d7ba0d0336 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -264,6 +264,10 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
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':
diff --git a/llvm/test/MC/ELF/section-numeric-flag.s b/llvm/test/MC/ELF/section-numeric-flag.s
new file mode 100644
index 00000000000..583c9b311fe
--- /dev/null
+++ b/llvm/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: }
OpenPOWER on IntegriCloud