Index: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
index c56d76c97d354f0886ad106f0ebdeb5b0d7b0544..e4290267998e16f2cdd0d215ffea22617b94030b 100644 |
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
@@ -30,6 +30,9 @@ import org.chromium.base.TraceEvent; |
public class LibraryLoader { |
private static final String TAG = "LibraryLoader"; |
+ // Set to true to enable debug logs. |
+ private static final boolean DEBUG = false; |
+ |
// Guards all access to the libraries |
private static final Object sLock = new Object(); |
@@ -54,6 +57,10 @@ public class LibraryLoader { |
// directly. |
private static boolean sLibraryWasLoadedFromApk = false; |
+ // One-way switch becomes false if the Chromium library should be loaded |
+ // directly from the APK file but it was not aligned. |
+ private static boolean sLibraryWasAlignedInApk = true; |
+ |
// One-way switch becomes true if the system library loading failed, |
// and the right native library was found and loaded by the hack. |
// The flag is used to report UMA stats later. |
@@ -165,9 +172,19 @@ public class LibraryLoader { |
Linker.prepareLibraryLoad(); |
for (String library : NativeLibraries.LIBRARIES) { |
+ // Don't self-load the linker. This is because the build system is |
+ // not clever enough to understand that all the libraries packaged |
+ // in the final .apk don't need to be explicitly loaded. |
+ if (Linker.isChromiumLinkerLibrary(library)) { |
+ if (DEBUG) Log.i(TAG, "ignoring self-linker load"); |
+ continue; |
+ } |
+ |
String zipfile = null; |
if (Linker.isInZipFile()) { |
zipfile = context.getApplicationInfo().sourceDir; |
+ sLibraryWasAlignedInApk = Linker.checkLibraryAlignedInApk( |
+ zipfile, System.mapLibraryName(library)); |
Log.i(TAG, "Loading " + library + " from within " + zipfile); |
} else { |
Log.i(TAG, "Loading: " + library); |
@@ -185,8 +202,8 @@ public class LibraryLoader { |
} |
isLoaded = true; |
} catch (UnsatisfiedLinkError e) { |
- Log.w(TAG, "Failed to load native library with shared RELRO, " + |
- "retrying without"); |
+ Log.w(TAG, "Failed to load native library with shared RELRO, " |
+ + "retrying without"); |
Linker.disableSharedRelros(); |
sLoadAtFixedAddressFailed = true; |
} |
@@ -209,7 +226,7 @@ public class LibraryLoader { |
System.loadLibrary(library); |
} catch (UnsatisfiedLinkError e) { |
if (context != null |
- && LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context, |
+ && LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context, |
library)) { |
sNativeLibraryHackWasUsed = true; |
} else { |
@@ -220,10 +237,10 @@ public class LibraryLoader { |
} |
if (context != null |
- && shouldDeleteOldWorkaroundLibraries |
- && !sNativeLibraryHackWasUsed) { |
+ && shouldDeleteOldWorkaroundLibraries |
+ && !sNativeLibraryHackWasUsed) { |
LibraryLoaderHelper.deleteWorkaroundLibrariesAsynchronously( |
- context); |
+ context); |
} |
long stopTime = SystemClock.uptimeMillis(); |
@@ -239,8 +256,8 @@ public class LibraryLoader { |
} |
// Check that the version of the library we have loaded matches the version we expect |
Log.i(TAG, String.format( |
- "Expected native library version number \"%s\"," + |
- "actual native library version number \"%s\"", |
+ "Expected native library version number \"%s\"," |
+ + "actual native library version number \"%s\"", |
NativeLibraries.sVersionNumber, |
nativeGetVersionNumber())); |
if (!NativeLibraries.sVersionNumber.equals(nativeGetVersionNumber())) { |
@@ -326,14 +343,18 @@ public class LibraryLoader { |
return LibraryLoadFromApkStatusCodes.SUCCESSFUL; |
} |
+ if (!sLibraryWasAlignedInApk) { |
+ return LibraryLoadFromApkStatusCodes.NOT_ALIGNED; |
+ } |
+ |
if (context == null) { |
Log.w(TAG, "Unknown APK filename due to null context"); |
return LibraryLoadFromApkStatusCodes.UNKNOWN; |
} |
- return Linker.checkLibraryLoadFromApkSupport(context.getApplicationInfo().sourceDir) ? |
- LibraryLoadFromApkStatusCodes.SUPPORTED : |
- LibraryLoadFromApkStatusCodes.NOT_SUPPORTED; |
+ return Linker.checkLibraryLoadFromApkSupport(context.getApplicationInfo().sourceDir) |
+ ? LibraryLoadFromApkStatusCodes.SUPPORTED |
+ : LibraryLoadFromApkStatusCodes.NOT_SUPPORTED; |
} |
// Register pending Chromium linker histogram state for renderer processes. This cannot be |