Skip to content

Commit 2d9ee6f

Browse files
committed
Fix TSAN tests failing in Docker containers due to setarch
ARM64 CI builds fail with "setarch: failed to set personality to (null): Operation not permitted" because Docker containers lack CAP_SYS_ADMIN capability required for setarch to modify process personality flags. Root cause: CI scripts were calling setarch -R externally before make, but the Makefile also wraps test execution with setarch via BIN_WRAPPER, causing double-wrapping and permission failures in containers. Solution: 1. Remove redundant setarch calls from CI scripts (both x64 and ARM64) 2. Add graceful fallback in Makefile's BIN_WRAPPER: sh -c 'setarch $(uname -m) -R "$@" 2>/dev/null || "$@"' -- This allows TSAN tests to run successfully in: - Native Linux (setarch works normally) - Docker containers (falls back without setarch) - macOS (already skips setarch, no change) TSAN still works correctly in containers because: - We use MAP_FIXED for 4GB allocation at fixed addresses - Container ASLR is limited compared to host systems - TSAN shadow memory layout remains valid Fixes: - host-arm64: "setarch failed" exit code 1 - host-x64: Redundant setarch removed for consistency
1 parent 061612c commit 2d9ee6f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ jobs:
258258
set -o pipefail
259259
260260
# TSAN requires ASLR disabled to prevent allocations in shadow memory
261+
# Note: setarch handled by Makefile's BIN_WRAPPER
261262
# Interpreter with FULL4G: Basic race detection across emulation core
262263
echo "=== TSAN Test 1/3: Interpreter + FULL4G ==="
263-
make distclean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 check $PARALLEL 2>&1 | tee tsan-interpreter.log
264+
make distclean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 check $PARALLEL 2>&1 | tee tsan-interpreter.log
264265
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-interpreter.log; then
265266
echo "ERROR: Data race detected in interpreter mode!"
266267
grep -A 10 "ThreadSanitizer:" tsan-interpreter.log
@@ -270,7 +271,7 @@ jobs:
270271
271272
# JIT tier-1: Race detection in template-based JIT compilation
272273
echo "=== TSAN Test 2/3: JIT Tier-1 ==="
273-
make ENABLE_JIT=1 clean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 check $PARALLEL 2>&1 | tee tsan-jit.log
274+
make ENABLE_JIT=1 clean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 check $PARALLEL 2>&1 | tee tsan-jit.log
274275
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-jit.log; then
275276
echo "ERROR: Data race detected in JIT tier-1 mode!"
276277
grep -A 10 "ThreadSanitizer:" tsan-jit.log
@@ -280,7 +281,7 @@ jobs:
280281
281282
# JIT tier-2 (T2C): Race detection across LLVM compilation thread
282283
echo "=== TSAN Test 3/3: JIT Tier-2 (T2C) ==="
283-
make ENABLE_JIT=1 clean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 ENABLE_T2C=1 check $PARALLEL 2>&1 | tee tsan-t2c.log
284+
make ENABLE_JIT=1 clean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 ENABLE_T2C=1 check $PARALLEL 2>&1 | tee tsan-t2c.log
284285
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-t2c.log; then
285286
echo "ERROR: Data race detected in JIT tier-2 (T2C) mode!"
286287
grep -A 10 "ThreadSanitizer:" tsan-t2c.log
@@ -447,25 +448,26 @@ jobs:
447448
make distclean && make ENABLE_EXT_F=0 ENABLE_JIT=1 check $PARALLEL
448449
make distclean && make ENABLE_EXT_C=0 ENABLE_JIT=1 check $PARALLEL
449450
# TSAN on ARM64: Fixed memory layout (0x150000000000 for main, 0x151000000000 for JIT)
451+
# Note: setarch handled by Makefile's BIN_WRAPPER (falls back gracefully in containers)
450452
set -o pipefail
451453
echo "=== TSAN Test 1/3: Interpreter + FULL4G (ARM64) ==="
452-
make distclean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 check $PARALLEL 2>&1 | tee tsan-interpreter.log
454+
make distclean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 check $PARALLEL 2>&1 | tee tsan-interpreter.log
453455
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-interpreter.log; then
454456
echo "ERROR: Data race detected in interpreter mode!"
455457
grep -A 10 "ThreadSanitizer:" tsan-interpreter.log
456458
exit 1
457459
fi
458460
echo "✓ No races detected in interpreter mode"
459461
echo "=== TSAN Test 2/3: JIT Tier-1 (ARM64) ==="
460-
make ENABLE_JIT=1 clean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 check $PARALLEL 2>&1 | tee tsan-jit.log
462+
make ENABLE_JIT=1 clean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 check $PARALLEL 2>&1 | tee tsan-jit.log
461463
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-jit.log; then
462464
echo "ERROR: Data race detected in JIT tier-1 mode!"
463465
grep -A 10 "ThreadSanitizer:" tsan-jit.log
464466
exit 1
465467
fi
466468
echo "✓ No races detected in JIT tier-1 mode"
467469
echo "=== TSAN Test 3/3: JIT Tier-2 (T2C) (ARM64) ==="
468-
make ENABLE_JIT=1 clean && setarch -R make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 ENABLE_T2C=1 check $PARALLEL 2>&1 | tee tsan-t2c.log
470+
make ENABLE_JIT=1 clean && make ENABLE_TSAN=1 ENABLE_FULL4G=1 ENABLE_JIT=1 ENABLE_T2C=1 check $PARALLEL 2>&1 | tee tsan-t2c.log
469471
if grep -q "ThreadSanitizer: data race\|ThreadSanitizer: race on\|WARNING: ThreadSanitizer:" tsan-t2c.log; then
470472
echo "ERROR: Data race detected in JIT tier-2 (T2C) mode!"
471473
grep -A 10 "ThreadSanitizer:" tsan-t2c.log

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ override ENABLE_LTO := 0 # LTO interferes with TSAN instrumentation
107107
CFLAGS += -DTSAN_ENABLED # Signal code to use TSAN-compatible allocations
108108
# Disable ASLR for TSAN tests to prevent allocations in TSAN shadow memory
109109
# Note: setarch is Linux-only; macOS requires different approach (SIP disable)
110+
# In containers (GitHub Actions), setarch may fail due to missing capabilities.
111+
# We use a wrapper script that falls back gracefully if setarch is unavailable.
110112
ifeq ($(UNAME_S),Linux)
111-
BIN_WRAPPER = setarch $(shell uname -m) -R
113+
BIN_WRAPPER = sh -c 'setarch $(shell uname -m) -R "$$@" 2>/dev/null || "$$@"' --
112114
else
113115
BIN_WRAPPER =
114116
endif

0 commit comments

Comments
 (0)