Re: Silence -fsanitize=function where we cast function pointers on purpose

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Silence -fsanitize=function where we cast function pointers on purpose
Date: 2026-09-29 09:18:10
Message-ID: B1A2B6F4-E3C9-46A9-A198-EF49CE0657F5@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Sep 29, 2026, at 13:47, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>
> In clang, -fsanitize=undefined includes -fsanitize=function, which reports every call made through a function pointer whose type does not exactly match the called function, so it fires all over the place on expression tree walkers and mutators, as well as a few other places. So -fsanitize=undefined hasn't been working cleanly under clang for a while. (Before clang 17, it only applied to C++.)
>
> This is the same issue that caused us to use -Wno-cast-function-type-strict with clang. That warning applies at the place where the mismatching function pointer is passed, so there are potentially hundreds of sites. Therefore, a global disabling is appropriate. The sanitizer, on the other hand, triggers where the function is called, which are only about two dozen places, so it seems possible to silence these checks individually and still main the check for accidental violations elsewhere.
>
> I propose to add pg_attribute_no_sanitize_function() and place it on the functions that make such calls. This is similar to some existing pg_attribute_no_sanitize_xxx attributes.
> <0001-Silence-fsanitize-function-where-we-cast-function-po.patch>

Overall looks good to me.

Just one comment, in dynahash.c, hash_search_with_hash_value() is marked with the new annotation, feels like hash_update_hash_key() also needs to be annotated, because it also invokes match and keycopy etc callbacks.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Anthonin Bonnefoy 2026-09-29 09:30:51 Protocol Compression (fourth attempt)
Previous Message shveta malik 2026-09-29 09:09:58 Re: Temporary slot leak when creation fails in a subtransaction