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.
--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.
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.
Section Name | Generated by | Final Location | Default linker-script MEMORY region | Implied attributes |
---|---|---|---|---|
.reset | Reset handler | Executable boot-code segment | kseg0_boot_mem | code |
.bev_excpt | BEV-Exception handler | Executable boot-code segment | kseg0_boot_mem | code |
.app_excpt | General-Exception handler | Executable boot-code segment | kseg0_boot_mem | code |
.vector_n | Interrupt Vector n | Executable boot-code segment | kseg0_boot_mem | code |
.startup | C startup code | Executable boot-code segment | kseg0_boot_mem | code |
.text | Compiler- or assembler-generated instructions | Executable code segment | kseg0_program_mem | code |
.rodata | Strings and C data declared const | Read-only data segment | kseg0_program_mem | code |
.sdata2 | Small initialized constant global and static data | Read-only data segment | kseg0_program_mem | data |
.sbss2 | Uninitialized constant global and static data (i.e., variables which will always be zero) | Read-only data segment | kseg0_program_mem | data |
.data | Variables >n bytes (compiled -Gn ) with an initial value. Values copied from program memory to data memory at C startup. | Initialized data segment | kseg1_data_mem & kseg0_program_mem | data |
.sdata | Variables <=n bytes (compiled -Gn ) with an initial value. Used for gp-relative addressing. | Small initialized data segment | kseg1_data_mem & kseg0_program_mem | data |
.lit4 / .lit8 | Constants (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 segment | kseg1_data_mem & kseg0_program_mem | data |
.sbss | Uninitialized variables <=n bytes (compiled -Gn ). Used for gp-relative addressing. | Small zero-filled segment | kseg1_data_mem | data |
.bss | Uninitialized larger variables | Zero-filled segment | kseg1_data_mem | data |
.heap | Heap used for dynamic memory | Reserved by linker script | kseg1_data_mem | data |
.stack | Minimum space reserved for stack | Reserved by linker script | kseg1_data_mem | data |
.ramfunc | RAM-functions, copied from program memory to data memory at C startup | Initialized data segment | kseg1_data_mem & kseg0_program_mem | data |
.reginfo
| Debug information | Not in load image | n/a | info |
.line | DWARF debug information | Not in load image | n/a | info |
.comment | #ident /.ident directive | Not in load image | n/a | info |
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.