7.3.3 Linker Script File

Linker scripts, or command files, can perform the following tasks:

  • Instruct the linker where to locate sections
  • Specify memory ranges for a given part
  • Allow user-defined sections to be located at specific addresses

For more on linker script files, see Linker Scripts.

Linker Script

Note: This simplified linker-script example is for illustrative purposes only; it is not a complete, working, linker script.
OUTPUT_FORMAT("elf32-tradlittlemips")
OUTPUT_ARCH(pic32mx)
ENTRY(_reset)
MEMORY
{
kseg0_program_mem(rx): ORIGIN=0x9D000000, LENGTH=0x8000
kseg0_boot_mem       : ORIGIN=0x9FC00490, LENGTH=0x970
exception_mem        : ORIGIN=0x9FC01000, LENGTH=0x1000
kseg1_boot_mem       : ORIGIN=0xBFC00000, LENGTH=0x490
debug_exec_mem       : ORIGIN=0xBFC02000, LENGTH=0xFF0
config3              : ORIGIN=0xBFC02FF0, LENGTH=0x4
config2              : ORIGIN=0xBFC02FF4, LENGTH=0x4
config1              : ORIGIN=0xBFC02FF8, LENGTH=0x4
config0              : ORIGIN=0xBFC02FFC, LENGTH=0x4
kseg1_data_mem  (w!x): ORIGIN=0xA0000000, LENGTH=0x2000
sfrs                 : ORIGIN=0xBF800000, LENGTH=0x100000
}
SECTIONS
{
.text ORIGIN(kseg0_program_mem)  :
{
_text_begin = . ;
*(.text .stub .text.* )
*(.mips16.fn.*)
*(.mips16.call.*)
_text_end = . ;
} >kseg0_program_mem =0
.data   :
{
_data_begin = . ;
*(.data .data.* .gnu.linkonce.d.*)
KEEP (*(.gnu.linkonce.d.*personality*))
*(.data1)
} >kseg1_data_mem AT>kseg0_program_mem
.bss   :
{
*(.dynbss)
*(.bss .bss.* )
*(COMMON)
. = ALIGN(32 / 8) ;
} >kseg1_data_mem
.stack ALIGN(4) :
{
. += _min_stack_size ;
} >kseg1_data_mem
}