1From 38cdfcc4b2cca8d251ff8d8d34201dfe9849333e Mon Sep 17 00:00:00 2001
2From: Max Filippov <jcmvbkbc@gmail.com>
3Date: Thu, 2 Mar 2023 09:45:41 -0800
4Subject: [PATCH] xtensa: add .note.GNU-stack section on linux
5
6gcc/
7	* config/xtensa/linux.h (TARGET_ASM_FILE_END): New macro.
8
9libgcc/
10	* config/xtensa/crti.S: Add .note.GNU-stack section on linux.
11	* config/xtensa/crtn.S: Likewise.
12	* config/xtensa/lib1funcs.S: Likewise.
13	* config/xtensa/lib2funcs.S: Likewise.
14
15Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
16Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
17Upstream: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6360bf9a2d08f08c151464c77c0da53cd702ff25
18---
19 gcc/config/xtensa/linux.h        | 1 +
20 libgcc/config/xtensa/crti.S      | 6 ++++++
21 libgcc/config/xtensa/crtn.S      | 6 ++++++
22 libgcc/config/xtensa/lib1funcs.S | 6 ++++++
23 libgcc/config/xtensa/lib2funcs.S | 6 ++++++
24 5 files changed, 25 insertions(+)
25
26diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
27index edce618fb94..fe0e3a43797 100644
28--- a/gcc/config/xtensa/linux.h
29+++ b/gcc/config/xtensa/linux.h
30@@ -69,3 +69,4 @@ along with GCC; see the file COPYING3.  If not see
31
32 #undef DBX_REGISTER_NUMBER
33
34+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
35diff --git a/libgcc/config/xtensa/crti.S b/libgcc/config/xtensa/crti.S
36index 3de7bc101f4..0996e7cb29b 100644
37--- a/libgcc/config/xtensa/crti.S
38+++ b/libgcc/config/xtensa/crti.S
39@@ -26,6 +26,12 @@
40
41 #include "xtensa-config.h"
42
43+/* An executable stack is *not* required for these functions.  */
44+#if defined(__ELF__) && defined(__linux__)
45+.section .note.GNU-stack,"",%progbits
46+.previous
47+#endif
48+
49 	.section .init
50 	.globl _init
51 	.type _init,@function
52diff --git a/libgcc/config/xtensa/crtn.S b/libgcc/config/xtensa/crtn.S
53index 06b932edb14..a4cc9830096 100644
54--- a/libgcc/config/xtensa/crtn.S
55+++ b/libgcc/config/xtensa/crtn.S
56@@ -27,6 +27,12 @@
57
58 #include "xtensa-config.h"
59
60+/* An executable stack is *not* required for these functions.  */
61+#if defined(__ELF__) && defined(__linux__)
62+.section .note.GNU-stack,"",%progbits
63+.previous
64+#endif
65+
66 	.section .init
67 #if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__
68 	retw
69diff --git a/libgcc/config/xtensa/lib1funcs.S b/libgcc/config/xtensa/lib1funcs.S
70index 5a2bd20534f..7177dd4f73a 100644
71--- a/libgcc/config/xtensa/lib1funcs.S
72+++ b/libgcc/config/xtensa/lib1funcs.S
73@@ -25,6 +25,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
74
75 #include "xtensa-config.h"
76
77+/* An executable stack is *not* required for these functions.  */
78+#if defined(__ELF__) && defined(__linux__)
79+.section .note.GNU-stack,"",%progbits
80+.previous
81+#endif
82+
83 /* Define macros for the ABS and ADDX* instructions to handle cases
84    where they are not included in the Xtensa processor configuration.  */
85
86diff --git a/libgcc/config/xtensa/lib2funcs.S b/libgcc/config/xtensa/lib2funcs.S
87index 681bac1be8c..a40c1a45604 100644
88--- a/libgcc/config/xtensa/lib2funcs.S
89+++ b/libgcc/config/xtensa/lib2funcs.S
90@@ -25,6 +25,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
91
92 #include "xtensa-config.h"
93
94+/* An executable stack is *not* required for these functions.  */
95+#if defined(__ELF__) && defined(__linux__)
96+.section .note.GNU-stack,"",%progbits
97+.previous
98+#endif
99+
100 /* __xtensa_libgcc_window_spill: This function flushes out all but the
101    current register window.  This is used to set up the stack so that
102    arbitrary frames can be accessed.  */
103--
1042.39.2
105
106