Antonio
Antonio

Reputation: 20306

Missing sync_val_compare_and_swap_1

I have a standalone toolchain NDK13b, api19, llvm 3.8 compiler, arm 32 bit, with libcpp (llvm C++ library)

I want to avoid depending on libgcc, so I build compiler-rt. The best version I could find (that which leaves me with the least undefined symbols) comes from https://android.googlesource.com/platform/external/compiler-rt/

In my link line I have:

-nodefaultlibs

to avoid linking to libgcc, and:

-lc++_static -lc++abi -lunwind -latomic -ldl -lm -lc -landroid -landroid_support -lclang_rt.builtins-arm -latomic

to link to all standard libraries.

When I try to link my program, I get the following undefined references:

/usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/src/algorithm.cpp:83: error: undefined reference to '__sync_val_compare_and_swap_1' /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/src/ios.cpp:74: error: undefined reference to '__sync_val_compare_and_swap_1' /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/src/locale.cpp:53: error: undefined reference to '__sync_val_compare_and_swap_1' /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/src/locale.cpp:464: error: undefined reference to '__sync_val_compare_and_swap_1'

Is there any way to circumvent this, for example by defining myself the function, or by linking an extra library?

When I tried to use the code from here (which is actually for sync_val_compare_and_swap without _1), I got:

../lib/builtins/sync_val_compare_and_swap_1.c ../lib/builtins/sync_val_compare_and_swap_1.c:6:16: error: conflicting types for '__sync_val_compare_and_swap_1' inline int32_t __sync_val_compare_and_swap_1(volatile int32_t* ptr, int32_t oldval, int32_t newval)

          ^

../lib/builtins/sync_val_compare_and_swap_1.c:6:16: note: '__sync_val_compare_and_swap_1' is a builtin with type 'char (volatile char *, char, char, ...)'

Upvotes: 1

Views: 746

Answers (1)

Antonio
Antonio

Reputation: 20306

The problem was that I was linking the libraries in

link_directories("${COMPILER_PATH}/../arm-linux-androideabi/lib")

Where effectively the varius libatomic.a, libstdc++.a etc. exist. But the correct version is apparently in the subfolder armv7-a, so it should have been:

link_directories("${COMPILER_PATH}/../arm-linux-androideabi/lib/armv7-a")

Upvotes: 1

Related Questions