xant / libhl

Simple and fast C library implementing a thread-safe API to manage hash-tables, linked lists, lock-free ring buffers and queues
GNU Lesser General Public License v3.0
420 stars 117 forks source link

ATOMIC_CAS cann't work on ARM #23

Closed luokj closed 6 years ago

luokj commented 6 years ago

Use hash function on ARM platform, but it crash when callinig ht_create

xant commented 6 years ago

ATOMIC_CAS makes use of __sync_bool_compare_and_swap which I believe it's provided by the compiler also on ARM. Could you provide the exception and the stacktrace (and maybe a coredump) for your crash?

xant commented 6 years ago

@luokj I think I understand what is your problem. If it is crashing at runtime with an "Unhandled fault: Alignment Exception", adding "-mno-unaligned-access" to CFLAGS should fix. I'll check myself when I'll have access again to a linux ARM system. Note that maybe on linux you can configure the linux kernel at runtime (/proc/cpu/alignment) to ignore the exception and don't kill the process.

luokj commented 6 years ago

Thank you for reply. I use other code from github, so I don't give a helpful information.

2017-10-24 7:49 GMT+08:00 Andrea Guzzo notifications@github.com:

@luokj https://github.com/luokj I think I understand what is your problem. Is it crashing at runtime with an "Unhandled fault: Alignment Exception". Adding "-mno-unaligned-access" to CFLAGS should fix. I'll check myself when I'll have access again to a linux ARM system. Note that maybe on linux you can configure the linux kernel at runtime (/proc/cpu/alignment) to ignore the exception and don't kill the process.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xant/libhl/issues/23#issuecomment-338828995, or mute the thread https://github.com/notifications/unsubscribe-auth/AK8LHF1l28MG4nnNLhOcbX3lQRhp52_Oks5svSX0gaJpZM4PhgkX .

xant commented 6 years ago

Ok, packing some structures was overriding the natural alignment and obviously making it not work on ARM unless the "-maligned-access" option was passed to the compiler (but then with obvious performance loss because of unaligned memory access) I just made packing of those structure optional and controlled by the USE_PACKED_STRUCTURES preprocessor symbol.

Fixed in 172f5a