From 6e5e32490e83deaf9ce3ad7552c6415430abcbea Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Wed, 28 Feb 2024 00:35:16 +0800 Subject: [PATCH 1/2] Add ENABLE_UBSAN option in Makefile for undefined behavior detection Add support for the ENABLE_UBSAN option in the Makefile, enabling the use of UBSan for detecting undefined behavior during testing. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 90160048..63b55fdd 100644 --- a/Makefile +++ b/Makefile @@ -136,6 +136,12 @@ ifeq ("$(CC_IS_EMCC)", "1") CFLAGS += -mtail-call endif +ENABLE_UBSAN ?= 0 +ifeq ("$(ENABLE_UBSAN)", "1") +CFLAGS += -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover=all +LDFLAGS += -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover=all +endif + $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-stack-check -fno-stack-protector # Clear the .DEFAULT_GOAL special variable, so that the following turns From 17db3b20363b8fb5fed1f5b8418a5baf167b5f0f Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Wed, 28 Feb 2024 00:38:18 +0800 Subject: [PATCH 2/2] CI: Add undefined behavior sanitizer checks Introduce the utilization of UBSan (Undefined Behavior Sanitizer) to identify any instances of undefined behavior within the codebase. The CI pipeline now includes tests specifically designed to catch such behavior. --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e0e7d0a5..f42abd73 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,6 +69,10 @@ jobs: make ENABLE_EXT_A=0 ENABLE_JIT=1 clean check make ENABLE_EXT_F=0 ENABLE_JIT=1 clean check make ENABLE_EXT_C=0 ENABLE_JIT=1 clean check + - name: undefined behavior test + run: | + make ENABLE_UBSAN=1 clean check + make ENABLE_JIT=1 ENABLE_UBSAN=1 clean check host-arm64: needs: [detect-code-related-file-changes]