Skip to content

Commit

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

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 9735716 commit ff221a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/include/nolibc/arch-i386.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,21 @@ struct sys_stat_struct {
char **environ __attribute__((weak));
const unsigned long *_auxv __attribute__((weak));

#define __ARCH_SUPPORTS_STACK_PROTECTOR

/* startup code */
/*
* i386 System V ABI mandates:
* 1) last pushed argument must be 16-byte aligned.
* 2) The deepest stack frame should be set to zero
*
*/
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 (
#ifdef NOLIBC_STACKPROTECTOR
"call __stack_chk_init\n" // initialize stack protector
#endif
"pop %eax\n" // argc (first arg, %eax)
"mov %esp, %ebx\n" // argv[] (second arg, %ebx)
"lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/nolibc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ endif
CFLAGS_STACKPROTECTOR = -DNOLIBC_STACKPROTECTOR \
$(call cc-option,-mstack-protector-guard=global) \
$(call cc-option,-fstack-protector-all)
CFLAGS_STKP_i386 = $(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 ff221a6

Please sign in to comment.