Refactor libprofile-extras to be added as a whole static library
Bug: http://b/134177005 Bug: http://b/116873221 Previously, the libprofile-extras dependency was added as a LateStaticLib and the constructor in this library was included during linking with the '-uinit_profile_extras' linker flag. This was done because at the deps() stage, the exact binaries that need coverage are not known (in fact the coverage-enabled variants are not created yet). This meant that for a link command, if one of the shared libraries already exported the constructor, the output of the link command did not load/link libprofile-extras. For other reasons, we now want to add more symbols to this library that need to be linked into all libraries and executables. To accomplish that, refactor the dependency handling so libprofile-extras can be added as a 'WholeStaticLib'. This is done by creating a new dependency type (with a coverageDepTag dependency tag) to add libprofile-extras as a dependency for all modules that can potentially link with coverage. During the flags() call, this dependency is moved as a WholeStaticLib dependency iff coverage is enabled in this link step. There are a few NFC changes as well: - deps() takes a DepsContext parameter. - flags() has an extra PathDeps parameter and return value. - add useSdk() helper to cc.Module. Test: Build with coverage and check that we can generate coverage using SIGUSR1 and the debug.coverage.flush sysprop. Change-Id: I7e7d8201956a150febbda5bb1794f8ece016db8b
This commit is contained in:
parent
9d42425f25
commit
82fe59b656
3
cc/cc.go
3
cc/cc.go
|
@ -368,6 +368,7 @@ var (
|
||||||
ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
|
ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
|
||||||
vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
|
vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
|
||||||
runtimeDepTag = dependencyTag{name: "runtime lib"}
|
runtimeDepTag = dependencyTag{name: "runtime lib"}
|
||||||
|
coverageDepTag = dependencyTag{name: "coverage"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Module contains the properties and members used by all C/C++ module types, and implements
|
// Module contains the properties and members used by all C/C++ module types, and implements
|
||||||
|
@ -974,7 +975,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||||
flags = c.sanitize.flags(ctx, flags)
|
flags = c.sanitize.flags(ctx, flags)
|
||||||
}
|
}
|
||||||
if c.coverage != nil {
|
if c.coverage != nil {
|
||||||
flags = c.coverage.flags(ctx, flags)
|
flags, deps = c.coverage.flags(ctx, flags, deps)
|
||||||
}
|
}
|
||||||
if c.lto != nil {
|
if c.lto != nil {
|
||||||
flags = c.lto.flags(ctx, flags)
|
flags = c.lto.flags(ctx, flags)
|
||||||
|
|
|
@ -17,6 +17,8 @@ package cc
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,30 +43,28 @@ func (cov *coverage) props() []interface{} {
|
||||||
return []interface{}{&cov.Properties}
|
return []interface{}{&cov.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov *coverage) deps(ctx BaseModuleContext, deps Deps) Deps {
|
func getProfileLibraryName(ctx ModuleContextIntf) string {
|
||||||
if cov.Properties.NeedCoverageBuild {
|
// This function should only ever be called for a cc.Module, so the
|
||||||
// Link libprofile-extras/libprofile-extras_ndk when coverage
|
// following statement should always succeed.
|
||||||
// variant is required. This is a no-op unless coverage is
|
if ctx.useSdk() {
|
||||||
// actually enabled during linking, when
|
return "libprofile-extras_ndk"
|
||||||
// '-uinit_profile_extras' is added (in flags()) to force the
|
} else {
|
||||||
// setup code in libprofile-extras be linked into the
|
return "libprofile-extras"
|
||||||
// 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
|
func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
|
||||||
// yet).
|
if cov.Properties.NeedCoverageVariant {
|
||||||
if !ctx.useSdk() {
|
ctx.AddVariationDependencies([]blueprint.Variation{
|
||||||
deps.LateStaticLibs = append(deps.LateStaticLibs, "libprofile-extras")
|
{Mutator: "link", Variation: "static"},
|
||||||
} else {
|
}, coverageDepTag, getProfileLibraryName(ctx))
|
||||||
deps.LateStaticLibs = append(deps.LateStaticLibs, "libprofile-extras_ndk")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
|
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
|
||||||
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
if !ctx.DeviceConfig().NativeCoverageEnabled() {
|
||||||
return flags
|
return flags, deps
|
||||||
}
|
}
|
||||||
|
|
||||||
if cov.Properties.CoverageEnabled {
|
if cov.Properties.CoverageEnabled {
|
||||||
|
@ -114,11 +114,11 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
if cov.linkCoverage {
|
if cov.linkCoverage {
|
||||||
flags.LdFlags = append(flags.LdFlags, "--coverage")
|
flags.LdFlags = append(flags.LdFlags, "--coverage")
|
||||||
|
|
||||||
// Force linking of constructor/setup code in libprofile-extras
|
coverage := ctx.GetDirectDepWithTag(getProfileLibraryName(ctx), coverageDepTag).(*Module)
|
||||||
flags.LdFlags = append(flags.LdFlags, "-uinit_profile_extras")
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags
|
return flags, deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov *coverage) begin(ctx BaseModuleContext) {
|
func (cov *coverage) begin(ctx BaseModuleContext) {
|
||||||
|
|
Loading…
Reference in New Issue