From 64a44f231dedcb704ef5069762ac3a3c5bfd49b0 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 18 Jan 2019 14:37:08 +0900 Subject: [PATCH] Make sure that ASAN runtime lib is the first DT_NEEDED one Introduce a new tag earlySharedDepTag which is added in front of the ordinary sharedDep dependencies. Dependency to the ASAN runtime lib is added with the new tag. Bug: 120894259 Bug: 121038155 Test: m; SANITIZE_TARGET=address m Use readelf -d to see if the runtime lib is in the first DT_NEEDED one. Change-Id: I90de6ab95df734a99995532d826564b13fe05316 --- cc/binary.go | 4 +++- cc/cc.go | 12 +++++++++--- cc/library.go | 4 +++- cc/sanitize.go | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cc/binary.go b/cc/binary.go index 9d0cf60be..65e8eb52f 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -363,8 +363,10 @@ func (binary *binaryDecorator) link(ctx ModuleContext, var sharedLibs android.Paths // Ignore shared libs for static executables. if !binary.static() { - sharedLibs = deps.SharedLibs + sharedLibs = deps.EarlySharedLibs + sharedLibs = append(sharedLibs, deps.SharedLibs...) sharedLibs = append(sharedLibs, deps.LateSharedLibs...) + linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...) linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) } diff --git a/cc/cc.go b/cc/cc.go index ee6cd4e5b..baee70a97 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -96,9 +96,9 @@ type Deps struct { type PathDeps struct { // Paths to .so files - SharedLibs, LateSharedLibs android.Paths + SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths // Paths to the dependencies to use for .so files (.so.toc files) - SharedLibsDeps, LateSharedLibsDeps android.Paths + SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths // Paths to .a files StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths @@ -328,6 +328,7 @@ type dependencyTag struct { var ( sharedDepTag = dependencyTag{name: "shared", library: true} sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} + earlySharedDepTag = dependencyTag{name: "early_shared", library: true} lateSharedDepTag = dependencyTag{name: "late shared", library: true} staticDepTag = dependencyTag{name: "static", library: true} staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} @@ -1570,6 +1571,11 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPtr = &depPaths.SharedLibsDeps depFile = ccDep.linker.(libraryInterface).toc() directSharedDeps = append(directSharedDeps, ccDep) + case earlySharedDepTag: + ptr = &depPaths.EarlySharedLibs + depPtr = &depPaths.EarlySharedLibsDeps + depFile = ccDep.linker.(libraryInterface).toc() + directSharedDeps = append(directSharedDeps, ccDep) case lateSharedDepTag, ndkLateStubDepTag: ptr = &depPaths.LateSharedLibs depPtr = &depPaths.LateSharedLibsDeps @@ -1663,7 +1669,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { // Export the shared libs to Make. switch depTag { - case sharedDepTag, sharedExportDepTag, lateSharedDepTag: + case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag: if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok { if dependentLibrary.buildStubs() && android.InAnyApex(depName) { // Add the dependency to the APEX(es) providing the library so that diff --git a/cc/library.go b/cc/library.go index 4adb0815f..09e5b5019 100644 --- a/cc/library.go +++ b/cc/library.go @@ -696,9 +696,11 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, } } - sharedLibs := deps.SharedLibs + sharedLibs := deps.EarlySharedLibs + sharedLibs = append(sharedLibs, deps.SharedLibs...) sharedLibs = append(sharedLibs, deps.LateSharedLibs...) + linkerDeps = append(linkerDeps, deps.EarlySharedLibsDeps...) linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) linkerDeps = append(linkerDeps, objs.tidyFiles...) diff --git a/cc/sanitize.go b/cc/sanitize.go index 0951efe6a..90656da89 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -809,7 +809,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { mctx.AddFarVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "shared"}, {Mutator: "arch", Variation: mctx.Target().String()}, - }, sharedDepTag, runtimeLibrary) + }, earlySharedDepTag, runtimeLibrary) } // static lib does not have dependency to the runtime library. The // dependency will be added to the executables or shared libs using