Question about bionic's linker in Android N

600 views
Skip to first unread message

art...@samsung.com

unread,
Jul 13, 2016, 10:55:39 AM7/13/16
to android-platform, dim...@google.com, randy...@samsung.com
Hello,
I have a third-party 32bit application that uses shared libraries. One of the library depends on the libandroid_runtime.so.
When I run the application on Android N I see that the libandroid_runtime.so loaded into memory twice.
I've investigated this behavior and found these things:
1. The zygote already has the libandroid_runtime.so library loaded into memory. This library is located in the g_default_namespace and has the RTLD_GLOBAL flag but has no the DF_1_GLOBAL flag.
2. When the application forkes from zygote the function init_namespaces is called in the linker.cpp. This function creates the g_anonymous_namespace with the parent g_default_namespace. But the g_anonymous_namespace
has empty soinfo_list because no one library has the DF_1_GLOBAL flag setted (function make_global_group returns empty list).
3. When the application tries to load the library which depends on the libandroid_runtime.so the function create_namespace is called with the parent_namespace equals to nullptr.
In this case the g_anonymous_namespace is used. So the new namespace also has empty soinfo_list.
4. When the linker resolves dependency to the libandroid_runtime.so library during loading the application's library it looks first in the current namespace and fails. After that the linker looks in the g_public_namespace (subset of the g_default_namespace) and also fails. After that linker decides to load the library libandroid_runtime.so again into memory.

I want to prevent second loading of the libandroid_runtime.so into memory. But I don't know how to do it.

Could anyone answer to my questions or advice me how to solve this problem without modifying the application.
1. Is the g_anonymous_namespace should have empty soinfo_list?
2. Is it correct way to add the libandroid_runtime.so and other libraries from the /system/lib*/ to the g_public_namespace (using /system/etc/public.libraries.txt)?

dim...@google.com

unread,
Jul 13, 2016, 2:56:44 PM7/13/16
to android-platform, dim...@google.com, randy...@samsung.com
Duplicating my reply here:

 This blog-post describes changes in N related to the behavior the app developer is observing:

  Bottom line here libandroid_runtime.so is not part of public API and is not supposed to be used by apps.

  I suspect that this is something that could be easily fixed by switching to public API (The app developer probably meant to call to JNI GetJavaVM instead of using private symbol from libandroid_runtime.so).

Answering your questions:

1. anonymous namespace is expected to be empty for most apps.
2. libandroid_runtime.so should not be used by apps. Adding it to /system/etc/public.libraries.txt will lead to CTS failure in N.

Glenn Kasten

unread,
Jul 15, 2016, 12:34:53 PM7/15/16
to android-platform, dim...@google.com, randy...@samsung.com
FYI - for future we have another group android-ndk:

Kaisa

unread,
Jul 15, 2016, 1:11:08 PM7/15/16
to android-platform, dim...@google.com, randy...@samsung.com
Reply all
Reply to author
Forward
0 new messages