Linker script errors and suggestions

Ponsheng Chen
1 min readMay 8, 2021

VMA vs LMA of section

  • VMA meaning the address of section that other sections think where it is
  • LMA is the address placed in real memory space used by loader, the it is not identical to VMA meaning it need to move to VMA before used. e.g. data used by ROM

By default, the two address will be the same unless specified.

For example, you can set different LMA with AT keyword

.rom.data : AT(__rom_used_ram_start__)
{
._rom.o(.data)
} > ROM

Section alignment

To align a section, simply add ALIGN() or BLOCK() after section name

.rom.data BLOCK(32) :
{
...
}
.rom.data ALIGN(32) :
{
...
}

Trashcan

Collect unhandled sections with .trashcan can prevent wanted sections missed or linker place unexpected sections at somewhere

/* Set all sections*//* Keep debug sections but no load */
.debug 0 (NOLOAD) : { ... }
/* Remove unwanted sections specifically */
/DISCARD/ : { ... }
/* Collect all wanted sections */
.trashcan :
{
*(*)
}
/* link failed it trashcan not empty */
ASSERT(SIZEOF(.trashcan) == 0, "Section(s) undefined in the linker script used.")

Warning: changing start of section …

The following warning might because the section alignment does not meet the alignment of included sections and cause shift.

warning: changing start of section .bss by 4 bytes

--

--