Commit f08bcae4 authored by Egor Pasko's avatar Egor Pasko Committed by Chromium LUCI CQ

base/android: replace dlopen() w/System.loadLibrary()

Because it is shorter and seems to work.

Bug: 1154224
Change-Id: I2e69ad5d016ef0e5a050613097645c66111da059
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616158
Commit-Queue: Egor Pasko <pasko@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843737}
parent e6d2f25e
...@@ -40,10 +40,7 @@ class ModernLinker extends Linker { ...@@ -40,10 +40,7 @@ class ModernLinker extends Linker {
long loadAddress = isFixedAddressPermitted ? mBaseLoadAddress : 0; long loadAddress = isFixedAddressPermitted ? mBaseLoadAddress : 0;
if (loadNoRelro) { if (loadNoRelro) {
// Cannot use System.loadLibrary(), as the library name is transformed (adding the "lib" // System.loadLibrary() below implements the fallback.
// prefix and ".so" suffix), making the name incorrect.
boolean ok = nativeLoadLibraryNoRelros(libFilePath);
if (!ok) resetAndThrow("Cannot load without relro sharing");
mState = State.DONE; mState = State.DONE;
} else if (provideRelro) { } else if (provideRelro) {
// Create the shared RELRO, and store it. // Create the shared RELRO, and store it.
...@@ -54,7 +51,7 @@ class ModernLinker extends Linker { ...@@ -54,7 +51,7 @@ class ModernLinker extends Linker {
libInfo.mLoadAddress, libInfo.mLoadSize); libInfo.mLoadAddress, libInfo.mLoadSize);
} else { } else {
Log.e(TAG, "Unable to load with ModernLinker, using the system linker instead"); Log.e(TAG, "Unable to load with ModernLinker, using the system linker instead");
nativeLoadLibraryNoRelros(libFilePath); // System.loadLibrary() below implements the fallback.
libInfo.mRelroFd = -1; libInfo.mRelroFd = -1;
} }
mLibInfo = libInfo; mLibInfo = libInfo;
...@@ -94,8 +91,8 @@ class ModernLinker extends Linker { ...@@ -94,8 +91,8 @@ class ModernLinker extends Linker {
try { try {
System.loadLibrary(library); System.loadLibrary(library);
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
throw new UnsatisfiedLinkError( if (loadNoRelro || provideRelro) resetAndThrow("Cannot load without relro sharing");
"Unable to load the library a second time with the system linker"); resetAndThrow("Unable to load the library a second time with the system linker");
} }
} }
...@@ -125,7 +122,6 @@ class ModernLinker extends Linker { ...@@ -125,7 +122,6 @@ class ModernLinker extends Linker {
throw new UnsatisfiedLinkError(message); throw new UnsatisfiedLinkError(message);
} }
private static native boolean nativeLoadLibraryNoRelros(String dlopenExtPath);
private static native boolean nativeLoadLibrary( private static native boolean nativeLoadLibrary(
String dlopenExtPath, long loadAddress, LibInfo libInfo, boolean spawnRelroRegion); String dlopenExtPath, long loadAddress, LibInfo libInfo, boolean spawnRelroRegion);
private static native boolean nativeUseRelros(LibInfo libInfo); private static native boolean nativeUseRelros(LibInfo libInfo);
......
...@@ -235,19 +235,6 @@ bool CallJniOnLoad(void* handle) { ...@@ -235,19 +235,6 @@ bool CallJniOnLoad(void* handle) {
return true; return true;
} }
bool LoadNoSharedRelocations(const String& path) {
void* handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
LOG_ERROR("dlopen: %s", dlerror());
return false;
}
if (!CallJniOnLoad(handle))
return false;
return true;
}
} // namespace } // namespace
void NativeLibInfo::ExportLoadInfoToJava() const { void NativeLibInfo::ExportLoadInfoToJava() const {
...@@ -634,15 +621,6 @@ Java_org_chromium_base_library_1loader_ModernLinker_nativeUseRelros( ...@@ -634,15 +621,6 @@ Java_org_chromium_base_library_1loader_ModernLinker_nativeUseRelros(
return true; return true;
} }
JNI_GENERATOR_EXPORT jboolean
Java_org_chromium_base_library_1loader_ModernLinker_nativeLoadLibraryNoRelros(
JNIEnv* env,
jclass clazz,
jstring jdlopen_ext_path) {
String library_path(env, jdlopen_ext_path);
return LoadNoSharedRelocations(library_path);
}
JNI_GENERATOR_EXPORT jint JNI_GENERATOR_EXPORT jint
Java_org_chromium_base_library_1loader_ModernLinker_nativeGetRelroSharingResult( Java_org_chromium_base_library_1loader_ModernLinker_nativeGetRelroSharingResult(
JNIEnv* env, JNIEnv* env,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment