DF-5580 / ubsan_stub.c
/* * Minimal UBSan handler stubs (gcc 8.3 / DragonFly ships no libubsan). * Restricted to the shift class: the compiler emits calls to * __ubsan_handle_shift_out_of_bounds[_abort]; we implement them so the * instrumentation links without libubsan, printing the source location * straight out of the ubsan SourceLocation struct that gcc 8 emits as the * first member of the check's static data. */ #include <stdio.h> #include <stdlib.h> typedef unsigned long uptr; struct ubsan_srcloc { const char *file; unsigned line, col; }; void __ubsan_handle_shift_out_of_bounds_abort(void *data, uptr lhs, uptr rhs) { struct ubsan_srcloc *sl = (struct ubsan_srcloc *)data; printf("UBSAN-FIRED: shift exponent out of bounds at %s:%u:%u " "(value=%lu shift=%lu)\n", sl->file ? sl->file : "?", sl->line, sl->col, lhs, rhs); fflush(stdout); abort(); } void __ubsan_handle_shift_out_of_bounds(void *data, uptr lhs, uptr rhs) { struct ubsan_srcloc *sl = (struct ubsan_srcloc *)data; printf("UBSAN-FIRED(recover): %s:%u:%u (value=%lu shift=%lu)\n", sl->file ? sl->file : "?", sl->line, sl->col, lhs, rhs); } |