All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU
@ 2026-10-20  4:00 Waldemar Brodkorb
  2026-10-20  6:57 ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Waldemar Brodkorb @ 2026-10-20  4:00 UTC (permalink / raw)
  To: linux-sh; +Cc: Max Filippov, Greg Ungerer, Damien Le Moal

binfmt_flat offsets the in-memory start of the data segment by
MAX_SHARED_LIBS words and then aligns it to FLAT_DATA_ALIGN, so FLAT_FLAG_RAM
binaries end up with a gap between text and data (commit 2217b9826246
("binfmt_flat: revert "binfmt_flat: don't offset the data start"")).

SH position-independent code finds the GOT with a PC-relative mova of
_GLOBAL_OFFSET_TABLE_, which assumes data follows text directly, as elf2flt
lays out the image. With the gap, the GOT register points below the real GOT,
so every GOT load reads the neighbouring slot and gets a wrong pointer. On a
J2 (sh2eb, noMMU) this made userland crash or hang right after start-up.
In my case the data was moved up by 0x20 bytes.

Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") added
CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET for architectures that cannot
tolerate such a gap; currently only riscv noMMU selects it. Select it on SH
as well when building without an MMU.

Tested on a J2 board (Numato Mimas V2, sh2eb, noMMU) with Linux 6.18 and
FLAT binaries built with elf2flt: with this change the data segment starts
exactly at the end of text and init runs.

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Assisted-by: LLM
---
 arch/sh/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index d60f1d5a94c0..b501153551c0 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -15,6 +15,7 @@ config SUPERH
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select ARCH_NEED_CMPXCHG_1_EMU
+	select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
 	select CPU_NO_EFFICIENT_FFS
 	select DMA_DECLARE_COHERENT
 	select GENERIC_ATOMIC64
-- 
2.47.3

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

* Re: [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU
  2026-10-20  4:00 [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU Waldemar Brodkorb
@ 2026-10-20  6:57 ` Geert Uytterhoeven
  2026-10-20  7:21   ` Waldemar Brodkorb
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-10-20  6:57 UTC (permalink / raw)
  To: Waldemar Brodkorb; +Cc: linux-sh, Max Filippov, Greg Ungerer, Damien Le Moal

Hi Waldemar,

On Tue, 20 Oct 2026 at 06:00, Waldemar Brodkorb <wbx@openadk.org> wrote:
> binfmt_flat offsets the in-memory start of the data segment by
> MAX_SHARED_LIBS words and then aligns it to FLAT_DATA_ALIGN, so FLAT_FLAG_RAM
> binaries end up with a gap between text and data (commit 2217b9826246
> ("binfmt_flat: revert "binfmt_flat: don't offset the data start"")).
>
> SH position-independent code finds the GOT with a PC-relative mova of
> _GLOBAL_OFFSET_TABLE_, which assumes data follows text directly, as elf2flt
> lays out the image. With the gap, the GOT register points below the real GOT,
> so every GOT load reads the neighbouring slot and gets a wrong pointer. On a
> J2 (sh2eb, noMMU) this made userland crash or hang right after start-up.
> In my case the data was moved up by 0x20 bytes.
>
> Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") added
> CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET for architectures that cannot
> tolerate such a gap; currently only riscv noMMU selects it. Select it on SH
> as well when building without an MMU.

Thanks for your patch!

> Tested on a J2 board (Numato Mimas V2, sh2eb, noMMU) with Linux 6.18 and
> FLAT binaries built with elf2flt: with this change the data segment starts
> exactly at the end of text and init runs.

V6.18 is getting a bit old. Can you please verify on v7.3?

>
> Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
> Assisted-by: LLM

This needs a Fixes tag.
Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU
  2026-10-20  6:57 ` Geert Uytterhoeven
@ 2026-10-20  7:21   ` Waldemar Brodkorb
  2026-10-20  7:37     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Waldemar Brodkorb @ 2026-10-20  7:21 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Waldemar Brodkorb, linux-sh, Max Filippov, Greg Ungerer,
	Damien Le Moal

Hi Geert,
Geert Uytterhoeven wrote,

> Hi Waldemar,
> 
> On Tue, 20 Oct 2026 at 06:00, Waldemar Brodkorb <wbx@openadk.org> wrote:
> > binfmt_flat offsets the in-memory start of the data segment by
> > MAX_SHARED_LIBS words and then aligns it to FLAT_DATA_ALIGN, so FLAT_FLAG_RAM
> > binaries end up with a gap between text and data (commit 2217b9826246
> > ("binfmt_flat: revert "binfmt_flat: don't offset the data start"")).
> >
> > SH position-independent code finds the GOT with a PC-relative mova of
> > _GLOBAL_OFFSET_TABLE_, which assumes data follows text directly, as elf2flt
> > lays out the image. With the gap, the GOT register points below the real GOT,
> > so every GOT load reads the neighbouring slot and gets a wrong pointer. On a
> > J2 (sh2eb, noMMU) this made userland crash or hang right after start-up.
> > In my case the data was moved up by 0x20 bytes.
> >
> > Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") added
> > CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET for architectures that cannot
> > tolerate such a gap; currently only riscv noMMU selects it. Select it on SH
> > as well when building without an MMU.
> 
> Thanks for your patch!
> 
> > Tested on a J2 board (Numato Mimas V2, sh2eb, noMMU) with Linux 6.18 and
> > FLAT binaries built with elf2flt: with this change the data segment starts
> > exactly at the end of text and init runs.
> 
> V6.18 is getting a bit old. Can you please verify on v7.3?

The problem with Linus 7.3 tree is, that Florian's patch which fixes the
compile error with nstree.c is not in. Or do you mean linux-sh tree
for-next branch with Florian's commit eb549e808390eeecf07618b8c3a82a6f2a887e70?
 
best regards
 Waldemar

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

* Re: [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU
  2026-10-20  7:21   ` Waldemar Brodkorb
@ 2026-10-20  7:37     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-10-20  7:37 UTC (permalink / raw)
  To: Waldemar Brodkorb; +Cc: linux-sh, Max Filippov, Greg Ungerer, Damien Le Moal

Hi Waldemar,

On Tue, 20 Oct 2026 at 09:21, Waldemar Brodkorb <wbx@openadk.org> wrote:
> > On Tue, 20 Oct 2026 at 06:00, Waldemar Brodkorb <wbx@openadk.org> wrote:
> > > binfmt_flat offsets the in-memory start of the data segment by
> > > MAX_SHARED_LIBS words and then aligns it to FLAT_DATA_ALIGN, so FLAT_FLAG_RAM
> > > binaries end up with a gap between text and data (commit 2217b9826246
> > > ("binfmt_flat: revert "binfmt_flat: don't offset the data start"")).
> > >
> > > SH position-independent code finds the GOT with a PC-relative mova of
> > > _GLOBAL_OFFSET_TABLE_, which assumes data follows text directly, as elf2flt
> > > lays out the image. With the gap, the GOT register points below the real GOT,
> > > so every GOT load reads the neighbouring slot and gets a wrong pointer. On a
> > > J2 (sh2eb, noMMU) this made userland crash or hang right after start-up.
> > > In my case the data was moved up by 0x20 bytes.
> > >
> > > Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") added
> > > CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET for architectures that cannot
> > > tolerate such a gap; currently only riscv noMMU selects it. Select it on SH
> > > as well when building without an MMU.
> >
> > Thanks for your patch!
> >
> > > Tested on a J2 board (Numato Mimas V2, sh2eb, noMMU) with Linux 6.18 and
> > > FLAT binaries built with elf2flt: with this change the data segment starts
> > > exactly at the end of text and init runs.
> >
> > V6.18 is getting a bit old. Can you please verify on v7.3?
>
> The problem with Linus 7.3 tree is, that Florian's patch which fixes the
> compile error with nstree.c is not in. Or do you mean linux-sh tree
> for-next branch with Florian's commit eb549e808390eeecf07618b8c3a82a6f2a887e70?

Sure, you can (and should ;-) include fixes for other issues when testing.
Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2026-10-20  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20  4:00 [PATCH] sh: select BINFMT_FLAT_NO_DATA_START_OFFSET for noMMU Waldemar Brodkorb
2026-10-20  6:57 ` Geert Uytterhoeven
2026-10-20  7:21   ` Waldemar Brodkorb
2026-10-20  7:37     ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.