From 0ff8c6cf906060e3612e2243aca7c3cb5e9c3b42 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Sun, 12 May 2019 14:17:08 +0100 Subject: [PATCH] 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 --- xen/common/ubsan/ubsan.c | 23 +++++++++++++++++++++++ xen/common/ubsan/ubsan.h | 9 +++++++++ 2 files changed, 32 insertions(+) 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; -- 2.30.2