Skip to content

Commit

Permalink
tools/nolibc: x86_64: add stackprotector support
Browse files Browse the repository at this point in the history
Enable the new stackprotector support for x86_64.

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>
  • Loading branch information
Thomas Weißschuh authored and Paul E. McKenney committed Mar 27, 2023
1 parent ff221a6 commit 0d8c461
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/include/nolibc/arch-x86_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ struct sys_stat_struct {
char **environ __attribute__((weak));
const unsigned long *_auxv __attribute__((weak));

#define __ARCH_SUPPORTS_STACK_PROTECTOR

/* startup code */
/*
* x86-64 System V ABI mandates:
Expand All @@ -191,6 +193,9 @@ const unsigned long *_auxv __attribute__((weak));
void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
{
__asm__ volatile (
#ifdef NOLIBC_STACKPROTECTOR
"call __stack_chk_init\n" // initialize stack protector
#endif
"pop %rdi\n" // argc (first arg, %rdi)
"mov %rsp, %rsi\n" // argv[] (second arg, %rsi)
"lea 8(%rsi,%rdi,8),%rdx\n" // then a NULL then envp (third arg, %rdx)
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/nolibc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ CFLAGS_STACKPROTECTOR = -DNOLIBC_STACKPROTECTOR \
$(call cc-option,-mstack-protector-guard=global) \
$(call cc-option,-fstack-protector-all)
CFLAGS_STKP_i386 = $(CFLAGS_STACKPROTECTOR)
CFLAGS_STKP_x86_64 = $(CFLAGS_STACKPROTECTOR)
CFLAGS_STKP_x86 = $(CFLAGS_STACKPROTECTOR)
CFLAGS_s390 = -m64
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables \
$(call cc-option,-fno-stack-protector) \
Expand Down

0 comments on commit 0d8c461

Please sign in to comment.