From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH master 3/3] RISC-V: add compiler barriers around unrelocated accesses
Date: Thu, 13 Oct 2022 12:36:26 +0200 [thread overview]
Message-ID: <5646a232-b4f7-75c9-31ba-128c49ba73ff@pengutronix.de> (raw)
In-Reply-To: <20221013090352.562170-4-a.fatoum@pengutronix.de>
On 13.10.22 11:03, Ahmad Fatoum wrote:
> We observed on ARM miscompilation because get_runtime_offset() was
> cached before relocation, while address computation of symbol happened
> after, effectively adding the base address twice to the symbol offset.
>
> New get_unrelocated() hides origin of the symbol going into the address
> calculation and thereby thwarts this optimization. Employ it in RISC-V
> code as well to avoid such issues as experienced on ARM.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> arch/riscv/boot/uncompress.c | 4 ++--
> arch/riscv/include/asm/sections.h | 2 +-
> arch/riscv/lib/reloc.c | 6 +++---
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/arch/riscv/boot/uncompress.c b/arch/riscv/boot/uncompress.c
> index ee24f81e0159..eab51c8d52bc 100644
> --- a/arch/riscv/boot/uncompress.c
> +++ b/arch/riscv/boot/uncompress.c
> @@ -36,8 +36,8 @@ void __noreturn barebox_pbl_start(unsigned long membase, unsigned long memsize,
> irq_init_vector(riscv_mode());
>
> /* piggy data is not relocated, so determine the bounds now */
> - pg_start = input_data + get_runtime_offset();
> - pg_end = input_data_end + get_runtime_offset();
> + pg_start = get_unrelocated(input_data);
> + pg_end = get_unrelocated(input_data_end);
> pg_len = pg_end - pg_start;
> uncompressed_len = input_data_len();
>
> diff --git a/arch/riscv/include/asm/sections.h b/arch/riscv/include/asm/sections.h
> index 6673648bcd58..b90f4d6d2ad5 100644
> --- a/arch/riscv/include/asm/sections.h
> +++ b/arch/riscv/include/asm/sections.h
> @@ -19,7 +19,7 @@ unsigned long get_runtime_offset(void);
>
> static inline unsigned int input_data_len(void)
> {
> - return get_unaligned((const u32 *)(input_data_end + get_runtime_offset() - 4));
> + return get_unaligned((const u32 *)get_unrelocated(input_data_end) - 1);
> }
>
> #endif
> diff --git a/arch/riscv/lib/reloc.c b/arch/riscv/lib/reloc.c
> index 13118a9ac54f..1dddf627d0b9 100644
> --- a/arch/riscv/lib/reloc.c
> +++ b/arch/riscv/lib/reloc.c
> @@ -42,9 +42,9 @@ void relocate_to_current_adr(void)
> if (!offset)
> return;
>
> - dstart = __rel_dyn_start + offset;
> - dend = __rel_dyn_end + offset;
> - dynsym = (void *)__dynsym_start + offset;
> + dstart = get_unrelocated(__rel_dyn_start);
> + dend = get_unrelocated(__rel_dyn_end);
> + dynsym = get_unrelocated(__dynsym_start) + offset;
Ouch, + offset shouldn't be here. Will fix for v2.
>
> for (rela = dstart; (void *)rela < dend; rela++) {
> unsigned long *fixup;
--
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 |
next prev parent reply other threads:[~2022-10-13 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 9:03 [PATCH master 0/3] Fix GCC 11 THUMB2 relocate_to_current_adr miscompile Ahmad Fatoum
2022-10-13 9:03 ` [PATCH master 1/3] include: asm-generic: reloc: implement get_unrelocated() Ahmad Fatoum
2022-10-13 9:03 ` [PATCH master 2/3] ARM: cpu: add compiler barrier around unrelocated access Ahmad Fatoum
2022-10-13 9:03 ` [PATCH master 3/3] RISC-V: add compiler barriers around unrelocated accesses Ahmad Fatoum
2022-10-13 10:36 ` Ahmad Fatoum [this message]
2022-10-13 11:52 ` [PATCH master 0/3] Fix GCC 11 THUMB2 relocate_to_current_adr miscompile Marco Felsch
2022-10-13 11:53 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5646a232-b4f7-75c9-31ba-128c49ba73ff@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox