public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well
@ 2023-08-31  9:05 Kito Cheng
  2023-09-05  7:17 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Kito Cheng @ 2023-08-31  9:05 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, palmer, jeffreyalaw; +Cc: Kito Cheng

We only emit that on linux target before, that not problem before,
however Qemu has fix a bug to make qemu user mode honor PT_GNU_STACK[1],
that will cause problem when we test baremetal with qemu.

So the straightforward is enable that as well for non-linux toolchian,
the price is that will increase few bytes for each binary.

[1] https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311

gcc/ChangeLog:

	* config/riscv/linux.h (TARGET_ASM_FILE_END): Move ...
	* config/riscv/riscv.cc (TARGET_ASM_FILE_END): to here.
---
 gcc/config/riscv/linux.h  | 2 --
 gcc/config/riscv/riscv.cc | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 3e625e0f867..7323ff30f70 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -59,8 +59,6 @@ along with GCC; see the file COPYING3.  If not see
       -dynamic-linker " GNU_USER_DYNAMIC_LINKER "} \
     %{static:-static}}"
 
-#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
-
 #define STARTFILE_PREFIX_SPEC 			\
    "/lib" XLEN_SPEC "/" ABI_SPEC "/ "		\
    "/usr/lib" XLEN_SPEC "/" ABI_SPEC "/ "	\
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 5dc303f89c7..2b3ab862816 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -9098,6 +9098,8 @@ riscv_frame_pointer_required (void)
 #define TARGET_ASM_FILE_START riscv_file_start
 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
+#undef TARGET_ASM_FILE_END
+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
 #undef TARGET_EXPAND_BUILTIN_VA_START
 #define TARGET_EXPAND_BUILTIN_VA_START riscv_va_start
-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well
  2023-08-31  9:05 [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well Kito Cheng
@ 2023-09-05  7:17 ` Jeff Law
  2023-09-05 12:14   ` Kito Cheng
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2023-09-05  7:17 UTC (permalink / raw)
  To: Kito Cheng, gcc-patches, kito.cheng, palmer



On 8/31/23 03:05, Kito Cheng wrote:
> We only emit that on linux target before, that not problem before,
> however Qemu has fix a bug to make qemu user mode honor PT_GNU_STACK[1],
> that will cause problem when we test baremetal with qemu.
> 
> So the straightforward is enable that as well for non-linux toolchian,
> the price is that will increase few bytes for each binary.
> 
> [1] https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
> 
> gcc/ChangeLog:
> 
> 	* config/riscv/linux.h (TARGET_ASM_FILE_END): Move ...
> 	* config/riscv/riscv.cc (TARGET_ASM_FILE_END): to here.
OK.
jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well
  2023-09-05  7:17 ` Jeff Law
@ 2023-09-05 12:14   ` Kito Cheng
  2023-09-05 20:53     ` Fangrui Song
  0 siblings, 1 reply; 5+ messages in thread
From: Kito Cheng @ 2023-09-05 12:14 UTC (permalink / raw)
  To: Jeff Law; +Cc: Kito Cheng, gcc-patches, palmer

committed, thanks :)

On Tue, Sep 5, 2023 at 3:18 PM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
>
> On 8/31/23 03:05, Kito Cheng wrote:
> > We only emit that on linux target before, that not problem before,
> > however Qemu has fix a bug to make qemu user mode honor PT_GNU_STACK[1],
> > that will cause problem when we test baremetal with qemu.
> >
> > So the straightforward is enable that as well for non-linux toolchian,
> > the price is that will increase few bytes for each binary.
> >
> > [1] https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
> >
> > gcc/ChangeLog:
> >
> >       * config/riscv/linux.h (TARGET_ASM_FILE_END): Move ...
> >       * config/riscv/riscv.cc (TARGET_ASM_FILE_END): to here.
> OK.
> jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well
  2023-09-05 12:14   ` Kito Cheng
@ 2023-09-05 20:53     ` Fangrui Song
  2023-09-06  2:57       ` Kito Cheng
  0 siblings, 1 reply; 5+ messages in thread
From: Fangrui Song @ 2023-09-05 20:53 UTC (permalink / raw)
  To: Kito Cheng; +Cc: Jeff Law, Kito Cheng, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

On Tue, Sep 5, 2023 at 5:14 AM Kito Cheng via Gcc-patches <
gcc-patches@gcc.gnu.org> wrote:

> committed, thanks :)
>
> On Tue, Sep 5, 2023 at 3:18 PM Jeff Law via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> >
> >
> > On 8/31/23 03:05, Kito Cheng wrote:
> > > We only emit that on linux target before, that not problem before,
> > > however Qemu has fix a bug to make qemu user mode honor
> PT_GNU_STACK[1],
> > > that will cause problem when we test baremetal with qemu.
> > >
> > > So the straightforward is enable that as well for non-linux toolchian,
> > > the price is that will increase few bytes for each binary.
> > >
> > > [1]
> https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
> > >
> > > gcc/ChangeLog:
> > >
> > >       * config/riscv/linux.h (TARGET_ASM_FILE_END): Move ...
> > >       * config/riscv/riscv.cc (TARGET_ASM_FILE_END): to here.
> > OK.
> > jeff
>

Does
https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
use #define EXSTACK_DEFAULT true
for riscv?




-- 
宋方睿

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well
  2023-09-05 20:53     ` Fangrui Song
@ 2023-09-06  2:57       ` Kito Cheng
  0 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2023-09-06  2:57 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Kito Cheng, Jeff Law, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]

RISC-V qemu default that to false, which mean stack can't execute anything
by default, that's match RISC-V linux kernel behaviour, but the problem is
risc-v bare metal toolchain may execute code on stack *without* that tag,
that does not cause problems before for running tests on qemu user mode,
but...it causes problems once using newer qemu (with that patch).

Fangrui Song <maskray@google.com> 於 2023年9月6日 週三 04:53 寫道:

> On Tue, Sep 5, 2023 at 5:14 AM Kito Cheng via Gcc-patches <
> gcc-patches@gcc.gnu.org> wrote:
>
>> committed, thanks :)
>>
>> On Tue, Sep 5, 2023 at 3:18 PM Jeff Law via Gcc-patches
>> <gcc-patches@gcc.gnu.org> wrote:
>> >
>> >
>> >
>> > On 8/31/23 03:05, Kito Cheng wrote:
>> > > We only emit that on linux target before, that not problem before,
>> > > however Qemu has fix a bug to make qemu user mode honor
>> PT_GNU_STACK[1],
>> > > that will cause problem when we test baremetal with qemu.
>> > >
>> > > So the straightforward is enable that as well for non-linux toolchian,
>> > > the price is that will increase few bytes for each binary.
>> > >
>> > > [1]
>> https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
>> > >
>> > > gcc/ChangeLog:
>> > >
>> > >       * config/riscv/linux.h (TARGET_ASM_FILE_END): Move ...
>> > >       * config/riscv/riscv.cc (TARGET_ASM_FILE_END): to here.
>> > OK.
>> > jeff
>>
>
> Does
> https://github.com/qemu/qemu/commit/872f3d046f2381e3f416519e82df96bd60818311
> use #define EXSTACK_DEFAULT true
> for riscv?
>
>
>
>
> --
> 宋方睿
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-06  2:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31  9:05 [PATCH] RISC-V: Emit .note.GNU-stack for non-linux target as well Kito Cheng
2023-09-05  7:17 ` Jeff Law
2023-09-05 12:14   ` Kito Cheng
2023-09-05 20:53     ` Fangrui Song
2023-09-06  2:57       ` Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).