From: Michal Privoznik Date: Fri, 3 May 2024 15:58:05 +0000 (+0200) Subject: meson: Disable -fsanitize=function X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=3f5a1fa234b078e90baa210da035f84350e1aa4d;p=libvirt.git meson: Disable -fsanitize=function Strictly speaking, xdrproc_t is declared as following: typedef bool_t (*xdrproc_t)(XDR *, ...); But our rpcgen generates properly typed functions, e.g.: bool_t xdr_virNetMessageError(XDR *xdrs, virNetMessageError *objp) Now, these functions of ours are passed around as callbacks (via an argument of xdrproc_t type), for instance in virNetMessageEncodePayload(). But these two types are strictly different. We silence the compiler by typecasting the callbacks when passing them, but strictly speaking - calling such callback later, when a function of xdrproc_t is expected is an undefined behavior. Ideally, we would fix our rpcgen to generate proper function headers, but: a) my brain is too small to do that, and b) we would lose compiler protection if an xdr_*() function is called directly but argument of a wrong type is passed. Silence UBSAN for now. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé Reviewed-by: Ján Tomko --- diff --git a/meson.build b/meson.build index f642247794..9cc0620e78 100644 --- a/meson.build +++ b/meson.build @@ -443,6 +443,19 @@ if cc.get_id() == 'clang' cc_flags += [ '-fsemantic-interposition' ] endif +if get_option('b_sanitize') != 'none' + # This is needed because of xdrproc_t. It's declared as a pointer to a + # function with variable arguments. But for catching type related problems at + # compile time, our rpcgen generates functions with proper types, say: + # + # bool_t xdr_TestEnum(XDR *, TestEnum *); + # + # But passing xdr_TestEnum as a callback where xdrproc_t type is expected is + # undefined behavior. Yet, we want the comfort of compile time checks, so + # just disable the sanitizer warning for now. It's a big hammer though. + cc_flags += [ '-fno-sanitize=function' ] +endif + supported_cc_flags = [] if get_option('warning_level') == '2' supported_cc_flags = cc.get_supported_arguments(cc_flags)