raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.62k stars 901 forks source link

templated linker scripts #398

Open kilograham opened 3 years ago

kilograham commented 3 years ago

I thought there was an issue for this already, but there isn't;

We should generate actual linker scripts from templates at build time, allowing for substitution of board parameters (e.g. PICO_FLASH_SIZE), but also either making it a) less brittle to make your own linker script (because you can easily compose the standardized pieces) in your own template b) easy to modify the existing linker scripts, by having the stock linker script templates be rich enough for customization by variables.

Note the overall goal here for a) & b) is to prevent people copying the existing flat scripts and customizing them (which is very brittle)

mvds00 commented 10 months ago

Hi @kilograham, we are in the process of customizing the Pi Pico SDK linker script right now, and would be happy to do this in a way that is useful to the community. Do you have any ideas already on how to provide customization options? As a suggestion, in a different (private) project I (ab)used the C preprocessor to customize the linker script, with various build targets having somewhat differing parameters and settings. It only takes this line in a makefile:

arm-none-eabi-cpp -E -x c -CC ${CFLAGS} -DLINKERSCRIPT $(LINKERSCRIPT).in | egrep -v '^#' > $(LINKERSCRIPT)

From that point on, anything can be done using #include, #ifdef, etc. Let me know if such an approach could work for you, in which case I can submit a PR.