[PATCH v2 057/113] ARM64: runtime-offset: make get_runtime_offset fully PIC

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Mar 4 10:59:42 PST 2024


get_runtime_offset returns the offset that needs to be added onto
code addresses to arrive at the runtime address. This is 0 after code
relocation and the function calculates it by keeping a reference to _text
and substituting it from the actual _text address, which is found out in
a position-independent manner.

For enabling barebox PBL text section to be mappable W^X, we need to
avoid relocation entries within code, so let's move the runtime offset
into the data section, which is always mapped writable.

As ldr has only a 4K range for label references, we switch to ldr_l,
which has a 4G range.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/lib64/runtime-offset.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/lib64/runtime-offset.S b/arch/arm/lib64/runtime-offset.S
index 822e323c142e..b10c104b4dd0 100644
--- a/arch/arm/lib64/runtime-offset.S
+++ b/arch/arm/lib64/runtime-offset.S
@@ -11,10 +11,12 @@
  */
 ENTRY(get_runtime_offset)
 	adr x0, _text
-	ldr x1, linkadr
+	ldr_l x1, linkadr
 	subs x0, x0, x1
 	ret
+ENDPROC(get_runtime_offset)
 
+.section ".data.runtime_offset","a"
 .align 3
 linkadr:
 /*
@@ -24,4 +26,3 @@ linkadr:
  * use _text here since that is 0x0 and is correct without relocation.
  */
 .quad _text
-ENDPROC(get_runtime_offset)
-- 
2.39.2




More information about the barebox mailing list