From 388ef3f5aacd8023102a076e81be14bc1a62a294 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 28 Jan 2019 19:47:32 +0900 Subject: [PATCH] Create sanitizer variants of APEX only when SANITIZE_TARGET is set This fixes a problem that APEX is unconditionally mutated for all sanitizer types. This can make an APEX to include sanitized version of a lib even when SANITIZE_TARGET is not set. It can happen when lib X is directly depended on by an APEX (e.g. via native_shared_libs) and X has a sanitized variant due to the dependency from another library Y which is force sanitized (via 'sanitize' property). In that case, regardless of lib Y is in the APEX or not, the APEX chooses the sanitized variant of lib X since the dependency from APEX to the lib is created with AddFarVariationDependency. Fixing this problem by mutating the APEX for a sanitizer type only when the device is requested to be sanitized. Bug: 122717287 Test: add libnetd_client to com.android.runtime APEX. Inspect build.ninja to verify that libnetd_client.so in the runtime APEX is not a sanitized one. Change-Id: I918bc8407137d74c5456142b3a29de13df68c0b3 --- apex/apex.go | 14 +++++++++++--- cc/sanitize.go | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 46c9dcf09..321e2e890 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -483,9 +483,17 @@ func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { } } -func (a *apexBundle) IsSanitizerEnabled() bool { - // APEX can be mutated for sanitizers - return true +func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool { + globalSanitizerNames := []string{} + if a.Host() { + globalSanitizerNames = ctx.Config().SanitizeHost() + } else { + arches := ctx.Config().SanitizeDeviceArch() + if len(arches) == 0 || android.InList(a.Arch().ArchType.Name, arches) { + globalSanitizerNames = ctx.Config().SanitizeDevice() + } + } + return android.InList(sanitizerName, globalSanitizerNames) } func getCopyManifestForNativeLibrary(cc *cc.Module) (fileToCopy android.Path, dirInApex string) { diff --git a/cc/sanitize.go b/cc/sanitize.go index 90656da89..b95e2a8d9 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -820,7 +820,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { type Sanitizeable interface { android.Module - IsSanitizerEnabled() bool + IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool } // Create sanitized variants for modules that need them @@ -924,7 +924,7 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { } } c.sanitize.Properties.SanitizeDep = false - } else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok && sanitizeable.IsSanitizerEnabled() { + } else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok && sanitizeable.IsSanitizerEnabled(mctx, t.String()) { // APEX modules fall here mctx.CreateVariations(t.String()) }