[PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel

Thomas Weißschuh posted 16 patches 4 months ago
There is a newer version of this series
[PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel
Posted by Thomas Weißschuh 4 months ago
Make sure the byte order and ABI of the userprogs matches the one of the
kernel, similar to how the bit size is handled.
Otherwise the userprogs may not be executable.
This happens for example on powerpc little endian, or riscv32.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45a2807dfa257f4 100644
--- a/Makefile
+++ b/Makefile
@@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
 LDFLAGS_vmlinux	+= --emit-relocs --discard-none
 endif
 
-# Align the bit size of userspace programs with the kernel
-USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
+# Align the bit size, byte order and architecture of userspace programs with the kernel
+USERFLAGS_FROM_KERNEL := -m32 -m64 -mlittle-endian -mbig-endian --target=% -march=% -mabi=%
 KBUILD_USERCFLAGS  += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
 KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
 

-- 
2.49.0

Re: [PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel
Posted by Masahiro Yamada 3 months, 3 weeks ago
On Wed, Jun 11, 2025 at 4:38 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> Make sure the byte order and ABI of the userprogs matches the one of the
> kernel, similar to how the bit size is handled.
> Otherwise the userprogs may not be executable.
> This happens for example on powerpc little endian, or riscv32.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
>  Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45a2807dfa257f4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
>  LDFLAGS_vmlinux        += --emit-relocs --discard-none
>  endif
>
> -# Align the bit size of userspace programs with the kernel
> -USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
> +# Align the bit size, byte order and architecture of userspace programs with the kernel
> +USERFLAGS_FROM_KERNEL := -m32 -m64 -mlittle-endian -mbig-endian --target=% -march=% -mabi=%
>  KBUILD_USERCFLAGS  += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
>  KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))


Why didn't you do like this?

USERFLAGS_FROM_KERNEL := $(filter -m32 -m64 -mlittle-endian
-mbig-endian --target=% -march=% -mabi=%, $(KBUILD_CPPFLAGS)
$(KBUILD_CFLAGS))
KBUILD_USERCFLAGS  += $(USERFLAGS_FROM_KERNEL)
KBUILD_USERLDFLAGS += $(USERFLAGS_FROM_KERNEL)



--
Best Regards
Masahiro Yamada
Re: [PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel
Posted by Thomas Weißschuh 3 months, 3 weeks ago
On Mon, Jun 16, 2025 at 11:49:41PM +0900, Masahiro Yamada wrote:
> On Wed, Jun 11, 2025 at 4:38 PM Thomas Weißschuh
> <thomas.weissschuh@linutronix.de> wrote:
> >
> > Make sure the byte order and ABI of the userprogs matches the one of the
> > kernel, similar to how the bit size is handled.
> > Otherwise the userprogs may not be executable.
> > This happens for example on powerpc little endian, or riscv32.
> >
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > ---
> >  Makefile | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45a2807dfa257f4 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
> >  LDFLAGS_vmlinux        += --emit-relocs --discard-none
> >  endif
> >
> > -# Align the bit size of userspace programs with the kernel
> > -USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
> > +# Align the bit size, byte order and architecture of userspace programs with the kernel
> > +USERFLAGS_FROM_KERNEL := -m32 -m64 -mlittle-endian -mbig-endian --target=% -march=% -mabi=%
> >  KBUILD_USERCFLAGS  += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> >  KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> 
> 
> Why didn't you do like this?
> 
> USERFLAGS_FROM_KERNEL := $(filter -m32 -m64 -mlittle-endian
> -mbig-endian --target=% -march=% -mabi=%, $(KBUILD_CPPFLAGS)
> $(KBUILD_CFLAGS))
> KBUILD_USERCFLAGS  += $(USERFLAGS_FROM_KERNEL)
> KBUILD_USERLDFLAGS += $(USERFLAGS_FROM_KERNEL)

The idea was to keep the USERFLAGS_FROM_KERNEL line free of clutter, as it is
probably going to change more often. To improve reviewability and gain some
available horizontal space in case it should be needed at some point.

If you prefer the other layout I'll be happy to switch it around.


Thomas
Re: [PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel
Posted by Masahiro Yamada 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 4:39 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> On Mon, Jun 16, 2025 at 11:49:41PM +0900, Masahiro Yamada wrote:
> > On Wed, Jun 11, 2025 at 4:38 PM Thomas Weißschuh
> > <thomas.weissschuh@linutronix.de> wrote:
> > >
> > > Make sure the byte order and ABI of the userprogs matches the one of the
> > > kernel, similar to how the bit size is handled.
> > > Otherwise the userprogs may not be executable.
> > > This happens for example on powerpc little endian, or riscv32.
> > >
> > > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > > ---
> > >  Makefile | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45a2807dfa257f4 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
> > >  LDFLAGS_vmlinux        += --emit-relocs --discard-none
> > >  endif
> > >
> > > -# Align the bit size of userspace programs with the kernel
> > > -USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
> > > +# Align the bit size, byte order and architecture of userspace programs with the kernel
> > > +USERFLAGS_FROM_KERNEL := -m32 -m64 -mlittle-endian -mbig-endian --target=% -march=% -mabi=%
> > >  KBUILD_USERCFLAGS  += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> > >  KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
> >
> >
> > Why didn't you do like this?
> >
> > USERFLAGS_FROM_KERNEL := $(filter -m32 -m64 -mlittle-endian
> > -mbig-endian --target=% -march=% -mabi=%, $(KBUILD_CPPFLAGS)
> > $(KBUILD_CFLAGS))
> > KBUILD_USERCFLAGS  += $(USERFLAGS_FROM_KERNEL)
> > KBUILD_USERLDFLAGS += $(USERFLAGS_FROM_KERNEL)
>
> The idea was to keep the USERFLAGS_FROM_KERNEL line free of clutter, as it is
> probably going to change more often. To improve reviewability and gain some
> available horizontal space in case it should be needed at some point.
>
> If you prefer the other layout I'll be happy to switch it around.


$(filter ... $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))

is duplicated in the two lines.

That is the reason for my suggestion.



-- 
Best Regards
Masahiro Yamada
Re: [PATCH v3 02/16] kbuild: userprogs: also inherit byte order and ABI from kernel
Posted by Nicolas Schier 4 months ago
On Wed, Jun 11, 2025 at 09:38:08AM +0200, Thomas Weißschuh wrote:
> Make sure the byte order and ABI of the userprogs matches the one of the
> kernel, similar to how the bit size is handled.
> Otherwise the userprogs may not be executable.
> This happens for example on powerpc little endian, or riscv32.
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
>  Makefile | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Nicolas Schier <n.schier@avm.de>