Skip to content

Default linker scripts

Andrey Eliseev edited this page Aug 10, 2026 · 12 revisions

Note

The contents of this document are irrelevant to the cdm-cocas target, because it uses Cocas for linking, which does not support linker scripts. See LLVM targets.

1 Introduction

The cdm target provides two default linker scripts. When the user does not pass a custom linker script with the -T option, one of these scripts is used, depending on the memory model (see Memory models).

Linker script Memory model
ldscripts/cdm-vonNeumann.ld von Neumann
ldscripts/cdm-harvard.ld Harvard

The von Neumann script uses matching VMA and LMA values for all sections. The Harvard script sets the VMA of .data, .rodata and .bss starting at address 0 and places them physically after .text and .progmem.

2 Sections

Both scripts verify and place the interrupt vector table automatically. The IVT consists of two sections with known names. These sections must have specific sizes.

Section Size Required Description
.ivt.exceptions 64 bytes Yes 16 exception vectors, placed at address 0x0
.ivt.interrupts <= 192 bytes No Application-specific interrupt vectors, placed at address 0x40

The required sections are normally provided by crt0.o (see Standard library). If you disable crt0.o with -nostartfiles, you'll have to define these sections yourself or use a custom linker script with -T.

The linker scripts also recognize the following sections:

Section Description
.text, .text.* Program code
.progmem, .progmem.* Program memory constants
.data, .data.* Non-zero-initialized data
.rodata, .rodata.* Non-zero-initialized data (read only)
.bss, .bss.* Zero-initialized data

Note

When using -mmem-model=vonNeumann, .progmem sections are placed in RAM.

3 Controlling RAM ranges

The range of addresses used for placing non-IVT sections can be controlled with special symbols in additional linker scripts (passed without -T). This is useful for reserving address ranges for memory-mapped I/O (MMIO).

Symbol Default value Description
RAM_ORIGIN 0x100 for von Neumann,
0x0 for Harvard (see Memory models)
Starting address for non-IVT sections
RAM_LENGTH 64K-RAM_ORIGIN Length of the address range used for non-IVT sections

Both values must be multiples of 2. Regular symbols can also be assigned a value directly in a linker script. This is useful for MMIO, when an I/O register is mapped to a fixed address in memory.

Clone this wiki locally