This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SK-AM64: Bare metal C++ on A53 core of AM64xx is not calling global objects' constructors

Part Number: SK-AM64

I am also having trouble running bare metal C++ on the A53 core of AM64xx. i'm on mcu_plus_sdk_am64x_08_05_00_24 and using gcc-arm-aarch64-none-eabi_9_2_1. the issue is that current SDK doesn't seem to handle init_array, fini_array and so on and as a consequence constructors for global objects are not called whereas those for every other object are.

i have worked this around by doing the following:

- make sure linker script includes the proper sections and that these are output on the elf file. this works but only if i inject the following in a section like ro_data:

PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);

whereas if i create separate sections called .preinit_array, .init_array and .fini_array these are stripped by elf2rprc.js

- add the following code in my main:

extern void (*__preinit_array_start []) (void) __attribute__((weak));
extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));
extern void (*__fini_array_start []) (void) __attribute__((weak));
extern void (*__fini_array_end []) (void) __attribute__((weak));

void __libc_init_array (void)
size_t count;
size_t i;

count = __preinit_array_end - __preinit_array_start;
for (i = 0; i < count; i++)
__preinit_array_start[i] ();

count = __fini_array_end - __fini_array_start;
for (i = 0; i < count; i++)
__fini_array_start[i] ();

count = __init_array_end - __init_array_start;
for (i = 0; i < count; i++)
__init_array_start[i] ();

so... with the above everything works BUT:

1) it's ugly to have to inject those sections somewhere else... why is elf2rprc.js stripping them if they're in the properly named sections?

2) would be nice to have the above code merged in \mcu_plus_sdk_am64x_08_05_00_24\source\kernel\nortos\dpl\a53\boot_armv8.c in __system_start() in a future revision of the sdk. so that other people could have that working out of the box