Repository navigation
ipc4: layout_check: add build-time checks for packed bit-field layout - #1
Open
orange-dot wants to merge 1 commit into
Open
orange-dot wants to merge 1 commit into
orange-dot wants to merge 1 commit into
Conversation
orange-dot
force-pushed
the
fix/ipc4-bitfield-layout-build-checks
branch
2 times, most recently
from
July 10, 2026 15:12
1cdde79 to
78f64f1
Compare
orange-dot
marked this pull request as ready for review
July 10, 2026 15:49
The IPC4 ABI headers describe the host <-> DSP wire format with bit-fields inside packed structs. The C standard leaves bit-field allocation order within a storage unit implementation-defined (C99/C11 6.7.2.1), so the wire format silently relies on the toolchain following the little-endian, LSB-first convention of the platform ABI. A toolchain that targets a big-endian core (Xtensa is bi-endian by design), is not GCC-compatible, or mishandles packed bit-fields would corrupt every IPC4 message without a build error. Add a two-part toolchain conformance check: - ipc4/layout_check.h, included from the always-built IPC4 handler code, rejects at preprocessing time any compiler that is not GCC-compatible or any target that is not little-endian - together these pin LSB-first bit-field allocation via the platform ABI (the same convention Linux relies on in <asm/byteorder.h>) - and defines a canary word mirroring the message-word bit-field idiom. - src/ipc/ipc4/layout_probe.c compiles that canary with the firmware toolchain; the build extracts its byte representation from the object file with objcopy (nothing is linked or executed, so cross and host builds are handled identically) and compares it against checked-in golden bytes. This observes the actual bit-field allocation order, which no C constant expression can express. The check runs for firmware and host library builds alike whenever CONFIG_IPC_MAJOR_4 code is built; a non-conforming toolchain fails the build with an expected-vs-actual byte diagnostic. Verified locally on all 14 working platforms: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl and nvl-s build clean with canary bytes matching the golden file in every build tree; imx8, imx8x, imx8m, imx8m_cm7, imx8ulp and imx95 (IPC3) build clean with the probe correctly not built. The host testbench build passes with matching bytes as well. A corrupted golden byte fails the tgl build with a clear diagnostic. Signed-off-by: Bojan Janjatovic <bojan.janjatovic@mamut-studio.com>
orange-dot
force-pushed
the
fix/ipc4-bitfield-layout-build-checks
branch
from
July 10, 2026 15:53
78f64f1 to
1265aec
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Build-time toolchain conformance check for the IPC4 wire format, which is defined with bit-fields inside packed structs — a layout the C standard leaves implementation-defined.
Two parts:
src/include/ipc4/layout_check.h(included from the always-built IPC4 handler code):#errorunless the compiler is GCC-compatible and the target little-endian — together these pin LSB-first bit-field allocation via the platform ABI (Xtensa is bi-endian by design, so a misconfigured toolchain is a real failure mode). Defines the canary word mirroring the IPC4 message-word idiom.src/ipc/ipc4/layout_probe.c: the canary compiled with the firmware toolchain; the build extracts its byte representation from the object file with objcopy (nothing linked or executed) and compares it against checked-in golden bytes — observing the actual bit-field allocation order, which no C constant expression can express (verified: union-pun reads are rejected in any static assert form by GCC 14/16).Runs for firmware and host library builds alike when IPC4 is enabled; a non-conforming toolchain fails the build with an expected-vs-actual byte diagnostic.
Verified locally on all 14 working platforms: 8 IPC4 platforms (tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, nvl-s) build clean with canary bytes matching golden in every build tree; 6 IPC3 platforms (imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95) build clean with the probe correctly not built; host testbench matches as well. A corrupted golden byte fails the build loudly.