diff options
author | Jerome Forissier <jerome@forissier.org> | 2020-11-27 11:01:56 +0100 |
---|---|---|
committer | Jérôme Forissier <jerome@forissier.org> | 2020-12-01 21:43:17 +0100 |
commit | f3368ec89a431332b10c7294227c903c9bb4e1bf (patch) | |
tree | 5661cfc305c4c654a0c4337ad95c3fbb6ec57959 /core | |
parent | eb5f87aaf387a03fca98d0683722a659aa6fdf6f (diff) |
core: arm: kern.ld.S: fix ROUNDUP() and ROUNDDOWN() for Clang
Fixes exceptions on boot when CFG_WITH_ASLR=y CFG_WITH_PAGER=y and the
Clang toolchain is used (tested with QEMUv8 and Clang 11.0.0).
The Clang linker happens to generate non-relocatable references to
symbols defined by expressions in the linker script which involve
some arithmetic operations on another symbol. More specifically, when
rounding up or down addresses to page boundaries using the expressions
defined in <util.h>. This commit introduces different ways of doing
ROUNDUP() and ROUNDDOWN() which work with both Clang and GCC:
- ROUNDUP() is replaced with the linker ALIGN() built-in function,
- ROUNDDOWN() is rewritten as 'symbol - something'.
Signed-off-by: Jerome Forissier <jerome@forissier.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/arch/arm/kernel/kern.ld.S | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/arch/arm/kernel/kern.ld.S b/core/arch/arm/kernel/kern.ld.S index f8a2bb42..50bde7a7 100644 --- a/core/arch/arm/kernel/kern.ld.S +++ b/core/arch/arm/kernel/kern.ld.S @@ -61,6 +61,13 @@ #define TEE_TEXT_VA_START (TEE_RAM_VA_START + \ (TEE_LOAD_ADDR - TEE_RAM_START)) +/* + * Note: + * Clang 11 (ld.lld) generates non-relocatable reference when using ROUNDDOWN() + * from <util.h>, which does not work with ASLR. + */ +#define LD_ROUNDDOWN(x, y) ((x) - ((x) % (y))) + OUTPUT_FORMAT(CFG_KERN_LINKER_FORMAT) OUTPUT_ARCH(CFG_KERN_LINKER_ARCH) @@ -81,7 +88,7 @@ SECTIONS * value will be mapped with unpaged "text" section attributes: * likely to be read-only/executable. */ - __flatmap_unpg_rx_start = ROUNDDOWN(__text_start, SMALL_PAGE_SIZE); + __flatmap_unpg_rx_start = LD_ROUNDDOWN(__text_start, SMALL_PAGE_SIZE); .text : { KEEP(*(.text._start)) @@ -325,7 +332,7 @@ SECTIONS __rodata_init_end = .; } - __init_end = ROUNDUP(__rodata_init_end, SMALL_PAGE_SIZE); + __init_end = ALIGN(__rodata_init_end, SMALL_PAGE_SIZE); __get_tee_init_end = __init_end; __init_size = __init_end - __init_start; |