I’m writing a boot script for an ARM-Cortex M3 based device. If I compile the assembler boot script and the C application code and then combine the object files and transfer them to my device everything works.
However, if I use ar to create an archive (libboot.a) and combine that archive with the C application there is a problem:
I’ve put the boot code in a section:
.section .boot, "ax"
.global _start
_start:
.word 0x10000800 /* Initial stack pointer (FIXME!) */
.word start
.word nmi_handler
.word hard_fault_handler
... etc ...
I’ve found that ld strips this from the final binary (the section “boot” is not available). This is quite natural as there is no dependency on it that ld knows about, but it causes the device to not boot correctly.
So my question is: what is the best way to force this code to be included?
Try adding something like:
in the
ldlinker script to tell the linker to keep the.bootsection.However, I’m not sure if this is enough to cause
ldto pull in any objects from the archive that are in the.bootsection – it might not consider an object at all unless some symbol in that object is causing it to be pulled in. If this is a problem, specifying_startas the entry point (using-e _starton the ld command line or usingENTRY(_start)in the linker script) may be the solution.