Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 412b80f

Browse files
author
Prakhar Bahuguna
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289785 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent af672fb commit 412b80f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ bool ELFAsmParser::ParseSectionName(StringRef &SectionName) {
264264
static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) {
265265
unsigned flags = 0;
266266

267+
// If a valid numerical value is set for the section flag, use it verbatim
268+
if (!flagsStr.getAsInteger(0, flags))
269+
return flags;
270+
267271
for (char i : flagsStr) {
268272
switch (i) {
269273
case 'a':

test/MC/ELF/section-numeric-flag.s

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: llvm-mc -filetype=obj %s -o - \
2+
// RUN: | llvm-readobj -s -t | FileCheck %s
3+
4+
.section .text, "0x806", %progbits, unique, 0
5+
.section .comment, "0x21"
6+
7+
8+
// CHECK: Section {
9+
// CHECK: Name: .text (1)
10+
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
11+
// CHECK-NEXT: Flags [ (0x6)
12+
// CHECK-NEXT: SHF_ALLOC (0x2)
13+
// CHECK-NEXT: SHF_EXECINSTR (0x4)
14+
// CHECK-NEXT: ]
15+
// CHECK: Size: 0
16+
// CHECK: }
17+
18+
// CHECK: Section {
19+
// CHECK: Name: .text (1)
20+
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
21+
// CHECK-NEXT: Flags [ (0x806)
22+
// CHECK-NEXT: SHF_ALLOC (0x2)
23+
// CHECK-NEXT: SHF_COMPRESSED (0x800)
24+
// CHECK-NEXT: SHF_EXECINSTR (0x4)
25+
// CHECK-NEXT: ]
26+
// CHECK: Size: 0
27+
// CHECK: }
28+
29+
// CHECK: Section {
30+
// CHECK: Name: .comment (7)
31+
// CHECK-NEXT: Type: SHT_PROGBITS (0x1)
32+
// CHECK-NEXT: Flags [ (0x21)
33+
// CHECK-NEXT: SHF_STRINGS (0x20)
34+
// CHECK-NEXT: SHF_WRITE (0x1)
35+
// CHECK-NEXT: ]
36+
// CHECK: Size: 0
37+
// CHECK: }

0 commit comments

Comments
 (0)