Search code examples
linkerembeddedld

How to print message to stdout from GNU ld script?


I have quite large ld link script for embedded platform which is low on RAM and ROM. I want to know how much memory is left available after I have relocated all the code. Actually, I want to print out the value of location counter . to stdout. How can I do it? Is there some magic command like print(.)?


Solution

  • Read the manual. There are no such commands - there cannot be.

    Linker "scripts" are actually more like configuration/descriptor files. They are not "executed" like a script. There is also not a single . (how could be for different memory areas?).

    You can, however, output a map which might exactly be what you need. Try option -M. If you have set up the memory regions in the linker script correctly, the linker will warn if some memory area overflows, which is actually what you want for automatic builds.


    Update: You could grep/filter the map file if you want to insist seeing the section sizes on each build.