Skip to content

Commit b847bd6

Browse files
keestsbogend
authored andcommitted
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: 200ed34 ("mips: Implement "current_stack_pointer"") Reported-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Nathan 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: Kees Cook <keescook@chromium.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 4d409ca commit b847bd6

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

arch/mips/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ config MIPS
44
default y
55
select ARCH_32BIT_OFF_T if !64BIT
66
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
7-
select ARCH_HAS_CURRENT_STACK_POINTER
7+
select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000
88
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
99
select ARCH_HAS_FORTIFY_SOURCE
1010
select ARCH_HAS_KCOV

arch/mips/include/asm/thread_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ static inline struct thread_info *current_thread_info(void)
6969
return __current_thread_info;
7070
}
7171

72+
#ifdef CONFIG_ARCH_HAS_CURRENT_STACK_POINTER
7273
register unsigned long current_stack_pointer __asm__("sp");
74+
#endif
7375

7476
#endif /* !__ASSEMBLY__ */
7577

arch/mips/kernel/irq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ void __init init_IRQ(void)
7575
#ifdef CONFIG_DEBUG_STACKOVERFLOW
7676
static inline void check_stack_overflow(void)
7777
{
78-
unsigned long sp = current_stack_pointer;
78+
unsigned long sp;
7979

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

8283
/*

arch/mips/lib/uncached.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ unsigned long run_uncached(void *func)
4040
register long ret __asm__("$2");
4141
long lfunc = (long)func, ufunc;
4242
long usp;
43-
long sp = current_stack_pointer;
43+
long sp;
44+
45+
__asm__("move %0, $sp" : "=r" (sp));
4446

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

0 commit comments

Comments
 (0)