[PATCH] strace: Fix crash caused over-optimization

Jon Turney jon.turney@dronecode.org.uk
Sun Apr 16 10:21:00 GMT 2017


On 15/04/2017 23:27, Daniel Santos wrote:
> Recent versions of gcc are optimizing away the TLS buffer allocated in
> main, so we need to tell gcc that it's really used.
> ---
>  winsup/utils/strace.cc | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
> index beab67b90..1e581b4a4 100644
> --- a/winsup/utils/strace.cc
> +++ b/winsup/utils/strace.cc
> @@ -1192,6 +1192,8 @@ main (int argc, char **argv)
>    char buf[CYGTLS_PADSIZE];
>
>    memset (buf, 0, sizeof (buf));
> +  /* Prevent buf from being optimized away.  */
> +  __asm__ __volatile__("" :: "m" (buf));

wouldn't adding volatile to the definition of buf be a better way to 
write this?

>    exit (main2 (argc, argv));
>  }
>
>



More information about the Cygwin-patches mailing list