2017-02-08 22:45:53 +01:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
2018-02-24 01:43:23 +01:00
|
|
|
"sync"
|
2017-06-15 23:45:18 +02:00
|
|
|
|
2017-06-24 00:06:31 +02:00
|
|
|
"android/soong/android"
|
2017-02-08 22:45:53 +01:00
|
|
|
"android/soong/cc/config"
|
|
|
|
)
|
|
|
|
|
2018-02-24 01:43:23 +01:00
|
|
|
var (
|
2020-11-19 09:30:49 +01:00
|
|
|
lsdumpPaths []string
|
|
|
|
lsdumpPathsLock sync.Mutex
|
2018-02-24 01:43:23 +01:00
|
|
|
)
|
|
|
|
|
2022-12-26 08:54:36 +01:00
|
|
|
// Properties for ABI compatibility checker in Android.bp.
|
|
|
|
type headerAbiCheckerProperties struct {
|
|
|
|
// Enable ABI checks (even if this is not an LLNDK/VNDK lib)
|
|
|
|
Enabled *bool
|
|
|
|
|
|
|
|
// Path to a symbol file that specifies the symbols to be included in the generated
|
|
|
|
// ABI dump file
|
|
|
|
Symbol_file *string `android:"path"`
|
|
|
|
|
|
|
|
// Symbol versions that should be ignored from the symbol file
|
|
|
|
Exclude_symbol_versions []string
|
|
|
|
|
|
|
|
// Symbol tags that should be ignored from the symbol file
|
|
|
|
Exclude_symbol_tags []string
|
|
|
|
|
|
|
|
// Run checks on all APIs (in addition to the ones referred by
|
|
|
|
// one of exported ELF symbols.)
|
|
|
|
Check_all_apis *bool
|
|
|
|
|
|
|
|
// Extra flags passed to header-abi-diff
|
|
|
|
Diff_flags []string
|
|
|
|
|
|
|
|
// Opt-in reference dump directories
|
|
|
|
Ref_dump_dirs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (props *headerAbiCheckerProperties) enabled() bool {
|
|
|
|
return Bool(props.Enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (props *headerAbiCheckerProperties) explicitlyDisabled() bool {
|
|
|
|
return !BoolDefault(props.Enabled, true)
|
|
|
|
}
|
|
|
|
|
2017-02-08 22:45:53 +01:00
|
|
|
type SAbiProperties struct {
|
2020-12-14 04:42:16 +01:00
|
|
|
// Whether ABI dump should be created for this module.
|
|
|
|
// Set by `sabiDepsMutator` if this module is a shared library that needs ABI check, or a static
|
|
|
|
// library that is depended on by an ABI checked library.
|
|
|
|
ShouldCreateSourceAbiDump bool `blueprint:"mutated"`
|
2020-11-19 09:30:49 +01:00
|
|
|
|
|
|
|
// Include directories that may contain ABI information exported by a library.
|
|
|
|
// These directories are passed to the header-abi-dumper.
|
2019-06-03 12:10:47 +02:00
|
|
|
ReexportedIncludes []string `blueprint:"mutated"`
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type sabi struct {
|
|
|
|
Properties SAbiProperties
|
|
|
|
}
|
|
|
|
|
2020-12-14 04:42:16 +01:00
|
|
|
func (sabi *sabi) props() []interface{} {
|
|
|
|
return []interface{}{&sabi.Properties}
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
|
|
|
|
2020-12-14 04:42:16 +01:00
|
|
|
func (sabi *sabi) flags(ctx ModuleContext, flags Flags) Flags {
|
2020-11-19 09:30:49 +01:00
|
|
|
// Filter out flags which libTooling don't understand.
|
|
|
|
// This is here for legacy reasons and future-proof, in case the version of libTooling and clang
|
|
|
|
// diverge.
|
|
|
|
flags.Local.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CFlags)
|
|
|
|
flags.Global.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CFlags)
|
|
|
|
flags.Local.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CppFlags)
|
|
|
|
flags.Global.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CppFlags)
|
|
|
|
return flags
|
2017-06-15 23:45:18 +02:00
|
|
|
}
|
|
|
|
|
2020-12-14 04:42:16 +01:00
|
|
|
// Returns true if ABI dump should be created for this library, either because library is ABI
|
|
|
|
// checked or is depended on by an ABI checked library.
|
|
|
|
// Could be called as a nil receiver.
|
|
|
|
func (sabi *sabi) shouldCreateSourceAbiDump() bool {
|
|
|
|
return sabi != nil && sabi.Properties.ShouldCreateSourceAbiDump
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a string that represents the class of the ABI dump.
|
|
|
|
// Returns an empty string if ABI check is disabled for this library.
|
|
|
|
func classifySourceAbiDump(ctx android.BaseModuleContext) string {
|
|
|
|
m := ctx.Module().(*Module)
|
2022-12-26 08:54:36 +01:00
|
|
|
headerAbiChecker := m.library.getHeaderAbiCheckerProperties(ctx)
|
|
|
|
if headerAbiChecker.explicitlyDisabled() {
|
2020-12-14 04:42:16 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// Return NDK if the library is both NDK and LLNDK.
|
|
|
|
if m.IsNdk(ctx.Config()) {
|
|
|
|
return "NDK"
|
|
|
|
}
|
2020-12-17 01:46:01 +01:00
|
|
|
if m.isImplementationForLLNDKPublic() {
|
2020-12-14 04:42:16 +01:00
|
|
|
return "LLNDK"
|
|
|
|
}
|
2020-12-17 01:46:01 +01:00
|
|
|
if m.UseVndk() && m.IsVndk() && !m.IsVndkPrivate() {
|
2021-04-01 15:49:36 +02:00
|
|
|
if m.IsVndkSp() {
|
2020-12-14 04:42:16 +01:00
|
|
|
if m.IsVndkExt() {
|
|
|
|
return "VNDK-SP-ext"
|
|
|
|
} else {
|
|
|
|
return "VNDK-SP"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if m.IsVndkExt() {
|
|
|
|
return "VNDK-ext"
|
|
|
|
} else {
|
|
|
|
return "VNDK-core"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-26 08:54:36 +01:00
|
|
|
if m.library.hasStubsVariants() && !m.InProduct() && !m.InVendor() {
|
|
|
|
return "PLATFORM"
|
|
|
|
}
|
|
|
|
if headerAbiChecker.enabled() {
|
|
|
|
if m.InProduct() {
|
|
|
|
return "PRODUCT"
|
|
|
|
}
|
|
|
|
if m.InVendor() {
|
|
|
|
return "VENDOR"
|
|
|
|
}
|
2020-12-14 04:42:16 +01:00
|
|
|
return "PLATFORM"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called from sabiDepsMutator to check whether ABI dumps should be created for this module.
|
|
|
|
// ctx should be wrapping a native library type module.
|
|
|
|
func shouldCreateSourceAbiDumpForLibrary(ctx android.BaseModuleContext) bool {
|
|
|
|
// Only generate ABI dump for device modules.
|
|
|
|
if !ctx.Device() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
m := ctx.Module().(*Module)
|
|
|
|
|
|
|
|
// Only create ABI dump for native library module types.
|
|
|
|
if m.library == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create ABI dump for static libraries only if they are dependencies of ABI checked libraries.
|
|
|
|
if m.library.static() {
|
|
|
|
return m.sabi.shouldCreateSourceAbiDump()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module is shared library type.
|
|
|
|
|
2020-11-30 13:00:42 +01:00
|
|
|
// Don't check uninstallable modules.
|
2020-12-16 19:20:23 +01:00
|
|
|
if m.IsHideFromMake() {
|
2020-11-30 13:00:42 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't check ramdisk or recovery variants. Only check core, vendor or product variants.
|
|
|
|
if m.InRamdisk() || m.InVendorRamdisk() || m.InRecovery() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-12-14 04:42:16 +01:00
|
|
|
// Don't create ABI dump for prebuilts.
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.Prebuilt() != nil || m.IsSnapshotPrebuilt() {
|
2020-12-14 04:42:16 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Coverage builds have extra symbols.
|
|
|
|
if m.isCoverageVariant() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some sanitizer variants may have different ABI.
|
|
|
|
if m.sanitize != nil && !m.sanitize.isVariantOnProductionDevice() {
|
2020-11-19 09:30:49 +01:00
|
|
|
return false
|
|
|
|
}
|
2020-12-14 04:42:16 +01:00
|
|
|
|
|
|
|
// Don't create ABI dump for stubs.
|
2020-12-17 01:46:01 +01:00
|
|
|
if m.isNDKStubLibrary() || m.IsLlndk() || m.IsStubs() {
|
2020-12-14 04:42:16 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-12-14 00:54:49 +01:00
|
|
|
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
|
|
|
|
if apexInfo.IsForPlatform() {
|
2020-11-30 13:00:42 +01:00
|
|
|
// Bionic libraries that are installed to the bootstrap directory are not ABI checked.
|
|
|
|
// Only the runtime APEX variants, which are the implementation libraries of bionic NDK stubs,
|
|
|
|
// are checked.
|
|
|
|
if InstallToBootstrap(m.BaseModuleName(), ctx.Config()) {
|
2020-12-14 04:42:16 +01:00
|
|
|
return false
|
|
|
|
}
|
2020-11-30 13:00:42 +01:00
|
|
|
} else {
|
|
|
|
// Don't create ABI dump if this library is for APEX but isn't exported.
|
|
|
|
if !m.HasStubsVariants() {
|
2020-12-14 04:42:16 +01:00
|
|
|
return false
|
2017-06-15 23:45:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-14 04:42:16 +01:00
|
|
|
return classifySourceAbiDump(ctx) != ""
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 09:30:49 +01:00
|
|
|
// Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps
|
|
|
|
// of their dependencies would be generated.
|
2017-02-08 22:45:53 +01:00
|
|
|
func sabiDepsMutator(mctx android.TopDownMutatorContext) {
|
2020-12-14 04:42:16 +01:00
|
|
|
// Escape hatch to not check any ABI dump.
|
|
|
|
if mctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Only create ABI dump for native shared libraries and their static library dependencies.
|
|
|
|
if m, ok := mctx.Module().(*Module); ok && m.sabi != nil {
|
|
|
|
if shouldCreateSourceAbiDumpForLibrary(mctx) {
|
|
|
|
// Mark this module so that .sdump / .lsdump for this library can be generated.
|
|
|
|
m.sabi.Properties.ShouldCreateSourceAbiDump = true
|
|
|
|
// Mark all of its static library dependencies.
|
|
|
|
mctx.VisitDirectDeps(func(child android.Module) {
|
|
|
|
depTag := mctx.OtherModuleDependencyTag(child)
|
2021-06-07 14:22:35 +02:00
|
|
|
if IsStaticDepTag(depTag) || depTag == reuseObjTag {
|
2020-12-14 04:42:16 +01:00
|
|
|
if c, ok := child.(*Module); ok && c.sabi != nil {
|
|
|
|
// Mark this module so that .sdump for this static library can be generated.
|
|
|
|
c.sabi.Properties.ShouldCreateSourceAbiDump = true
|
|
|
|
}
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
2020-12-14 04:42:16 +01:00
|
|
|
})
|
|
|
|
}
|
2017-02-08 22:45:53 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 11:10:45 +02:00
|
|
|
|
2020-11-19 09:30:49 +01:00
|
|
|
// Add an entry to the global list of lsdump. The list is exported to a Make variable by
|
|
|
|
// `cc.makeVarsProvider`.
|
2019-07-31 11:10:45 +02:00
|
|
|
func addLsdumpPath(lsdumpPath string) {
|
2020-11-19 09:30:49 +01:00
|
|
|
lsdumpPathsLock.Lock()
|
|
|
|
defer lsdumpPathsLock.Unlock()
|
2019-07-31 11:10:45 +02:00
|
|
|
lsdumpPaths = append(lsdumpPaths, lsdumpPath)
|
|
|
|
}
|