Merge changes from topic "apex_libc_malloc"
* changes: Don't load libc_malloc_* libs from runtime ns for libc_scudo Load libc_malloc_* libraries from the runtime APEX
This commit is contained in:
commit
c345d87aab
3 changed files with 40 additions and 1 deletions
|
@ -1578,6 +1578,9 @@ cc_library {
|
|||
"ld-android",
|
||||
"libdl",
|
||||
],
|
||||
static_libs: [
|
||||
"libdl_android",
|
||||
],
|
||||
whole_static_libs: [
|
||||
"libjemalloc5",
|
||||
],
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <android/dlext.h>
|
||||
|
||||
#include <private/bionic_config.h>
|
||||
#include <private/bionic_defs.h>
|
||||
#include <private/bionic_malloc_dispatch.h>
|
||||
|
@ -277,8 +279,41 @@ bool InitSharedLibrary(void* impl_handle, const char* shared_lib, const char* pr
|
|||
return true;
|
||||
}
|
||||
|
||||
// Note about USE_SCUDO. This file is compiled into libc.so and libc_scudo.so.
|
||||
// When compiled into libc_scudo.so, the libc_malloc_* libraries don't need
|
||||
// to be loaded from the runtime namespace since libc_scudo.so is not from
|
||||
// the runtime APEX, but is copied to any APEX that needs it.
|
||||
#ifndef USE_SCUDO
|
||||
extern "C" struct android_namespace_t* android_get_exported_namespace(const char* name);
|
||||
#endif
|
||||
|
||||
void* LoadSharedLibrary(const char* shared_lib, const char* prefix, MallocDispatch* dispatch_table) {
|
||||
void* impl_handle = dlopen(shared_lib, RTLD_NOW | RTLD_LOCAL);
|
||||
void* impl_handle = nullptr;
|
||||
#ifndef USE_SCUDO
|
||||
// Try to load the libc_malloc_* libs from the "runtime" namespace and then
|
||||
// fall back to dlopen() to load them from the default namespace.
|
||||
//
|
||||
// The libraries are packaged in the runtime APEX together with libc.so.
|
||||
// However, since the libc.so is searched via the symlink in the system
|
||||
// partition (/system/lib/libc.so -> /apex/com.android.runtime/bionic.libc.so)
|
||||
// libc.so is loaded into the default namespace. If we just dlopen() here, the
|
||||
// linker will load the libs found in /system/lib which might be incompatible
|
||||
// with libc.so in the runtime APEX. Use android_dlopen_ext to explicitly load
|
||||
// the ones in the runtime APEX.
|
||||
struct android_namespace_t* runtime_ns = android_get_exported_namespace("runtime");
|
||||
if (runtime_ns != nullptr) {
|
||||
const android_dlextinfo dlextinfo = {
|
||||
.flags = ANDROID_DLEXT_USE_NAMESPACE,
|
||||
.library_namespace = runtime_ns,
|
||||
};
|
||||
impl_handle = android_dlopen_ext(shared_lib, RTLD_NOW | RTLD_LOCAL, &dlextinfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (impl_handle == nullptr) {
|
||||
impl_handle = dlopen(shared_lib, RTLD_NOW | RTLD_LOCAL);
|
||||
}
|
||||
|
||||
if (impl_handle == nullptr) {
|
||||
error_log("%s: Unable to open shared library %s: %s", getprogname(), shared_lib, dlerror());
|
||||
return nullptr;
|
||||
|
|
|
@ -114,6 +114,7 @@ cc_library {
|
|||
name: "libdl_android",
|
||||
|
||||
defaults: ["linux_bionic_supported"],
|
||||
recovery_available: true,
|
||||
|
||||
// NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
|
||||
// libgcc.a are made static to libdl.so. This in turn ensures that libraries that
|
||||
|
|
Loading…
Reference in a new issue