]> xenbits.xensource.com Git - libvirt.git/commitdiff
meson: Disable -fsanitize=function
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 3 May 2024 15:58:05 +0000 (17:58 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 14 May 2024 13:12:23 +0000 (15:12 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
meson.build

index f64224779455c1d6daea37cb17416e20d5fc0d0d..9cc0620e7889731e399dd1688e123c0e68b556e2 100644 (file)
@@ -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)