Skip to content

Commit 262d8cf

Browse files
committed
[AArch64][ELF] Section alignment of 4 for AArch64 instruction
The integrated assembler sets a minimum alignment for the .text section of 4. However user defined sections get an alignment of 1. Unlike the GNU assembler which raises the section alignment to 4 if an AArch64 instruction is used, the integrated assembler leaves the alignment at 1
1 parent 00922f4 commit 262d8cf

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

llvm/lib/MC/MCParser/ELFAsmParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ bool ELFAsmParser::parseSectionArguments(bool IsPush, SMLoc loc) {
700700
getContext().getELFSection(SectionName, Type, Flags, Size, GroupName,
701701
IsComdat, UniqueID, LinkedToSym);
702702
getStreamer().switchSection(Section, Subsection);
703-
704703
// Check that flags are used consistently. However, the GNU assembler permits
705704
// to leave out in subsequent uses of the same sections; for compatibility,
706705
// do likewise.

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class AArch64ELFStreamer : public MCELFStreamer {
327327
MCELFStreamer::changeSection(Section, Subsection);
328328

329329
// Section alignment of 4 to match GNU Assembler
330-
if (Section->getAlign() < 4) {
330+
if ((Section->getAlign() < 4) && Section->isText()) {
331331
Section->setAlignment(Align(4));
332332
emitValueToAlignment(Align(4), 0, 1, 0);
333333
}
Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
// RUN: llvm-mc -triple aarch64-windows -filetype obj -o %t.obj %s
2-
// RUN: llvm-objdump -d -r %t.obj | FileCheck %s
1+
// RUN: llvm-mc -triple=aarch64-none-linux-gnu -filetype=obj -o %t.obj %s
2+
// RUN: llvm-readobj -S --sd %t.obj | FileCheck %s --check-prefix=CHECK-OBJ
3+
// RUN: llvm-readelf -s %t.obj | FileCheck %s --check-prefix=CHECK-ELF
34

45
.section sec00, "ax"
6+
.byte 1
7+
.section sec01, "ax"
58
nop
69
nop
7-
nop
8-
.section sec01, "ax"
10+
.section sec02, "ax"
911
.balign 4
1012
nop
1113
nop
14+
.section sec03, "ax"
15+
.byte 0
16+
.section sec04, "aw"
1217
nop
18+
nop
19+
20+
// CHECK-OBJ: Name: sec00
21+
// CHECK-OBJ-NEXT: Type: SHT_PROGBITS (0x1)
22+
// CHECK-OBJ-NEXT: Flags [ (0x6)
23+
// CHECK-OBJ: AddressAlignment: 4
24+
// CHECK-OBJ: Name: sec01
25+
// CHECK-OBJ-NEXT: Type: SHT_PROGBITS (0x1)
26+
// CHECK-OBJ-NEXT: Flags [ (0x6)
27+
// CHECK-OBJ: AddressAlignment: 4
28+
// CHECK-OBJ: Name: sec02
29+
// CHECK-OBJ-NEXT: Type: SHT_PROGBITS (0x1)
30+
// CHECK-OBJ-NEXT: Flags [ (0x6)
31+
// CHECK-OBJ: Name: sec03
32+
// CHECK-OBJ-NEXT: Type: SHT_PROGBITS (0x1)
33+
// CHECK-OBJ-NEXT: Flags [ (0x6)
34+
// CHECK-OBJ: AddressAlignment: 4
35+
// CHECK-OBJ: Name: sec04
36+
// CHECK-OBJ-NEXT: Type: SHT_PROGBITS (0x1)
37+
// CHECK-OBJ-NEXT: Flags [ (0x3)
38+
// CHECK-OBJ: AddressAlignment: 1
1339

14-
// CHECK: 0000000000000000 <sec00>:
15-
// CHECK-NEXT: 0: d503201f nop
16-
// CHECK-NEXT: 4: d503201f nop
17-
// CHECK-NEXT: 8: d503201f nop
18-
// CHECK: 0000000000000000 <sec01>:
19-
// CHECK-NEXT: 0: d503201f nop
20-
// CHECK-NEXT: 4: d503201f nop
21-
// CHECK-NEXT: 8: d503201f nop
40+
//CHECK-ELF: sec00 PROGBITS 0000000000000000 000040 000001 00 AX 0 0 4
41+
//CHECK-ELF-NEXT: sec01 PROGBITS 0000000000000000 000044 000008 00 AX 0 0 4
42+
//CHECK-ELF-NEXT: sec02 PROGBITS 0000000000000000 00004c 000008 00 AX 0 0 4
43+
//CHECK-ELF-NEXT: sec03 PROGBITS 0000000000000000 000054 000001 00 AX 0 0 4
44+
//CHECK-ELF-NEXT: sec04 PROGBITS 0000000000000000 000055 000008 00 WA 0 0 1

0 commit comments

Comments
 (0)