10.4 Creating a Custom Linker Script

The standard XC32 linker scripts are general purpose and will satisfy the demands of most applications. Various attributes that are supported in C source code can be used to customize the memory layout. Examples of complex applications such as bootloaders and dual-core applications are provided by Microchip, all based on the standard linker scripts. However, occasions may arise where a custom linker script is desired.

To create a custom linker script, start with a copy of the standard linker script that is appropriate for the target device. For example, to customize a linker script for the PIC32AK1216GC41064 device, start with a copy of p32AK1216GC41064.gld.

Customizing a standard linker script will usually involve editing sections or commands that are already present. For example, a stub for user-defined sections in program memory is included. This stub may be renamed and/or customized with absolute addresses if required.

It is recommended that unused sections be retained in a custom linker script, since unused sections will not impact application memory usage. If a section must be removed for a custom script, C style comments can be used to disable it.