arch/arm: stop boards silently discarding --fixed-r10#19508
Open
casaroli wants to merge 2 commits into
Open
Conversation
| # misbehaves, reading its data through a register the firmware has since | ||
| # felt free to reuse. | ||
|
|
||
| CFLAGS += --fixed-r10 |
Contributor
There was a problem hiding this comment.
let's move to ARCHCFLAGS instead. it's better to fix the root cause directly.
Contributor
Author
There was a problem hiding this comment.
I agree that your suggestion is the correct fix, however we need to change all 500 arm files, so that ARCHPICFLAGS and CPICFLAGS all move to Toolchain.defs
This is a huge change, so I have prepared the fix in a separate PR so you can analyze and compare, and we can check the CI status:
Toolchain.defs adds --fixed-r10 to CFLAGS under CONFIG_PIC, but nearly
every board Make.defs includes that file and then assigns
CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) ...
with ':=', which discards it. 266 of the 269 ARM board files assign
CFLAGS that way; the remaining three delegate to a shared makefile that
does the same thing.
The flag is what keeps the base firmware from allocating r10, the
register a PIC module reaches its own data through. Losing it is silent
and the symptom is remote from the cause: the build succeeds, and only a
callback from base firmware into module code -- qsort() with a module
comparison function is the standard case -- misbehaves, reading its data
through a register the firmware has since felt free to reuse.
mps3-an547:picostest is the only defconfig in the tree that enables
CONFIG_PIC, so it is the only board fixed here. It re-applies the flag
after the ':=' and filters it back out of CPICFLAGS and CELFFLAGS,
because GCC rejects --fixed-r10 alongside the -mpic-register=r10 those
carry ("unable to use 'r10' for PIC register").
That filtering is also why the flag cannot simply move to ARCHCPUFLAGS to
survive the ':=': the module flags derive from CFLAGS, so it would land
in exactly that rejected combination. Toolchain.defs now says so, since
the next board to enable CONFIG_PIC will otherwise hit this again.
Before, with CONFIG_PIC=y: CFLAGS has --fixed-r10: NO
After: CFLAGS has --fixed-r10: YES
CPICFLAGS/CELFFLAGS: NO
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
codespell reads "siz" in # instruct the gsize to generate a "*.siz" file that contains the # detailed section size as a misspelling of "size" or "six". It is neither: ".siz" is the filename extension gsize produces. The hit predates this branch and fires for anyone who touches arch/arm/src/common/Toolchain.defs, because checkpatch scans whole files rather than changed lines, so any PR editing that file fails CI on it. Recorded in .codespell-ignore-lines, which the config documents as the place for exotic-but-correct word occurrences, rather than in ignore-words-list, which is reserved for frequently used words. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
fix-pic-fixed-register-lost
branch
from
July 23, 2026 09:51
a9832ac to
7498ef2
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.
Summary
arch/arm/src/common/Toolchain.defsadds--fixed-r10toCFLAGSwhenCONFIG_PICis enabled. Nearly every boardMake.defsincludes that file andthen assigns
with
:=, which discards it. 346 of the tree's board files contain that exactCPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)idiom, and every one of them assignsCFLAGSthis way first.That flag is what stops the base firmware from allocating r10 — the register a
PIC module reaches its own data through. When it is lost, a base firmware
routine that calls back into module code (
qsort()with a module comparisonfunction is the standard case) arrives with r10 holding whatever the firmware
last put there, and the module reads its data through a bad base pointer.
The failure is silent and remote from its cause: the build succeeds, every
module loads, and only the callback misbehaves.
mps3-an547:picostestis the only defconfig in the tree that setsCONFIG_PIC=y, so it is the only board changed here. It re-applies the flagafter the
:=and filters it back out ofCPICFLAGSandCELFFLAGS, becauseGCC rejects
--fixed-r10alongside the-mpic-register=r10those carry once-fpicis in effect:That filtering is also why the flag cannot simply move to
ARCHCPUFLAGStosurvive the
:=— the module flags derive fromCFLAGS, so it would land inexactly that rejected combination.
Toolchain.defsnow records this, since thenext board to enable
CONFIG_PICwill otherwise hit the same trap.Why the second commit touches the spellcheck config
tools: exempt the "*.siz" gsize comment from codespellis unrelated to theregister, and is here only because CI will not go green without it. An existing
comment in
arch/arm/src/common/Toolchain.defsreads:# instruct the gsize to generate a "*.siz" file that contains the detailed section sizecodespell reports
siz ==> size, six. It is neither —.sizis the filenameextension gsize produces. The line is on master and this PR does not touch it;
it adds no line containing
sizat all.It fails anyway because
tools/checkpatch.sh:224invokespassing the filename, so codespell scans the whole file rather than the
changed hunks. checkpatch builds its file list from the commit range, so
editing
Toolchain.defsfor any reason pulls all ~600 of its lines into thecheck. Confirmed by the other two PRs in this series: they do not touch that
file and report
✔️ All checks pass.I put the line in
.codespell-ignore-lines, which.codespellrcdocuments asthe place for exotic-but-correct occurrences, rather than in
ignore-words-list, which that file reserves for frequently used words. It is aseparate commit so it can be dropped, taken separately, or replaced with a
different remedy without disturbing the fix itself.
Impact
CONFIG_PICconfigurations only.mps3-an547:picostestnow genuinely reserves r10 in the base firmware.
Toolchain.defsand nothing else. No new warnings.CONFIG_PICfirmwareonly (one fewer allocatable register, which is the point).
CONFIG_PICin future still needsthe same three lines. A tree-wide mechanical change to all 346 files would
fix it once and for all; I did not attempt that, and would rather a
maintainer say whether it is wanted before 346 files are touched.
.codespell-ignore-lines(see above). It changes no build behaviour andunblocks CI for every future PR touching
Toolchain.defs, not just this one.Testing
Board:
mps3-an547:picostest— the only defconfig withCONFIG_PIC=y.Because the failure is a lost compiler flag, the test is what the build system
computes for
CFLAGS. Reproduce with:Before (master
7df7c6ee) — the flag is gone:After this patch — firmware reserves r10, module flags do not:
The conflict that makes the filtering necessary, shown directly:
Limitation, stated plainly: I could not produce a full link of
mps3-an547:picostest, and it is not for want of a toolchain — I repeated thiswith the Arm GNU Toolchain 15.2.Rel1 (full newlib). The Makefile build of this
board does not complete on unmodified master either, for reasons unrelated
to this patch:
CONFIG_STACK_USAGE_WARNINGis unset for this config, andToolchain.defsonly omits
-Wstack-usage=when the value is exactly0, so an empty value ispassed through. Setting it to
0gets further, and then:Both failures reproduce identically on master with and without this patch, so
they are pre-existing and out of scope here — but they do mean the one board in
the tree that enables
CONFIG_PICcurrently has no working Makefile build,which is probably why this flag went missing unnoticed. The flag-level evidence
above is therefore the strongest available; a maintainer with a working
CONFIG_PICbuild is very welcome to add a link log.The same mechanism is exercised end-to-end in a downstream tree of mine on
RP2350 hardware, where the equivalent register (r9, for FDPIC modules) being
lost to this same
:=caused a firmwareqsort()callback into module code toread garbage, and re-applying the flag fixed it.
Tree checks, both commits applied:
Without the second commit this reports
arch/arm/src/common/Toolchain.defs:485: siz ==> size, six.