mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
690d9163bf
Some versions of GCC suboptimally generate calls to the __multi3()
intrinsic for MIPS64r6 builds, resulting in link failures due to the
missing function:
LD vmlinux.o
MODPOST vmlinux.o
kernel/bpf/verifier.o: In function `kmalloc_array':
include/linux/slab.h:631: undefined reference to `__multi3'
fs/select.o: In function `kmalloc_array':
include/linux/slab.h:631: undefined reference to `__multi3'
...
We already have a workaround for this in which we provide the
instrinsic, but we do so selectively for GCC 7 only. Unfortunately the
issue occurs with older GCC versions too - it has been observed with
both GCC 5.4.0 & GCC 6.4.0.
MIPSr6 support was introduced in GCC 5, so all major GCC versions prior
to GCC 8 are affected and we extend our workaround accordingly to all
MIPS64r6 builds using GCC versions older than GCC 8.
Signed-off-by: Paul Burton <paul.burton@mips.com>
Reported-by: Vladimir Kondratiev <vladimir.kondratiev@intel.com>
Fixes: ebabcf17bc
("MIPS: Implement __multi3 for GCC7 MIPS64r6 builds")
Patchwork: https://patchwork.linux-mips.org/patch/20297/
Cc: James Hogan <jhogan@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org # 4.15+
55 lines
1.3 KiB
C
55 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/export.h>
|
|
|
|
#include "libgcc.h"
|
|
|
|
/*
|
|
* GCC 7 & older can suboptimally generate __multi3 calls for mips64r6, so for
|
|
* that specific case only we implement that intrinsic here.
|
|
*
|
|
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82981
|
|
*/
|
|
#if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPSR6) && (__GNUC__ < 8)
|
|
|
|
/* multiply 64-bit values, low 64-bits returned */
|
|
static inline long long notrace dmulu(long long a, long long b)
|
|
{
|
|
long long res;
|
|
|
|
asm ("dmulu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
|
|
return res;
|
|
}
|
|
|
|
/* multiply 64-bit unsigned values, high 64-bits of 128-bit result returned */
|
|
static inline long long notrace dmuhu(long long a, long long b)
|
|
{
|
|
long long res;
|
|
|
|
asm ("dmuhu %0,%1,%2" : "=r" (res) : "r" (a), "r" (b));
|
|
return res;
|
|
}
|
|
|
|
/* multiply 128-bit values, low 128-bits returned */
|
|
ti_type notrace __multi3(ti_type a, ti_type b)
|
|
{
|
|
TWunion res, aa, bb;
|
|
|
|
aa.ti = a;
|
|
bb.ti = b;
|
|
|
|
/*
|
|
* a * b = (a.lo * b.lo)
|
|
* + 2^64 * (a.hi * b.lo + a.lo * b.hi)
|
|
* [+ 2^128 * (a.hi * b.hi)]
|
|
*/
|
|
res.s.low = dmulu(aa.s.low, bb.s.low);
|
|
res.s.high = dmuhu(aa.s.low, bb.s.low);
|
|
res.s.high += dmulu(aa.s.high, bb.s.low);
|
|
res.s.high += dmulu(aa.s.low, bb.s.high);
|
|
|
|
return res.ti;
|
|
}
|
|
EXPORT_SYMBOL(__multi3);
|
|
|
|
#endif /* 64BIT && CPU_MIPSR6 && GCC7 */
|