Skip to content

Commit bff6015

Browse files
lzufalconwtarreau
authored andcommitted
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/[email protected]/ Suggested-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 7f85485 ("tools/nolibc: make compiler and assembler agree on the section around _start") Signed-off-by: Zhangjin Wu <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
1 parent 2023349 commit bff6015

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

tools/include/nolibc/arch-aarch64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ char **environ __attribute__((weak));
175175
const unsigned long *_auxv __attribute__((weak));
176176

177177
/* startup code */
178-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
178+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
179179
{
180180
__asm__ volatile (
181181
#ifdef _NOLIBC_STACKPROTECTOR

tools/include/nolibc/arch-arm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ char **environ __attribute__((weak));
225225
const unsigned long *_auxv __attribute__((weak));
226226

227227
/* startup code */
228-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
228+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
229229
{
230230
__asm__ volatile (
231231
#ifdef _NOLIBC_STACKPROTECTOR

tools/include/nolibc/arch-i386.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak));
190190
* 2) The deepest stack frame should be set to zero
191191
*
192192
*/
193-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
193+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
194194
{
195195
__asm__ volatile (
196196
#ifdef _NOLIBC_STACKPROTECTOR

tools/include/nolibc/arch-loongarch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const unsigned long *_auxv __attribute__((weak));
167167
#endif
168168

169169
/* startup code */
170-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
170+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
171171
{
172172
__asm__ volatile (
173173
#ifdef _NOLIBC_STACKPROTECTOR

tools/include/nolibc/arch-mips.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ char **environ __attribute__((weak));
205205
const unsigned long *_auxv __attribute__((weak));
206206

207207
/* startup code, note that it's called __start on MIPS */
208-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector __start(void)
208+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void)
209209
{
210210
__asm__ volatile (
211211
/*".set nomips16\n"*/

tools/include/nolibc/arch-riscv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ char **environ __attribute__((weak));
180180
const unsigned long *_auxv __attribute__((weak));
181181

182182
/* startup code */
183-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
183+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
184184
{
185185
__asm__ volatile (
186186
".option push\n"

tools/include/nolibc/arch-s390.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ char **environ __attribute__((weak));
166166
const unsigned long *_auxv __attribute__((weak));
167167

168168
/* startup code */
169-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
169+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
170170
{
171171
__asm__ volatile (
172172
"lg %r2,0(%r15)\n" /* argument count */

tools/include/nolibc/arch-x86_64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const unsigned long *_auxv __attribute__((weak));
190190
* 2) The deepest stack frame should be zero (the %rbp).
191191
*
192192
*/
193-
void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_protector _start(void)
193+
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
194194
{
195195
__asm__ volatile (
196196
#ifdef _NOLIBC_STACKPROTECTOR

0 commit comments

Comments
 (0)