From what I can find, .fini is used for the destruction of static storage duration objects after main
returns. In a typical bare-metal application, main
does not return. Is there any reason not to simply remove these symbols from the linker script?
In a typical bare-metal application, main does not return.
main()
can indeed return to the startup code, which can be customized to do something after the application exited, e.g. restart it, cut the power, or start a firmware update. It that case, static destructors can be needed.
Is there any reason not to simply remove these symbols from the linker script?
If main()
never returns and exit()
is never called, then of course you can remove these symols, but then the library startup will miss them, and you'll have to provide a function to override the library function that iterates through __fini_array
.
If you are using newlib
, you can recompile it with --enable-lite-exit
to omit all fini
stuff.