• Paul Burton's avatar
    MIPS: Always use -march=<arch>, not -<arch> shortcuts · 344ebf09
    Paul Burton authored
    The VDSO Makefile filters CFLAGS to select a subset which it uses whilst
    building the VDSO ELF. One of the flags it allows through is the -march=
    flag that selects the architecture/ISA to target.
    
    Unfortunately in cases where CONFIG_CPU_MIPS32_R{1,2}=y and the
    toolchain defaults to building for MIPS64, the main MIPS Makefile ends
    up using the short-form -<arch> flags in cflags-y. This is because the
    calls to cc-option always fail to use the long-form -march=<arch> flag
    due to the lack of an -mabi=<abi> flag in KBUILD_CFLAGS at the point
    where the cc-option function is executed. The resulting GCC invocation
    is something like:
    
      $ mips64-linux-gcc -Werror -march=mips32r2 -c -x c /dev/null -o tmp
      cc1: error: '-march=mips32r2' is not compatible with the selected ABI
    
    These short-form -<arch> flags are dropped by the VDSO Makefile's
    filtering, and so we attempt to build the VDSO without specifying any
    architecture. This results in an attempt to build the VDSO using
    whatever the compiler's default architecture is, regardless of whether
    that is suitable for the kernel configuration.
    
    One encountered build failure resulting from this mismatch is a
    rejection of the sync instruction if the kernel is configured for a
    MIPS32 or MIPS64 r1 or r2 target but the toolchain defaults to an older
    architecture revision such as MIPS1 which did not include the sync
    instruction:
    
        CC      arch/mips/vdso/gettimeofday.o
      /tmp/ccGQKoOj.s: Assembler messages:
      /tmp/ccGQKoOj.s:273: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:329: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:520: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:714: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1009: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1066: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1114: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1279: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1334: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1374: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1459: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1514: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:1814: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:2002: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      /tmp/ccGQKoOj.s:2066: Error: opcode not supported on this processor: mips1 (mips1) `sync'
      make[2]: *** [scripts/Makefile.build:318: arch/mips/vdso/gettimeofday.o] Error 1
      make[1]: *** [scripts/Makefile.build:558: arch/mips/vdso] Error 2
      make[1]: *** Waiting for unfinished jobs....
    
    This can be reproduced for example by attempting to build
    pistachio_defconfig using Arnd's GCC 8.1.0 mips64 toolchain from
    kernel.org:
    
      https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-mips64-linux.tar.xz
    
    Resolve this problem by using the long-form -march=<arch> in all cases,
    which makes it through the arch/mips/vdso/Makefile's filtering & is thus
    consistently used to build both the kernel proper & the VDSO.
    
    The use of cc-option to prefer the long-form & fall back to the
    short-form flags makes no sense since the short-form is just an
    abbreviation for the also-supported long-form in all GCC versions that
    we support building with. This means there is no case in which we have
    to use the short-form -<arch> flags, so we can simply remove them.
    
    The manual redefinition of _MIPS_ISA is removed naturally along with the
    use of the short-form flags that it accompanied, and whilst here we
    remove the separate assembler ISA selection. I suspect that both of
    these were only required due to the mips32 vs mips2 mismatch that was
    introduced by commit 59b3e8e9 ("[MIPS] Makefile crapectomy.") and
    fixed but not cleaned up by commit 9200c0b2 ("[MIPS] Fix Makefile
    bugs for MIPS32/MIPS64 R1 and R2.").
    
    I've marked this for backport as far as v4.4 where the MIPS VDSO was
    introduced. In earlier kernels there should be no ill effect to using
    the short-form flags.
    Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
    Cc: Ralf Baechle <ralf@linux-mips.org>
    Cc: linux-mips@linux-mips.org
    Cc: stable@vger.kernel.org # v4.4+
    Reviewed-by: default avatarJames Hogan <jhogan@kernel.org>
    Patchwork: https://patchwork.linux-mips.org/patch/19579/
    344ebf09
Makefile 19.2 KB