mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] ARM64: reloc: fix relocation error for big fat bareboxes
@ 2024-05-13 14:01 Ahmad Fatoum
  2024-05-15  5:55 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2024-05-13 14:01 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

A multi_v8 barebox with KASAN enabled is 2051804 bytes even after
compression and this breaks linking for me:

  arch/arm/cpu/common.o: in function `global_variable_offset':
  arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x1c):
    relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
    `_text' defined in .text section in .tmp_barebox1
  arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x40):
    relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
    `_text' defined in .text section in .tmp_barebox1

This is due to adr's limitation of only addressing bytes +/- 1 MiB from
the current PC. We have a solution for this in the form of the adr_l
macro, which we define for out-of-line assembly. Opencode this into the
inline assembly function, by using adrp to compute the page offset and
then add to arrive at the correct offset within the page.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - fix typos: s/adrp/adr_l/, add unit (bytes) after barebox size
---
 arch/arm/include/asm/reloc.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/reloc.h b/arch/arm/include/asm/reloc.h
index 95b4ef0af88b..2d7411ab5284 100644
--- a/arch/arm/include/asm/reloc.h
+++ b/arch/arm/include/asm/reloc.h
@@ -18,7 +18,8 @@ static inline __prereloc unsigned long global_variable_offset(void)
 	unsigned long text;
 
 	__asm__ __volatile__(
-		"adr    %0, _text\n"
+		"adrp   %0, _text\n"
+		"add    %0, %0, :lo12:_text\n"
 		: "=r" (text)
 		:
 		: "memory");
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ARM64: reloc: fix relocation error for big fat bareboxes
  2024-05-13 14:01 [PATCH v2] ARM64: reloc: fix relocation error for big fat bareboxes Ahmad Fatoum
@ 2024-05-15  5:55 ` Sascha Hauer
  2024-05-15 13:05   ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2024-05-15  5:55 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 13 May 2024 16:01:21 +0200, Ahmad Fatoum wrote:
> A multi_v8 barebox with KASAN enabled is 2051804 bytes even after
> compression and this breaks linking for me:
> 
>   arch/arm/cpu/common.o: in function `global_variable_offset':
>   arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x1c):
>     relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
>     `_text' defined in .text section in .tmp_barebox1
>   arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x40):
>     relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
>     `_text' defined in .text section in .tmp_barebox1
> 
> [...]

Applied, thanks!

[1/1] ARM64: reloc: fix relocation error for big fat bareboxes
      https://git.pengutronix.de/cgit/barebox/commit/?id=9246c916a25a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ARM64: reloc: fix relocation error for big fat bareboxes
  2024-05-15  5:55 ` Sascha Hauer
@ 2024-05-15 13:05   ` Ahmad Fatoum
  0 siblings, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-05-15 13:05 UTC (permalink / raw)
  To: Sascha Hauer, barebox

Hi,

On 15.05.24 07:55, Sascha Hauer wrote:
> 
> On Mon, 13 May 2024 16:01:21 +0200, Ahmad Fatoum wrote:
>> A multi_v8 barebox with KASAN enabled is 2051804 bytes even after
>> compression and this breaks linking for me:
>>
>>   arch/arm/cpu/common.o: in function `global_variable_offset':
>>   arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x1c):
>>     relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
>>     `_text' defined in .text section in .tmp_barebox1
>>   arch/arm/include/asm/reloc.h:20:(.text.relocate_to_current_adr+0x40):
>>     relocation truncated to fit: R_AARCH64_ADR_PREL_LO21 against symbol
>>     `_text' defined in .text section in .tmp_barebox1
>>
>> [...]
> 
> Applied, thanks!

Thanks for applying. I thought some more about whether we should instead
have:

#ifdef __PBL__
        "adr    %0, _text\n"
#else
        /* (Decompressed) barebox proper should always be 4K aligned
         * so adrp here should be fine. PBL may also have adrp
         * references
         */
        "adrp   %0, _text\n"
        "add    %0, %0, :lo12:_text\n"
#endif

Otherwise, we require PBL to be placed 4K-aligned. Looking at GCC 13.2.1
output for an i.MX8M board, there are quite a lot of adrp references already,
so I think this shouldn't break anything that's not broken already anyway.

Just writing my thoughts for future reference.

Cheers,
Ahmad

> 
> [1/1] ARM64: reloc: fix relocation error for big fat bareboxes
>       https://git.pengutronix.de/cgit/barebox/commit/?id=9246c916a25a (link may not be stable)
> 
> Best regards,

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-15 13:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 14:01 [PATCH v2] ARM64: reloc: fix relocation error for big fat bareboxes Ahmad Fatoum
2024-05-15  5:55 ` Sascha Hauer
2024-05-15 13:05   ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox