[PATCH v3 01/66] util: Suppress -Wstringop-overflow in qemu_thread_start

Richard Henderson posted 66 patches 2 years, 10 months ago
Maintainers: Alistair Francis <Alistair.Francis@wdc.com>, Eduardo Habkost <ehabkost@redhat.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Marek Vasut <marex@denx.de>, Alistair Francis <alistair.francis@wdc.com>, Greg Kurz <groug@kaod.org>, Michael Rolnik <mrolnik@gmail.com>, Stefan Weil <sw@weilnetz.de>, Yoshinori Sato <ysato@users.sourceforge.jp>, Mahmoud Mandour <ma.mandourr@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Stafford Horne <shorne@gmail.com>, Alexandre Iooss <erdnaxe@crans.org>, David Hildenbrand <david@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Palmer Dabbelt <palmer@dabbelt.com>, Aurelien Jarno <aurelien@aurel32.net>, "Alex Bennée" <alex.bennee@linaro.org>, Chris Wulff <crwulff@gmail.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Bin Meng <bin.meng@windriver.com>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Max Filippov <jcmvbkbc@gmail.com>, Thomas Huth <thuth@redhat.com>, Taylor Simpson <tsimpson@quicinc.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Cornelia Huck <cohuck@redhat.com>
[PATCH v3 01/66] util: Suppress -Wstringop-overflow in qemu_thread_start
Posted by Richard Henderson 2 years, 10 months ago
This seems to be either a glibc or gcc bug, but the code
appears to be fine with the warning suppressed.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/qemu-thread-posix.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index fd9d714038..6c5004220d 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -537,9 +537,28 @@ static void *qemu_thread_start(void *args)
     QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name);
     g_free(qemu_thread_args->name);
     g_free(qemu_thread_args);
+
+    /*
+     * GCC 11 with glibc 2.17 on PowerPC reports
+     *
+     * qemu-thread-posix.c:540:5: error: ‘__sigsetjmp’ accessing 656 bytes
+     *   in a region of size 528 [-Werror=stringop-overflow=]
+     * 540 |     pthread_cleanup_push(qemu_thread_atexit_notify, NULL);
+     *     |     ^~~~~~~~~~~~~~~~~~~~
+     *
+     * which is clearly nonsense.
+     */
+#pragma GCC diagnostic push
+#ifndef __clang__
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
+
     pthread_cleanup_push(qemu_thread_atexit_notify, NULL);
     r = start_routine(arg);
     pthread_cleanup_pop(1);
+
+#pragma GCC diagnostic pop
+
     return r;
 }
 
-- 
2.25.1


Re: [PATCH v3 01/66] util: Suppress -Wstringop-overflow in qemu_thread_start
Posted by Peter Maydell 2 years, 10 months ago
On Wed, 18 Aug 2021 at 20:22, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This seems to be either a glibc or gcc bug, but the code
> appears to be fine with the warning suppressed.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  util/qemu-thread-posix.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index fd9d714038..6c5004220d 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -537,9 +537,28 @@ static void *qemu_thread_start(void *args)
>      QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name);
>      g_free(qemu_thread_args->name);
>      g_free(qemu_thread_args);
> +
> +    /*
> +     * GCC 11 with glibc 2.17 on PowerPC reports
> +     *
> +     * qemu-thread-posix.c:540:5: error: ‘__sigsetjmp’ accessing 656 bytes
> +     *   in a region of size 528 [-Werror=stringop-overflow=]
> +     * 540 |     pthread_cleanup_push(qemu_thread_atexit_notify, NULL);
> +     *     |     ^~~~~~~~~~~~~~~~~~~~
> +     *
> +     * which is clearly nonsense.
> +     */
> +#pragma GCC diagnostic push
> +#ifndef __clang__
> +#pragma GCC diagnostic ignored "-Wstringop-overflow"
> +#endif
> +
>      pthread_cleanup_push(qemu_thread_atexit_notify, NULL);

Fixed in glibc in commit
https://sourceware.org/git/?p=glibc.git;a=commit;h=548f467fa14ffe7d955beeb31b30e2aeae4467e0

I think.

I found this mailing list thread:
https://www.mail-archive.com/dm-devel@redhat.com/msg20144.html

which suggests that another workaround would be to include pthread.h
before setjmp.h. For us that would mean we'd have to pull
pthread.h in in osdep.h, though...

>      r = start_routine(arg);
>      pthread_cleanup_pop(1);
> +
> +#pragma GCC diagnostic pop
> +
>      return r;
>  }

With a link to the glibc commit in the comment,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM