Initialize data section in arm/crt0.S

Pilhofer, Frank
Mon Jul 14 14:33:00 GMT 2014


I am targeting a barebones STM32F0 Cortex-M0 using gcc-4.7.4 and newlib-2.1.0 with nano.specs.

I figured out that the startup code from newlib-2.1.0/libgloss/arm/crt0.S gets used. It initializes the C/C++ runtime environment, provides initialization hooks, and eventually calls main. It looks sensible, so I would like to use it (i.e., use _start as the reset vector) instead of rolling my own.

However, while the code does zero out the BSS segment and calls C++ constructors (__libc_init_array), it does not initialize the data section. So when I get to main, static data is not initialized as it should be.

The attached patch adds data segment initialization.

The gcc-arm-embedded folks suggest that data segment initialization should happen in CPU-specific startup code, i.e., in the code that defines the vector table. Not sure if I agree. But in that case, BSS zeroization should be removed from crt0.S: either do both, or do neither.


Frank Pilhofer
Zühlke Engineering GmbH
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crt0.S.patch
Type: application/octet-stream
Size: 1034 bytes
Desc: crt0.S.patch
URL: <>

More information about the Newlib mailing list