Reputation: 4012
when gcc/g++ encounters an ICE (internal compiler error), then recent versions of the compiler will print a neat stack trace before exiting.
Questions: What technology is used to implement that? GCC is written in C++, afaik some conservative revision like C++03.
In particular
GCC does not use Boost.
GCC does not use external libraries like linunwind or libexcept to all of my knowledge.
GCC does not necessarily use glibc. For example I can cross-compile GCC on linux for host mingw32, and stack traces work just fine.
So before blindly closing this question, please make sure the linked answer does not need any of these libraries.
Upvotes: 0
Views: 1750
Reputation: 21974
As many people mentioned in comments GCC statically links against libbacktrace
which uses libgcc
on ELF platforms (e.g. Linux) and custom code on AIX and Windows. Assuming that most people will be interested in Linux, I expand on that one that below.
GCC runtime library (libgcc
) contains stack unwinding code which is used for C++ exceptions and error reporting. In particular it's used by Glibc (backtrace(3)), AddressSanitizer and GCC itself.
Internal implementation of unwinding is highly target-dependent. For example on amd64 it uses stack layout metadata stored in .eh_frame
sections (see https://uclibc.org/docs/psABI-x86_64.pdf), on ARM it uses metadata as well (but in different format) and on i386 it manually parses the function prologue instructions (for platform-specific details one can study the relevant unwind files in https://github.com/gcc-mirror/gcc/tree/master/libgcc).
Upvotes: 3