Skip to content

Commit d1beb5a

Browse files
committed
Fix build system regressions
This commit addresses multiple regressions introduced in recent changes: 1. DTB compilation regression - DTB dependencies moved outside CC_IS_EMCC conditional - Ensures DTB builds for system mode regardless of compiler - Fixes mk/wasm.mk structure for cross-platform consistency 2. Makefile syntax error in mk/toolchain.mk - Fixed TAB characters before $(warning) on lines 25, 28 - Changed to spaces for proper control flow - This was blocking all Makefile parsing 3. emcc configuration pollution - Added 'make distclean' before emcc builds in workflow - Prevents ENABLE_SYSTEM=1 from leaking between builds - Fixes "build/minimal.dtb does not exist" errors 4. Ubuntu ARM64 apt-get failures - Implemented exponential backoff retry mechanism (30s, 60s delays) - Added pipefail to preserve apt exit codes through tee - Explicit APT_EXIT capture to detect masked failures - Added InRelease to failure pattern (modern combined Release+GPG) - Ignore non-critical dep11 metadata failures - Focus on core package indices (Packages/Sources/Release/InRelease) 5. TSAN cross-compiler compatibility (fixed __has_feature issue) - Changed from defined(__has_feature) to defined(__clang__) - GCC doesn't support __has_feature, causing preprocessor errors - __has_feature only works when __clang__ is defined - Ensures __tsan_default_options() works with both GCC and clang 6. TSAN cross-platform compatibility - Guarded setarch with ifeq ($(UNAME_S),Linux) in Makefile - setarch doesn't exist on macOS, now conditionally applied - macOS TSAN builds require SIP disabled for ASLR control 7. Trace functionality regression - Reverted .log_level from LOG_INFO back to LOG_TRACE - LOG_INFO suppressed rv_log_trace() stream used by -t flag - Restores instruction trace output for debugging
1 parent 2cc7b01 commit d1beb5a

File tree

5 files changed

+97
-19
lines changed

5 files changed

+97
-19
lines changed

