tools/nolibc: riscv: add stackprotector support
authorThomas Weißschuh <linux@weissschuh.net>
Sat, 20 May 2023 09:53:35 +0000 (11:53 +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>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/include/nolibc/arch-riscv.h
tools/testing/selftests/nolibc/Makefile

index 992a1739dd9c47581e16d9c1753d8968f05addb3..d0439249c9c93b890aba154b0a7349197e7639a0 100644 (file)
@@ -177,14 +177,19 @@ struct sys_stat_struct {
 char **environ __attribute__((weak));
 const unsigned long *_auxv __attribute__((weak));
 
+#define __ARCH_SUPPORTS_STACK_PROTECTOR
+
 /* startup code */
-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 (
                ".option push\n"
                ".option norelax\n"
                "lla   gp, __global_pointer$\n"
                ".option pop\n"
+#ifdef NOLIBC_STACKPROTECTOR
+               "call __stack_chk_init\n"    /* initialize stack protector                          */
+#endif
                REG_L" a0, 0(sp)\n"          /* argc (a0) was in the stack                          */
                "add   a1, sp, "SZREG"\n"    /* argv (a1) = sp                                      */
                "slli  a2, a0, "PTRLOG"\n"   /* envp (a2) = SZREG*argc ...                          */
index 6d660d9222403da21a6089f0ee23d0f36a384682..bd41102ea299545d173ce78c88179fba879a5109 100644 (file)
@@ -85,6 +85,7 @@ CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_arm64 = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_arm = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_mips = $(CFLAGS_STACKPROTECTOR)
+CFLAGS_STKP_riscv = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_STKP_loongarch = $(CFLAGS_STACKPROTECTOR)
 CFLAGS_s390 = -m64
 CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \