tools/nolibc: mips: add stackprotector support
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 17 Apr 2023 16:01:36 +0000 (18:01 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 9 Jun 2023 18:46:08 +0000 (11:46 -0700)
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/include/nolibc/arch-mips.h
tools/testing/selftests/nolibc/Makefile

index 8822f150e72f73f61e69d80932231c2e60f44e42..65c19ccc7f9d1c454fc88e903f01fe651eb579ba 100644 (file)
@@ -179,14 +179,20 @@ struct sys_stat_struct {
 char **environ __attribute__((weak));
 const unsigned long *_auxv __attribute__((weak));
 
+#define __ARCH_SUPPORTS_STACK_PROTECTOR
+
 /* startup code, note that it's called __start on MIPS */
-void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __start(void)
+void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_protector)) __start(void)
 {
        __asm__ volatile (
                /*".set nomips16\n"*/
                ".set push\n"
                ".set    noreorder\n"
                ".option pic0\n"
+#ifdef NOLIBC_STACKPROTECTOR
+               "jal __stack_chk_init\n" /* initialize stack protector                         */
+               "nop\n"                  /* delayed slot                                       */
+#endif
                /*".ent __start\n"*/
                /*"__start:\n"*/
                "lw $a0,($sp)\n"        /* argc was in the stack                               */
index ab6e7c0c2494dec652a82c85a410dbd7f71eb8d9..6d660d9222403da21a6089f0ee23d0f36a384682 100644 (file)
@@ -84,6 +84,7 @@ CFLAGS_STKP_x86_64 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_arm64 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_arm = $(CFLAGS_STACKPROTECTOR)
+CFLAGS_STKP_mips = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_loongarch = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_s390 = -m64
 CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \