-
Notifications
You must be signed in to change notification settings - Fork 124
Enable ThreadSanitizer across the entire multi-threaded JIT pipeline #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2a2a5c4
f1b685e
f6b94f1
2cc7b01
d1beb5a
b7dd6a7
061612c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # JIT Debug Test Script | ||
| # This script tests JIT compiler with debug mode enabled to catch issues early | ||
|
|
||
| set -e | ||
|
|
||
| PARALLEL="${PARALLEL:--j$(nproc 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 4)}" | ||
|
|
||
| echo "======================================" | ||
| echo "JIT Debug Mode Test" | ||
| echo "======================================" | ||
|
|
||
| # Test 1: Standard JIT with debug | ||
| echo "" | ||
| echo "Test 1: Building with ENABLE_JIT_DEBUG=1..." | ||
| make distclean | ||
| make ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 $PARALLEL | ||
|
|
||
| echo "" | ||
| echo "Running basic tests with JIT debug..." | ||
| make ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check | ||
|
|
||
| # Test 2: JIT with EXT_C=0 and debug (regression test) | ||
| echo "" | ||
| echo "Test 2: Building with ENABLE_EXT_C=0 ENABLE_JIT_DEBUG=1..." | ||
| make distclean | ||
| make ENABLE_EXT_C=0 ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 $PARALLEL | ||
|
|
||
| echo "" | ||
| echo "Running tests with EXT_C=0 and JIT debug..." | ||
| make ENABLE_EXT_C=0 ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check | ||
|
|
||
| # Test 3: JIT with various extension combinations | ||
| echo "" | ||
| echo "Test 3: Testing multiple JIT configurations with debug..." | ||
| for config in \ | ||
| "ENABLE_EXT_A=0" \ | ||
| "ENABLE_EXT_F=0" \ | ||
| "ENABLE_EXT_M=0" \ | ||
| "ENABLE_Zba=0" \ | ||
| "ENABLE_Zbb=0"; do | ||
| echo "" | ||
| echo "Testing: $config with JIT debug" | ||
| make distclean | ||
| make $config ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 $PARALLEL | ||
| make $config ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check | ||
| done | ||
|
|
||
| echo "" | ||
| echo "======================================" | ||
| echo "All JIT debug tests passed!" | ||
| echo "======================================" |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,13 +20,6 @@ CFLAGS += -include src/common.h -Isrc/ | |||||
|
|
||||||
| OBJS_EXT := | ||||||
|
|
||||||
| # In the system test suite, the executable is an ELF file (e.g., MMU). | ||||||
| # However, the Linux kernel emulation includes the Image, DT, and | ||||||
| # root filesystem (rootfs). Therefore, the test suite needs this | ||||||
| # flag to load the ELF and differentiate it from the kernel emulation. | ||||||
| ENABLE_ELF_LOADER ?= 0 | ||||||
| $(call set-feature, ELF_LOADER) | ||||||
|
|
||||||
| # Enable MOP fusion, easier for ablation study | ||||||
| ENABLE_MOP_FUSION ?= 1 | ||||||
| $(call set-feature, MOP_FUSION) | ||||||
|
|
@@ -80,6 +73,49 @@ endif | |||||
| ENABLE_ARCH_TEST ?= 0 | ||||||
| $(call set-feature, ARCH_TEST) | ||||||
|
|
||||||
| # In the system test suite, the executable is an ELF file (e.g., MMU). | ||||||
| # However, the Linux kernel emulation includes the Image, DT, and | ||||||
| # root filesystem (rootfs). Therefore, the test suite needs this | ||||||
| # flag to load the ELF and differentiate it from the kernel emulation. | ||||||
| # User-space emulation (SYSTEM=0) always needs ELF loader, except for architecture tests. | ||||||
| ifeq ($(ENABLE_SYSTEM), 0) | ||||||
| ifneq ($(ENABLE_ARCH_TEST), 1) | ||||||
| override ENABLE_ELF_LOADER := 1 | ||||||
| else | ||||||
| ENABLE_ELF_LOADER ?= 0 | ||||||
| endif | ||||||
| else | ||||||
| ENABLE_ELF_LOADER ?= 0 | ||||||
| endif | ||||||
| $(call set-feature, ELF_LOADER) | ||||||
|
|
||||||
| # ThreadSanitizer support | ||||||
| # TSAN on x86-64 memory layout: | ||||||
| # Shadow: 0x02a000000000 - 0x7cefffffffff (reserved by TSAN) | ||||||
| # App: 0x7cf000000000 - 0x7ffffffff000 (usable by application) | ||||||
| # | ||||||
| # We use MAP_FIXED to allocate FULL4G's 4GB memory at a fixed address | ||||||
| # (0x7d0000000000) within TSAN's app range, ensuring compatibility. | ||||||
| # | ||||||
| # IMPORTANT: TSAN requires ASLR (Address Space Layout Randomization) to be | ||||||
| # disabled to prevent system allocations from landing in TSAN's shadow memory. | ||||||
| # Tests are run with 'setarch $(uname -m) -R' to disable ASLR. | ||||||
| ENABLE_TSAN ?= 0 | ||||||
| ifeq ("$(ENABLE_TSAN)", "1") | ||||||
| override ENABLE_SDL := 0 # SDL (uninstrumented system lib) creates threads TSAN cannot track | ||||||
| override ENABLE_LTO := 0 # LTO interferes with TSAN instrumentation | ||||||
| CFLAGS += -DTSAN_ENABLED # Signal code to use TSAN-compatible allocations | ||||||
| # Disable ASLR for TSAN tests to prevent allocations in TSAN shadow memory | ||||||
| # Note: setarch is Linux-only; macOS requires different approach (SIP disable) | ||||||
| ifeq ($(UNAME_S),Linux) | ||||||
| BIN_WRAPPER = setarch $(shell uname -m) -R | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TSAN runs now always prepend Prompt for AI agents
Suggested change
|
||||||
| else | ||||||
| BIN_WRAPPER = | ||||||
| endif | ||||||
| else | ||||||
| BIN_WRAPPER = | ||||||
| endif | ||||||
|
|
||||||
| # Enable link-time optimization (LTO) | ||||||
| ENABLE_LTO ?= 1 | ||||||
| ifeq ($(call has, LTO), 1) | ||||||
|
|
@@ -280,6 +316,11 @@ ENABLE_JIT ?= 0 | |||||
| $(call set-feature, JIT) | ||||||
| ifeq ($(call has, JIT), 1) | ||||||
| OBJS_EXT += jit.o | ||||||
| # JIT debug mode for early issue detection in CI/CD | ||||||
| ENABLE_JIT_DEBUG ?= 0 | ||||||
| ifeq ("$(ENABLE_JIT_DEBUG)", "1") | ||||||
| CFLAGS += -DENABLE_JIT_DEBUG=1 | ||||||
| endif | ||||||
| ENABLE_T2C ?= 1 | ||||||
| $(call set-feature, T2C) | ||||||
| ifeq ($(call has, T2C), 1) | ||||||
|
|
@@ -332,6 +373,12 @@ CFLAGS += -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover=all | |||||
| LDFLAGS += -fsanitize=undefined -fno-sanitize=alignment -fno-sanitize-recover=all | ||||||
| endif | ||||||
|
|
||||||
| # ThreadSanitizer flags (ENABLE_TSAN is set earlier to override SDL/FULL4G) | ||||||
| ifeq ("$(ENABLE_TSAN)", "1") | ||||||
| CFLAGS += -fsanitize=thread -g | ||||||
| LDFLAGS += -fsanitize=thread | ||||||
| endif | ||||||
|
|
||||||
| $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-stack-check -fno-stack-protector | ||||||
|
|
||||||
| # .DEFAULT_GOAL should be set to all since the very first target is not all | ||||||
|
|
@@ -350,7 +397,7 @@ DTB_DEPS := $(BUILD_DTB) $(BUILD_DTB2C) | |||||
| endif | ||||||
| endif | ||||||
|
|
||||||
| all: config $(DTB_DEPS) $(BUILD_DTB) $(BUILD_DTB2C) $(BIN) | ||||||
| all: config $(DTB_DEPS) $(BIN) | ||||||
|
|
||||||
| OBJS := \ | ||||||
| map.o \ | ||||||
|
|
@@ -395,7 +442,7 @@ $(OUT): | |||||
|
|
||||||
| $(BIN): $(OBJS) $(DEV_OBJS) | $(OUT) | ||||||
| $(VECHO) " LD\t$@\n" | ||||||
| $(Q)$(CC) -o $@ $(CFLAGS_emcc) $^ $(LDFLAGS) | ||||||
| $(Q)$(CC) -o $@ $(CFLAGS_emcc) $(filter-out %.dtb %.h,$^) $(LDFLAGS) | ||||||
|
|
||||||
| $(CONFIG_FILE): FORCE | ||||||
| $(Q)mkdir -p $(OUT) | ||||||
|
|
@@ -445,7 +492,7 @@ define check-test | |||||
| $(Q)true; \ | ||||||
| $(PRINTF) "Running $(3) ... "; \ | ||||||
| OUTPUT_FILE="$$(mktemp)"; \ | ||||||
| if (LC_ALL=C $(BIN) $(1) $(2) > "$$OUTPUT_FILE") && \ | ||||||
| if (LC_ALL=C $(BIN_WRAPPER) $(BIN) $(1) $(2) > "$$OUTPUT_FILE") && \ | ||||||
| [ "$$(cat "$$OUTPUT_FILE" | $(LOG_FILTER) | $(4))" = "$(5)" ]; then \ | ||||||
| $(call notice, [OK]); \ | ||||||
| else \ | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setarchis Linux-only; with TSAN enabled on macOS the test recipe expands tosetarch $(uname -m) -R …and fails because the binary is missing. Please gate the wrapper by host OS or provide a macOS-safe alternative so TSAN checks remain usable cross-platform.Prompt for AI agents