On Sun, Jan 30, 2022 at 04:46:36PM -0800, Greg Steuck wrote:
> In case somebody hits this, here's a resolved issue: -fno-wrapv is
> matters for UBSan coverage.
>
> Confusion starts with:
>
> $ uname -srm; cat a.c && clang -fsanitize=undefined a.c -c -o a.o && nm a.o
> OpenBSD 7.0 amd64
> int main(int argc, char **argv) {
> int k = 0x7fff;
> k += argc;
> return 0;
> }
> W __llvm_retpoline_r11
> W __retguard_2371
> F a.c
> T main
>
> Notice the lack of `__ubsan` symbols. Adding -fno-wrav (which I found in
> kernel Makefile.amd64) restores the desired instrumentation:
>
> % clang -fsanitize=undefined -fno-wrapv a.c -c -o a.o && nm a.o
> W __llvm_retpoline_r11
> W __retguard_2371
> U __ubsan_handle_add_overflow
> F a.c
> T main
>
With -fwrapv the addition is no longer undefined behaviour, so the
compiler does not need to insert the __ubsan_handle_add_overflow hook.
-Otto