d99kris / nchat

Terminal-based Telegram / WhatsApp client for Linux and macOS
MIT License
538 stars 41 forks source link

Abnormal closure due to "undefined symbol: __atomic_load" on x86 #76

Closed Theldus closed 1 year ago

Theldus commented 1 year ago

Description

I'm trying to use nchat on an old x86 machine and the program crashes during '--setup'.

How to reproduce it

Environment


My guess:

Doing a strace in the execution of nchat, one can see the attempt to load/call the '__atomic_load' function during execution... which is not successful and the program closes:

$ strace -ff -o dump ./nchat --setup
Protocols:
0. Dummy
1. Telegram
2. WhatsAppMd
3. Exit setup
Select protocol (3): 1
Enter phone number (ex. +6511111111): +my_phone
$
$ echo $?
127

$ grep -r "exit" dump.*
dump.192:exit_group(127)
dump.192: *** exited with 127 ***
dump.193: *** exited with 127 ***
dump.194: *** exited with 127 ***
dump.195: *** exited with 127 ***
dump.196: *** exited with 127 ***
dump.197: *** exited with 127 ***

$ grep "exited with 127" dump.192 -C 2
writev(2, [{iov_base="./nchat", iov_len=7}, {iov_base=": ", iov_len=2}, {iov_base="symbol 
lookup error", iov_len=19}, {iov_base=": ", iov_len=2}, 
{iov_base="/home/david/Down/nchat/build/lib"..., iov_len=53}, {iov_base=": ", iov_len=2}, 
{iov_base="undefined symbol: __atomic_load", iov_len=31}, {iov_base="", iov_len=0}, 
{iov_base="", iov_len=0}, {iov_base="\n", iov_len=1}], 10) = 117
exit_group(127)                         = ?
+++ exited with 127 +++

The __atomic_load function seems to belong to libatomic, which is not linked to nchat.

If I add libatomic as one of the dependencies, the program works as expected:

patchelf --add-needed libatomic.so.1 nchat

This function is probably used by one of nchat's dependencies, although I don't know exactly which one. It's also worth noting that this only happens on x86, not x86_64.

(Maybe) proposed fix:

Add 'atomic' to one of nchat's link libraries in CMakeLists.txt

d99kris commented 1 year ago

Hi @Theldus - many thanks for the detailed bug report! :+1:

Yes, nchat probably needs some fixes to how it detects that inbuilt atomics are not present. I have some ideas on how to address it. I'll prepare a fix in a couple of days.

d99kris commented 1 year ago

Hi, I believe this issue should be fixed with above commit. I reproduced the issue and tested above fix on Debian 11.5.0 i386 in a VM. Please let me know if you still encounter issues after the fix. Thanks!

Theldus commented 1 year ago

Hi @d99kris, I just tested it here and works like a charm now.

Thanks a lot for the quick fix and your work on nchat, it's amazing 🙂.

d99kris commented 1 year ago

Thanks 🙂