What is the benefit of using -fno-unwind-tables
in addtion to -fno-exceptions
– especially on a (freestanding) C++ Embedded Systems?
According to Practical Guide to Bare Metal C++ — § Exceptions there should be both used:
It is possible to forbid usage of throw statements by providing certain options to the compiler. For GNU compiler (gcc) please use
-fno-exceptions
in conjunction with-fno-unwind-tables
options.
However there's no explanation what -fno-unwind-tables
acutally does.
If one thing is done or used in conjunction with another, the two things are done or used together. The army should have operated in conjunction with the fleet to raid the enemy's coast. Since iron destroys vitamin E, these two nutrients should not be taken in conjunction.
— Connectives are usually used only once in a sentence. and, also, as well as, moreover, furthermore, besides, in addition, etc. because, so, therefore, thus, consequently, as a result of, etc.
Per the GCC documentation, it suppresses the generation of static unwind tables (as opposed to complete exception-handling code), the main benefit of which is likely to be smaller object files due to not containing that data. Note that such tables might be used for things like stack-walking code for backtrace generation even in the absence of full-blown exception-handling (e.g. in C code).
I don't know for sure, but I'd imagine that in the case where, by default, full exception-handling code is already disabled but static unwind tables are enabled, -fno-exceptions
probably doesn't affect the latter, hence using both options covers all bases. In other words, the compiler may want to generate one or the other, but when size and efficiency matter you definitely want it to do neither.
Having hacked about with the makefile of some hapless C++ project (already using -fno-exceptions
) to cross-compile it 3 ways, it's apparent which way my particular toolchain defaults:
default : 576KB
CPPFLAGS += -fno-unwind-tables : 576KB
CPPFLAGS += -funwind-tables : 580KB
The tables themselves reside in an additional .ARM.extab
ELF section in the latter - of course, for an embedded project you may well have a finely-tuned linker script which would end up discarding that anyway, but hey, still better not to waste time and effort generating it in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With