Skip to content

ci: add QEMU UBSan tests and fix unaligned memory access - #1976

Open
johnny9 wants to merge 1 commit into
bitaxeorg:masterfrom
johnny9:test/upstream-qemu-ubsan
Open

johnny9 wants to merge 1 commit into
bitaxeorg:masterfrom
johnny9:test/upstream-qemu-ubsan

Conversation

@johnny9

@johnny9 johnny9 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Adds a separate UBSan job for QEMU tests, with alignment and shift checks enabled.

Fixes unaligned hash access and allocations for cJSON and Stratum timing records. Firmware and tests use the same cJSON allocator.

Run locally with bash tools/run_qemu_tests.sh --ubsan.

All 105 tests pass with and without UBSan at both -Og and -O2, including mixed alignment and overlapping buffers.

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown

Test Results

  3 files  +  1    3 suites  +1   2s ⏱️ ±0s
191 tests +  5  191 ✅ +  5  0 💤 ±0  0 ❌ ±0 
298 runs  +110  298 ✅ +110  0 💤 ±0  0 ❌ ±0 

Results for commit a3e5540. ± Comparison against base commit e9645da.

♻️ This comment has been updated with latest results.

@johnny9
johnny9 marked this pull request as ready for review September 15, 2026 14:04
@johnny9
johnny9 force-pushed the test/upstream-qemu-ubsan branch from 2d700e0 to deb28f3 Compare September 15, 2026 14:54
@johnny9 johnny9 changed the title ci: add QEMU UBSan checks and fix unaligned hash helpers ci: add QEMU UBSan tests and fix unaligned memory access Sep 15, 2026
Comment thread components/stratum/utils.c Outdated
d[7] = s[0];
uint8_t reversed[32];

for (size_t i = 0; i < 8; i++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this loop and memcpy will all be compiled away into register operations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dug into this and checked the ESP32-S3 assembly. ESP-IDF sets -fno-builtin-memcpy, so the loop was keeping its copy calls.

I restored the unrolled assignments, aligned the midstate buffers, and added a checked fast path using __builtin_memcpy. At -O2, both copies disappear, leaving eight word loads and eight stores. Unaligned buffers keep a safe fallback.

All 105 tests pass with and without UBSan at both -Og and -O2, including mixed alignment and overlapping buffers.

@johnny9
johnny9 force-pushed the test/upstream-qemu-ubsan branch from deb28f3 to a3e5540 Compare September 15, 2026 17:38
johnny9 added a commit to johnny9/skot-ESP-Miner that referenced this pull request Sep 16, 2026
Port the relevant fixes from UBSan PR bitaxeorg#1976 (a3e5540), retaining the existing byte-safe target conversion. Validate alignment at compile time and overlapping buffers in the ordinary QEMU suite.

Validation: 144 QEMU tests passed; full ESP-IDF firmware build passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants