Linker scripts are one of those things which nobody who does software development really wants to deal with, but like many things in life sometimes they are inevitable to make things work. Although one could keep pretending linker scripts do not exist and let IDEs handle such pesky details, some of us suffer from this unfortunate condition called ‘curiosity’ and just have to know. People like [Thea].
Recently, [Thea] wrote a blog post on exactly what the linker script generated by the Microchip IDE for a Cortex-M-based SAM D21 project does. The result is a nicely annotated overview of the file’s contents, accompanied by links to the Arm and GCC documentation as well as other references where appropriate. The entire linker script (.ld file) can be viewed on GitHub. With the SAM D21 being a popular choice for Arduino and Arduino-compatible board, this article is a good starting point to understanding what a linker script does and how it affects one’s project.
For other (Cortex-M) MCUs this linker script is also useful as a starting point. Especially knowing which sections are required and what changing them affects in the final (ELF) binary and the firmware that is ultimately written to the MCU. We recently covered linker scripts for Cortex-M as well, along with the concept of memory-mapped I/O.
I actually found it really readable, and super useful for those who haven’t dug into a linker file before :) Is there a format you think would be better? It would be great if you could contribute a specific improvement with a pull request on GitHub. Perhaps you could even create your own linker walkthrough if you have an improved format in mind.
Another reminder to try using literate programming some time.
Been messing with linker files too and did not find solution for following RAM layout – dynamic heap, stack, data+bss. Basically I want to go down from the end. stack is fixed size, data+bss is also fixed size known at/after link time but I want to put it at the end of RAM, not beginning. Dynamic heap is the rest but should start at the beginning. Reason – it is nrf5x with BLE softdevice stack that dynamically allocates RAM from the beginning at init time based on requested features and number of supported connections. Current lame solution in all SDKs is that you decide BLE setup, test how much ram it really takes and then hardcode linker script for data+bss to start right above it.
Not sure if this is not supported (as you must fist collect everything into data+bss and only then you know where it should begin – you need two passes?) or I simply did not find correct syntax for this.
She. The author is a woman. https://github.com/theacodes
And her heavily commented file looks a lot more readable than any linker script I’ve ever written.
I learned a lot from it, damned good work. The whole file is not designed to be a production linker script but a guided tour of a good linker script, reads like a tour of the LD museum, and a fascinating one at that.
The author is a transgender person who identifies as a woman, which is not the same as a woman. I’d really like to find more people who have this kind of enthusiasm for code/hardware design that haven’t been influenced by being a dude in the past.
Never met an under-20 girl who wanted to learn to program, but know plenty of lads that have tried it and decided it’s not for them.
Part of why me and the missus thought about kids is that I loved the idea of teaching a little girl to solder at 6, and curse at segfaults at 7, like my dad did with me.