Bug#1071210: libc++abi1-18:amd64: libc++abi probably should not use libunwind, seqfaults with pthread_cancel
Norbert Lange
nolange79 at gmail.com
Thu May 16 09:41:06 BST 2024
Package: libc++abi1-18
Version: 1:18.1.2-1
Severity: normal
X-Debbugs-Cc: nolange79 at gmail.com
Dear Maintainer,
I am obsorving reproducible crashes when compiling using libc++,
it seems that the cause is mixing unwinding from libgcc_s
with libunwind.
I also ofen observe debugging sessions just closing down, which
I havent narrowed down but they seem to be the same cause.
There is an upstream issue [1], it seems its reproducible on
many clang/debian versions. Yet it is fine on Fedora, the obvious
difference is that libc++abi is not linked against libunwind there
To reproduce, compile with: clang++ -stdlib=libc++ test_cancel.cpp
```
#include <pthread.h>
#include <thread>
extern "C" int main()
{
std::thread systhr([]() { std::this_thread::sleep_for(std::chrono::seconds(10000)); });
std::this_thread::sleep_for(std::chrono::seconds(1));
pthread_cancel(systhr.native_handle());
systhr.join();
return 0;
}
```
Running the produced executable will end in an SEGFAULT, with the following trace:
```
#0 0x0000000000000000 in ?? ()
#1 0x00007f70fc3b1baa in unw_get_proc_info () at build-llvm/tools/clang/stage2-bins/runtimes/runtimes-bins/libunwind/src/libunwind.cpp:188
#2 0x00007f70fc3b588c in _Unwind_GetLanguageSpecificData () at build-llvm/tools/clang/stage2-bins/runtimes/runtimes-bins/libunwind/src/UnwindLevel1.c:478
#3 0x00007f70fc3a001d in scan_eh_tab () at build-llvm/tools/clang/stage2-bins/runtimes/runtimes-bins/libcxxabi/src/cxa_personality.cpp:617
#4 __gxx_personality_v0 () at build-llvm/tools/clang/stage2-bins/runtimes/runtimes-bins/libcxxabi/src/cxa_personality.cpp:947
#5 0x00007f70fc28fab6 in _Unwind_ForcedUnwind_Phase2 (exc=exc at entry=0x7f70fc092d30, context=context at entry=0x7f70fc091650,
frames_p=frames_p at entry=0x7f70fc091558) at ../../../src/libgcc/unwind.inc:183
#6 0x00007f70fc2901b0 in _Unwind_ForcedUnwind (exc=0x7f70fc092d30, stop=0x7f70fc1272c0 <unwind_stop>, stop_argument=<optimized out>)
at ../../../src/libgcc/unwind.inc:218
#7 0x00007f70fc127440 in __GI___pthread_unwind (buf=<optimized out>) at ./nptl/unwind.c:130
#8 0x00007f70fc11d73b in __do_cancel () at ../sysdeps/nptl/pthreadP.h:282
#9 sigcancel_handler (sig=32, si=0x7f70fc0918f0, ctx=<optimized out>) at ./nptl/pthread_cancel.c:65
#10 sigcancel_handler (sig=<optimized out>, si=0x7f70fc0918f0, ctx=<optimized out>) at ./nptl/pthread_cancel.c:32
#11 <signal handler called>
#12 0x00007f70fc165485 in __GI___clock_nanosleep (clock_id=clock_id at entry=0, flags=flags at entry=0, req=0x7f70fc091db8, rem=0x7f70fc091db8)
at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:48
#13 0x00007f70fc169d93 in __GI___nanosleep (req=<optimized out>, rem=<optimized out>) at ../sysdeps/unix/sysv/linux/nanosleep.c:25
#14 0x00007f70fc41df9b in __libcpp_thread_sleep_for () at build-llvm/tools/clang/stage2-bins/include/c++/v1/__threading_support:411
#15 sleep_for () at build-llvm/tools/clang/stage2-bins/runtimes/runtimes-bins/libcxx/src/thread.cpp:108
#16 0x000055bf7ab29a5e in void std::__1::this_thread::sleep_for<long long, std::__1::ratio<1l, 1l> >(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > const&) ()
#17 0x000055bf7ab297fd in main::$_0::operator()() const ()
#18 0x000055bf7ab29795 in decltype ((static_cast<main::$_0>({parm#1}))()) std::__1::__invoke<main::$_0>(main::$_0&&) ()
#19 0x000055bf7ab29775 in void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, main::$_0>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, main::$_0>&, std::__1::__tuple_indices<>) ()
#20 0x000055bf7ab29532 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, main::$_0> >(void*) ()
#21 0x00007f70fc11f134 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#22 0x00007f70fc19f7dc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
```
[1] - https://github.com/llvm/llvm-project/issues/90041
Regards, Norbert
-- System Information:
Debian Release: 12.5
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 6.1.0-21-amd64 (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages libc++abi1-18:amd64 depends on:
ii libc6 2.36-9+deb12u7
ii libunwind-18 1:18.1.2-1
libc++abi1-18:amd64 recommends no packages.
libc++abi1-18:amd64 suggests no packages.
-- no debconf information
More information about the Pkg-llvm-team
mailing list