Boot section is removed (gcc, ld, ar, as)
FreePreventing boot section removal in LPC17xx with GNU tools
FreeFree tier
About Boot section is removed (gcc, ld, ar, as)
A forum thread on EmbeddedRelated.com discussing a problem where the boot section of an LPC17xx device is removed when using gcc, ld, ar, as with an archive library. The user Jonatan Magnusson describes that linking assembler boot code and C application works with direct object files but fails when using ar to create a library archive. Solutions include using KEEP in the linker script, the -u (_start) switch, or placing boot code in the .text section. The thread includes replies from Igor Skochinsky and David Smead.
Key Features
KEEP directive in linker script to retain boot section
-u (_start) linker switch to force inclusion of boot code
Place boot code in .text section as a simpler alternative
Pros & Cons
Pros
- Provides practical community-vetted solutions to a common embedded linking problem
- Relevant for LPC17xx and many ARM Cortex-M microcontrollers using GCC toolchain
- Includes expert advice from experienced embedded engineers
Cons
- Solutions are specific to LPC17xx and GNU toolchain; may not directly apply to other microcontrollers
- Requires modifying linker scripts, which may be non-obvious for beginners
Best For
Embedded system development for LPC17xx and similar ARM devicesLinking assembler boot scripts with C applicationsDebugging boot section removal during GNU linker archive linking
FAQ
Why does ld strip the boot section when using an archive?
Because there is no direct dependency from the C application to the boot code. The linker removes unused sections by default.
How can I force ld to include the boot section?
Use the KEEP directive in the linker script, or use the -u (undefined symbol) switch to add a reference to _start.
Should I put boot code in .text section instead?
Putting it in .text may not guarantee it is placed at the beginning of the image. Using a separate section with KEEP is recommended.