Source level suppression of UBsan finding

Jeffrey Walton noloader@gmail.com
Tue Dec 26 23:41:00 GMT 2017


On Mon, Dec 18, 2017 at 10:12 AM, Mikhail Maltsev <maltsevm@gmail.com> wrote:
> On Sat, Dec 16, 2017 at 3:28 PM, Jeffrey Walton <noloader@gmail.com> wrote:
>>
>> I'm looking for a source-level method to tell UBsan to ignore a
>> function that is producing a finding. We are pretty sure it is a false
>> positive so we want UBsan to skip analysis of the function.
>>
>> We want source-level because it is a lot easier for us to make the
>> change in one place and document it. Otherwise, a whitelist using a
>> separate file will cause a lot of work for us and downstream. Lots of
>> build systems will need to be modified to accommodate the recipe
>> changes.
>>
>> With Memory Sanitizer we can do something like:
>>
>>     #if __has_feature(memory_sanitizer)
>>     # define MSAN_AVAILABLE 1
>>     #endif
>>
>>     # ifdef MSAN_AVAILABLE
>>     __msan_unpoison(&m_readfds, sizeof(m_readfds));
>>     __msan_unpoison(&m_writefds, sizeof(m_writefds));
>>     # endif
>>
>> How can we do similar with UBSan?
>
> There is a function attribute "no_sanitize_undefined":
> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

Thanks Mikhail .

Would you happen to know if the attribute works on inlined functions?
In my case there are 4 inlined functions, and I am still seeing the
findings.

Jeff



More information about the Gcc-help mailing list