Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

start_kernel: Omit prevent_tail_call_optimization() for newer toolchains

prevent_tail_call_optimization() was added in
commit a9a3ed1eff36 ("x86: Fix early boot crash on gcc-10, third try")
to work around stack canaries getting inserted into functions that would
initialize the stack canary in the first place.

Now that we have no_stack_protector function attribute (gcc-11+,
clang-7+) and use it on start_kernel(), remove the call to
prevent_tail_call_optimization() such that we may one day remove it
outright.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20230412-no_stackp-v2-2-116f9fe4bbe7@google.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

authored by

ndesaulniers@google.com and committed by
Josh Poimboeuf
dc1d0553 514ca14e

+6
+6
init/main.c
··· 1088 1088 /* Do the rest non-__init'ed, we're now alive */ 1089 1089 arch_call_rest_init(); 1090 1090 1091 + /* 1092 + * Avoid stack canaries in callers of boot_init_stack_canary for gcc-10 1093 + * and older. 1094 + */ 1095 + #if !__has_attribute(__no_stack_protector__) 1091 1096 prevent_tail_call_optimization(); 1097 + #endif 1092 1098 } 1093 1099 1094 1100 /* Call all constructor functions linked into the kernel. */