From: "Paul E. McKenney" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected],
"Thomas Weißschuh" <[email protected]>,
"Willy Tarreau" <[email protected]>,
"Paul E . McKenney" <[email protected]>
Subject: [PATCH v2 nolibc 32/53] tools/nolibc: fix segfaults on compilers without attribute no_stack_protector
Date: Mon, 12 Jun 2023 13:44:53 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop>
From: Thomas Weißschuh <[email protected]>
Not all compilers, notably GCC < 10, have support for
__attribute__((no_stack_protector)).
Fall back to a mechanism that also works there.
Tested with GCC 9.5.0 from kernel.org crosstools.
Signed-off-by: Thomas Weißschuh <[email protected]>
Signed-off-by: Willy Tarreau <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
tools/include/nolibc/arch-aarch64.h | 2 +-
tools/include/nolibc/arch-arm.h | 2 +-
tools/include/nolibc/arch-i386.h | 2 +-
tools/include/nolibc/arch-loongarch.h | 2 +-
tools/include/nolibc/arch-mips.h | 2 +-
tools/include/nolibc/arch-riscv.h | 2 +-
tools/include/nolibc/arch-x86_64.h | 2 +-
tools/include/nolibc/compiler.h | 10 ++++++++++
tools/include/nolibc/stackprotector.h | 2 +-
9 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/tools/include/nolibc/arch-aarch64.h b/tools/include/nolibc/arch-aarch64.h
index 64ec65b4ee38..11f294a406b7 100644
--- a/tools/include/nolibc/arch-aarch64.h
+++ b/tools/include/nolibc/arch-aarch64.h
@@ -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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h
index 924169522cf7..45b89ffe8247 100644
--- a/tools/include/nolibc/arch-arm.h
+++ b/tools/include/nolibc/arch-arm.h
@@ -202,7 +202,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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h
index 37f813912957..3d672d925e9e 100644
--- a/tools/include/nolibc/arch-i386.h
+++ b/tools/include/nolibc/arch-i386.h
@@ -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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h
index d8ea7e787df4..ad3f266e7093 100644
--- a/tools/include/nolibc/arch-loongarch.h
+++ b/tools/include/nolibc/arch-loongarch.h
@@ -172,7 +172,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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h
index 9860236e5340..db24e0837a39 100644
--- a/tools/include/nolibc/arch-mips.h
+++ b/tools/include/nolibc/arch-mips.h
@@ -182,7 +182,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("omit-frame-pointer"))) __no_stack_protector __start(void)
{
__asm__ volatile (
/*".set nomips16\n"*/
diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h
index 86616aeb77a0..a2e8564e66d6 100644
--- a/tools/include/nolibc/arch-riscv.h
+++ b/tools/include/nolibc/arch-riscv.h
@@ -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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
".option push\n"
diff --git a/tools/include/nolibc/arch-x86_64.h b/tools/include/nolibc/arch-x86_64.h
index 485a7ff72a87..6fc4d8392742 100644
--- a/tools/include/nolibc/arch-x86_64.h
+++ b/tools/include/nolibc/arch-x86_64.h
@@ -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("omit-frame-pointer"))) __no_stack_protector _start(void)
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
index 57da75cea799..beddc3665d69 100644
--- a/tools/include/nolibc/compiler.h
+++ b/tools/include/nolibc/compiler.h
@@ -12,4 +12,14 @@
#endif /* defined(__SSP__) ... */
+#if defined(__has_attribute)
+# if __has_attribute(no_stack_protector)
+# define __no_stack_protector __attribute__((no_stack_protector))
+# else
+# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
+# endif
+#else
+# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
+#endif /* defined(__has_attribute) */
+
#endif /* _NOLIBC_COMPILER_H */
diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h
index 0a89e2b89ca6..88f7b2d098ff 100644
--- a/tools/include/nolibc/stackprotector.h
+++ b/tools/include/nolibc/stackprotector.h
@@ -37,7 +37,7 @@ void __stack_chk_fail_local(void)
__attribute__((weak,section(".data.nolibc_stack_chk")))
uintptr_t __stack_chk_guard;
-__attribute__((weak,no_stack_protector,section(".text.nolibc_stack_chk")))
+__attribute__((weak,section(".text.nolibc_stack_chk"))) __no_stack_protector
void __stack_chk_init(void)
{
my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0);
--
2.40.1
next prev parent reply other threads:[~2023-06-12 20:45 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 14:55 [PATCH nolibc 0/15] nolibc updates for v6.5] Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 01/15] tools/nolibc: tests: use volatile to force stack smashing Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 02/15] tools/nolibc: tests: fix build on non-c99 compliant compilers Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 03/15] tools/nolibc: fix build of the test case using glibc Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 04/15] tools/nolibc: add libc-test binary Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 05/15] tools/nolibc: add wrapper for memfd_create Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 06/15] tools/nolibc: implement fd-based FILE streams Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 07/15] tools/nolibc: add testcases for vfprintf Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 08/15] tools/nolibc: Fix build of stdio.h due to header ordering Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 09/15] tools/nolibc: use standard __asm__ statements Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 10/15] tools/nolibc: use __inline__ syntax Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 11/15] tools/nolibc: use C89 comment syntax Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 12/15] tools/nolibc: validate C89 compatibility Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 13/15] tools/nolibc: s390: provide custom implementation for sys_fork Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 14/15] tools/nolibc: add testcase for fork()/waitpid() Paul E. McKenney
2023-05-18 14:55 ` [PATCH v2 nolibc 15/15] tools/nolibc: remove LINUX_REBOOT_ constants Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 0/15] nolibc updates for v6.5] Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 01/53] tools/nolibc: tests: use volatile to force stack smashing Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 02/53] tools/nolibc: tests: fix build on non-c99 compliant compilers Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 03/53] tools/nolibc: fix build of the test case using glibc Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 04/53] tools/nolibc: add libc-test binary Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 05/53] tools/nolibc: add wrapper for memfd_create Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 06/53] tools/nolibc: implement fd-based FILE streams Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 07/53] tools/nolibc: add testcases for vfprintf Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 08/53] tools/nolibc: Fix build of stdio.h due to header ordering Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 09/53] tools/nolibc: use standard __asm__ statements Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 10/53] tools/nolibc: use __inline__ syntax Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 11/53] tools/nolibc: use C89 comment syntax Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 12/53] tools/nolibc: validate C89 compatibility Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 13/53] tools/nolibc: s390: provide custom implementation for sys_fork Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 14/53] tools/nolibc: add testcase for fork()/waitpid() Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 15/53] tools/nolibc: remove LINUX_REBOOT_ constants Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 16/53] tools/nolibc: riscv: Fix up load/store instructions for rv32 Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 17/53] tools/nolibc/unistd: add syscall() Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 18/53] selftests/nolibc: syscall_args: use generic __NR_statx Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 19/53] selftests/nolibc: reduce syscalls during space padding Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 20/53] tools/nolibc: aarch64: add stackprotector support Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 21/53] tools/nolibc: arm: " Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 22/53] tools/nolibc: loongarch: " Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 23/53] tools/nolibc: mips: " Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 24/53] tools/nolibc: riscv: " Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 25/53] tools/nolibc: fix typo pint -> point Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 26/53] tools/nolibc: x86_64: disable stack protector for _start Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 27/53] tools/nolibc: ensure stack protector guard is never zero Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 28/53] tools/nolibc: add test for __stack_chk_guard initialization Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 29/53] tools/nolibc: reformat list of headers to be installed Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 30/53] tools/nolibc: add autodetection for stackprotector support Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 31/53] tools/nolibc: simplify stackprotector compiler flags Paul E. McKenney
2023-06-12 20:44 ` Paul E. McKenney [this message]
2023-06-12 20:44 ` [PATCH v2 nolibc 33/53] tools/nolibc: s390: disable stackprotector in _start Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 34/53] tools/nolibc: add support for prctl() Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 35/53] selftests/nolibc: prevent coredumps during test execution Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 36/53] tools/nolibc: support nanoseconds in stat() Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 37/53] selftests/nolibc: print name instead of number for EOVERFLOW Paul E. McKenney
2023-06-12 20:44 ` [PATCH v2 nolibc 38/53] selftests/nolibc: remove the duplicated gettimeofday_bad2 Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 39/53] tools/nolibc: ppoll/ppoll_time64: add a missing argument Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 40/53] selftests/nolibc: test_fork: fix up duplicated print Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 41/53] tools/nolibc: ensure fast64 integer types have 64 bits Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 42/53] selftests/nolibc: remove test gettimeofday_null Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 43/53] selftests/nolibc: allow specify extra arguments for qemu Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 44/53] selftests/nolibc: fix up compile warning with glibc on x86_64 Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 45/53] selftests/nolibc: not include limits.h for nolibc Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 46/53] selftests/nolibc: use INT_MAX instead of __INT_MAX__ Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 47/53] tools/nolibc: arm: add missing my_syscall6 Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 48/53] tools/nolibc: open: fix up compile warning for arm Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 49/53] selftests/nolibc: support two errnos with EXPECT_SYSER2() Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 50/53] selftests/nolibc: remove gettimeofday_bad1/2 completely Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 51/53] selftests/nolibc: add new gettimeofday test cases Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 52/53] selftests/nolibc: also count skipped and failed tests in output Paul E. McKenney
2023-06-12 20:45 ` [PATCH v2 nolibc 53/53] selftests/nolibc: make sure gcc always use little endian on MIPS Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox