Include libprofile-extras to all coverage variants
Bug: http://b/128524141
Include libprofile-extras (defined in system/extras/toolchain-extras) to
all modules that need a coverage variant. Also add
'-uinit_profile_extras' when linking with coverage. This causes the
setup code in libprofile-extras to be linked into binaries/libraries
with coverage enabled.
We add the static library to the non-coverage variants as well but is a
no-op for them (since the '-u...' flag is not added for them).
Adding this dependency creates several circular dependencies since
coverage variants were being created for other module types that never
had any compilation or linking done during the build. This change stops
creating coverage variants for toolchain_library, cc_prebuilt_library_*,
cc_library_headers module types (by adding a function to the linker
interface to specify whether native coverage is enabled).
Test: m NATIVE_COVERAGE=true COVERAGE_PATHS=*
Test: blueline_coverage target in internal branch (using forrest)
Change-Id: I5db876eb953639a55ba007248dd24e497f987730
diff --git a/cc/binary.go b/cc/binary.go
index 60ef2ce..51e68fc 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -417,6 +417,10 @@
return binary.symlinks
}
+func (binary *binaryDecorator) nativeCoverage() bool {
+ return true
+}
+
// /system/bin/linker -> /apex/com.android.runtime/bin/linker
func (binary *binaryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) {
dir := binary.baseInstaller.installDir(ctx)
diff --git a/cc/cc.go b/cc/cc.go
index a7f1417..f5a1567 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -267,6 +267,7 @@
isStubs() bool
bootstrap() bool
mustUseVendorVariant() bool
+ nativeCoverage() bool
}
type ModuleContext interface {
@@ -312,6 +313,8 @@
link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
appendLdflags([]string)
unstrippedOutputFilePath() android.Path
+
+ nativeCoverage() bool
}
type installer interface {
@@ -604,6 +607,10 @@
return Bool(c.Properties.Bootstrap)
}
+func (c *Module) nativeCoverage() bool {
+ return c.linker != nil && c.linker.nativeCoverage()
+}
+
func isBionic(name string) bool {
switch name {
case "libc", "libm", "libdl", "linker":
@@ -794,6 +801,10 @@
return ctx.mod.bootstrap()
}
+func (ctx *moduleContextImpl) nativeCoverage() bool {
+ return ctx.mod.nativeCoverage()
+}
+
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{
hod: hod,
diff --git a/cc/coverage.go b/cc/coverage.go
index fabcbf4..9dc7f06 100644
--- a/cc/coverage.go
+++ b/cc/coverage.go
@@ -42,6 +42,23 @@
}
func (cov *coverage) deps(ctx BaseModuleContext, deps Deps) Deps {
+ if cov.Properties.NeedCoverageBuild {
+ // Link libprofile-extras/libprofile-extras_ndk when coverage
+ // variant is required. This is a no-op unless coverage is
+ // actually enabled during linking, when
+ // '-uinit_profile_extras' is added (in flags()) to force the
+ // setup code in libprofile-extras be linked into the
+ // binary/library.
+ //
+ // We cannot narrow it further to only the 'cov' variant since
+ // the mutator hasn't run (and we don't have the 'cov' variant
+ // yet).
+ if !ctx.useSdk() {
+ deps.LateStaticLibs = append(deps.LateStaticLibs, "libprofile-extras")
+ } else {
+ deps.LateStaticLibs = append(deps.LateStaticLibs, "libprofile-extras_ndk")
+ }
+ }
return deps
}
@@ -96,6 +113,9 @@
if cov.linkCoverage {
flags.LdFlags = append(flags.LdFlags, "--coverage")
+
+ // Force linking of constructor/setup code in libprofile-extras
+ flags.LdFlags = append(flags.LdFlags, "-uinit_profile_extras")
}
return flags
@@ -113,10 +133,8 @@
if ctx.Host() {
// TODO(dwillemsen): because of -nodefaultlibs, we must depend on libclang_rt.profile-*.a
// Just turn off for now.
- } else if ctx.isStubs() {
- // Do not enable coverage for platform stub libraries
- } else if ctx.isNDKStubLibrary() {
- // Do not enable coverage for NDK stub libraries
+ } else if !ctx.nativeCoverage() {
+ // Native coverage is not supported for this module type.
} else {
// Check if Native_coverage is set to false. This property defaults to true.
needCoverageVariant = BoolDefault(cov.Properties.Native_coverage, true)
diff --git a/cc/library.go b/cc/library.go
index bb2e1df..cab75ac 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -761,6 +761,13 @@
return library.unstrippedOutputFile
}
+func (library *libraryDecorator) nativeCoverage() bool {
+ if library.header() || library.buildStubs() {
+ return false
+ }
+ return true
+}
+
func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
isLlndk := inList(ctx.baseModuleName(), llndkLibraries) || inList(ctx.baseModuleName(), ndkMigratedLibs)
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index cdd2c48..5a36b7f 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -161,6 +161,10 @@
return stub.libraryDecorator.link(ctx, flags, deps, objs)
}
+func (stub *llndkStubDecorator) nativeCoverage() bool {
+ return false
+}
+
func NewLLndkStubLibrary() *Module {
module, library := NewLibrary(android.DeviceSupported)
library.BuildOnlyShared()
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 3ae4452..7199467 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -338,6 +338,10 @@
return stub.libraryDecorator.link(ctx, flags, deps, objs)
}
+func (stub *stubDecorator) nativeCoverage() bool {
+ return false
+}
+
func (stub *stubDecorator) install(ctx ModuleContext, path android.Path) {
arch := ctx.Target().Arch.ArchType.Name
apiLevel := stub.properties.ApiLevel
diff --git a/cc/object.go b/cc/object.go
index c9ca07a..50ecc38 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -114,3 +114,7 @@
func (object *objectLinker) unstrippedOutputFilePath() android.Path {
return nil
}
+
+func (object *objectLinker) nativeCoverage() bool {
+ return true
+}
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 4c893d4..966ec36 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -108,6 +108,10 @@
return p.libraryDecorator.shared()
}
+func (p *prebuiltLibraryLinker) nativeCoverage() bool {
+ return false
+}
+
func prebuiltSharedLibraryFactory() android.Module {
module, _ := NewPrebuiltSharedLibrary(android.HostAndDeviceSupported)
return module.Init()
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 5811b01..ae08b1c 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -77,3 +77,7 @@
return android.PathForSource(ctx, *library.Properties.Src)
}
+
+func (library *toolchainLibraryDecorator) nativeCoverage() bool {
+ return false
+}