My assumption of these sections is that they contain pointers to constructors and destructors of global objects that need to be called in init routine. My question is, do I need these sections if I just avoid global objects and can I just discard them? Or is there more than that in this init pointer arrays?
Note: I am trying to migrate from C to C++, so far I never used builtin initializers like libc_init function, I have my own initialization routine.
compiler: arm-none-eabi-g++, target: armv7-m
If you can guarantee that there are no global objects then yes you can simply discard these sections. However, you can only really guarantee that if you are using a freestanding implementation (that is, not a hosted implementation. - lots of stuff relies on initialization in a hosted implementation, standard C and C++ streams for example).
A freestanding implementation means that you are likely working on an OS kernel or a bare-metal equivalent for a machine without an operating system. And in that case you can do pretty much whatever you like, since you are in control of both what the loader expects to find and how it handles it once it does.