Commit b847bd64 authored by Kees Cook's avatar Kees Cook Committed by Thomas Bogendoerfer
Browse files

MIPS: Only use current_stack_pointer on GCC



Unfortunately, Clang did not have support for "sp" as a global register
definition, and was crashing after the addition of current_stack_pointer.
This has been fixed in Clang 14, but earlier Clang versions need to
avoid this code, so add a versioned test and revert back to the
open-coded asm instances. Fixes Clang build error:

fatal error: error in backend: Invalid register name global variable

Fixes: 200ed341 ("mips: Implement "current_stack_pointer"")
Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/lkml/YikTQRql+il3HbrK@dev-arch.thelio-3990X


Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Yanteng Si <siyanteng01@gmail.com>
Cc: linux-mips@vger.kernel.org
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent 4d409ca3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ config MIPS
	default y
	select ARCH_32BIT_OFF_T if !64BIT
	select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
	select ARCH_HAS_CURRENT_STACK_POINTER
	select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000
	select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
	select ARCH_HAS_FORTIFY_SOURCE
	select ARCH_HAS_KCOV
+2 −0
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ static inline struct thread_info *current_thread_info(void)
	return __current_thread_info;
}

#ifdef CONFIG_ARCH_HAS_CURRENT_STACK_POINTER
register unsigned long current_stack_pointer __asm__("sp");
#endif

#endif /* !__ASSEMBLY__ */

+2 −1
Original line number Diff line number Diff line
@@ -75,8 +75,9 @@ void __init init_IRQ(void)
#ifdef CONFIG_DEBUG_STACKOVERFLOW
static inline void check_stack_overflow(void)
{
	unsigned long sp = current_stack_pointer;
	unsigned long sp;

	__asm__ __volatile__("move %0, $sp" : "=r" (sp));
	sp &= THREAD_MASK;

	/*
+3 −1
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ unsigned long run_uncached(void *func)
	register long ret __asm__("$2");
	long lfunc = (long)func, ufunc;
	long usp;
	long sp = current_stack_pointer;
	long sp;

	__asm__("move %0, $sp" : "=r" (sp));

	if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
		usp = CKSEG1ADDR(sp);