blob: 1037181db9021e17ad873d374f2b8f1aa8c903f9 [file] [log] [blame]
Colin Cross16b23492016-01-06 14:41:07 -08001// Copyright 2016 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 (
18 "fmt"
Colin Cross8ff9ef42017-05-08 13:44:11 -070019 "io"
Jeff Gaston72765392017-11-28 16:37:53 -080020 "sort"
Colin Cross16b23492016-01-06 14:41:07 -080021 "strings"
Vishwath Mohane7128792017-11-17 11:08:10 -080022 "sync"
Colin Cross16b23492016-01-06 14:41:07 -080023
Colin Cross6b753602018-06-21 13:03:07 -070024 "github.com/google/blueprint"
25
Colin Cross635c3b02016-05-18 15:37:25 -070026 "android/soong/android"
Evgenii Stepanovaf36db12016-08-15 14:18:24 -070027 "android/soong/cc/config"
Colin Cross16b23492016-01-06 14:41:07 -080028)
29
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070030var (
31 // Any C flags added by sanitizer which libTooling tools may not
32 // understand also need to be added to ClangLibToolingUnknownCflags in
33 // cc/config/clang.go
Vishwath Mohanf3918d32017-02-14 07:59:33 -080034
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070035 asanCflags = []string{"-fno-omit-frame-pointer"}
36 asanLdflags = []string{"-Wl,-u,__asan_preinit"}
37 asanLibs = []string{"libasan"}
38
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000039 cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso",
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070040 "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"}
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -070041 cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
Pirama Arumuga Nainarbdb17f02017-08-28 21:50:17 -070042 "-Wl,-plugin-opt,O1"}
Vishwath Mohane7128792017-11-17 11:08:10 -080043 cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
Vishwath Mohane7128792017-11-17 11:08:10 -080044 cfiStaticLibsMutex sync.Mutex
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -070045
Ivan Lozano30c5db22018-02-21 15:49:20 -080046 intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"}
47 minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer", "-fno-sanitize-recover=integer"}
Dan Willemsencbceaab2016-10-13 16:44:07 -070048)
49
Colin Cross16b23492016-01-06 14:41:07 -080050type sanitizerType int
51
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070052func boolPtr(v bool) *bool {
53 if v {
54 return &v
55 } else {
56 return nil
57 }
58}
59
Colin Cross16b23492016-01-06 14:41:07 -080060const (
61 asan sanitizerType = iota + 1
62 tsan
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -070063 intOverflow
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000064 cfi
Colin Cross16b23492016-01-06 14:41:07 -080065)
66
67func (t sanitizerType) String() string {
68 switch t {
69 case asan:
70 return "asan"
71 case tsan:
72 return "tsan"
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -070073 case intOverflow:
74 return "intOverflow"
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000075 case cfi:
76 return "cfi"
Colin Cross16b23492016-01-06 14:41:07 -080077 default:
78 panic(fmt.Errorf("unknown sanitizerType %d", t))
79 }
80}
81
82type SanitizeProperties struct {
83 // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer
84 Sanitize struct {
Nan Zhang0007d812017-11-07 10:57:05 -080085 Never *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -080086
87 // main sanitizers
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070088 Address *bool `android:"arch_variant"`
89 Thread *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -080090
91 // local sanitizers
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -070092 Undefined *bool `android:"arch_variant"`
93 All_undefined *bool `android:"arch_variant"`
94 Misc_undefined []string `android:"arch_variant"`
95 Coverage *bool `android:"arch_variant"`
96 Safestack *bool `android:"arch_variant"`
97 Cfi *bool `android:"arch_variant"`
98 Integer_overflow *bool `android:"arch_variant"`
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -070099 Scudo *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -0800100
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700101 // Sanitizers to run in the diagnostic mode (as opposed to the release mode).
102 // Replaces abort() on error with a human-readable error message.
103 // Address and Thread sanitizers always run in diagnostic mode.
104 Diag struct {
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700105 Undefined *bool `android:"arch_variant"`
106 Cfi *bool `android:"arch_variant"`
107 Integer_overflow *bool `android:"arch_variant"`
108 Misc_undefined []string `android:"arch_variant"`
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700109 }
110
111 // value to pass to -fsanitize-recover=
Colin Cross16b23492016-01-06 14:41:07 -0800112 Recover []string
113
114 // value to pass to -fsanitize-blacklist
115 Blacklist *string
116 } `android:"arch_variant"`
117
Ivan Lozano30c5db22018-02-21 15:49:20 -0800118 SanitizerEnabled bool `blueprint:"mutated"`
119 SanitizeDep bool `blueprint:"mutated"`
120 MinimalRuntimeDep bool `blueprint:"mutated"`
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700121 UbsanRuntimeDep bool `blueprint:"mutated"`
Ivan Lozano30c5db22018-02-21 15:49:20 -0800122 InSanitizerDir bool `blueprint:"mutated"`
Colin Cross16b23492016-01-06 14:41:07 -0800123}
124
125type sanitize struct {
126 Properties SanitizeProperties
Colin Cross8ff9ef42017-05-08 13:44:11 -0700127
Jiyong Park27b188b2017-07-18 13:23:39 +0900128 runtimeLibrary string
129 androidMkRuntimeLibrary string
Colin Cross16b23492016-01-06 14:41:07 -0800130}
131
Vishwath Mohane7128792017-11-17 11:08:10 -0800132func init() {
133 android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider)
134}
135
Colin Cross16b23492016-01-06 14:41:07 -0800136func (sanitize *sanitize) props() []interface{} {
137 return []interface{}{&sanitize.Properties}
138}
139
140func (sanitize *sanitize) begin(ctx BaseModuleContext) {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700141 s := &sanitize.Properties.Sanitize
142
Colin Cross16b23492016-01-06 14:41:07 -0800143 // Don't apply sanitizers to NDK code.
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700144 if ctx.useSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800145 s.Never = BoolPtr(true)
Colin Cross16b23492016-01-06 14:41:07 -0800146 }
147
148 // Never always wins.
Nan Zhang0007d812017-11-07 10:57:05 -0800149 if Bool(s.Never) {
Colin Cross16b23492016-01-06 14:41:07 -0800150 return
151 }
152
Colin Cross16b23492016-01-06 14:41:07 -0800153 var globalSanitizers []string
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700154 var globalSanitizersDiag []string
155
Colin Cross16b23492016-01-06 14:41:07 -0800156 if ctx.clang() {
157 if ctx.Host() {
Pirama Arumuga Nainar83d716c2018-06-26 14:01:40 -0700158 if !ctx.Windows() {
159 globalSanitizers = ctx.Config().SanitizeHost()
160 }
Colin Cross16b23492016-01-06 14:41:07 -0800161 } else {
Colin Cross6510f912017-11-29 00:27:14 -0800162 arches := ctx.Config().SanitizeDeviceArch()
Colin Cross23ae82a2016-11-02 14:34:39 -0700163 if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) {
Colin Cross6510f912017-11-29 00:27:14 -0800164 globalSanitizers = ctx.Config().SanitizeDevice()
165 globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag()
Colin Cross23ae82a2016-11-02 14:34:39 -0700166 }
Colin Cross16b23492016-01-06 14:41:07 -0800167 }
168 }
169
Colin Cross16b23492016-01-06 14:41:07 -0800170 if len(globalSanitizers) > 0 {
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000171 var found bool
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700172 if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
173 s.All_undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000174 }
Colin Cross16b23492016-01-06 14:41:07 -0800175
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700176 if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
177 s.Undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000178 }
179
Evgenii Stepanov774cb812016-12-28 15:52:54 -0800180 if found, globalSanitizers = removeFromList("address", globalSanitizers); found {
181 if s.Address == nil {
182 s.Address = boolPtr(true)
183 } else if *s.Address == false {
184 // Coverage w/o address is an error. If globalSanitizers includes both, and the module
185 // disables address, then disable coverage as well.
186 _, globalSanitizers = removeFromList("coverage", globalSanitizers)
187 }
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000188 }
189
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700190 if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
191 s.Thread = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000192 }
193
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700194 if found, globalSanitizers = removeFromList("coverage", globalSanitizers); found && s.Coverage == nil {
195 s.Coverage = boolPtr(true)
196 }
197
198 if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
199 s.Safestack = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000200 }
201
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700202 if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
Colin Cross6510f912017-11-29 00:27:14 -0800203 if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700204 s.Cfi = boolPtr(true)
205 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700206 }
207
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700208 // Global integer_overflow builds do not support static libraries.
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700209 if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700210 if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() {
Ivan Lozano5f595532017-07-13 14:46:05 -0700211 s.Integer_overflow = boolPtr(true)
212 }
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700213 }
214
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700215 if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil {
216 s.Scudo = boolPtr(true)
217 }
218
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000219 if len(globalSanitizers) > 0 {
220 ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
221 }
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700222
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700223 // Global integer_overflow builds do not support static library diagnostics.
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700224 if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found &&
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700225 s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() {
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700226 s.Diag.Integer_overflow = boolPtr(true)
227 }
228
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700229 if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found &&
230 s.Diag.Cfi == nil && Bool(s.Cfi) {
231 s.Diag.Cfi = boolPtr(true)
232 }
233
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700234 if len(globalSanitizersDiag) > 0 {
235 ctx.ModuleErrorf("unknown global sanitizer diagnostics option %s", globalSanitizersDiag[0])
236 }
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700237 }
Colin Cross3c344ef2016-07-18 15:44:56 -0700238
Vishwath Mohan1c54f662018-05-24 18:36:18 -0700239 // Enable CFI for all components in the include paths (for Aarch64 only)
240 if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 {
Vishwath Mohan3af8ee02018-03-30 02:55:23 +0000241 s.Cfi = boolPtr(true)
242 if inList("cfi", ctx.Config().SanitizeDeviceDiag()) {
243 s.Diag.Cfi = boolPtr(true)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700244 }
245 }
246
Evgenii Stepanova83fdac2017-01-31 18:37:30 -0800247 // CFI needs gold linker, and mips toolchain does not have one.
Colin Cross6510f912017-11-29 00:27:14 -0800248 if !ctx.Config().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 {
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800249 s.Cfi = nil
250 s.Diag.Cfi = nil
251 }
252
Vishwath Mohan6d67e6e2017-02-07 20:31:41 -0800253 // Also disable CFI for arm32 until b/35157333 is fixed.
254 if ctx.Arch().ArchType == android.Arm {
255 s.Cfi = nil
256 s.Diag.Cfi = nil
257 }
258
Vishwath Mohan8f4fdd82017-04-20 07:42:52 -0700259 // Also disable CFI if ASAN is enabled.
260 if Bool(s.Address) {
261 s.Cfi = nil
262 s.Diag.Cfi = nil
263 }
264
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700265 // Disable sanitizers that depend on the UBSan runtime for host builds.
Vishwath Mohane7128792017-11-17 11:08:10 -0800266 if ctx.Host() {
267 s.Cfi = nil
268 s.Diag.Cfi = nil
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700269 s.Misc_undefined = nil
270 s.Undefined = nil
271 s.All_undefined = nil
272 s.Integer_overflow = nil
Vishwath Mohane7128792017-11-17 11:08:10 -0800273 }
274
Vishwath Mohan9ccbba02018-05-28 13:54:48 -0700275 // Also disable CFI for VNDK variants of components
276 if ctx.isVndk() && ctx.useVndk() {
Vishwath Mohan7589c822018-05-23 19:29:55 -0700277 s.Cfi = nil
278 s.Diag.Cfi = nil
279 }
280
Colin Cross3c344ef2016-07-18 15:44:56 -0700281 if ctx.staticBinary() {
282 s.Address = nil
Colin Cross91169fe2016-08-11 15:54:20 -0700283 s.Coverage = nil
Colin Cross3c344ef2016-07-18 15:44:56 -0700284 s.Thread = nil
Colin Cross16b23492016-01-06 14:41:07 -0800285 }
286
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700287 if Bool(s.All_undefined) {
288 s.Undefined = nil
289 }
290
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700291 if !ctx.toolchain().Is64Bit() {
292 // TSAN and SafeStack are not supported on 32-bit architectures
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700293 s.Thread = nil
294 s.Safestack = nil
Colin Cross16b23492016-01-06 14:41:07 -0800295 // TODO(ccross): error for compile_multilib = "32"?
296 }
297
Evgenii Stepanov76cee232017-01-27 15:44:44 -0800298 if ctx.Os() != android.Windows && (Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) || Bool(s.Thread) ||
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700299 Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) || Bool(s.Integer_overflow) || len(s.Misc_undefined) > 0 ||
300 Bool(s.Scudo)) {
Colin Cross3c344ef2016-07-18 15:44:56 -0700301 sanitize.Properties.SanitizerEnabled = true
302 }
303
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700304 // Disable Scudo if ASan or TSan is enabled.
305 if Bool(s.Address) || Bool(s.Thread) {
306 s.Scudo = nil
307 }
308
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700309 if Bool(s.Coverage) {
310 if !Bool(s.Address) {
Colin Cross16b23492016-01-06 14:41:07 -0800311 ctx.ModuleErrorf(`Use of "coverage" also requires "address"`)
312 }
313 }
314}
315
316func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
317 if !sanitize.Properties.SanitizerEnabled { // || c.static() {
318 return deps
319 }
320
321 if ctx.Device() {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700322 if Bool(sanitize.Properties.Sanitize.Address) {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700323 deps.StaticLibs = append(deps.StaticLibs, asanLibs...)
Colin Cross16b23492016-01-06 14:41:07 -0800324 }
325 }
326
327 return deps
328}
329
330func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
Ivan Lozano59fdea22018-05-10 14:17:22 -0700331 minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a"
332 minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib
Ivan Lozano30c5db22018-02-21 15:49:20 -0800333
334 if ctx.Device() && sanitize.Properties.MinimalRuntimeDep {
335 flags.LdFlags = append(flags.LdFlags, minimalRuntimePath)
Ivan Lozano59fdea22018-05-10 14:17:22 -0700336 flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800337 }
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700338 if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
Colin Cross16b23492016-01-06 14:41:07 -0800339 return flags
340 }
341
342 if !ctx.clang() {
343 ctx.ModuleErrorf("Use of sanitizers requires clang")
344 }
345
346 var sanitizers []string
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700347 var diagSanitizers []string
Colin Cross16b23492016-01-06 14:41:07 -0800348
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700349 if Bool(sanitize.Properties.Sanitize.All_undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800350 sanitizers = append(sanitizers, "undefined")
Colin Cross16b23492016-01-06 14:41:07 -0800351 } else {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700352 if Bool(sanitize.Properties.Sanitize.Undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800353 sanitizers = append(sanitizers,
354 "bool",
355 "integer-divide-by-zero",
356 "return",
357 "returns-nonnull-attribute",
358 "shift-exponent",
359 "unreachable",
360 "vla-bound",
361 // TODO(danalbert): The following checks currently have compiler performance issues.
362 //"alignment",
363 //"bounds",
364 //"enum",
365 //"float-cast-overflow",
366 //"float-divide-by-zero",
367 //"nonnull-attribute",
368 //"null",
369 //"shift-base",
370 //"signed-integer-overflow",
371 // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
372 // https://llvm.org/PR19302
373 // http://reviews.llvm.org/D6974
374 // "object-size",
375 )
376 }
377 sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...)
378 }
379
Ivan Lozano651275b2017-06-13 10:24:34 -0700380 if Bool(sanitize.Properties.Sanitize.Diag.Undefined) {
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700381 diagSanitizers = append(diagSanitizers, "undefined")
382 }
383
Ivan Lozano651275b2017-06-13 10:24:34 -0700384 diagSanitizers = append(diagSanitizers, sanitize.Properties.Sanitize.Diag.Misc_undefined...)
385
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700386 if Bool(sanitize.Properties.Sanitize.Address) {
Colin Cross635c3b02016-05-18 15:37:25 -0700387 if ctx.Arch().ArchType == android.Arm {
Colin Cross16b23492016-01-06 14:41:07 -0800388 // Frame pointer based unwinder in ASan requires ARM frame setup.
389 // TODO: put in flags?
390 flags.RequiredInstructionSet = "arm"
391 }
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700392 flags.CFlags = append(flags.CFlags, asanCflags...)
393 flags.LdFlags = append(flags.LdFlags, asanLdflags...)
Colin Cross16b23492016-01-06 14:41:07 -0800394
Colin Cross16b23492016-01-06 14:41:07 -0800395 if ctx.Host() {
396 // -nodefaultlibs (provided with libc++) prevents the driver from linking
397 // libraries needed with -fsanitize=address. http://b/18650275 (WAI)
Colin Cross16b23492016-01-06 14:41:07 -0800398 flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
399 } else {
400 flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
401 flags.DynamicLinker = "/system/bin/linker_asan"
402 if flags.Toolchain.Is64Bit() {
403 flags.DynamicLinker += "64"
404 }
405 }
406 sanitizers = append(sanitizers, "address")
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700407 diagSanitizers = append(diagSanitizers, "address")
Colin Cross16b23492016-01-06 14:41:07 -0800408 }
409
Yabin Cui6be405e2017-10-19 15:52:11 -0700410 if Bool(sanitize.Properties.Sanitize.Thread) {
411 sanitizers = append(sanitizers, "thread")
412 }
413
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700414 if Bool(sanitize.Properties.Sanitize.Coverage) {
Zach Riggle06bbd892017-08-21 17:12:32 -0400415 flags.CFlags = append(flags.CFlags, "-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp")
Colin Cross16b23492016-01-06 14:41:07 -0800416 }
417
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700418 if Bool(sanitize.Properties.Sanitize.Safestack) {
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700419 sanitizers = append(sanitizers, "safe-stack")
420 }
421
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700422 if Bool(sanitize.Properties.Sanitize.Cfi) {
Evgenii Stepanov7ebf9fa2017-01-20 14:13:06 -0800423 if ctx.Arch().ArchType == android.Arm {
424 // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up
425 // to do this on a function basis, so force Thumb on the entire module.
426 flags.RequiredInstructionSet = "thumb"
427 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700428 sanitizers = append(sanitizers, "cfi")
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000429
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700430 flags.CFlags = append(flags.CFlags, cfiCflags...)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000431 // Only append the default visibility flag if -fvisibility has not already been set
432 // to hidden.
433 if !inList("-fvisibility=hidden", flags.CFlags) {
434 flags.CFlags = append(flags.CFlags, "-fvisibility=default")
435 }
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700436 flags.LdFlags = append(flags.LdFlags, cfiLdflags...)
Zhizhou Yang51be6322018-02-08 18:32:11 -0800437 flags.ArGoldPlugin = true
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700438 if Bool(sanitize.Properties.Sanitize.Diag.Cfi) {
439 diagSanitizers = append(diagSanitizers, "cfi")
440 }
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000441
442 if ctx.staticBinary() {
443 _, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags)
444 _, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags)
445 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700446 }
447
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700448 if Bool(sanitize.Properties.Sanitize.Integer_overflow) {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700449 sanitizers = append(sanitizers, "unsigned-integer-overflow")
450 sanitizers = append(sanitizers, "signed-integer-overflow")
451 flags.CFlags = append(flags.CFlags, intOverflowCflags...)
452 if Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) {
453 diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow")
454 diagSanitizers = append(diagSanitizers, "signed-integer-overflow")
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700455 }
456 }
457
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700458 if Bool(sanitize.Properties.Sanitize.Scudo) {
459 sanitizers = append(sanitizers, "scudo")
460 }
461
Colin Cross16b23492016-01-06 14:41:07 -0800462 if len(sanitizers) > 0 {
463 sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",")
Ivan Lozano30c5db22018-02-21 15:49:20 -0800464
Colin Cross16b23492016-01-06 14:41:07 -0800465 flags.CFlags = append(flags.CFlags, sanitizeArg)
466 if ctx.Host() {
467 flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
468 flags.LdFlags = append(flags.LdFlags, sanitizeArg)
Evgenii Stepanov76cee232017-01-27 15:44:44 -0800469 // Host sanitizers only link symbols in the final executable, so
470 // there will always be undefined symbols in intermediate libraries.
471 _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
Colin Cross16b23492016-01-06 14:41:07 -0800472 } else {
Colin Cross263abbd2016-07-15 13:10:48 -0700473 flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
Ivan Lozano30c5db22018-02-21 15:49:20 -0800474
475 if enableMinimalRuntime(sanitize) {
476 flags.CFlags = append(flags.CFlags, strings.Join(minimalRuntimeFlags, " "))
477 flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...)
Ivan Lozano59fdea22018-05-10 14:17:22 -0700478 flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800479 }
Colin Cross16b23492016-01-06 14:41:07 -0800480 }
481 }
482
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700483 if len(diagSanitizers) > 0 {
Ivan Lozanob7d0f522018-01-20 01:44:38 +0000484 flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ","))
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700485 }
486 // FIXME: enable RTTI if diag + (cfi or vptr)
487
Andreas Gampe97071162017-05-08 13:15:23 -0700488 if sanitize.Properties.Sanitize.Recover != nil {
489 flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+
490 strings.Join(sanitize.Properties.Sanitize.Recover, ","))
491 }
492
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700493 // Link a runtime library if needed.
494 runtimeLibrary := ""
495 if Bool(sanitize.Properties.Sanitize.Address) {
496 runtimeLibrary = config.AddressSanitizerRuntimeLibrary(ctx.toolchain())
Yabin Cui6be405e2017-10-19 15:52:11 -0700497 } else if Bool(sanitize.Properties.Sanitize.Thread) {
498 runtimeLibrary = config.ThreadSanitizerRuntimeLibrary(ctx.toolchain())
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700499 } else if Bool(sanitize.Properties.Sanitize.Scudo) {
500 runtimeLibrary = config.ScudoRuntimeLibrary(ctx.toolchain())
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700501 } else if len(diagSanitizers) > 0 || sanitize.Properties.UbsanRuntimeDep {
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700502 runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain())
503 }
504
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700505 if runtimeLibrary != "" {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700506 runtimeLibraryPath := "${config.ClangAsanLibDir}/" + runtimeLibrary
507 if !ctx.static() {
508 runtimeLibraryPath = runtimeLibraryPath + ctx.toolchain().ShlibSuffix()
509 } else {
510 runtimeLibraryPath = runtimeLibraryPath + ".a"
511 }
512
Jiyong Park27b188b2017-07-18 13:23:39 +0900513 // ASan runtime library must be the first in the link order.
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700514 flags.libFlags = append([]string{runtimeLibraryPath}, flags.libFlags...)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700515 sanitize.runtimeLibrary = runtimeLibrary
Jiyong Park27b188b2017-07-18 13:23:39 +0900516
517 // When linking against VNDK, use the vendor variant of the runtime lib
518 sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700519 if ctx.useVndk() {
Jiyong Park27b188b2017-07-18 13:23:39 +0900520 sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix
521 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700522 }
523
Colin Cross635c3b02016-05-18 15:37:25 -0700524 blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist)
Colin Cross16b23492016-01-06 14:41:07 -0800525 if blacklist.Valid() {
526 flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String())
527 flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path())
528 }
529
530 return flags
531}
532
Colin Cross8ff9ef42017-05-08 13:44:11 -0700533func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross27a4b052017-08-10 16:32:23 -0700534 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Jiyong Park27b188b2017-07-18 13:23:39 +0900535 if sanitize.androidMkRuntimeLibrary != "" {
536 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700537 }
Colin Cross8ff9ef42017-05-08 13:44:11 -0700538 })
Vishwath Mohane7128792017-11-17 11:08:10 -0800539
540 // Add a suffix for CFI-enabled static libraries to allow surfacing both to make without a
541 // name conflict.
542 if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Cfi) {
543 ret.SubName += ".cfi"
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000544 }
Colin Cross8ff9ef42017-05-08 13:44:11 -0700545}
546
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700547func (sanitize *sanitize) inSanitizerDir() bool {
548 return sanitize.Properties.InSanitizerDir
Colin Cross30d5f512016-05-03 18:02:42 -0700549}
550
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000551func (sanitize *sanitize) getSanitizerBoolPtr(t sanitizerType) *bool {
Vishwath Mohan95229302017-08-11 00:53:16 +0000552 switch t {
553 case asan:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000554 return sanitize.Properties.Sanitize.Address
Vishwath Mohan95229302017-08-11 00:53:16 +0000555 case tsan:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000556 return sanitize.Properties.Sanitize.Thread
Vishwath Mohan95229302017-08-11 00:53:16 +0000557 case intOverflow:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000558 return sanitize.Properties.Sanitize.Integer_overflow
559 case cfi:
560 return sanitize.Properties.Sanitize.Cfi
Vishwath Mohan95229302017-08-11 00:53:16 +0000561 default:
562 panic(fmt.Errorf("unknown sanitizerType %d", t))
563 }
564}
565
Dan Albert7d1eecf2018-01-19 12:30:45 -0800566func (sanitize *sanitize) isUnsanitizedVariant() bool {
567 return !sanitize.isSanitizerEnabled(asan) &&
568 !sanitize.isSanitizerEnabled(tsan) &&
569 !sanitize.isSanitizerEnabled(cfi)
570}
571
Jayant Chowdharyb7e08ca2018-05-10 15:29:24 -0700572func (sanitize *sanitize) isVariantOnProductionDevice() bool {
573 return !sanitize.isSanitizerEnabled(asan) &&
574 !sanitize.isSanitizerEnabled(tsan)
575}
576
Colin Cross16b23492016-01-06 14:41:07 -0800577func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) {
578 switch t {
579 case asan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700580 sanitize.Properties.Sanitize.Address = boolPtr(b)
Colin Cross91169fe2016-08-11 15:54:20 -0700581 if !b {
582 sanitize.Properties.Sanitize.Coverage = nil
583 }
Colin Cross16b23492016-01-06 14:41:07 -0800584 case tsan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700585 sanitize.Properties.Sanitize.Thread = boolPtr(b)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700586 case intOverflow:
587 sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000588 case cfi:
589 sanitize.Properties.Sanitize.Cfi = boolPtr(b)
Colin Cross16b23492016-01-06 14:41:07 -0800590 default:
591 panic(fmt.Errorf("unknown sanitizerType %d", t))
592 }
593 if b {
594 sanitize.Properties.SanitizerEnabled = true
595 }
596}
597
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000598// Check if the sanitizer is explicitly disabled (as opposed to nil by
599// virtue of not being set).
600func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t sanitizerType) bool {
601 if sanitize == nil {
602 return false
603 }
604
605 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
606 return sanitizerVal != nil && *sanitizerVal == false
607}
608
609// There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled)
610// because enabling a sanitizer either directly (via the blueprint) or
611// indirectly (via a mutator) sets the bool ptr to true, and you can't
612// distinguish between the cases. It isn't needed though - both cases can be
613// treated identically.
614func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool {
615 if sanitize == nil {
616 return false
617 }
618
619 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
620 return sanitizerVal != nil && *sanitizerVal == true
621}
622
Colin Cross6b753602018-06-21 13:03:07 -0700623func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
624 t, ok := tag.(dependencyTag)
625 return ok && t.library || t == reuseObjTag
626}
627
Colin Cross16b23492016-01-06 14:41:07 -0800628// Propagate asan requirements down from binaries
Colin Cross635c3b02016-05-18 15:37:25 -0700629func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) {
630 return func(mctx android.TopDownMutatorContext) {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000631 if c, ok := mctx.Module().(*Module); ok && c.sanitize.isSanitizerEnabled(t) {
Colin Cross6b753602018-06-21 13:03:07 -0700632 mctx.WalkDeps(func(child, parent android.Module) bool {
633 if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) {
634 return false
635 }
636 if d, ok := child.(*Module); ok && d.sanitize != nil &&
Nan Zhang0007d812017-11-07 10:57:05 -0800637 !Bool(d.sanitize.Properties.Sanitize.Never) &&
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000638 !d.sanitize.isSanitizerExplicitlyDisabled(t) {
639 if (t == cfi && d.static()) || t != cfi {
640 d.sanitize.Properties.SanitizeDep = true
641 }
Colin Cross16b23492016-01-06 14:41:07 -0800642 }
Colin Cross6b753602018-06-21 13:03:07 -0700643 return true
Colin Cross16b23492016-01-06 14:41:07 -0800644 })
645 }
646 }
647}
648
Ivan Lozano30c5db22018-02-21 15:49:20 -0800649// Propagate the ubsan minimal runtime dependency when there are integer overflow sanitized static dependencies.
Colin Cross6b753602018-06-21 13:03:07 -0700650func sanitizerRuntimeDepsMutator(mctx android.TopDownMutatorContext) {
651 if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil {
652 mctx.WalkDeps(func(child, parent android.Module) bool {
653 if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) {
654 return false
655 }
656 if d, ok := child.(*Module); ok && d.static() && d.sanitize != nil {
Ivan Lozano30c5db22018-02-21 15:49:20 -0800657
Colin Cross6b753602018-06-21 13:03:07 -0700658 if enableMinimalRuntime(d.sanitize) {
659 // If a static dependency is built with the minimal runtime,
660 // make sure we include the ubsan minimal runtime.
661 c.sanitize.Properties.MinimalRuntimeDep = true
662 } else if Bool(d.sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
663 len(d.sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0 {
664 // If a static dependency runs with full ubsan diagnostics,
665 // make sure we include the ubsan runtime.
666 c.sanitize.Properties.UbsanRuntimeDep = true
Ivan Lozano30c5db22018-02-21 15:49:20 -0800667 }
Colin Cross6b753602018-06-21 13:03:07 -0700668 }
669 return true
670 })
Ivan Lozano30c5db22018-02-21 15:49:20 -0800671 }
672}
673
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000674// Create sanitized variants for modules that need them
Colin Cross635c3b02016-05-18 15:37:25 -0700675func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
676 return func(mctx android.BottomUpMutatorContext) {
Vishwath Mohane6153452017-08-11 00:52:44 +0000677 if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000678 if c.isDependencyRoot() && c.sanitize.isSanitizerEnabled(t) {
Colin Cross30d5f512016-05-03 18:02:42 -0700679 modules := mctx.CreateVariations(t.String())
680 modules[0].(*Module).sanitize.SetSanitizer(t, true)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000681 } else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep {
682 // Save original sanitizer status before we assign values to variant
683 // 0 as that overwrites the original.
684 isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t)
685
Colin Crossb0f28952016-09-19 16:46:53 -0700686 modules := mctx.CreateVariations("", t.String())
687 modules[0].(*Module).sanitize.SetSanitizer(t, false)
688 modules[1].(*Module).sanitize.SetSanitizer(t, true)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000689
Colin Crossb0f28952016-09-19 16:46:53 -0700690 modules[0].(*Module).sanitize.Properties.SanitizeDep = false
691 modules[1].(*Module).sanitize.Properties.SanitizeDep = false
Vishwath Mohane7128792017-11-17 11:08:10 -0800692
693 // We don't need both variants active for anything but CFI-enabled
694 // target static libraries, so suppress the appropriate variant in
695 // all other cases.
696 if t == cfi {
697 if c.static() {
698 if !mctx.Device() {
699 if isSanitizerEnabled {
700 modules[0].(*Module).Properties.PreventInstall = true
701 modules[0].(*Module).Properties.HideFromMake = true
702 } else {
703 modules[1].(*Module).Properties.PreventInstall = true
704 modules[1].(*Module).Properties.HideFromMake = true
705 }
706 } else {
Colin Cross6510f912017-11-29 00:27:14 -0800707 cfiStaticLibs := cfiStaticLibs(mctx.Config())
Vishwath Mohane7128792017-11-17 11:08:10 -0800708
709 cfiStaticLibsMutex.Lock()
710 *cfiStaticLibs = append(*cfiStaticLibs, c.Name())
711 cfiStaticLibsMutex.Unlock()
712 }
713 } else {
714 modules[0].(*Module).Properties.PreventInstall = true
715 modules[0].(*Module).Properties.HideFromMake = true
716 }
717 } else if t == asan {
718 if mctx.Device() {
719 // CFI and ASAN are currently mutually exclusive so disable
720 // CFI if this is an ASAN variant.
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000721 modules[1].(*Module).sanitize.Properties.InSanitizerDir = true
722 modules[1].(*Module).sanitize.SetSanitizer(cfi, false)
723 }
Vishwath Mohane21fe422017-11-01 19:42:45 -0700724 if isSanitizerEnabled {
725 modules[0].(*Module).Properties.PreventInstall = true
Vishwath Mohane7128792017-11-17 11:08:10 -0800726 modules[0].(*Module).Properties.HideFromMake = true
Vishwath Mohane21fe422017-11-01 19:42:45 -0700727 } else {
728 modules[1].(*Module).Properties.PreventInstall = true
Vishwath Mohane7128792017-11-17 11:08:10 -0800729 modules[1].(*Module).Properties.HideFromMake = true
Vishwath Mohane21fe422017-11-01 19:42:45 -0700730 }
731 }
Colin Cross16b23492016-01-06 14:41:07 -0800732 }
733 c.sanitize.Properties.SanitizeDep = false
734 }
735 }
736}
Vishwath Mohane7128792017-11-17 11:08:10 -0800737
738func cfiStaticLibs(config android.Config) *[]string {
739 return config.Once("cfiStaticLibs", func() interface{} {
740 return &[]string{}
741 }).(*[]string)
742}
743
Ivan Lozano30c5db22018-02-21 15:49:20 -0800744func enableMinimalRuntime(sanitize *sanitize) bool {
745 if !Bool(sanitize.Properties.Sanitize.Address) &&
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700746 !Bool(sanitize.Properties.Sanitize.Scudo) &&
Ivan Lozano30c5db22018-02-21 15:49:20 -0800747 (Bool(sanitize.Properties.Sanitize.Integer_overflow) ||
748 len(sanitize.Properties.Sanitize.Misc_undefined) > 0) &&
749 !(Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
750 Bool(sanitize.Properties.Sanitize.Diag.Cfi) ||
751 len(sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0) {
752 return true
753 }
754 return false
755}
756
Vishwath Mohane7128792017-11-17 11:08:10 -0800757func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
758 cfiStaticLibs := cfiStaticLibs(ctx.Config())
Jeff Gaston72765392017-11-28 16:37:53 -0800759 sort.Strings(*cfiStaticLibs)
Vishwath Mohane7128792017-11-17 11:08:10 -0800760 ctx.Strict("SOONG_CFI_STATIC_LIBRARIES", strings.Join(*cfiStaticLibs, " "))
761}