[PATCH v1 3/6] arm: Prepare linker scripts for memory permissions
Ilias Apalodimas
ilias.apalodimas at linaro.org
Wed Feb 5 08:16:47 CET 2025
Upcoming patches are switching the memory mappings to RW, RO, RX
after the U-Boot binary and its data are relocated. Add
annotations in the linker scripts to and mark text, data, rodata
sections and align them to a page boundary.
It's worth noting that efi_runtime relocations are left untouched for
now. The efi runtime regions can be relocated by the OS when the latter
is calling SetVirtualAddressMap. Which means we have to configure the
pages as RX for U-Boot but convert them to RWX just before
ExitBootServices. It also needs extra code in efi_tuntime relocation
code since R_AARCH64_NONE are emitted as well if we page align the
section. Keep it out for now and we can fix it in future patches.
Acked-by: Jerome Forissier <jerome.forissier at linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
---
arch/arm/cpu/armv8/u-boot.lds | 29 +++++++++++++++++------------
include/asm-generic/sections.h | 2 ++
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
index 857f44412e07..35afc3cbe7ec 100644
--- a/arch/arm/cpu/armv8/u-boot.lds
+++ b/arch/arm/cpu/armv8/u-boot.lds
@@ -22,7 +22,7 @@ SECTIONS
. = ALIGN(8);
__image_copy_start = ADDR(.text);
- .text :
+ .text ALIGN(4096):
{
CPUDIR/start.o (.text*)
}
@@ -36,9 +36,12 @@ SECTIONS
__efi_runtime_stop = .;
}
- .text_rest :
+ .text_rest ALIGN(4096) :
{
+ __text_start = .;
*(.text*)
+ . = ALIGN(4096);
+ __text_end = .;
}
#ifdef CONFIG_ARMV8_PSCI
@@ -98,18 +101,20 @@ SECTIONS
}
#endif
- . = ALIGN(8);
- .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
+ .rodata ALIGN(4096): {
+ __start_rodata = .;
+ *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
+ . = ALIGN(4096);
+ __end_rodata = .;
+ }
- . = ALIGN(8);
- .data : {
+ .data ALIGN(4096) : {
+ __start_data = .;
*(.data*)
+ . = ALIGN(4096);
+ __end_data = .;
}
- . = ALIGN(8);
-
- . = .;
-
. = ALIGN(8);
__u_boot_list : {
KEEP(*(SORT(__u_boot_list*)));
@@ -136,10 +141,10 @@ SECTIONS
/*
* arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0
*/
- .bss ALIGN(8) : {
+ .bss ALIGN(4096) : {
__bss_start = .;
*(.bss*)
- . = ALIGN(8);
+ . = ALIGN(4096);
__bss_end = .;
}
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 3fd5c772a1af..024b1adde270 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -23,6 +23,7 @@ extern char __kprobes_text_start[], __kprobes_text_end[];
extern char __entry_text_start[], __entry_text_end[];
extern char __initdata_begin[], __initdata_end[];
extern char __start_rodata[], __end_rodata[];
+extern char __start_data[], __end_data[];
extern char __efi_helloworld_begin[];
extern char __efi_helloworld_end[];
extern char __efi_var_file_begin[];
@@ -63,6 +64,7 @@ static inline int arch_is_kernel_data(unsigned long addr)
/* Start of U-Boot text region */
extern char __text_start[];
+extern char __text_end[];
/* This marks the text region which must be relocated */
extern char __image_copy_start[], __image_copy_end[];
--
2.47.2
More information about the U-Boot
mailing list