Re: [PATCH v3] MIPS: Truncate link address into 32bit for 32bit kernel

From: Maciej W. Rozycki
Date: Fri Apr 10 2020 - 19:42:40 EST


On Fri, 10 Apr 2020, Kees Cook wrote:

> > diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
> > index d6e97df51cfb..0178f7085317 100644
> > --- a/arch/mips/kernel/Makefile
> > +++ b/arch/mips/kernel/Makefile
> > @@ -112,4 +112,13 @@ obj-$(CONFIG_MIPS_CPC) += mips-cpc.o
> > obj-$(CONFIG_CPU_PM) += pm.o
> > obj-$(CONFIG_MIPS_CPS_PM) += pm-cps.o
> >
> > -CPPFLAGS_vmlinux.lds := $(KBUILD_CFLAGS)
> > +# When linking a 32-bit executable the LLVM linker cannot cope with a
> > +# 32-bit load address that has been sign-extended to 64 bits. Simply
> > +# remove the upper 32 bits then, as it is safe to do so with other
> > +# linkers.
> > +ifdef CONFIG_64BIT
> > + load-ld = $(VMLINUX_LOAD_ADDRESS)
> > +else
> > + load-ld = $(shell $(objtree)/arch/mips/tools/truncate32 $(VMLINUX_LOAD_ADDRESS))
>
> This is major overkill. Just use the Makefile's builtin text
> manipulation:
>
> load-ld = $(subst 0xffffffff,0x,$(VMLINUX_LOAD_ADDRESS))

This looks like the best approach to me, thank you for the hint! And we
only ever want to strip 0xffffffff anyway. (I forgot about this function
of `make', doh!)

Maciej