-
Notifications
You must be signed in to change notification settings - Fork 122
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
Open
jserv
wants to merge
5
commits into
master
Choose a base branch
from
fix-regressions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+518
−47
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a2a5c4
Enable TSAN with FULL4G and T2C support
jserv f1b685e
Add Arm64 TSAN support and fix JIT cache coherency
jserv f6b94f1
Detect early JIT compilation issues in CI/CD
jserv 2cc7b01
Fix user-space emulation requiring ELF loader
jserv d1beb5a
Fix build system regressions
jserv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "======================================" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 \ | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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