I'm working in an Android app in which one shared library (that I build in Android Studio, and let's call it libA.so) dynamically loads another shared library provider by a vendor (let's call it libB.so). I know that I shouldn't use multiple C++ runtime libraries in my app (https://developer.android.com/ndk/guides/cpp-support.html#important_considerations) so we've decided to use c++_shared in both libs.
libB.so (the one provided by a vendor) is compiled and linked when AOSP is built (the vendor insists in building the library this way, can't do much about it). The makefile for libB.so is setting the STL flag to c++_shared with this:
LOCAL_NDK_STL_VARIANT := c++_shared
When I look at the NEEDED tag in the libB.so library, I can see the dependency to libc++.so
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libc++.so] <----
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x000000000000000e (SONAME) Library soname: [libB.so]
When I run readelf -d libc++.so to check the content of AOSP's libc++.so I get this
Dynamic section at offset 0xe4b40 contains 29 entries:
Tag Type Name/Value
0x0000000000000003 (PLTGOT) 0xe6310
0x0000000000000002 (PLTRELSZ) 22128 (bytes)
0x0000000000000017 (JMPREL) 0x39ff8
0x0000000000000014 (PLTREL) RELA
0x0000000000000007 (RELA) 0x2ce58
0x0000000000000008 (RELASZ) 53664 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000006ffffff9 (RELACOUNT) 380
0x0000000000000006 (SYMTAB) 0x238
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000005 (STRTAB) 0xdeb8
0x000000000000000a (STRSZ) 102917 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x270c0
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x000000000000000e (SONAME) Library soname: [libc++.so]
0x000000000000001a (FINI_ARRAY) 0xe08e0
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x0000000000000019 (INIT_ARRAY) 0xe5b38
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW
0x000000006ffffff0 (VERSYM) 0x2bb7c
0x000000006ffffffc (VERDEF) 0x2cddc
0x000000006ffffffd (VERDEFNUM) 1
0x000000006ffffffe (VERNEED) 0x2cdf8
0x000000006fffffff (VERNEEDNUM) 2
0x0000000000000000 (NULL) 0x0
I know the NDK provides also libc++.so, but when I run the same command in the library distributed in the Android NDK, I get an error
readelf: Error: libc++.so: Failed to read file header
And if I'm not mistaken, that's because in the NDK, libc++.so is in fact a linker script.
libA.so (the one that I build with my app and loads libB.so) ends up with a dependency to libc++_shared.so
Dynamic section at offset 0x4bca50 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [liblog.so]
0x0000000000000001 (NEEDED) Shared library: [libc++_shared.so] <---
0x0000000000000001 (NEEDED) Shared library: [libc.so]
0x000000000000000e (SONAME) Library soname: [libA.so]
I don't think I can (or should) bundle both libc++.so and libc++_shared.so in my app.
So, is AOSP's libc++.so the same as NDK's libc++_shared.so?
Someone knows why AOSP adds a dynamic dependency to libc++.so instead of libc++_shared.so even when LOCAL_NDK_STL_VARIANT := c++_shared is used? Should I ask my provider to link against libc++_shared.so instead? Maybe someone has a better recommendation to fix this dependency mismatch.