Minimal implementation of UBSAN, which can be utilized inside freestanding environments.
Not all of the handlers are implemented, only the major ones.
To test the project on Linux or macOS, clone the repository and run.
$ make
$ ./mubsantest
mubsan @ test.c:21:8: array out of bounds, for type 'int [4]', by index type 'int' 4Statically link the mubsan.c file with your existing project.
Then, define a function with the following signature:
int mubsan_log(const char* format, ...) {
// code
}This function should work like printf.
mubsan.c depends on stdint.h.
So, finding documentation for this was pretty abysmal, so I had to utilize other implementations and using them as reference.
However, the only main reference I even used was GCC itself, however, I'll credit the others that I viewed anyways.
OSDev Wiki Page on UBSAN
GCC Mirror
Sortix
optee_os
tinyubsan
barebones
dgos