5

The -T command to the GCC linker replaces the default linker script. But I don't want to replace the default linker script. I want to append my new section definitions to the existing default linker script.

How to add new memory sections to the default linker script?

djondal
  • 2,521
  • 3
  • 24
  • 40
  • 1
    Not answering your question per se, but did you consider using __attribute__((section("special_secion_name"))) to mark the parts of the code you want in a separate section? This way you get to keep the original linker behavior for everything except your denoted variables/functions – Ishay Peled Apr 08 '15 at 09:23
  • 2
    It's possible to add sections and memory locations to the default linker script by using `INSERT` as mentioned [here](https://stackoverflow.com/questions/6877922/injecting-sections-into-gnu-ld-script-script-compatibility-between-versions-of). Once you have created the file you can add it with `-T path-to-file/flash.ld` as linker option (filename is only an example). For the path it depends on your IDE for Atmel Studio you need to do `../flash.ld` and for MPLABX it's just `./flash.ld` (if file is located at the root of your project) – AWolf Oct 28 '19 at 23:46

1 Answers1

5

I don't think there is a direct way to do what you want to.

What you could do though, is to have ld print the default script file (with -Wl,-verbose, the section between ===============s is the linker script), put it in a file, modify the file with your additions and finally feed this to your link command as the linker script.

It should be fairly easy to write a script that does this and integrate it in your build scripts.

simurg
  • 1,208
  • 7
  • 14
  • 2
    There is a way to INSERT custom data into the default linker script. See: https://stackoverflow.com/a/7225328 – Anders Oct 31 '20 at 02:01