This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BUG: GCC linker scripts don't keep .init_array sections

The GCC linker scripts included with the nRF51822 SDK (checked: 6.0.0 and 6.1.0 as well as nrf51-pure-gcc-setup) include .init_array sections, but do not specify them as KEEP sections (as .init is). This causes them to be discarded when linking with the --gc-sections option, necessary to remove unused code (combined with compiler options -ffunction-sections and -fdata-sections), along with whatever vtables and methods are referenced solely from those sections.

I am using GNU Tools for ARM Embedded Processors 4.8-2014-q2 (on a Windows host).

When I add KEEP() around the .preinit_array, .init_array, and .fini_array lines in gcc_nrf51_common.ld it fixes the issue (I will try to attach an updated version from 6.0.0).

(This is not a question as such, but this forum appears to also be used to post bug reports. I don't need further support, although it would be nice to see the fix in a future SDK.)

  • Note that might be useful for others hitting this issue: (1) it is fixed in the nRF5 SDK 11.0.0 (and 11.0.0-2.alpha), but not nRF52 SDK 0.9.2, and (2) nRF5 SDK 11.0.0 (but not 11.0.0-2.alpha) renamed the ISR table from Vectors to isr_vector, so if you had a local override of nrf52_common.ld or equivalent with this fix or other changes, upgrading to 11.0.0 would cause a crash at startup as the ISR table would no longer be in the correct location.

Related