embeddedldobjcopy

Why does objcopy remove my section from binary?


I'm trying to link my tiny bare-metal educational project for ARM. I have one simple assembly source and linker script. There is a special separate section for exception vectors and startup code:

.section STARTUP_SECTION, "x"
_reset:
    b reset_handler     @ Reset
    b .                 @ Undefined instruction
    b .                 @ SWI
    b .                 @ Prefetch Abort
    b .                 @ Data Abort
    b .                 @ reserved
    b .                 @ IRQ
    b .                 @ FIQ

reset_handler:
    @ some code here
    b .

@ then .text and .data section

And simple linker script:

ENTRY(_reset)
SECTIONS
{
    . = 0;
    .startup . :
    {
        startup.o (STARTUP_SECTION)
        reset_section_end = .;
    }

    .text. : {*(.text)}
    .data . : {*(.data)}
    .bss  . : {*(.bss COMMON)}

}

I see all my sections in the map file produced by linker, and .text section lies at higher address than .startup as expected. But when I convert it to binary with:

arm-none-eabi-objcopy -O binary startup.elf startup.bin

I see that it starts from .text contents, and my startup section is missing. I'm still able to see all sections in the elf file when I disassemble it with objdump, but objcopy removes .startup. The section is not marked as NOLOAD or something like this. Is NOLOAD type a default for such section and if so, why? And how to mark it as LOAD since there is no such section type according to linker manual.

What is going on here?


Solution

  • Seems that a non-standard code section marked with "x" flag is considered by the linker as not "allocatable" by default. "a" flag solves the issue. So, the section declaration finally looks like this:

    .section STARTUP_SECTION, "xa"