From d2f37cc575920909e0e5712dbcf97e02f5e522c0 Mon Sep 17 00:00:00 2001 From: "Torne (Richard Coles)" Date: Mon, 1 Apr 2019 15:11:00 -0400 Subject: [PATCH] Allow the WebView native library to have dependencies. The WebView native library has so far only depended on native libraries that were already loaded by the zygote, and has only shipped a single .so file in its APK. Splitting the code into multiple libraries worked, but only the top-level library would have its RELRO section shared, causing a memory regression. To avoid this regression if we do decide to split up the native code in future, load the native library using the new RESERVED_ADDRESS_RECURSIVE flag in the linker, which means that any depended-upon libraries will also be loaded into the reserved address region and will have their RELRO sections saved and reused. Fixes: 128623590 Test: tested manually with modified WebView Change-Id: I19ee3ff971e8dcd1c683f94af304abf918860a10 --- native/webview/loader/loader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/native/webview/loader/loader.cpp b/native/webview/loader/loader.cpp index 7f71f6312f00d..1265763d47d3e 100644 --- a/native/webview/loader/loader.cpp +++ b/native/webview/loader/loader.cpp @@ -93,7 +93,8 @@ jboolean DoCreateRelroFile(JNIEnv* env, const char* lib, const char* relro, } android_dlextinfo extinfo; extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS | ANDROID_DLEXT_WRITE_RELRO | - ANDROID_DLEXT_USE_NAMESPACE; + ANDROID_DLEXT_USE_NAMESPACE | + ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE; extinfo.reserved_addr = gReservedAddress; extinfo.reserved_size = gReservedSize; extinfo.relro_fd = tmp_fd; @@ -131,7 +132,8 @@ jint DoLoadWithRelroFile(JNIEnv* env, const char* lib, const char* relro, } android_dlextinfo extinfo; extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS | ANDROID_DLEXT_USE_RELRO | - ANDROID_DLEXT_USE_NAMESPACE; + ANDROID_DLEXT_USE_NAMESPACE | + ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE; extinfo.reserved_addr = gReservedAddress; extinfo.reserved_size = gReservedSize; extinfo.relro_fd = relro_fd;