mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
tools/nolibc: fix up startup failures for -O0 under gcc < 11.1.0
As gcc doc [1] shows:
Most optimizations are completely disabled at -O0 or if an -O level is
not set on the command line, even if individual optimization flags are
specified.
Test result [2] shows, gcc>=11.1.0 deviates from the above description,
but before gcc 11.1.0, "-O0" still forcely uses frame pointer in the
_start function even if the individual optimize("omit-frame-pointer")
flag is specified.
The frame pointer related operations will change the stack pointer (e.g.
In x86_64, an extra "push %rbp" will be inserted at the beginning of
_start) and make it differs from the one we expected, as a result, break
the whole startup function.
To fix up this issue, as suggested by Thomas, the individual "Os" and
"omit-frame-pointer" optimize flags are used together on _start function
to disable frame pointer completely even if the -O0 is set on the
command line.
[1]: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
[2]: https://lore.kernel.org/lkml/20230714094723.140603-1-falcon@tinylab.org/
Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/lkml/34b21ba5-7b59-4b3b-9ed6-ef9a3a5e06f7@t-8ch.de/
Fixes: 7f85485896
("tools/nolibc: make compiler and assembler agree on the section around _start")
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
This commit is contained in:
parent
2023349835
commit
bff60150f7
8 changed files with 8 additions and 8 deletions
|
@ -175,7 +175,7 @@ char **environ __attribute__((weak));
|
|||
const unsigned long *_auxv __attribute__((weak));
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
#ifdef _NOLIBC_STACKPROTECTOR
|
||||
|
|
|
@ -225,7 +225,7 @@ char **environ __attribute__((weak));
|
|||
const unsigned long *_auxv __attribute__((weak));
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
#ifdef _NOLIBC_STACKPROTECTOR
|
||||
|
|
|
@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak));
|
|||
* 2) The deepest stack frame should be set to zero
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
#ifdef _NOLIBC_STACKPROTECTOR
|
||||
|
|
|
@ -167,7 +167,7 @@ const unsigned long *_auxv __attribute__((weak));
|
|||
#endif
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
#ifdef _NOLIBC_STACKPROTECTOR
|
||||
|
|
|
@ -205,7 +205,7 @@ char **environ __attribute__((weak));
|
|||
const unsigned long *_auxv __attribute__((weak));
|
||||
|
||||
/* startup code, note that it's called __start on MIPS */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector __start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
/*".set nomips16\n"*/
|
||||
|
|
|
@ -180,7 +180,7 @@ char **environ __attribute__((weak));
|
|||
const unsigned long *_auxv __attribute__((weak));
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".option push\n"
|
||||
|
|
|
@ -166,7 +166,7 @@ char **environ __attribute__((weak));
|
|||
const unsigned long *_auxv __attribute__((weak));
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"lg %r2,0(%r15)\n" /* argument count */
|
||||
|
|
|
@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak));
|
|||
* 2) The deepest stack frame should be zero (the %rbp).
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
#ifdef _NOLIBC_STACKPROTECTOR
|
||||
|
|
Loading…
Add table
Reference in a new issue