This is very clever.. in my CLI I use a dedicated section to build a command table, but the linker script often has to be modified for this to work. The above avoids the need to change the linker script at all (but you do need an init function, which I don't..). It means you have to compile as C++, right?
constructor works fine in C as with GCC/clang. It links down to .init/.init_array on ELF (though all the linker cares about is PT_DYNAMIC and DT_INIT / DT_INIT_ARRAY)
This is very clever.. in my CLI I use a dedicated section to build a command table, but the linker script often has to be modified for this to work. The above avoids the need to change the linker script at all (but you do need an init function, which I don't..). It means you have to compile as C++, right?