On 02/14/17 19:50, Joe Savage wrote: >> I can not compile your code with clang-3.8, gcc works well. But looks >> like clang does not support libatomic so -latomic -mcx16 does not work >> for functions ending on _16" >> ./test.c:(.text+0x61): undefined reference to `__atomic_load_16' >> ./test.c:(.text+0x92): undefined reference to `__atomic_store_16' >> ./test.c:(.text+0xcb): undefined reference to `__atomic_compare_exchange_16' >> >> but clang compiles well for n functions. >> __atomic_com__atomic_compare_exchange_n(pare_exchange_n( >> >> >> You saw that I send m4 checks for test compilations which worked well >> with gcc. Now we need to fix clang before merging it. >> >> I reproduce it with that code: >> >> int main() { >> unsigned __int128 x = 0, y = 0; >> y = __atomic_load_16(&x, 0); >> __atomic_store_16(&x, y, 0); >> __atomic_compare_exchange_16(&x, &y, x, 0, 0, 0); >> return 0; >> } >> >> Do you have any ideas? > > With regards to the code snippet that reproduces the issue, you shouldn't be > using the "*_16" versions of the atomic built-ins. On changing the code to > take this into consideration, clang compiles and links just fine for me: > > int main(void) > { > unsigned __int128 x = 0, y = 0; > y = __atomic_load_n(&x, 0); > __atomic_store_n(&x, y, 0); > __atomic_compare_exchange_n(&x, &y, x, 0, 0, 0); > > return 0; > } > > The code in the example directory already does this, though, so this > shouldn't be the problem. My guess is that something needs to be adjusted > within the project's build infrastructure, as "__atomic_compare_exchange_n" > works perfectly fine within e.g. platform/linux-generic/pktio/ring.c. >
ok, it looks like in case of clang we need to pass -mcx16 and no need to pass libatomic. I will check if I do that in my patch. I compiled it also: root:22:37 /tmp $cat > test2.c int main(void) { unsigned __int128 x = 0, y = 0; y = __atomic_load_n(&x, 0); __atomic_store_n(&x, y, 0); __atomic_compare_exchange_n(&x, &y, x, 0, 0, 0); return 0; } root:22:37 /tmp $clang-3.8 test2.c /tmp/test2-d3255f.o: In function `main': test2.c:(.text+0x51): undefined reference to `__sync_val_compare_and_swap_16' test2.c:(.text+0x75): undefined reference to `__sync_lock_test_and_set_16' test2.c:(.text+0xcd): undefined reference to `__sync_val_compare_and_swap_16' clang: error: linker command failed with exit code 1 (use -v to see invocation) root:22:37 /tmp $clang-3.8 test2.c -latomic /usr/bin/ld: cannot find -latomic clang: error: linker command failed with exit code 1 (use -v to see invocation) root:22:38 /tmp $clang-3.8 test2.c -mcx16 root:22:38 /tmp $