Repository navigation
Add custom target specs for riscv boards to silence the relax warning on all riscv board builds - #5084
Conversation
872fb05 to
06b9e9a
Compare
bradjc
left a comment
There was a problem hiding this comment.
This is the absolute best and stupidest PR.
I ran the rust update script and got:
Checking RISC-V custom target specs...
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 298, in load
return loads(fp.read(),
cls=cls, object_hook=object_hook,
parse_float=parse_float, parse_int=parse_int,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 352, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 363, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 298, in load
return loads(fp.read(),
cls=cls, object_hook=object_hook,
parse_float=parse_float, parse_int=parse_int,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 352, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 363, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 298, in load
return loads(fp.read(),
cls=cls, object_hook=object_hook,
parse_float=parse_float, parse_int=parse_int,
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/__init__.py", line 352, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.14.3_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/json/decoder.py", line 363, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
06b9e9a to
663f7c3
Compare
|
UGH... today in "Pat learns more about the limitations of AI and how closely you have to police these things..." I ask it to explain how it claimed it "tested the script worked correctly" (and it had reported that it had tested the script because I told it to do that, but exactly how it tested was admittedly opaque as I didn't prompt that...)
Cleaned up and actually tested now, sorry |
bradjc
left a comment
There was a problem hiding this comment.
Updated script worked for me.
663f7c3 to
624b1ac
Compare
…rning The +relax RISC-V target feature (which emits relaxable relocations for the linker to perform size-saving relaxation) has no lint code in rustc, so it cannot be suppressed via -A. Upstream has no active stabilization effort. Instead, add custom target JSON specs for each RISC-V variant Tock uses (riscv32imc, riscv32imac, riscv64imac) with +relax baked into the base features field. Features in the target spec do not trigger the unstable warning. Update all RISC-V board cargo configs to reference these specs by path, and add json-target-spec to riscv_flags.toml to enable the required Cargo unstable feature. When updating rust-toolchain.toml, re-run: rustc -Z unstable-options --print target-spec-json --target <triple> for each of the three targets and diff against the checked-in JSON to catch any upstream changes. Also fixes two consumers that were bypassing or breaking under the new .json TARGET value: - boards/veer_el2_sim/Makefile hardcoded TARGET=riscv32imc-unknown-none-elf directly rather than leaving it unset like every other RISC-V board, which bypassed the .cargo/config.toml auto-detection in Makefile.common and silently opted veer_el2_sim out of the new target spec (and +relax). - Several RISC-V board Makefiles (hifive1, hifive_inventor, arty_e21, redboard_redv, qemu_rv32_virt, qemu_rv64_virt, opentitan/earlgrey-cw310, esp32-c3-devkitM-1, tutorials/qemu_rv32_virt-tutorial, configurations/qemu_rv64_virt-test-ci) built their flash/qemu/run/ install target paths directly as $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/..., which breaks once TARGET is a relative path to a custom JSON spec: the literal path segment gets glued onto target/ instead of resolving to Cargo's actual output directory. Makefile.common already computes TARGET_PATH for exactly this (strips the .json suffix and any path prefix down to the target's basename); switched these rules to use it, matching the pattern veer_el2_sim and opentitan's own .PHONY build rules already used. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
Tock uses custom target JSON specs (boards/cargo/riscv*.json) rather than the built-in RISC-V targets so that the +relax feature (which enables LLVM to emit relaxable relocations for linker relaxation, providing significant code size savings) can be included in the base target definition. Features specified via -Ctarget-feature trigger an "unstable feature" warning for +relax because rustc has not yet stabilized it; features in the target spec itself do not. There is no active upstream stabilization effort as of 2026; track progress at rust-lang/rust#109426. When the toolchain version changes, the upstream target spec JSON may change too. Extend update_rust_version.sh to automatically compare and update the three custom RISC-V target spec files in boards/cargo/ using the new toolchain's --print target-spec-json output (re-adding +relax). Co-Authored-By: Claude Sonnet 5 <[email protected]>
624b1ac to
277c318
Compare
brghena
left a comment
There was a problem hiding this comment.
The changes themselves are fine. The last question I've got is whether this is too much churn and custom stuff to be worth removing a warning. It's reasonably documented at least.
|
I think there is real value in removing this warning — it's a bit of an opaque thing that it prints, and I don't think it's a great first user experience to build a board and have a large warning you have to puzzle through. There's a lot of warning about potential churn in here, because it does technically exist, but I don't think there will be much churn in practice — targets rarely change, and we won't need to change our infra here until |
Pull Request Overview
All of our riscv board builds print a multi-line warning right now because we enable
+relax(for good reason, as it leads to real code size improvements). The warning comes becauserelaxisn't stabilized and the path to general stabilization is a bit fuzzy as far as I can tell—but I don't think it's going anywhere, it's just passing through an llvm intrinsic. The stabilization concerns are more around how to handle 'default behavior' whenrelaxworking requires some platform support (settinggpcorrectly, which Tock does do).The approach this takes, then, is to create custom targets for riscv boards, because if
relaxis in the target specs definition, then no warning is emitted; the warning only comes when you use Cargo to turn onrelax. In practice, upstream default target specs rarely change, and I had Claude update the toolchain update script to check / update these as-needed.A better solution would be to pick back up the thread on #4464, since then we could include
relaxin the upstream specs for thetocktarget — but that's a much bigger project. This is an immediate cleanup of some real noise in our builds.Testing Strategy
This pull request was tested by compiling.
TODO or Help Wanted
I'm unsure whether or not we want this, as it's a bit more 'custom' board machinery. I don't think it's too bad, and it would be nice to eliminate the multi-line warning that prints with every riscv board build.
Checklist
make prepush.PR Contents
Documentation
/docsand the Book.AI Use
I asked Claude where the warning was coming from and whether we could silence it. We iterated for a while, and this was the best approach I came to.
Here's a summary of some of the other things I forced Claude to try that didn't work.
Empirical results, each tested for real:Bottom line: No config-file-based mechanism — including PR #5076's --config merge trick — can suppress this warning for Tock's own crates; it's a hard-coded rustc diagnostic with no lint name, confirming the branch's existing commit message claim. The custom JSON target-spec approach (embedding +relax in the target's features field rather than passing it as a -C target-feature flag) remains the only working path, since it doesn't go through the "unstable -C flag" warning at all. Recommend sticking with the current dev/riscv/custom-target-relax design.