From: Andrew Cooper Date: Sun, 12 May 2019 13:17:08 +0000 (+0100) Subject: xen/ubsan: Support for -fsanitise=builtin X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~1981 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0ff8c6cf906060e3612e2243aca7c3cb5e9c3b42;p=xen.git xen/ubsan: Support for -fsanitise=builtin This fixes the UBSAN build for GCC 8 and later. The sanitiser checks for passing 0 to the ctz()/clz() builtins. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- diff --git a/xen/common/ubsan/ubsan.c b/xen/common/ubsan/ubsan.c index 50a4e14fac..0fddacabda 100644 --- a/xen/common/ubsan/ubsan.c +++ b/xen/common/ubsan/ubsan.c @@ -518,3 +518,26 @@ void __ubsan_handle_pointer_overflow(struct pointer_overflow_data *data, ubsan_epilogue(&flags); } + +void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data) +{ + unsigned long flags; + const char *fn = NULL; + + if (suppress_report(&data->location)) + return; + + ubsan_prologue(&data->location, &flags); + + switch (data->kind) { + case kind_ctz: fn = "ctz"; break; + case kind_clz: fn = "clz"; break; + } + + if (fn) + pr_err("passing zero to %s(), which is not a valid argument\n", fn); + else + pr_err("Unknown kind %u\n", data->kind); + + ubsan_epilogue(&flags); +} diff --git a/xen/common/ubsan/ubsan.h b/xen/common/ubsan/ubsan.h index 2710cd423e..a3159040fe 100644 --- a/xen/common/ubsan/ubsan.h +++ b/xen/common/ubsan/ubsan.h @@ -84,6 +84,15 @@ struct pointer_overflow_data { struct source_location location; }; +struct invalid_builtin_data { + struct source_location location; + unsigned char kind; +}; +enum { + kind_ctz, + kind_clz, +}; + #if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) typedef __int128 s_max; typedef unsigned __int128 u_max;