Skip to content

Commit 1b2d73f

Browse files
committed
Aarch64: use bigger section alignment
In UEFI Mantis 2549, ARM proposes to recommend 64kB section alignment in UEFI binaries. The reason for this is that some machines may be configured to have no pages smaller than 64kB for performance reasons, and in such a scenario things like W^X will be impossible to correctly implement on binaries where one section ends and another begins on the same 64kB page. This change makes aarch64 binaries use a 64kB rather than 4kB section alignment. Note that this only actually changes virtual addresses, not file addresses, so the size is unchanged: Before: SectionAlignment 00001000 FileAlignment 00001000 Sections: Idx Name Size VMA LMA File off Algn 0 .eh_frame 00018c64 0000000000005000 0000000000005000 00001000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .text 0006bd9c 000000000001e000 000000000001e000 0001a000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .reloc 0000000a 000000000008a000 000000000008a000 00086000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .data.ident 00000088 000000000008c000 000000000008c000 00087000 2**2 CONTENTS, ALLOC, LOAD, DATA 4 .sbatlevel 0000006c 000000000008d000 000000000008d000 00088000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .data 0002f268 000000000008e000 000000000008e000 00089000 2**2 CONTENTS, ALLOC, LOAD, DATA 6 .vendor_cert 00000010 00000000000be000 00000000000be000 000b9000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 .dynamic 000000f0 00000000000bf000 00000000000bf000 000ba000 2**2 CONTENTS, ALLOC, LOAD, DATA 8 .rela 0001d760 00000000000c0000 00000000000c0000 000bb000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 9 .sbat 00000083 00000000000de000 00000000000de000 000d9000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA $ /bin/ls -l shimaa64.efi -rwxr-xr-x. 1 pjones pjones 1036357 Oct 28 13:34 shimaa64.efi After: SectionAlignment 00010000 FileAlignment 00001000 Sections: Idx Name Size VMA LMA File off Algn 0 .eh_frame 00018c64 0000000000010000 0000000000010000 00001000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .text 0006bd9c 0000000000030000 0000000000030000 0001a000 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .reloc 0000000a 00000000000a0000 00000000000a0000 00086000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .data.ident 00000088 00000000000c0000 00000000000c0000 00087000 2**2 CONTENTS, ALLOC, LOAD, DATA 4 .sbatlevel 0000006c 00000000000d0000 00000000000d0000 00088000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .data 0002f268 00000000000e0000 00000000000e0000 00089000 2**2 CONTENTS, ALLOC, LOAD, DATA 6 .vendor_cert 00000010 0000000000110000 0000000000110000 000b9000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 .dynamic 000000f0 0000000000120000 0000000000120000 000ba000 2**2 CONTENTS, ALLOC, LOAD, DATA 8 .rela 0001d760 0000000000130000 0000000000130000 000bb000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 9 .sbat 00000083 0000000000150000 0000000000150000 000d9000 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA $ /bin/ls -l shimaa64.efi -rwxr-xr-x. 1 pjones pjones 1036357 Oct 28 13:18 shimaa64.efi On my test machine, that changes the text and data load addresses (both physical and virtual, we're still on a 1:1 map) as follows: Before: _text:0x0000000092FF7000 _data:0x0000000093067000 After: _text:0x0000000092F80000 _data:0x0000000093030000 Signed-off-by: Peter Jones <pjones@redhat.com>
1 parent a84655c commit 1b2d73f

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Make.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ifeq ($(ARCH),aarch64)
8888
ARCH_SUFFIX_UPPER ?= AA64
8989
ARCH_LDFLAGS ?=
9090
ARCH_CFLAGS ?=
91-
ARCH_SECTION_ALIGNMENT ?= 0x1000
91+
ARCH_SECTION_ALIGNMENT ?= 0x10000
9292
endif
9393
ifeq ($(ARCH),arm)
9494
ARCH_CFLAGS ?= -DMDE_CPU_ARM -DPAGE_SIZE=4096 -mno-unaligned-access

elf_aarch64_efi.lds

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ SECTIONS
66
. = 0;
77
ImageBase = .;
88
.hash : { *(.hash) } /* this MUST come first! */
9-
. = ALIGN(4096);
9+
. = ALIGN(65536);
1010
.eh_frame :
1111
{
1212
*(.eh_frame)
1313
}
14-
. = ALIGN(4096);
14+
. = ALIGN(65536);
1515
.text :
1616
{
1717
_text = .;
@@ -20,26 +20,26 @@ SECTIONS
2020
*(.gnu.linkonce.t.*)
2121
_etext = .;
2222
}
23-
. = ALIGN(4096);
23+
. = ALIGN(65536);
2424
.reloc :
2525
{
2626
*(.reloc)
2727
}
28-
. = ALIGN(4096);
28+
. = ALIGN(65536);
2929
.note.gnu.build-id : {
3030
*(.note.gnu.build-id)
3131
}
3232

33-
. = ALIGN(4096);
33+
. = ALIGN(65536);
3434
.data.ident : {
3535
*(.data.ident)
3636
}
37-
. = ALIGN(4096);
37+
. = ALIGN(65536);
3838
.sbatlevel : {
3939
*(.sbatlevel)
4040
}
4141

42-
. = ALIGN(4096);
42+
. = ALIGN(65536);
4343
.data :
4444
{
4545
_data = .;
@@ -58,14 +58,14 @@ SECTIONS
5858
*(.rel.local)
5959
}
6060

61-
. = ALIGN(4096);
61+
. = ALIGN(65536);
6262
.vendor_cert :
6363
{
6464
*(.vendor_cert)
6565
}
66-
. = ALIGN(4096);
66+
. = ALIGN(65536);
6767
.dynamic : { *(.dynamic) }
68-
. = ALIGN(4096);
68+
. = ALIGN(65536);
6969
.rela :
7070
{
7171
*(.rela.data*)
@@ -74,7 +74,7 @@ SECTIONS
7474
}
7575
_edata = .;
7676
_data_size = . - _data;
77-
. = ALIGN(4096);
77+
. = ALIGN(65536);
7878
.sbat :
7979
{
8080
_sbat = .;
@@ -84,11 +84,11 @@ SECTIONS
8484
_esbat = .;
8585
_sbat_size = . - _sbat;
8686

87-
. = ALIGN(4096);
87+
. = ALIGN(65536);
8888
.dynsym : { *(.dynsym) }
89-
. = ALIGN(4096);
89+
. = ALIGN(65536);
9090
.dynstr : { *(.dynstr) }
91-
. = ALIGN(4096);
91+
. = ALIGN(65536);
9292
.ignored.reloc :
9393
{
9494
*(.rela.reloc)

0 commit comments

Comments
 (0)