Linker script section assignment issue

binutils@eliasoenal.com binutils@eliasoenal.com
Thu Apr 3 20:27:00 GMT 2014


Since I wanted to prefix my firmware with a custom header containing a 
checksum, I've added an empty section called ".header". My target has a 
RAM and a FLASH region, so I assigned the ".header" section to the FLASH 
region. Whenever I leave the section completely empty it ends up in a 
segment different from the others (.text/.rodata) and gets ignored when 
I try to copy it using objcopy. Yet if I add a single BYTE(0), or even a 
C array sized 0 to the section, it ends up in the same segment as the 
others and I have no issues copying it. I would like to understand why 
it ends up in a different segment when left empty.

-Elias

Linker script excerpt:
> MEMORY
> {
>   RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
>   FLASH (rx) : ORIGIN = 0x8010000, LENGTH = 1024K
> }
> SECTIONS {
>     .header : /* size and checksum */
>     {
>         _sflash = .;
>         /* BYTE(0) This solves the problem */
>         . = _sflash + 0x200;
>     }>FLASH
>
>     .isr_vector : /* interrupt vector */
>     {
>         . = ALIGN(4);
>         _svector = .;
>         KEEP(*(.isr_vector))
>         . = ALIGN(4);
>     }>FLASH
>
>     .text : /* code goes here*/
>     {
>         . = ALIGN(4);
>         *(.text)
>         *(.text.*)
>         . = ALIGN(4);
>             _etext = .;
>     } > FLASH
Output from arm-none-eabi-readelf -S -l
> Program Headers:
>   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz Flg Align
>   LOAD           0x008000 0x08010000 0x08010000 0x00000 0x00200 RW  0x8000
>   LOAD           0x000200 0x08010200 0x08010200 0x24ca8 0x24ca8 R E 0x8000
>   LOAD           0x028000 0x10000000 0x08034ea8 0x002c8 0x012b4 RW  0x8000
>
>  Section to Segment mapping:
>   Segment Sections...
>    00     .header
>    01     .isr_vector .text .rodata
>    02     .data .bss 



More information about the Binutils mailing list