Assembled the code behind feature macros, and fixed the POP it found - #608
Merged
fdesbiens merged 1 commit intoAug 13, 2026
Merged
Conversation
scripts/check_clang.sh assembled every source with default flags, so the
preprocessor discarded each #ifdef block before the assembler saw it. Nothing in
the tree had ever assembled a guarded path. That covers the VFP context save and
restore in ten ports, and 218 files carrying TX_LOW_POWER or
TX_ENABLE_EXECUTION_CHANGE_NOTIFY.
Turning those on found a defect. The Cortex-M0 and Cortex-M23 execution-profile
paths bracket their call with
PUSH {r0, lr}
BL _tx_execution_isr_enter
POP {r0, lr}
and the last of those is invalid on Armv6-M and Armv8-M Baseline, where the
16-bit Thumb POP takes r0-r7 and pc and nothing else. GNU rejects it as well --
"cannot honor width suffix" -- so TX_ENABLE_EXECUTION_CHANGE_NOTIFY and
TX_EXECUTION_PROFILE_ENABLE have never been buildable on either port with either
toolchain. Four files, all the same shape.
The fix pops into a scratch register and moves it, MOV to a high register being
permitted where POP is not. r1 is free: the BL may clobber r0-r3, which is the
reason r0 is saved in the first place. Disassembling the result gives
push {r0, lr} / bl / pop {r0, r1} / mov lr, r1 / bx lr, one 16-bit instruction
more than before and otherwise the same.
Two findings that were not defects, recorded in the script so they are not
rediscovered:
Cortex-R4 needs an -mfpu to assemble its VFP path, because its FPU is an option
rather than part of the core. GNU fails identically without one, so this is a
flags requirement and not a toolchain divergence.
The A profile ports must not be given one. Adding -mfpu=vfpv3-d16 uniformly broke
28 files with "register expected", because those ports save D16-D31 and a -d16
FPU does not have those registers. Their defaults were already right.
The new stage runs under --asm-only as well, needing no target C library, and
reports 37 of 37 VFP files, 8 of 8 TX_LOW_POWER and 218 of 218
TX_ENABLE_EXECUTION_CHANGE_NOTIFY. Restoring the POP for one run makes it fail
with 217 of 218 and name the file and the error, so the stage is not vacuous.
The other four stages are unchanged: 711 of 711 assembled, 185 of 185 common C
sources for each of nine cores, 42 of 42 script-driven examples and 5 of 5 CMake
images.
The fixed code is verified to assemble with both toolchains and to encode as
intended. It is not verified running: there is no Cortex-M0 or Cortex-M23 model
here, and these are context save and restore paths, so that gap is worth stating.
Assisted-by: Claude Code (Opus 5) <noreply@anthropic.com>
|
Hello @fdesbiens, I've successfully tested this patch and confirmed it to be working on a Cortex M23. |
Contributor
Author
|
Thank you for the feedback, @Lvbor! Merging this to dev now. |
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.
scripts/check_clang.shassembled every source with default flags, so thepreprocessor discarded each
#ifdefblock before the assembler saw it. Noguarded path in the tree had ever been assembled — that covers the VFP context
save and restore in ten ports, plus 218 files carrying
TX_LOW_POWERorTX_ENABLE_EXECUTION_CHANGE_NOTIFY.Turning them on found a defect.
The defect
The Cortex-M0 and Cortex-M23 execution-profile paths bracket their call like this:
That last instruction is invalid on Armv6-M and Armv8-M Baseline, where the 16-bit
Thumb
POPtakesr0-r7andpcand nothing else. GNU rejects it too —"cannot honor width suffix" — so
TX_ENABLE_EXECUTION_CHANGE_NOTIFYandTX_EXECUTION_PROFILE_ENABLEhave never been buildable on either port, witheither toolchain. Four files, all the same shape.
The fix pops into a scratch register and moves it,
MOVto a high register beingpermitted where
POPis not.r1is free — theBLmay clobberr0-r3, which isprecisely why
r0is saved. Disassembled:One 16-bit instruction more than before, otherwise identical.
Two findings that were not defects
Both are recorded in the script, because both cost me a detour:
Cortex-R4 needs an
-mfputo assemble its VFP path. Its FPU is an optionrather than part of the core. GNU fails identically without one, so this is a
flags requirement, not a toolchain divergence.
The A profile ports must not be given one. Adding
-mfpu=vfpv3-d16uniformlybroke 28 files with "register expected", because those ports save
D16-D31and a-d16FPU does not have those registers. Their defaults were already correct. Thecomment in the script says so, so the next person does not repeat it.
The new stage
Each guarded file is assembled a second time with its macro defined. It runs under
--asm-onlyas well, since it needs no target C library.Verified non-vacuous: restoring the
POPfor one run makes the stage exit 1with
217 of 218, naming the file and the error.The other four stages are unchanged — 711 of 711 assembly sources, 185 of 185
common C sources for each of nine cores, 42 of 42 script-driven examples, 5 of 5
CMake images — and the whole check passes.
What is not verified
The fixed code assembles with both toolchains and encodes as intended. It is
not verified running: there is no Cortex-M0 or Cortex-M23 model available
here, and these are context save and restore paths. Worth a careful review of the
four hunks on that basis, or a run on real hardware by anyone who has either part
to hand.