https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123746
Bug ID: 123746
Summary: Add cfi_ directives to config/arm/libunwind.S for
better (DWARF) backtraces
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: georgepee at gmail dot com
Target Milestone: ---
Using
```
#include <thread>
#include <stdexcept>
struct Buffer {
virtual ~Buffer() noexcept(false) {
throw std::runtime_error("nested exception");
}
};
__attribute__((noinline)) void init() {
auto buffer = std::make_unique<Buffer>();
throw std::runtime_error("initial exception");
}
void thread_run() {
try {
init();
} catch (...) {}
}
int main() {
std::thread worker(thread_run);
worker.join();
return 0;
}
```
Compiled with GCC-14.2 with
CFLAGS=-g -Os
```
#0 __libc_do_syscall () at ../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47
#1 0x64d2ebea in __pthread_kill_implementation (threadid=<optimized out>,
signo=6, no_tid=<optimized out>)
at pthread_kill.c:43
#2 0x64cfea40 in __GI_raise (sig=sig@entry=6) at
/usr/src/debug/glibc/2.38/sysdeps/posix/raise.c:26
#3 0x64cf025c in __GI_abort () at abort.c:79
#4 0x438bb2b6 in __gnu_cxx::__verbose_terminate_handler ()
at
/usr/src/debug/gcc-runtime/15.2.0/libstdc++-v3/libsupc++/vterminate.cc:95
#5 0x438b9bd0 in __cxxabiv1::__terminate (handler=<optimized out>)
at
/usr/src/debug/gcc-runtime/15.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:48
#6 0x438b20cc in __cxa_call_terminate (ue_header_in=0x643006f0)
at /usr/src/debug/gcc-runtime/15.2.0/libstdc++-v3/libsupc++/eh_call.cc:56
#7 0x438b96a4 in __cxxabiv1::__gxx_personality_v0 (state=<optimized out>,
ue_header=0x643006f0, context=<optimized out>)
at
/usr/src/debug/gcc-runtime/15.2.0/libstdc++-v3/libsupc++/eh_personality.cc:692
#8 0x460d5e90 in unwind_phase2 (ucbp=ucbp@entry=0x643006f0,
vrs=vrs@entry=0x64cd0d64)
at /usr/src/debug/libgcc/15.2.0/libgcc/unwind-arm-common.inc:448
#9 0x460d6040 in __gnu_Unwind_Resume (ucbp=0x643006f0, entry_vrs=0x64cd0d64)
at /usr/src/debug/libgcc/15.2.0/libgcc/unwind-arm-common.inc:701
#10 0x460d68de in _Unwind_Resume () at
/usr/src/debug/libgcc/15.2.0/libgcc/config/arm/libunwind.S:357
--Type <RET> for more, q to quit, c to continue without paging--
#11 0x00010bb4 in std::default_delete<Buffer>::operator() (this=<optimized
out>, __ptr=0x64300600)
at /opt/gcc-14/arm-linux-gnueabi/include/c++/14.2.0/bits/unique_ptr.h:87
#12 std::unique_ptr<Buffer, std::default_delete<Buffer> >::~unique_ptr
(this=<synthetic pointer>, __in_chrg=<optimized out>)
at /opt/gcc-14/arm-linux-gnueabi/include/c++/14.2.0/bits/unique_ptr.h:398
#13 init () at test2.cpp:14
#14 0x64cd1400 in ?? ()
```
Was expecting frames (shows properly in x86-64 binary)
```
#14 thread_run
#15 std::execute_native_thread_routine
#16 start_thread
```
Because there's no DWARF debug for libunwind.S, gdb uses a fallback to
determine the next frame, but gets it wrong in this case. I think that adding
cfi to the assembly would help it along.