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
This commit is contained in:
Jiyong Park 2019-01-18 14:37:08 +09:00
parent de54534d2a
commit 64a44f231d
4 changed files with 16 additions and 6 deletions

View File

@ -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...)
}

View File

@ -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

View File

@ -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...)

View File

@ -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