https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112322
Bug ID: 112322 Summary: std::stacktrace fails Product: gcc Version: 12.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libbacktrace Assignee: unassigned at gcc dot gnu.org Reporter: josopait at goopax dot com CC: ian at gcc dot gnu.org Target Milestone: --- I installed gcc on gentoo linux: EXTRA_ECONF="--enable-libstdcxx-backtrace=yes" emerge gcc and compiled the following program: #include <iostream> #include <stacktrace> int main() { std::cout << std::stacktrace::current() << std::endl; } $ g++-13 -g -std=c++23 a.cpp -o a -lstdc++_libbacktrace When compiled with GCC 13 or GCC 14, the program output is weird: $ ./a 0# at :32764 1# at :32764 2# at :32764 3# at :32764 4# The number 32764 changes randomly between program calls, in the range 32764 .. 32767. When compiled with GCC 12, the program crashes with a segmentation fault: (gdb) bt #0 0x0000000000000000 in ?? () #1 0x000055555555ad41 in elf_nodebug (state=<optimized out>, pc=<optimized out>, callback=<optimized out>, data=<optimized out>, error_callback=<optimized out>) at elf.c:585 #2 elf_nodebug (state=<optimized out>, pc=<optimized out>, callback=<optimized out>, error_callback=<optimized out>, data=<optimized out>) at elf.c:565 #3 0x0000555555557c0f in std::stacktrace_entry::_M_get_info (this=0x55555557e2b0, __desc=0x7fffffffdb60, __file=0x7fffffffdb80, __line=0x7fffffffdb5c) at /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/stacktrace:191 #4 0x0000555555557db2 in std::operator<< (__os=..., __f=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/stacktrace:722 #5 0x00005555555585ce in std::operator<< <std::allocator<std::stacktrace_entry> > (__os=..., __st=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/stacktrace:737 #6 0x0000555555557492 in main () at a.cpp:8 Here, parameter `state` of function elf_nodebug points to: (gdb) p *__state $10 = {filename = 0x0, threaded = 1, lock = 0x0, fileline_fn = 0x55555555a5f0 <elf_nodebug>, fileline_data = 0x0, syminfo_fn = 0x55555555a5d0 <elf_nosyms>, syminfo_data = 0x0, fileline_initialization_failed = 0, lock_alloc = 0, freelist = 0x7ffff7fc4048} and error_callback is NULL, which causes the segmentation fault.