Skip to content

Commit

Permalink
Modules: Always resolve native library paths through ClassLoader
Browse files Browse the repository at this point in the history
Normally, the system linker and Crazy Linker can resolve libraries.
However, if a module is installed via SplitCompat, and hasn't yet been
fully installed, then the module (and libraries) reside at an alternate
location unknown to the linkers.

In order to find these libraries, we need to call on the Java
ClassLoader. This is already being done for production libraries, but
not in the component build case (currently affecting only the Test
Dummy module).

As a result, bundle smoke tests running with "fake install" would fail
with component builds - that scenario is meant to look like the
SplitCompat'ed case.

Bug: 1025316
Change-Id: If2bcf2de85b323e5e14ed70561e3f31d50bf8287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922276
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716475}
  • Loading branch information
Christopher Grant authored and Commit Bot committed Nov 19, 2019
1 parent 91f1096 commit cd6ec21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions base/android/bundle_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const void* ReadRelPtr(const int32_t* relptr) {
return reinterpret_cast<const char*>(relptr) + *relptr;
}

std::string ResolveLibraryPath(const std::string& library_name) {
} // namespace

// static
std::string BundleUtils::ResolveLibraryPath(const std::string& library_name) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> java_path = Java_BundleUtils_getNativeLibraryPath(
env, base::android::ConvertUTF8ToJavaString(env, library_name));
Expand All @@ -58,8 +61,6 @@ std::string ResolveLibraryPath(const std::string& library_name) {
return base::android::ConvertJavaStringToUTF8(env, java_path);
}

} // namespace

// static
bool BundleUtils::IsBundle() {
return Java_BundleUtils_isBundle(base::android::AttachCurrentThread());
Expand Down
5 changes: 5 additions & 0 deletions base/android/bundle_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class BASE_EXPORT BundleUtils {
// Returns true if the current build is a bundle.
static bool IsBundle();

// Helper function asking Java to resolve a library path. This is required for
// resolving a module library made available via SplitCompat, rather than in
// its eventual fully-installed state.
static std::string ResolveLibraryPath(const std::string& library_name);

// dlopen wrapper that works for partitioned native libraries in dynamic
// feature modules. This routine looks up the partition's address space in a
// table of main library symbols, and uses it when loading the feature
Expand Down
4 changes: 2 additions & 2 deletions components/module_installer/android/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void* LoadLibrary(const std::string& library_name,
library_handle =
BundleUtils::DlOpenModuleLibraryPartition(library_name, partition_name);
#elif defined(COMPONENT_BUILD)
const std::string lib_name = "lib" + library_name + ".so";
library_handle = dlopen(lib_name.c_str(), RTLD_LOCAL);
std::string library_path = BundleUtils::ResolveLibraryPath(library_name);
library_handle = dlopen(library_path.c_str(), RTLD_LOCAL);
#else
#error "Unsupported configuration."
#endif // defined(COMPONENT_BUILD)
Expand Down

0 comments on commit cd6ec21

Please sign in to comment.