.github/workflows/main.yml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ jobs:
135135
- name: default build using emcc
136136
if: success()
137137
run: |
138+
make distclean
138139
make CC=emcc ENABLE_JIT=0 $PARALLEL
139140
140141
- name: default build for system emulation using emcc
141142
if: success()
142143
run: |
143144
make distclean
144145
make CC=emcc ENABLE_SYSTEM=1 ENABLE_JIT=0 $PARALLEL
145-
make distclean ENABLE_SYSTEM=1
146+
make distclean
146147
147148
- name: Build with various optimization levels
148149
if: success()
@@ -301,17 +302,56 @@ jobs:
301302
githubToken: ${{ github.token }}
302303
# No 'sudo' is available
303304
install: |
304-
apt update -qq
305-
apt install -yqq make git curl wget clang libsdl2-dev libsdl2-mixer-dev lsb-release software-properties-common gnupg bc
306-
which wget || echo "WARNING: wget not found after installation"
305+
# Retry apt update with exponential backoff for mirror sync issues
306+
# Note: dep11 (AppStream metadata) failures are non-critical for build tools
307+
set -o pipefail
308+
for i in 1 2 3; do
309+
if apt update -qq --allow-releaseinfo-change 2>&1 | tee /tmp/apt-update.log; then
310+
APT_EXIT=0
311+
else
312+
APT_EXIT=$?
313+
fi
314+
# Check for critical failures (package indices), ignore dep11 metadata
315+
# Include InRelease which is the combined Release+Release.gpg file
316+
if [ $APT_EXIT -eq 0 ] && ! grep -E "Failed to fetch.*/(Packages|Sources|Release|InRelease)" /tmp/apt-update.log; then
317+
echo "apt update succeeded (core package lists available)"
318+
break
319+
fi
320+
if [ $i -lt 3 ]; then
321+
delay=$((i * 30))
322+
echo "apt update attempt $i: errors detected (exit=$APT_EXIT), waiting ${delay}s..."
323+
sleep $delay
324+
else
325+
echo "Warning: Proceeding after 3 attempts - some package lists may be incomplete"
326+
fi
327+
done
328+
# Install packages - exit 0 even if dep11 metadata is incomplete
329+
apt install -yqq make git curl wget clang libsdl2-dev libsdl2-mixer-dev lsb-release software-properties-common gnupg bc 2>&1 | tee /tmp/apt-install.log || true
330+
# Verify critical packages were installed
331+
for pkg in make git curl clang bc; do
332+
if ! command -v $pkg >/dev/null 2>&1; then
333+
echo "ERROR: Critical package $pkg failed to install!"
334+
cat /tmp/apt-install.log
335+
exit 1
336+
fi
337+
done
338+
echo "All critical build tools installed successfully"
307339
# FIXME: gcc build fails on Aarch64/Linux hosts
308340
env: |
309341
CC: clang-18
310342
# Append custom commands here
311343
run: |
312344
# Verify and install wget if needed (workaround for install step issues)
313345
if ! command -v wget > /dev/null 2>&1; then
314-
apt update -qq && apt install -yqq wget
346+
echo "wget not found, attempting to install..."
347+
apt update -qq --allow-releaseinfo-change 2>&1 | tee /tmp/apt-update-wget.log || true
348+
apt install -yqq wget 2>&1 | tee /tmp/wget-install.log || true
349+
if ! command -v wget > /dev/null 2>&1; then
350+
echo "ERROR: wget installation failed!"
351+
cat /tmp/wget-install.log
352+
exit 1
353+
fi
354+
echo "wget installed successfully"
315355
fi
316356
git config --global --add safe.directory ${{ github.workspace }}
317357
git config --global --add safe.directory ${{ github.workspace }}/src/softfloat
@@ -435,14 +475,15 @@ jobs:
435475
- name: default build using emcc
436476
if: success()
437477
run: |
478+
make distclean
438479
make CC=emcc ENABLE_JIT=0 $PARALLEL
439480
440481
- name: default build for system emulation using emcc
441482
if: success()
442483
run: |
443484
make distclean
444485
make CC=emcc ENABLE_SYSTEM=1 ENABLE_JIT=0 $PARALLEL
445-
make distclean ENABLE_SYSTEM=1
486+
make distclean
446487
447488
- name: check + tests
448489
if: success()
@@ -499,14 +540,14 @@ jobs:
499540
fi
500541
done
501542
502-
- name: JIT debug test
503-
env:
504-
CC: ${{ steps.install_cc.outputs.cc }}
505-
run: |
506-
# Run JIT tests with debug mode to catch register allocation and cache coherency issues
507-
make distclean && make ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check $PARALLEL
508-
make distclean && make ENABLE_EXT_C=0 ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check $PARALLEL
509-
if: ${{ always() }}
543+
- name: JIT debug test
544+
env:
545+
CC: ${{ steps.install_cc.outputs.cc }}
546+
run: |
547+
# Run JIT tests with debug mode to catch register allocation and cache coherency issues
548+
make distclean && make ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check $PARALLEL
549+
make distclean && make ENABLE_EXT_C=0 ENABLE_JIT=1 ENABLE_JIT_DEBUG=1 check $PARALLEL
550+
if: ${{ always() }}
510551

511552
- name: undefined behavior test
512553
if: (success() || failure()) && steps.install_cc.outputs.cc == 'clang' # gcc on macOS/arm64 does not support sanitizers

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,15 @@ override ENABLE_SDL := 0 # SDL (uninstrumented system lib) creates threads
106106
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
109+
# Note: setarch is Linux-only; macOS requires different approach (SIP disable)
110+
ifeq ($(UNAME_S),Linux)
109111
BIN_WRAPPER = setarch $(shell uname -m) -R
110112
else
111113
BIN_WRAPPER =
112114
endif
115+
else
116+
BIN_WRAPPER =
117+
endif
113118

114119
# Enable link-time optimization (LTO)
115120
ENABLE_LTO ?= 1
@@ -392,7 +397,7 @@ DTB_DEPS := $(BUILD_DTB) $(BUILD_DTB2C)
392397
endif
393398
endif
394399

395-
all: config $(DTB_DEPS) $(BUILD_DTB) $(BUILD_DTB2C) $(BIN)
400+
all: config $(DTB_DEPS) $(BIN)
396401

