mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 0/3] Fix GCC 11 THUMB2 relocate_to_current_adr miscompile
@ 2022-10-13  9:03 Ahmad Fatoum
  2022-10-13  9:03 ` [PATCH master 1/3] include: asm-generic: reloc: implement get_unrelocated() Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2022-10-13  9:03 UTC (permalink / raw)
  To: barebox

TL;DR: GCC can prove that variables aren't supposed to overlap and as
such it generated code than readded get_runtime_offset() on top of an
already relocated linker-defined variable's address.
See PATCH 2/3 for a disassembly of the affected code. Board code can
be similarly micompiled, but that's a fix for another day.

I am not so sure about the name of the new macro. I chose
get_unrelocated for similarity with get_unaligned, but it doesn't
dereference the argument, just get its address. Looking at it that way,
it's just a UB-infested way to say & (address-of). Perhaps just
call it runtime_address()? After all, it works before and after
relocation. We can change that later though, once I get around
to patch board entry points.

Ahmad Fatoum (3):
  include: asm-generic: reloc: implement get_unrelocated()
  ARM: cpu: add compiler barrier around unrelocated access
  RISC-V: add compiler barriers around unrelocated accesses

 arch/arm/cpu/common.c             | 11 +++--
 arch/arm/cpu/uncompress.c         |  4 +-
 arch/riscv/boot/uncompress.c      |  4 +-
 arch/riscv/include/asm/sections.h |  2 +-
 arch/riscv/lib/reloc.c            |  6 +--
 include/asm-generic/reloc.h       | 68 +++++++++++++++++++++++++++++++
 6 files changed, 81 insertions(+), 14 deletions(-)

-- 
2.30.2




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

end of thread, other threads:[~2022-10-13 11:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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