[PATCH] meson: -Wno-error=format-overflow for ubsan

Akihiko Odaki posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231120112329.4149-1-akihiko.odaki@daynix.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
meson.build | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] meson: -Wno-error=format-overflow for ubsan
Posted by Akihiko Odaki 1 year ago
ubsan causes wrong -Wformat-overflow warnings as follows:

In file included from /usr/include/stdio.h:906,
                 from /home/alarm/q/var/qemu/include/qemu/osdep.h:114,
                 from ../disas/cris.c:21:
In function 'sprintf',
    inlined from 'format_dec' at ../disas/cris.c:1737:3,
    inlined from 'print_with_operands' at ../disas/cris.c:2477:12,
    inlined from 'print_insn_cris_generic.constprop' at ../disas/cris.c:2690:8:
/usr/include/bits/stdio2.h:30:10: warning: null destination pointer [-Wformat-overflow=]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~

Don't let these errors stop the build.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index d7d841e71e..02f1a18080 100644
--- a/meson.build
+++ b/meson.build
@@ -365,7 +365,9 @@ if get_option('sanitizers')
   # Detect static linking issue with ubsan - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
   if cc.links('int main(int argc, char **argv) { return argc + 1; }',
               args: [qemu_ldflags, '-fsanitize=undefined'])
-    qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
+    # 87884 – ubsan causes wrong -Wformat-overflow warning
+    # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87884
+    qemu_cflags = ['-fsanitize=undefined', '-Wno-error=format-overflow'] + qemu_cflags
     qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
   endif
 endif
-- 
2.42.1


Re: [PATCH] meson: -Wno-error=format-overflow for ubsan
Posted by Philippe Mathieu-Daudé 1 year ago
Hi Akihiko,

On 20/11/23 12:23, Akihiko Odaki wrote:
> ubsan causes wrong -Wformat-overflow warnings as follows:
> 
> In file included from /usr/include/stdio.h:906,
>                   from /home/alarm/q/var/qemu/include/qemu/osdep.h:114,
>                   from ../disas/cris.c:21:
> In function 'sprintf',
>      inlined from 'format_dec' at ../disas/cris.c:1737:3,
>      inlined from 'print_with_operands' at ../disas/cris.c:2477:12,
>      inlined from 'print_insn_cris_generic.constprop' at ../disas/cris.c:2690:8:
> /usr/include/bits/stdio2.h:30:10: warning: null destination pointer [-Wformat-overflow=]
>     30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
>        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     31 |                                   __glibc_objsize (__s), __fmt,
>        |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     32 |                                   __va_arg_pack ());
>        |                                   ~~~~~~~~~~~~~~~~~
> 
> Don't let these errors stop the build.

Which compiler/version?

> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>   meson.build | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/meson.build b/meson.build
> index d7d841e71e..02f1a18080 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -365,7 +365,9 @@ if get_option('sanitizers')
>     # Detect static linking issue with ubsan - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
>     if cc.links('int main(int argc, char **argv) { return argc + 1; }',
>                 args: [qemu_ldflags, '-fsanitize=undefined'])
> -    qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
> +    # 87884 – ubsan causes wrong -Wformat-overflow warning
> +    # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87884
> +    qemu_cflags = ['-fsanitize=undefined', '-Wno-error=format-overflow'] + qemu_cflags
>       qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
>     endif
>   endif


Re: [PATCH] meson: -Wno-error=format-overflow for ubsan
Posted by Philippe Mathieu-Daudé 1 year ago
On 20/11/23 14:16, Philippe Mathieu-Daudé wrote:
> Hi Akihiko,
> 
> On 20/11/23 12:23, Akihiko Odaki wrote:
>> ubsan causes wrong -Wformat-overflow warnings as follows:
>>
>> In file included from /usr/include/stdio.h:906,
>>                   from /home/alarm/q/var/qemu/include/qemu/osdep.h:114,
>>                   from ../disas/cris.c:21:
>> In function 'sprintf',
>>      inlined from 'format_dec' at ../disas/cris.c:1737:3,
>>      inlined from 'print_with_operands' at ../disas/cris.c:2477:12,
>>      inlined from 'print_insn_cris_generic.constprop' at 
>> ../disas/cris.c:2690:8:
>> /usr/include/bits/stdio2.h:30:10: warning: null destination pointer 
>> [-Wformat-overflow=]
>>     30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
>>        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>     31 |                                   __glibc_objsize (__s), __fmt,
>>        |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>     32 |                                   __va_arg_pack ());
>>        |                                   ~~~~~~~~~~~~~~~~~
>>
>> Don't let these errors stop the build.
> 
> Which compiler/version?
> 
>>
>> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>> ---
>>   meson.build | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/meson.build b/meson.build
>> index d7d841e71e..02f1a18080 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -365,7 +365,9 @@ if get_option('sanitizers')
>>     # Detect static linking issue with ubsan - 
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
>>     if cc.links('int main(int argc, char **argv) { return argc + 1; }',
>>                 args: [qemu_ldflags, '-fsanitize=undefined'])
>> -    qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
>> +    # 87884 – ubsan causes wrong -Wformat-overflow warning
>> +    # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87884

I posted an alternative less intrusive patch, see:
https://lore.kernel.org/all/20231120132222.82138-1-philmd@linaro.org/

>> +    qemu_cflags = ['-fsanitize=undefined', 
>> '-Wno-error=format-overflow'] + qemu_cflags
>>       qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
>>     endif
>>   endif
>