397402
OBJS := \
398403
map.o \
@@ -437,7 +442,7 @@ $(OUT):
437442

438443
$(BIN): $(OBJS) $(DEV_OBJS) | $(OUT)
439444
$(VECHO) " LD\t$@\n"
440-
$(Q)$(CC) -o $@ $(CFLAGS_emcc) $^ $(LDFLAGS)
445+
$(Q)$(CC) -o $@ $(CFLAGS_emcc) $(filter-out %.dtb %.h,$^) $(LDFLAGS)
441446

442447
$(CONFIG_FILE): FORCE
443448
$(Q)mkdir -p $(OUT)

mk/toolchain.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ ifneq ($(shell $(CC) --version | head -n 1 | grep emcc),)
2222
$(warning $(SDL_MUSIC_CANNOT_PLAY_WARNING))
2323
endif
2424
else
25-
$(warning $(SDL_MUSIC_CANNOT_PLAY_WARNING))
25+
$(warning $(SDL_MUSIC_CANNOT_PLAY_WARNING))
2626
endif
2727
else
28-
$(warning $(SDL_MUSIC_CANNOT_PLAY_WARNING))
28+
$(warning $(SDL_MUSIC_CANNOT_PLAY_WARNING))
2929
endif
3030

3131
# see commit 165c1a3 of emscripten

mk/wasm.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,21 @@ start-web: $(start_web_deps)
166166
.PHONY: check-demo-dir-exist start-web
167167

168168
endif
169+
170+
# For SYSTEM mode, DTB needs to be built regardless of whether we're using emcc
171+
# DTB is only built when SYSTEM=1 and ELF_LOADER=0
172+
ifeq ($(call has, SYSTEM), 1)
173+
ifeq ($(call has, ELF_LOADER), 0)
174+
# Add DTB as dependency for compilation stages
175+
# This is used by mk/system.mk for device object files
176+
deps_emcc += $(BUILD_DTB) $(BUILD_DTB2C)
177+
178+
# For emcc builds: ensure DTB exists before emcc embeds it
179+
# Make BIN directly depend on DTB files as regular prerequisites
180+
# This will cause them to be built, but they'll also be passed to the linker
181+
# We need to filter them out in the linker command
182+
ifeq ("$(CC_IS_EMCC)", "1")
183+
$(BIN): $(BUILD_DTB) $(BUILD_DTB2C)
184+
endif
185+
endif
186+
endif

src/main.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*
2929
* Configuration optimizes for race detection with minimal overhead.
3030
*/
31+
/* GCC uses __SANITIZE_THREAD__, clang uses __has_feature(thread_sanitizer) */
3132
#if defined(__SANITIZE_THREAD__)
3233
const char *__tsan_default_options()
3334
{
@@ -39,6 +40,19 @@ const char *__tsan_default_options()
3940
":history_size=7" /* Larger race detection window */
4041
":io_sync=0"; /* Don't sync on I/O */
4142
}
43+
#elif defined(__clang__)
44+
#if __has_feature(thread_sanitizer)
45+
const char *__tsan_default_options()
46+
{
47+
return "halt_on_error=0" /* Continue after errors */
48+
":report_bugs=1" /* Report data races */
49+
":second_deadlock_stack=1" /* Full deadlock info */
50+
":verbosity=0" /* Reduce noise */
51+
":memory_limit_mb=0" /* No memory limit */
52+
":history_size=7" /* Larger race detection window */
53+
":io_sync=0"; /* Don't sync on I/O */
54+
}
55+
#endif
4256
#endif
4357

4458
/* enable program trace mode */
@@ -304,7 +318,7 @@ int main(int argc, char **args)
304318
.args_offset_size = ARGS_OFFSET_SIZE,
305319
.argc = prog_argc,
306320
.argv = prog_args,
307-
.log_level = LOG_INFO,
321+
.log_level = LOG_TRACE,
308322
.run_flag = run_flag,
309323
.profile_output_file = prof_out_file,
310324
.cycle_per_step = CYCLE_PER_STEP,

0 commit comments

Comments
 (0)