Commit 5e961649 authored by Brian Sheedy's avatar Brian Sheedy Committed by Commit Bot

Revert "android: Reintroduce and rework ModernLinker."

This reverts commit ac8fe0e9.

Reason for revert: crbug.com/986879

Original change's description:
> android: Reintroduce and rework ModernLinker.
> 
> This is partially a revert of two commits:
> - 53a10113: "Delete unused file:
>    base/android/linker/android_dlext.h"
> - fdb31883: "Use the LegacyLinker instead of the
>    ModernLinker"
> 
> ModernLinker has been reworked, especially the native side. Notable changes:
> - The library is only loaded once, not twice in the browser process
> - Relocations are always shared between the browser process and the other ones.
> 
> This is enabled only on N+ for Chrome.apk, neither for Monochrome nor for TriChrome.
> 
>              on Q, further commit will trim it as well.
> 
> Binary-Size: Increase due to bringing back ModernLinker. Required to save memory
> Bug: 979638
> Change-Id: Ia76773b58a71854a36ea49ab82daef1af717b606
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1683245
> Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Egor Pasko <pasko@chromium.org>
> Commit-Queue: Benoit L <lizeb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#679535}

TBR=pasko@chromium.org,yfriedman@chromium.org,agrieve@chromium.org,lizeb@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 979638
Change-Id: I431aa2011c4a0c4b23b725099e414a52443778f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715745Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680141}
parent a59cbd48
......@@ -3237,7 +3237,6 @@ if (is_android) {
"android/java/src/org/chromium/base/library_loader/LibraryPrefetcher.java",
"android/java/src/org/chromium/base/library_loader/Linker.java",
"android/java/src/org/chromium/base/library_loader/LoaderErrors.java",
"android/java/src/org/chromium/base/library_loader/ModernLinker.java",
"android/java/src/org/chromium/base/library_loader/NativeLibraryPreloader.java",
"android/java/src/org/chromium/base/library_loader/ProcessInitException.java",
"android/java/src/org/chromium/base/metrics/CachedMetrics.java",
......
......@@ -4,10 +4,12 @@
package org.chromium.base.library_loader;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Parcel;
import android.support.annotation.Nullable;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.JniIgnoreNatives;
......@@ -35,13 +37,51 @@ class LegacyLinker extends Linker {
// Log tag for this class.
private static final String TAG = "LegacyLinker";
// Becomes true after linker initialization.
private boolean mInitialized;
// Set to true if this runs in the browser process. Disabled by initServiceProcess().
private boolean mInBrowserProcess = true;
// Becomes true to indicate this process needs to wait for a shared RELRO in
// finishLibraryLoad().
private boolean mWaitForSharedRelros;
// The map of all RELRO sections either created or used in this process.
private Bundle mSharedRelros;
// Current common random base load address. A value of -1 indicates not yet initialized.
private long mBaseLoadAddress = -1;
// Current fixed-location load address for the next library called by loadLibrary().
// A value of -1 indicates not yet initialized.
private long mCurrentLoadAddress = -1;
// The map of libraries that are currently loaded in this process.
private HashMap<String, LibInfo> mLoadedLibraries;
LegacyLinker() {}
// Used internally to initialize the linker's data. Assumes lock is held.
// Loads JNI, and sets mMemoryDeviceConfig and mBrowserUsesSharedRelro.
@GuardedBy("sLock")
private void ensureInitializedLocked() {
assert Thread.holdsLock(sLock);
if (mInitialized) return;
// On first call, load libchromium_android_linker.so. Cannot be done in the
// constructor because instantiation occurs on the UI thread.
loadLinkerJniLibrary();
mInitialized = true;
}
/**
* Call this method just before loading any native shared libraries in this process.
*/
@Override
void prepareLibraryLoad(@Nullable String apkFilePath) {
public void prepareLibraryLoad(@Nullable String apkFilePath) {
if (DEBUG) Log.i(TAG, "prepareLibraryLoad() called");
synchronized (sLock) {
ensureInitializedLocked();
......@@ -63,7 +103,7 @@ class LegacyLinker extends Linker {
* received, i.e. when another thread calls useSharedRelros().
*/
@Override
void finishLibraryLoad() {
public void finishLibraryLoad() {
if (DEBUG) Log.i(TAG, "finishLibraryLoad() called");
synchronized (sLock) {
......@@ -81,30 +121,31 @@ class LegacyLinker extends Linker {
if (mInBrowserProcess) {
// Create new Bundle containing RELRO section information
// for all loaded libraries. Make it available to getSharedRelros().
mSharedRelrosBundle = createBundleFromLibInfoMap(mLoadedLibraries);
mSharedRelros = createBundleFromLibInfoMap(mLoadedLibraries);
if (DEBUG) {
Log.i(TAG, "Shared RELRO created");
dumpBundle(mSharedRelrosBundle);
dumpBundle(mSharedRelros);
}
useSharedRelrosLocked(mSharedRelrosBundle);
useSharedRelrosLocked(mSharedRelros);
}
if (mWaitForSharedRelros) {
assert !mInBrowserProcess;
// Wait until the shared relro bundle is received from useSharedRelros().
while (mSharedRelrosBundle == null) {
while (mSharedRelros == null) {
try {
sLock.wait();
} catch (InterruptedException ie) {
// Continue waiting even if we were just interrupted.
// Restore the thread's interrupt status.
Thread.currentThread().interrupt();
}
}
useSharedRelrosLocked(mSharedRelrosBundle);
useSharedRelrosLocked(mSharedRelros);
// Clear the Bundle to ensure its file descriptor references can't be reused.
mSharedRelrosBundle.clear();
mSharedRelrosBundle = null;
mSharedRelros.clear();
mSharedRelros = null;
}
}
......@@ -144,7 +185,7 @@ class LegacyLinker extends Linker {
synchronized (sLock) {
// Note that in certain cases, this can be called before
// initServiceProcess() in service processes.
mSharedRelrosBundle = clonedBundle;
mSharedRelros = clonedBundle;
// Tell any listener blocked in finishLibraryLoad() about it.
sLock.notifyAll();
}
......@@ -167,8 +208,44 @@ class LegacyLinker extends Linker {
}
// Return the Bundle created in finishLibraryLoad().
if (DEBUG) Log.i(TAG, "... returning %s", mSharedRelrosBundle);
return mSharedRelrosBundle;
if (DEBUG) Log.i(TAG, "... returning %s", mSharedRelros);
return mSharedRelros;
}
}
/**
* Call this method before loading any libraries to indicate that this
* process shall neither create or reuse shared RELRO sections.
*/
@Override
public void disableSharedRelros() {
if (DEBUG) Log.i(TAG, "disableSharedRelros() called");
synchronized (sLock) {
ensureInitializedLocked();
mInBrowserProcess = false;
mWaitForSharedRelros = false;
}
}
/**
* Call this method before loading any libraries to indicate that this
* process is ready to reuse shared RELRO sections from another one.
* Typically used when starting service processes.
*
* @param baseLoadAddress the base library load address to use.
*/
@Override
public void initServiceProcess(long baseLoadAddress) {
if (DEBUG) {
Log.i(TAG,
String.format(Locale.US, "initServiceProcess(0x%x) called", baseLoadAddress));
}
synchronized (sLock) {
ensureInitializedLocked();
mInBrowserProcess = false;
mWaitForSharedRelros = true;
mBaseLoadAddress = baseLoadAddress;
mCurrentLoadAddress = baseLoadAddress;
}
}
......@@ -190,12 +267,30 @@ class LegacyLinker extends Linker {
}
setupBaseLoadAddressLocked();
if (DEBUG) Log.i(TAG, "getBaseLoadAddress() returns 0x%x", mBaseLoadAddress);
if (DEBUG) {
Log.i(TAG,
String.format(
Locale.US, "getBaseLoadAddress() returns 0x%x", mBaseLoadAddress));
}
return mBaseLoadAddress;
}
}
// Used internally to lazily setup the common random base load address.
@GuardedBy("sLock")
private void setupBaseLoadAddressLocked() {
if (mBaseLoadAddress == -1) {
mBaseLoadAddress = getRandomBaseLoadAddress();
mCurrentLoadAddress = mBaseLoadAddress;
if (mBaseLoadAddress == 0) {
// If the random address is 0 there are issues with finding enough
// free address space, so disable RELRO shared / fixed load addresses.
Log.w(TAG, "Disabling shared RELROs due address space pressure");
mWaitForSharedRelros = false;
}
}
}
// Used for debugging only.
private void dumpBundle(Bundle bundle) {
if (DEBUG) Log.i(TAG, "Bundle has " + bundle.size() + " items: " + bundle);
......@@ -244,6 +339,27 @@ class LegacyLinker extends Linker {
if (DEBUG) Log.i(TAG, "Linker.useSharedRelrosLocked() exiting");
}
/**
* Load the Linker JNI library. Throws UnsatisfiedLinkError on error.
*/
@SuppressLint({"UnsafeDynamicallyLoadedCode"})
protected static void loadLinkerJniLibrary() {
LibraryLoader.setEnvForNative();
if (DEBUG) {
String libName = "lib" + LINKER_JNI_LIBRARY + ".so";
Log.i(TAG, "Loading %s", libName);
}
try {
System.loadLibrary(LINKER_JNI_LIBRARY);
} catch (UnsatisfiedLinkError e) {
if (LibraryLoader.PLATFORM_REQUIRES_NATIVE_FALLBACK_EXTRACTION) {
System.load(LibraryLoader.getExtractedLibraryPath(
ContextUtils.getApplicationContext().getApplicationInfo(),
LINKER_JNI_LIBRARY));
}
}
}
/**
* Implements loading a native shared library with the Chromium linker.
*
......
......@@ -117,6 +117,31 @@ public class LibraryLoader {
// will be reported via UMA. Set once when the libraries are done loading.
private long mLibraryLoadTimeMs;
/**
* Call this method to determine if this chromium project must
* use this linker. If not, System.loadLibrary() should be used to load
* libraries instead.
*/
public static boolean useCrazyLinker() {
// A non-monochrome APK (such as ChromePublic.apk) can be installed on N+ in these
// circumstances:
// * installing APK manually
// * after OTA from M to N
// * side-installing Chrome (possibly from another release channel)
// * Play Store bugs leading to incorrect APK flavor being installed
// * installing other Chromium-based browsers
//
// For Chrome builds regularly shipped to users on N+, the system linker (or the Android
// Framework) provides the necessary functionality to load without crazylinker. The
// crazylinker is risky to auto-enable on newer Android releases, as it may interfere with
// regular library loading. See http://crbug.com/980304 as example.
if (Build.VERSION.SDK_INT >= VERSION_CODES.N) return false;
// The auto-generated NativeLibraries.sUseLinker variable will be true if the
// build has not explicitly disabled Linker features.
return NativeLibraries.sUseLinker;
}
/**
* Call this method to determine if the chromium project must load the library
* directly from a zip file.
......@@ -186,15 +211,16 @@ public class LibraryLoader {
*/
public void preloadNowOverrideApplicationContext(Context appContext) {
synchronized (mLock) {
if (useChromiumLinker()) return;
preloadAlreadyLocked(appContext.getApplicationInfo());
if (!useCrazyLinker()) {
preloadAlreadyLocked(appContext.getApplicationInfo());
}
}
}
private void preloadAlreadyLocked(ApplicationInfo appInfo) {
try (TraceEvent te = TraceEvent.scoped("LibraryLoader.preloadAlreadyLocked")) {
// Preloader uses system linker, we shouldn't preload if Chromium linker is used.
assert !useChromiumLinker();
assert !useCrazyLinker();
if (mLibraryPreloader != null && !mLibraryPreloaderCalled) {
mLibraryPreloader.loadLibrary(appInfo);
mLibraryPreloaderCalled = true;
......@@ -323,7 +349,7 @@ public class LibraryLoader {
long startTime = SystemClock.uptimeMillis();
if (useChromiumLinker() && !inZygote) {
if (useCrazyLinker() && !inZygote) {
// Load libraries using the Chromium linker.
Linker linker = Linker.getInstance();
......@@ -554,7 +580,7 @@ public class LibraryLoader {
// Called after all native initializations are complete.
public void onBrowserNativeInitializationComplete() {
synchronized (mLock) {
if (useChromiumLinker()) {
if (useCrazyLinker()) {
RecordHistogram.recordTimesHistogram(
"ChromiumAndroidLinker.BrowserLoadTime", mLibraryLoadTimeMs);
}
......@@ -567,21 +593,12 @@ public class LibraryLoader {
// RecordChromiumAndroidLinkerRendererHistogram() will record it correctly.
public void registerRendererProcessHistogram() {
synchronized (mLock) {
if (useChromiumLinker()) {
if (useCrazyLinker()) {
nativeRecordRendererLibraryLoadTime(mLibraryLoadTimeMs);
}
}
}
/**
* Call this method to determine if this chromium project must
* use this linker. If not, System.loadLibrary() should be used to load
* libraries instead.
*/
public static boolean useChromiumLinker() {
return NativeLibraries.sUseLinker;
}
/**
* Override the library loader (normally with a mock) for testing.
* @param loader the mock library loader.
......
......@@ -13,8 +13,6 @@ shared_library("chromium_android_linker") {
"legacy_linker_jni.h",
"linker_jni.cc",
"linker_jni.h",
"modern_linker_jni.cc",
"modern_linker_jni.h",
]
# The NDK contains the crazy_linker here:
......
......@@ -67,6 +67,25 @@ class ScopedLibrary {
crazy_library_t* lib_;
};
// We identify the abi tag for which the linker is running. This allows
// us to select the library which matches the abi of the linker.
#if defined(__arm__) && defined(__ARM_ARCH_7A__)
#define CURRENT_ABI "armeabi-v7a"
#elif defined(__arm__)
#define CURRENT_ABI "armeabi"
#elif defined(__i386__)
#define CURRENT_ABI "x86"
#elif defined(__mips__)
#define CURRENT_ABI "mips"
#elif defined(__x86_64__)
#define CURRENT_ABI "x86_64"
#elif defined(__aarch64__)
#define CURRENT_ABI "arm64-v8a"
#else
#error "Unsupported target abi"
#endif
// Add a zip archive file path to the context's current search path
// list. Making it possible to load libraries directly from it.
JNI_GENERATOR_EXPORT bool
......@@ -107,7 +126,7 @@ Java_org_chromium_base_library_1loader_LegacyLinker_nativeLoadLibrary(
jobject lib_info_obj) {
String library_name(env, lib_name_obj);
LOG_INFO("Called for %s, at address 0x%llx", library_name.c_str(),
static_cast<unsigned long long>(load_address));
load_address);
crazy_context_t* context = GetCrazyContext();
if (!IsValidAddress(load_address)) {
......
......@@ -20,7 +20,6 @@
#include <sys/mman.h>
#include "legacy_linker_jni.h"
#include "modern_linker_jni.h"
namespace chromium_android_linker {
......@@ -133,8 +132,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
}
// Initialize linker base and implementations.
if (!LinkerJNIInit(vm, env) || !LegacyLinkerJNIInit(vm, env) ||
!ModernLinkerJNIInit(vm, env)) {
if (!LinkerJNIInit(vm, env) || !LegacyLinkerJNIInit(vm, env)) {
return -1;
}
......
......@@ -43,6 +43,13 @@
#define UNUSED __attribute__((unused))
// See commentary in crazy_linker_elf_loader.cpp for the effect of setting
// this. If changing there, change here also.
//
// For more, see:
// https://crbug.com/504410
#define RESERVE_BREAKPAD_GUARD_REGION 1
#if defined(ARCH_CPU_X86)
// Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on
// x86 - use force_align_arg_pointer to realign the stack at the JNI
......@@ -53,27 +60,18 @@
#define JNI_GENERATOR_EXPORT extern "C" __attribute__((visibility("default")))
#endif
#if defined(__arm__) && defined(__ARM_ARCH_7A__)
#define CURRENT_ABI "armeabi-v7a"
#elif defined(__arm__)
#define CURRENT_ABI "armeabi"
#elif defined(__i386__)
#define CURRENT_ABI "x86"
#elif defined(__mips__)
#define CURRENT_ABI "mips"
#elif defined(__x86_64__)
#define CURRENT_ABI "x86_64"
#elif defined(__aarch64__)
#define CURRENT_ABI "arm64-v8a"
#else
#error "Unsupported target abi"
#endif
namespace chromium_android_linker {
// Larger than the largest library we might attempt to load.
static const size_t kAddressSpaceReservationSize = 192 * 1024 * 1024;
// Size of any Breakpad guard region. 16MB is comfortably larger than the
// ~6MB relocation packing of the current 64-bit libchrome.so, the largest we
// expect to encounter.
#if RESERVE_BREAKPAD_GUARD_REGION
static const size_t kBreakpadGuardRegionBytes = 16 * 1024 * 1024;
#endif
// A simple scoped UTF String class that can be initialized from
// a Java jstring handle. Modeled like std::string, which cannot
// be used here.
......
This diff is collapsed.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_ANDROID_LINKER_MODERN_LINKER_JNI_H_
#define BASE_ANDROID_LINKER_MODERN_LINKER_JNI_H_
#include <jni.h>
namespace chromium_android_linker {
// JNI_OnLoad() initialization hook for the modern linker.
// Sets up JNI and other initializations for native linker code.
// |vm| is the Java VM handle passed to JNI_OnLoad().
// |env| is the current JNI environment handle.
// On success, returns true.
extern bool ModernLinkerJNIInit(JavaVM* vm, JNIEnv* env);
} // namespace chromium_android_linker
#endif // BASE_ANDROID_LINKER_MODERN_LINKER_JNI_H_
......@@ -27,10 +27,6 @@ public class ChromiumLinkerParams {
// registered in the service process.
public final String mTestRunnerClassNameForTesting;
// If mTestRunnerClassNameForTesting is not empty, the Linker implementation
// to force for testing.
public final int mLinkerImplementationForTesting;
private static final String EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS =
"org.chromium.content.common.linker_params.base_load_address";
......@@ -40,25 +36,20 @@ public class ChromiumLinkerParams {
private static final String EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME =
"org.chromium.content.common.linker_params.test_runner_class_name";
private static final String EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION =
"org.chromium.content.common.linker_params.linker_implementation";
public ChromiumLinkerParams(long baseLoadAddress, boolean waitForSharedRelro) {
mBaseLoadAddress = baseLoadAddress;
mWaitForSharedRelro = waitForSharedRelro;
mTestRunnerClassNameForTesting = null;
mLinkerImplementationForTesting = 0;
}
/**
* Use this constructor to create a LinkerParams instance for testing.
*/
public ChromiumLinkerParams(long baseLoadAddress, boolean waitForSharedRelro,
String testRunnerClassName, int linkerImplementation) {
public ChromiumLinkerParams(
long baseLoadAddress, boolean waitForSharedRelro, String testRunnerClassName) {
mBaseLoadAddress = baseLoadAddress;
mWaitForSharedRelro = waitForSharedRelro;
mTestRunnerClassNameForTesting = testRunnerClassName;
mLinkerImplementationForTesting = linkerImplementation;
}
/**
......@@ -71,8 +62,7 @@ public class ChromiumLinkerParams {
public static ChromiumLinkerParams create(Bundle bundle) {
if (!bundle.containsKey(EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS)
|| !bundle.containsKey(EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO)
|| !bundle.containsKey(EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME)
|| !bundle.containsKey(EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION)) {
|| !bundle.containsKey(EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME)) {
return null;
}
return new ChromiumLinkerParams(bundle);
......@@ -83,8 +73,6 @@ public class ChromiumLinkerParams {
mWaitForSharedRelro = bundle.getBoolean(EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO, false);
mTestRunnerClassNameForTesting =
bundle.getString(EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME);
mLinkerImplementationForTesting =
bundle.getInt(EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION, 0);
}
/**
......@@ -97,7 +85,6 @@ public class ChromiumLinkerParams {
bundle.putBoolean(EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO, mWaitForSharedRelro);
bundle.putString(
EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME, mTestRunnerClassNameForTesting);
bundle.putInt(EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION, mLinkerImplementationForTesting);
}
// For debugging traces only.
......@@ -105,8 +92,8 @@ public class ChromiumLinkerParams {
public String toString() {
return String.format(Locale.US,
"LinkerParams(baseLoadAddress:0x%x, waitForSharedRelro:%s, "
+ "testRunnerClassName:%s, linkerImplementation:%d",
+ "testRunnerClassName:%s",
mBaseLoadAddress, Boolean.toString(mWaitForSharedRelro),
mTestRunnerClassNameForTesting, mLinkerImplementationForTesting);
mTestRunnerClassNameForTesting);
}
}
......@@ -81,7 +81,7 @@ public class ContentChildProcessServiceDelegate implements ChildProcessServiceDe
mCpuFeatures = connectionBundle.getLong(ContentChildProcessConstants.EXTRA_CPU_FEATURES);
assert mCpuCount > 0;
if (LibraryLoader.useChromiumLinker() && !LibraryLoader.getInstance().isLoadedByZygote()) {
if (LibraryLoader.useCrazyLinker() && !LibraryLoader.getInstance().isLoadedByZygote()) {
Bundle sharedRelros = connectionBundle.getBundle(Linker.EXTRA_LINKER_SHARED_RELROS);
if (sharedRelros != null) {
getLinker().useSharedRelros(sharedRelros);
......@@ -107,7 +107,7 @@ public class ContentChildProcessServiceDelegate implements ChildProcessServiceDe
Linker linker = null;
boolean requestedSharedRelro = false;
if (LibraryLoader.useChromiumLinker()) {
if (LibraryLoader.useCrazyLinker()) {
assert mLinkerParams != null;
linker = getLinker();
if (mLinkerParams.mWaitForSharedRelro) {
......@@ -187,8 +187,7 @@ public class ContentChildProcessServiceDelegate implements ChildProcessServiceDe
// For testing, set the Linker implementation and the test runner
// class name to match those used by the parent.
assert mLinkerParams != null;
Linker.setupForTesting(mLinkerParams.mLinkerImplementationForTesting,
mLinkerParams.mTestRunnerClassNameForTesting);
Linker.setupForTesting(mLinkerParams.mTestRunnerClassNameForTesting);
}
return Linker.getInstance();
}
......
......@@ -132,7 +132,7 @@ public final class ChildProcessLauncherHelperImpl {
ContentChildProcessConstants.EXTRA_CPU_COUNT, CpuFeatures.getCount());
connectionBundle.putLong(
ContentChildProcessConstants.EXTRA_CPU_FEATURES, CpuFeatures.getMask());
if (LibraryLoader.useChromiumLinker()) {
if (LibraryLoader.useCrazyLinker()) {
connectionBundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS,
Linker.getInstance().getSharedRelros());
}
......@@ -596,7 +596,7 @@ public final class ChildProcessLauncherHelperImpl {
private static void initLinker() {
assert LauncherThread.runningOnLauncherThread();
if (sLinkerInitialized) return;
if (LibraryLoader.useChromiumLinker()) {
if (LibraryLoader.useCrazyLinker()) {
sLinkerLoadAddress = Linker.getInstance().getBaseLoadAddress();
if (sLinkerLoadAddress == 0) {
Log.i(TAG, "Shared RELRO support disabled!");
......@@ -617,8 +617,7 @@ public final class ChildProcessLauncherHelperImpl {
if (Linker.areTestsEnabled()) {
Linker linker = Linker.getInstance();
return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros,
linker.getTestRunnerClassNameForTesting(),
linker.getImplementationForTesting());
linker.getTestRunnerClassNameForTesting());
} else {
return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros);
}
......
......@@ -46,11 +46,6 @@ jboolean RunChecks(bool in_browser_process) {
//
// "/dev/ashmem/RELRO:<libname> (deleted)"
//
// and for the ModernLinker, something like:
//
// "/data/data/org.chromium.chromium_linker_test_apk/
// app_chromium_linker_test/RELRO:<libname> (deleted)"
//
// Where <libname> is the library name and '(deleted)' is actually
// added by the kernel to indicate there is no corresponding file
// on the filesystem.
......@@ -59,7 +54,6 @@ jboolean RunChecks(bool in_browser_process) {
// section, but for the component build, there are several libraries,
// each one with its own RELRO.
static const char kLegacyRelroSectionPattern[] = "/dev/ashmem/RELRO:.*";
static const char kModernRelroSectionPattern[] = "/data/.*/RELRO:.*";
// Parse /proc/self/maps and builds a list of region mappings in this
// process.
......@@ -78,7 +72,6 @@ jboolean RunChecks(bool in_browser_process) {
}
const RE2 legacy_linker_re(kLegacyRelroSectionPattern);
const RE2 modern_linker_re(kModernRelroSectionPattern);
int num_shared_relros = 0;
int num_bad_shared_relros = 0;
......@@ -88,15 +81,8 @@ jboolean RunChecks(bool in_browser_process) {
const std::string path = region.path;
const bool is_legacy_relro = re2::RE2::FullMatch(path, legacy_linker_re);
const bool is_modern_relro = re2::RE2::FullMatch(path, modern_linker_re);
if (is_legacy_relro && is_modern_relro) {
LOG(ERROR) << prefix
<< "FAIL RELRO cannot be both Legacy and Modern (test error)";
return false;
}
if (!is_legacy_relro && !is_modern_relro) {
if (!is_legacy_relro) {
// Ignore any mapping that isn't a shared RELRO.
continue;
}
......@@ -127,16 +113,6 @@ jboolean RunChecks(bool in_browser_process) {
continue;
}
// Shared RELROs implemented by ModernLinker are not in ashmem. ModernLinker
// (via android_dlopen_ext()) maps everything with MAP_PRIVATE rather than
// MAP_SHARED. Remapping such a RELRO section read-write will therefore
// succeed, but it is not a problem. The memory copy-on-writes, and updates
// are not visible to either the mapped file or other processes mapping the
// same file. So... we skip the remap test for ModernLinker.
if (is_modern_relro) {
continue;
}
// Check that trying to remap it read-write fails with EACCES
size_t region_size = region.end - region.start;
int ret = ::mprotect(region_start, region_size, PROT_READ | PROT_WRITE);
......
......@@ -36,8 +36,7 @@ public class ChromiumLinkerTestActivity extends Activity {
super.onCreate(savedInstanceState);
// Setup the TestRunner class name.
Linker.setupForTesting(Linker.LINKER_IMPLEMENTATION_LEGACY,
"org.chromium.chromium_linker_test_apk.LinkerTests");
Linker.setupForTesting("org.chromium.chromium_linker_test_apk.LinkerTests");
// Load the library in the browser process, this will also run the test
// runner in this process.
......
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