9.3 Default Linker Script

If no linker script is specified on the command line, the linker will use an internal version known as the built-in default linker script. The default linker script has section mapping that is appropriate for all 32-bit devices. It uses an INCLUDE directive to include the device-specific memory regions.

The default linker script is appropriate for most applications. Only applications with specific memory-allocation needs will require an application-specific linker script. The default linker script can be examined by invoking the linker with the --verbose option:
xc32-ld --verbose

In a normal tool-suite installation, a copy of the default linker script is shipped. Note that this file is only a copy of the default linker script. The script that the linker uses is internal to the linker. If the -mdfp and -mprocessor option is used with an XC32 application to indicate an alternate device family pack (DFP), the linker script from that DFP will be used instead.

For PIC32MX Devices

A copy of the default linker script is located at /pic32mx/lib/ldscripts/elf32pic32mx.x. Note that this file is only a copy of the default linker script. The script that the linker uses is internal to the linker.

The device-specific portions of the linker script are located in /pic32mx/lib/proc/device/, where device is the device name specified with the -mprocessor compilation-driver (xc32-gcc) option.

For PIC32MZ and Later Devices

The linker script for PIC32MZ devices are contained within a single file (e.g. pic32mx/lib/proc/32MZ2048ECH100/p32MZ2048ECH100.ld). This eliminates the dependency on two files (elf32pic32mx.x and procdefs.ld) used by the older linker-script model. Like before, the xc32-gcc compilation driver will pass the device-specific linker script to the linker when building with -mprocessor option.

Note: The Compiler guide relevant for you target device examines the contents of the default linker script in detail. The discussion applies to both assembly-code and C-code projects.

The default linker script maps each standard input section to one or more specific MEMORY regions. In turn, each MEMORY region maps to an address segment on the PIC32 MCU (e.g. kseg0, kseg1). See the Section 3 of the PIC32MX Family Reference Manual (DS61115) for a full description of the user/kernel address segments.

The table below shows how the default linker script maps standard sections to MEMORY regions.

Table 9-1. PIC32 Reserved, Standard Section Names in Default Linker Script
Section NameGenerated byFinal LocationDefault linker-script MEMORY regionImplied attributes
.resetReset handlerExecutable boot-code segmentkseg0_boot_memcode
.bev_excptBEV-Exception handlerExecutable boot-code segmentkseg0_boot_memcode
.app_excptGeneral-Exception handlerExecutable boot-code segmentkseg0_boot_memcode
.vector_nInterrupt Vector nExecutable boot-code segmentkseg0_boot_memcode
.startupC startup codeExecutable boot-code segmentkseg0_boot_memcode
.textCompiler- or assembler-generated instructionsExecutable code segmentkseg0_program_memcode
.rodataStrings and C data declared constRead-only data segmentkseg0_program_memcode
.sdata2Small initialized constant global and static dataRead-only data segmentkseg0_program_memdata
.sbss2Uninitialized constant global and static data (i.e., variables which will always be zero)Read-only data segmentkseg0_program_memdata
.dataVariables >n bytes (compiled -Gn) with an initial value. Values copied from program memory to data memory at C startup.Initialized data segmentkseg1_data_mem & kseg0_program_memdata
.sdataVariables <=n bytes (compiled -Gn) with an initial value. Used for gp-relative addressing.Small initialized data segmentkseg1_data_mem & kseg0_program_memdata
.lit4 / .lit8Constants (usually floating point) which the assembler decides to store in memory rather than in the instruction stream. Used for gp-relative addressing.Small initialized data segmentkseg1_data_mem & kseg0_program_memdata
.sbssUninitialized variables <=n bytes (compiled -Gn). Used for gp-relative addressing.Small zero-filled segmentkseg1_data_memdata
.bssUninitialized larger variablesZero-filled segmentkseg1_data_memdata
.heapHeap used for dynamic memoryReserved by linker scriptkseg1_data_memdata
.stackMinimum space reserved for stackReserved by linker scriptkseg1_data_memdata
.ramfuncRAM-functions, copied from program memory to data memory at C startupInitialized data segmentkseg1_data_mem & kseg0_program_memdata
.reginfo

.stab*

.debug*

Debug informationNot in load imagen/ainfo
.lineDWARF debug informationNot in load imagen/ainfo
.comment#ident /.ident directiveNot in load imagen/ainfo
Note: The table above contains sections that are no longer mapped in the linker script. Starting with XC32 v2.00, the best-fit allocator allocates them.

For PIC32C/SAM Devices

A copy of the default linker script is located at /pic32c/lib/ldscripts/elf32pic32c.x. Note that this file is only a copy of the default linker script. The script that the linker uses is internal to the linker.

The device-specific portions of the linker script are located in /pic32c/lib/proc/device/, where device is the device name specified with the -mprocessor compilation-driver (xc32-gcc) option.