C Compilation Tips
Custom Linker Scripts
If you start to run out of stack or heap memory, altering your linker script can help. A linker script tells the tools where in memory to place certain types of code. To alter your linker settings, in your software project in SDK you should see a file ldscript.ld
. Double-click it.
The default values of 0x2000 (8KiB) are fairly small when we have 1GiB of DDR on the Zybo Z7, so you can increase these (within reason) if you need more dynamic memory space for your C code.
You can also use this file to modify the DDR region used by your program, if you need to reserve an area of memory for storing data outside of your C program.
Compiler Optimisation Options
It is possible to reduce code size and increase the speed of your program by turning on optimisation in the C compiler options within Xilinx SDK.
The 'release' build configuration in SDK sets optimisation to level 2 (-O2
), whereas the default 'debug' configuration uses no optimisation (-O0
).
To change the build configuration, ensure that your main project is selected (the options will be greyed-out otherwise) and choose Project | Build Configurations | Set Active | Release.
Ensure that the Release build is also used for your current Run Configuration, so the correct executable is sent to the board.
For more information on GCC optimisation flags, see the GCC manual.