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
diff --git a/cc/cc.go b/cc/cc.go
index ee6cd4e..baee70a 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -96,9 +96,9 @@
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 @@
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 @@
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 @@
// 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