Imagine there’s an embedded system that needs to persist some state when the
processor restarts (either intentionally or due to a catastrophic error).
This is a companion discussion topic for the original entry at https://interrupt.memfault.com/blog/noinit-memory
I chuckled at the use of gcc to ‘edit’ the .ld file, replacing, via a -D directive, FLASH__ with either the bootloader or application string.
I too have used the idea of a .ld.in file, i.e. a template linker script with ‘holes’ to fill in, but have always used good old sed as the edit tool.
Surely this is at least as suitable as gcc? Doing this task with gcc just seems wrong to me, something about ‘if you’ve only got a hammer, everything looks like a nail’ ???
You caught me!
sed is usually a better option for this kind of work; in this case I was trying to keep the set of tools used in the examples as low as possible (eg, windows may not have
sed installed : ).
This approach was inspired by how zephyr assembles linker scripts BTW, if you’re interested in seeing some serious magic:
ld itself has a lot of features around taking fragments of script files- for example, you can specify multiple scripts with
ld will combine the
SECTIONS and other groups in the scripts:
You can also use the
INSERT command in a linker script to control placement: