To crt0 or not to crt0

Asked by Hermann Kleier

In contrast to Sourcery CodeBench 2014.05-36, your tool chain loads crt0.o unconditionally. I admit, crt0.o is required for ISO C compatibility. Without crt0.o there is not exit()/atexit(). But does a BARE METAL main() ever return? Shouldn't a bare metal main() have __attribute__ ((noreturn)) set by default?

Other tasks of crt0.o, notably the initialization of static data, are commonly handled by the Reset_Handler(). It could be argued that the Reset_Handler() should invoke _mainCRTStartup() for the initialization of static data rather than doing it by itself. But, because you have defined __USES_INITFINI__, this would leave the needless calls to atexit() and to __libc_init_array().

So it all boils down to the question whether or not to define __USES_INITFINI__. IMHO there is no point of doing so in a bare metal environment.

Anyway, loading crt0.o does not impose a serious problem for my environment because I use an ld-wrapper that prevents specified object from being loaded. But for the unaware this leads to the error message:

fini.c:(.text.__libc_fini_array+0x20): undefined reference to `_fini'

Is there a point of loading crt0.o unconditionally? Shouldn't this point be well-documented?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#1

I suggest you report a bug

Revision history for this message
Hermann Kleier (hermann-kleier) said :
#2

Thanks actionparsnip, that solved my question.