Subject: bug#65727: 30.0.50; Build failure in MSYS2 when --with-native-compilation

From: Andrea Corallo <[email-masked]>
Date: Tue, 14 May 2024 16:33:53 -0400

Cyril Arnould <[email-masked]> writes:

> I believe the problem is centered around the mark_threads function (in
> thread.c). I still have no idea if the issue is with emacs or GCC, but
> I hope this helps narrow it down.
>
> I found it by trying to suppress the sibling call optimization through
> printf statements at the end of every function that showed differences
> between the objdump files. With the additional printf calls, the
> native-compilation build works together with the
> -foptimize-sibling-calls flag.
>
> After that, it was just a matter of narrowing it down. You can try it
> for yourself with the following patch:
>
> diff --git a/src/thread.c b/src/thread.c
> index 040ca39511e..b522d146779 100644
> --- a/src/thread.c
> +++ b/src/thread.c
> @@ -696,6 +696,7 @@ mark_threads_callback (void *ignore)
>  mark_threads (void)
>  {
>    flush_stack_call_func (mark_threads_callback, NULL);
> +  printf("");
>  }
>
>  void
>
> Note that by now I've moved on to emacs-29.3 on GCC 14, however it
> seems that the issue is still exactly the same.

Interesting, would you mind instead of using 'printf' to try using
'__attribute__((optimize("O0")))' on the function to verify that the
issue is really an optimization?

Thanks

  Andrea