Re: [PATCH v2 1/4] meson: hide tsan related warnings

Pierrick Bouvier
2024-08-15T17:57:54Z

On 8/15/24 02:50, Thomas Huth wrote:
> On 15/08/2024 00.41, Pierrick Bouvier wrote:
>> When building with gcc-12 -fsanitize=thread, gcc reports some
>> constructions not supported with tsan.
>> Found on debian stable.
>>
>> qemu/include/qemu/atomic.h:36:52: error: ‘atomic_thread_fence’ is not supported with ‘-fsanitize=thread’ [-Werror=tsan]
>> 36 | #define smp_mb() ({ barrier(); __atomic_thread_fence(__ATOMIC_SEQ_CST); })
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> meson.build | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/meson.build b/meson.build
>> index 81ecd4bae7c..52e5aa95cc0 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -499,7 +499,15 @@ if get_option('tsan')
>> prefix: '#include <sanitizer/tsan_interface.h>')
>> error('Cannot enable TSAN due to missing fiber annotation interface')
>> endif
>> - qemu_cflags = ['-fsanitize=thread'] + qemu_cflags
>> + tsan_warn_suppress = []
>> + # gcc (>=11) will report constructions not supported by tsan:
>> + # "error: ‘atomic_thread_fence’ is not supported with ‘-fsanitize=thread’"
>> + # https://gcc.gnu.org/gcc-11/changes.html
>> + # However, clang does not support this warning and this triggers an error.
>> + if cc.has_argument('-Wno-tsan')
>> + tsan_warn_suppress = ['-Wno-tsan']
>> + endif
>> + qemu_cflags = ['-fsanitize=thread'] + tsan_warn_suppress + qemu_cflags
>> qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
>> endif
>>
>
> Not sure if we should hide these warnings ... they seem to be there for a
> reason? Paolo, any ideas?
>

This is a new warning added in gcc-11, to prevent that not all
constructions are supported by thread sanitizer. This was true before,
and will be true after. Basically, manual memory barriers are not
supported to model concurrency. We can hardly change something on QEMU
side as it's a limitation of tsan itself.

Good news is that it does not seem to bring false positives when
executing a qemu with tsan. Thus, this patch to ignore this for now.

> Thomas
>