Merge "Enable memory-mapped coverage instrumentation" am: 6609484961 am: 74eb07ae42 am: b80d71f553 am: 351126907c

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1729633

Change-Id: I988a26c1b70ec893a3a0a8ed1bb6bcbe7ed23b75
This commit is contained in:
Pirama Arumuga Nainar
2022-01-10 23:51:57 +00:00
committed by Automerger Merge Worker
2 changed files with 17 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import (
"android/soong/android"
)
// Add '%c' to default specifier after we resolve http://b/210012154
const profileInstrFlag = "-fprofile-instr-generate=/data/misc/trace/clang-%p-%m.profraw"
type CoverageProperties struct {
@@ -77,6 +78,11 @@ func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps {
return deps
}
func EnableContinuousCoverage(ctx android.BaseModuleContext) bool {
// http://b/210012154 Disable continuous coverage if we're instrumenting bionic/libc.
return !ctx.DeviceConfig().NativeCoverageEnabledForPath("bionic/libc")
}
func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled()
gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled()
@@ -98,6 +104,9 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
} else if clangCoverage {
flags.Local.CommonFlags = append(flags.Local.CommonFlags, profileInstrFlag,
"-fcoverage-mapping", "-Wno-pass-failed", "-D__ANDROID_CLANG_COVERAGE__")
if EnableContinuousCoverage(ctx) {
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-mllvm", "-runtime-counter-relocation")
}
}
}
@@ -149,6 +158,9 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
} else if clangCoverage {
flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrFlag)
if EnableContinuousCoverage(ctx) {
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm=-runtime-counter-relocation")
}
coverage := ctx.GetDirectDepWithTag(getClangProfileLibraryName(ctx), CoverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())