blob: 5fd6f5da38fc2967c25d6eab4b741b3fc798075a [file] [log] [blame]
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080018 "sync"
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070019
Colin Cross36242852017-06-23 15:06:31 -070020 "android/soong/android"
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080021 "android/soong/cc/config"
22)
23
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080024var (
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080025 lsdumpPaths []string
26 lsdumpPathsLock sync.Mutex
Jayant Chowdharydcd33b62018-02-23 16:43:23 -080027)
28
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080029type SAbiProperties struct {
Yo Chiang2bbadfa2020-12-14 11:42:16 +080030 // Whether ABI dump should be created for this module.
31 // Set by `sabiDepsMutator` if this module is a shared library that needs ABI check, or a static
32 // library that is depended on by an ABI checked library.
33 ShouldCreateSourceAbiDump bool `blueprint:"mutated"`
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080034
35 // Include directories that may contain ABI information exported by a library.
36 // These directories are passed to the header-abi-dumper.
Inseob Kim69378442019-06-03 19:10:47 +090037 ReexportedIncludes []string `blueprint:"mutated"`
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080038}
39
40type sabi struct {
41 Properties SAbiProperties
42}
43
Yo Chiang2bbadfa2020-12-14 11:42:16 +080044func (sabi *sabi) props() []interface{} {
45 return []interface{}{&sabi.Properties}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080046}
47
Yo Chiang2bbadfa2020-12-14 11:42:16 +080048func (sabi *sabi) flags(ctx ModuleContext, flags Flags) Flags {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080049 // Filter out flags which libTooling don't understand.
50 // This is here for legacy reasons and future-proof, in case the version of libTooling and clang
51 // diverge.
52 flags.Local.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CFlags)
53 flags.Global.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CFlags)
54 flags.Local.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CppFlags)
55 flags.Global.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CppFlags)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080056 return flags
57}
58
Yo Chiang2bbadfa2020-12-14 11:42:16 +080059// Returns true if ABI dump should be created for this library, either because library is ABI
60// checked or is depended on by an ABI checked library.
61// Could be called as a nil receiver.
62func (sabi *sabi) shouldCreateSourceAbiDump() bool {
63 return sabi != nil && sabi.Properties.ShouldCreateSourceAbiDump
64}
65
66// Returns a string that represents the class of the ABI dump.
67// Returns an empty string if ABI check is disabled for this library.
68func classifySourceAbiDump(ctx android.BaseModuleContext) string {
69 m := ctx.Module().(*Module)
70 if m.library.headerAbiCheckerExplicitlyDisabled() {
71 return ""
72 }
73 // Return NDK if the library is both NDK and LLNDK.
74 if m.IsNdk(ctx.Config()) {
75 return "NDK"
76 }
Colin Cross127bb8b2020-12-16 16:46:01 -080077 if m.isImplementationForLLNDKPublic() {
Yo Chiang2bbadfa2020-12-14 11:42:16 +080078 return "LLNDK"
79 }
Colin Cross127bb8b2020-12-16 16:46:01 -080080 if m.UseVndk() && m.IsVndk() && !m.IsVndkPrivate() {
Ivan Lozanod7586b62021-04-01 09:49:36 -040081 if m.IsVndkSp() {
Yo Chiang2bbadfa2020-12-14 11:42:16 +080082 if m.IsVndkExt() {
83 return "VNDK-SP-ext"
84 } else {
85 return "VNDK-SP"
86 }
87 } else {
88 if m.IsVndkExt() {
89 return "VNDK-ext"
90 } else {
91 return "VNDK-core"
92 }
93 }
94 }
95 if m.library.headerAbiCheckerEnabled() || m.library.hasStubsVariants() {
96 return "PLATFORM"
97 }
98 return ""
99}
100
101// Called from sabiDepsMutator to check whether ABI dumps should be created for this module.
102// ctx should be wrapping a native library type module.
103func shouldCreateSourceAbiDumpForLibrary(ctx android.BaseModuleContext) bool {
104 if ctx.Fuchsia() {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800105 return false
106 }
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800107
108 // Only generate ABI dump for device modules.
109 if !ctx.Device() {
110 return false
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800111 }
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800112
113 m := ctx.Module().(*Module)
114
115 // Only create ABI dump for native library module types.
116 if m.library == nil {
117 return false
118 }
119
120 // Create ABI dump for static libraries only if they are dependencies of ABI checked libraries.
121 if m.library.static() {
122 return m.sabi.shouldCreateSourceAbiDump()
123 }
124
125 // Module is shared library type.
126
Yo Chiangd737d3f2020-11-30 20:00:42 +0800127 // Don't check uninstallable modules.
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800128 if m.IsHideFromMake() {
Yo Chiangd737d3f2020-11-30 20:00:42 +0800129 return false
130 }
131
132 // Don't check ramdisk or recovery variants. Only check core, vendor or product variants.
133 if m.InRamdisk() || m.InVendorRamdisk() || m.InRecovery() {
134 return false
135 }
136
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800137 // Don't create ABI dump for prebuilts.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400138 if m.Prebuilt() != nil || m.IsSnapshotPrebuilt() {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800139 return false
140 }
141
142 // Coverage builds have extra symbols.
143 if m.isCoverageVariant() {
144 return false
145 }
146
147 // Some sanitizer variants may have different ABI.
148 if m.sanitize != nil && !m.sanitize.isVariantOnProductionDevice() {
149 return false
150 }
151
152 // Don't create ABI dump for stubs.
Colin Cross127bb8b2020-12-16 16:46:01 -0800153 if m.isNDKStubLibrary() || m.IsLlndk() || m.IsStubs() {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800154 return false
155 }
156
Yo Chiangd737d3f2020-11-30 20:00:42 +0800157 isPlatformVariant := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
158 if isPlatformVariant {
159 // Bionic libraries that are installed to the bootstrap directory are not ABI checked.
160 // Only the runtime APEX variants, which are the implementation libraries of bionic NDK stubs,
161 // are checked.
162 if InstallToBootstrap(m.BaseModuleName(), ctx.Config()) {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800163 return false
164 }
Yo Chiangd737d3f2020-11-30 20:00:42 +0800165 } else {
166 // Don't create ABI dump if this library is for APEX but isn't exported.
167 if !m.HasStubsVariants() {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800168 return false
169 }
170 }
171 return classifySourceAbiDump(ctx) != ""
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800172}
173
174// Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps
175// of their dependencies would be generated.
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800176func sabiDepsMutator(mctx android.TopDownMutatorContext) {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800177 // Escape hatch to not check any ABI dump.
178 if mctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
179 return
180 }
181 // Only create ABI dump for native shared libraries and their static library dependencies.
182 if m, ok := mctx.Module().(*Module); ok && m.sabi != nil {
183 if shouldCreateSourceAbiDumpForLibrary(mctx) {
184 // Mark this module so that .sdump / .lsdump for this library can be generated.
185 m.sabi.Properties.ShouldCreateSourceAbiDump = true
186 // Mark all of its static library dependencies.
187 mctx.VisitDirectDeps(func(child android.Module) {
188 depTag := mctx.OtherModuleDependencyTag(child)
Yi-Yo Chiang21d1c6d2021-06-07 20:22:35 +0800189 if IsStaticDepTag(depTag) || depTag == reuseObjTag {
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800190 if c, ok := child.(*Module); ok && c.sabi != nil {
191 // Mark this module so that .sdump for this static library can be generated.
192 c.sabi.Properties.ShouldCreateSourceAbiDump = true
193 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800194 }
Yo Chiang2bbadfa2020-12-14 11:42:16 +0800195 })
196 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800197 }
198}
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800199
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800200// Add an entry to the global list of lsdump. The list is exported to a Make variable by
201// `cc.makeVarsProvider`.
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800202func addLsdumpPath(lsdumpPath string) {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800203 lsdumpPathsLock.Lock()
204 defer lsdumpPathsLock.Unlock()
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800205 lsdumpPaths = append(lsdumpPaths, lsdumpPath)
Hsin-Yi Chen53489642019-07-31 17:10:45 +0800206}