RFC: Templated Linker Scripts #317
Closed
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.
This PR pulls in
minilink; a small wrapper around MiniJinja for linker scripts. I believe that this can make linker script customization far easier. For example,esp-halplaces.trapsections in RAM (esp-rs/esp-hal#541), and I would like to open a PR which does the same. Using templated linker scripts would make the addition fairly trivial:{% if contains(cfg.feature, "trap-region") %} .trap : ALIGN(4) { *(.trap); *(.trap.*); } > REGION_TRAP {% endif %} .text _stext : { ... {% if not contains(cfg.feature, "trap-region") %} *(.trap); *(.trap.rust); {% endif %} }The biggest downside is the addition of build dependencies, and all that comes with it:
Here are some
cargo build --timings --package riscv-rtresults for{debug,release} x {warm,cold}builds when executed on my laptop.Test varied with about ±0.05s when rerun. As you can see, warm build times remain pretty much unaffected. Cold builds had about 0.2s or 10% added to them. I personally think this is manageable given the advantages of templating with MiniJinja.
I chose to create a separate crate for this, as I believe that the linker script templating may be useful outside this repo. However, since
minilinkis about 200 lines of code—documentation excluded—there's not much in the way of copying relevant parts directly intoriscv-rt.Alternatives
esp-halhas a very simple C-like preprocessor. Suppose something similar could be used. But there is something to be said about using a less bespoke, and well documented solution.