hidden symbol “sync_fetch_and_add_4” - is this a issue for android ndk link ?

668 views
Skip to first unread message

MIke Gao

unread,
Jul 16, 2013, 1:08:37 PM7/16/13
to andro...@googlegroups.com

/proj/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__sync_fetch_and_add_4' in /proj/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/libgcc.a(linux-atomic.o) is referenced by DSO

I did some search and it is pretty well known issue with g++ linker. It is said to add -lgcc along with -lgcc_s to fix it because "sync_fetch_and_add_4" doesn't exist in libgcc_s which g++ will use instead of libgcc.

But, there is no libgcc_s lib with android ndk. So it is not the same case but with the same issue.

http://gcc.gnu.org/ml/gcc-help/2010-11/msg00198.html

I did a test with below code:

TYPE K;
int main ()
{
 __sync_fetch_and_add(&K, 1);
 return 0;
}

if TYPE is long long, no complain. If TYPE is int, gives warning similar as above.

In my project, I do use a third part library which use sync_fetch_and_add in its atomic define head file. Will this warning cause problem if not fix it? How to fix it?

Thanks!

David Turner

unread,
Jul 16, 2013, 1:21:09 PM7/16/13
to andro...@googlegroups.com
It seems you're using a custom link command, just add -lgcc _after_ object files and libraries, and _before_ dependent shared libraries. That will statically link the __sync_fetch_and_add_4() implementation code into your shared library, and you won't get a warning.

This issue doesn't exist if you use ndk-build or a standalone toolchain.



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

MIke Gao

unread,
Jul 16, 2013, 3:07:42 PM7/16/13
to andro...@googlegroups.com
But this result is from what I used ndk-build and it has -lgcc.

Executable     : my_test
/proj/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=/proj/android/android-ndk-r8e/platforms/android-9/arch-arm ./obj/local/armeabi/objs/my_test/my_test.o -lgcc ./obj/local/armeabi/libgnustl_shared.so -no-canonical-prefixes  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  -L/proj/android/android-ndk-r8e/platforms/android-9/arch-arm/usr/lib -lstdc++ -Ljni/../../../thirdpart/build/lib -lthirdpart_1 -lthirdpart_2 -lthirdpart_3 -Ljni/../../../liblocalbuild/build/lib -llocalbuild -Ljni/../../../utils/openssl-android/libs/armeabi -lcrypto -lssl -L/proj/android/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi -lgnustl_shared /proj/android/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/libsupc++.a -lc -lm -o ./obj/local/armeabi/my_test
/proj/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__sync_fetch_and_add_4' in /proj/android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/libgcc.a(linux-atomic.o) is referenced by DSO jni/../../../liblocalbuild/build/lib/mybuild.so

David Turner

unread,
Jul 16, 2013, 4:22:41 PM7/16/13
to andro...@googlegroups.com
That's really weird, and I can't reproduce this locally. Can you file a bug on b.android.com and attach a sample project file that reproduces it for you? I'll take a look.

Thanks in advance,


--

MIke Gao

unread,
Jul 16, 2013, 9:51:41 PM7/16/13
to andro...@googlegroups.com
I found this is caused by the shared library which is reported as reference "__sync_fetch_and_add_4". When I built simple test file, I didn't change Android.mk and kept LOCAL_LDLIBS as before. So if I remove this shared library (mybuild.so showing above), everything is fine even though I reference "__sync_fetch_and_add" directly. I don't know what difference with "-4" suffix.
This shared library doesn't use this function directly, it depend boost library which use it as atomic incline. For some reason, they are conflict.


--
You received this message because you are subscribed to a topic in the Google Groups "android-ndk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-ndk/7J8JUIXT_WQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-ndk...@googlegroups.com.

David Turner

unread,
Jul 30, 2013, 9:15:14 AM7/30/13
to andro...@googlegroups.com
On Tue, Jul 16, 2013 at 6:51 PM, MIke Gao <ygao.de...@gmail.com> wrote:
I found this is caused by the shared library which is reported as reference "__sync_fetch_and_add_4". When I built simple test file, I didn't change Android.mk and kept LOCAL_LDLIBS as before. So if I remove this shared library (mybuild.so showing above), everything is fine even though I reference "__sync_fetch_and_add" directly. I don't know what difference with "-4" suffix.
This shared library doesn't use this function directly, it depend boost library which use it as atomic incline. For some reason, they are conflict.

In a nutshell, your shared library was not built properly.

In a bit more details, __sync_fetch_and_add is a bit magic in GCC, the corresponding generated machine code will actually call __sync_fetch_and_add_<N>, where <N> is a size depending on the size of the parameters (e.g. 4 for 32-bit values). This function is located in libgcc.a which must be linked into any shared library / executable that needs it.

Order is important when using Unix linkers. -lgcc was probably not provided at the right location when creating your shared library, as such, it contained a symbol import relocation that could not be resolved when you were trying to load it (libgcc.a is a static library, there is no corresponding system shared library on Android, unlike regular Linux distributions which come with /lib/libgcc_s.so. This difference is due to various historical binary compatibility issues).
Reply all
Reply to author
Forward
0 new messages