From 20f8af224b536e8e883269639c47f8792952980b Mon Sep 17 00:00:00 2001 From: Mika Kuoppala Date: Sat, 1 Jun 2024 22:45:05 +0300 Subject: [PATCH] hints/linux.370: Add support for ubsan (undefined behaviour sanitizer) for gcc This will add an option to compile and link nethack executable with ubsan and catch undefined behaviour errors on runtime. --- sys/unix/README-hints | 3 +++ sys/unix/hints/include/compiler.370 | 4 ++++ sys/unix/hints/linux.370 | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/sys/unix/README-hints b/sys/unix/README-hints index 45185521e..5a531efbd 100644 --- a/sys/unix/README-hints +++ b/sys/unix/README-hints @@ -60,6 +60,9 @@ make WANT_SPEECH=1 If one of the sound libraries was included, also make WANT_ASAN=1 Include support for the address sanitizer in the build. +make WANT_UBSAN=1 Include support for the undefined behaviour + sanitizer in the build. + make WANT_SHARE_INSTALL=1 Place the results of the install/update portion of the build into a shared area on a multiuser system. diff --git a/sys/unix/hints/include/compiler.370 b/sys/unix/hints/include/compiler.370 index 7445888eb..1a0c3b990 100755 --- a/sys/unix/hints/include/compiler.370 +++ b/sys/unix/hints/include/compiler.370 @@ -33,6 +33,10 @@ ifeq "$(WANT_ASAN)" "1" USE_ASAN=1 endif +ifeq "$(WANT_UBSAN)" "1" +USE_UBSAN=1 +endif + # If you want to override the compiler detection just carried out # uncomment one of the following pairs. Note, however, that # doing this after the detection above will likely result in diff --git a/sys/unix/hints/linux.370 b/sys/unix/hints/linux.370 index 9d81d1404..c17706de2 100755 --- a/sys/unix/hints/linux.370 +++ b/sys/unix/hints/linux.370 @@ -87,6 +87,11 @@ CFLAGS+=-fsanitize=address LFLAGS+=-fsanitize=address endif +ifeq "$(USE_UBSAN)" "1" +CFLAGS+=-fsanitize=undefined +LFLAGS+=-fsanitize=undefined +endif + ifeq "$(USE_CURSESLIB)" "1" # default CURSESLIB = -lncurses -ltinfo