That’s not good at all, this indicates that there might be something wrong with the startup script or the linker script and only zeroes out the memory (as if it was .bss) but doesn’t copy the init data (.data) into RAM
@maxgerhardt, I added a simple variable b and it seems that the init data copy does work but that the constructor is not called. Still file a bug?
Test
class A {
public:
A(int val): val_(val) {}
int val_;
};
A a1(11);
int b = 123;
void main(void) {
A a2(22);
printk("a1.val_=%d, a2.val_=%d, b=%d\n", a1.val_, a2.val_, b);
}
A a1(11);
int b = 123;
extern "C" void __libc_init_array();
void main(void) {
__libc_init_array();
for(;;) {
A a2(22);
printk("a1.val_=%d, a2.val_=%d, b=%d\n", a1.val_, a2.val_, b);
k_msleep(500);
}
}
Linking .pio\build\nrf52_dk\zephyr\firmware-pre.elf
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/8.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: C:\Users\user.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\lib\thumb\v7e-m\nofp\libc_nano.a(lib_a-init.o): in function __libc_init_array': init.c:(.text.__libc_init_array+0x14): undefined reference to _init’Preformatted text