I would like to know how GCC implements exception handling for C++ programs. I couldn\'t find an easy-to-understand and self-explanatory article on the Web (although there are m
The Itanium ABI (which both gcc, clang and a number of others follow) specify that exception handling should follow the Zero-Cost strategy.
The idea of the Zero-Cost strategy is to push all exception handling in side-tables that are not kept on the main program execution path (and thus not trashing the instruction cache). These tables are indexed by the program point.
Furthermore, DWARF information (which is debug information really) is used to unwind the stack. This functionality is usually provided as a library such as libunwind for example, the source code is chokeful of assembly (and thus very platform specific).
Advantages:
try
/catch
block (as fast as if there was none)throw
statement in a function (as long as it is not taken)Disadvantage:
if
strategy) because the side tables are usually not in cache and then there are expensive computations to run to know which catch
clause actually matches (based on RTTI)It is a very popular strategy implement on both 32 bits and 64 bits platform for all major compilers... except MSVC 32 bits (if I remember correctly).