blob: 28c6ef5265a73e3604177fdb07a8650e30e165d8 [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"
19 "strings"
20
21 "github.com/google/blueprint"
22
Colin Cross635c3b02016-05-18 15:37:25 -070023 "android/soong/android"
Evgenii Stepanovaf36db12016-08-15 14:18:24 -070024 "android/soong/cc/config"
Colin Cross16b23492016-01-06 14:41:07 -080025)
26
Dan Willemsencbceaab2016-10-13 16:44:07 -070027const (
Dan Willemsen78ffeea2016-10-20 18:46:48 -070028 asanCflags = "-fno-omit-frame-pointer"
Dan Willemsencbceaab2016-10-13 16:44:07 -070029 asanLdflags = "-Wl,-u,__asan_preinit"
Dan Willemsen78ffeea2016-10-20 18:46:48 -070030 asanLibs = "libasan"
Vishwath Mohanf3918d32017-02-14 07:59:33 -080031
32 cfiCflags = "-flto -fsanitize-cfi-cross-dso -fvisibility=default " +
33 "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"
34 // FIXME: revert the __cfi_check flag when clang is updated to r280031.
35 cfiLdflags = "-flto -fsanitize-cfi-cross-dso -fsanitize=cfi " +
36 "-Wl,-plugin-opt,O1 -Wl,-export-dynamic-symbol=__cfi_check"
Dan Willemsencbceaab2016-10-13 16:44:07 -070037)
38
Colin Cross16b23492016-01-06 14:41:07 -080039type sanitizerType int
40
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070041func boolPtr(v bool) *bool {
42 if v {
43 return &v
44 } else {
45 return nil
46 }
47}
48
Colin Cross16b23492016-01-06 14:41:07 -080049const (
50 asan sanitizerType = iota + 1
51 tsan
52)
53
54func (t sanitizerType) String() string {
55 switch t {
56 case asan:
57 return "asan"
58 case tsan:
59 return "tsan"
60 default:
61 panic(fmt.Errorf("unknown sanitizerType %d", t))
62 }
63}
64
65type SanitizeProperties struct {
66 // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer
67 Sanitize struct {
68 Never bool `android:"arch_variant"`
69
70 // main sanitizers
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070071 Address *bool `android:"arch_variant"`
72 Thread *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -080073
74 // local sanitizers
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070075 Undefined *bool `android:"arch_variant"`
76 All_undefined *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -080077 Misc_undefined []string `android:"arch_variant"`
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -070078 Coverage *bool `android:"arch_variant"`
79 Safestack *bool `android:"arch_variant"`
Evgenii Stepanov1e405e12016-08-16 15:39:54 -070080 Cfi *bool `android:"arch_variant"`
Colin Cross16b23492016-01-06 14:41:07 -080081
Evgenii Stepanov1e405e12016-08-16 15:39:54 -070082 // Sanitizers to run in the diagnostic mode (as opposed to the release mode).
83 // Replaces abort() on error with a human-readable error message.
84 // Address and Thread sanitizers always run in diagnostic mode.
85 Diag struct {
86 Undefined *bool `android:"arch_variant"`
87 Cfi *bool `android:"arch_variant"`
88 }
89
90 // value to pass to -fsanitize-recover=
Colin Cross16b23492016-01-06 14:41:07 -080091 Recover []string
92
93 // value to pass to -fsanitize-blacklist
94 Blacklist *string
95 } `android:"arch_variant"`
96
97 SanitizerEnabled bool `blueprint:"mutated"`
98 SanitizeDep bool `blueprint:"mutated"`
Colin Cross30d5f512016-05-03 18:02:42 -070099 InData bool `blueprint:"mutated"`
Colin Cross16b23492016-01-06 14:41:07 -0800100}
101
102type sanitize struct {
103 Properties SanitizeProperties
104}
105
106func (sanitize *sanitize) props() []interface{} {
107 return []interface{}{&sanitize.Properties}
108}
109
110func (sanitize *sanitize) begin(ctx BaseModuleContext) {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700111 s := &sanitize.Properties.Sanitize
112
Colin Cross16b23492016-01-06 14:41:07 -0800113 // Don't apply sanitizers to NDK code.
114 if ctx.sdk() {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700115 s.Never = true
Colin Cross16b23492016-01-06 14:41:07 -0800116 }
117
118 // Never always wins.
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700119 if s.Never {
Colin Cross16b23492016-01-06 14:41:07 -0800120 return
121 }
122
Colin Cross16b23492016-01-06 14:41:07 -0800123 var globalSanitizers []string
124 if ctx.clang() {
125 if ctx.Host() {
126 globalSanitizers = ctx.AConfig().SanitizeHost()
127 } else {
Colin Cross23ae82a2016-11-02 14:34:39 -0700128 arches := ctx.AConfig().SanitizeDeviceArch()
129 if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) {
130 globalSanitizers = ctx.AConfig().SanitizeDevice()
131 }
Colin Cross16b23492016-01-06 14:41:07 -0800132 }
133 }
134
Colin Cross16b23492016-01-06 14:41:07 -0800135 if len(globalSanitizers) > 0 {
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000136 var found bool
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700137 if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
138 s.All_undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000139 }
Colin Cross16b23492016-01-06 14:41:07 -0800140
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700141 if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
142 s.Undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000143 }
144
Evgenii Stepanov774cb812016-12-28 15:52:54 -0800145 if found, globalSanitizers = removeFromList("address", globalSanitizers); found {
146 if s.Address == nil {
147 s.Address = boolPtr(true)
148 } else if *s.Address == false {
149 // Coverage w/o address is an error. If globalSanitizers includes both, and the module
150 // disables address, then disable coverage as well.
151 _, globalSanitizers = removeFromList("coverage", globalSanitizers)
152 }
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000153 }
154
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700155 if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
156 s.Thread = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000157 }
158
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700159 if found, globalSanitizers = removeFromList("coverage", globalSanitizers); found && s.Coverage == nil {
160 s.Coverage = boolPtr(true)
161 }
162
163 if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
164 s.Safestack = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000165 }
166
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700167 if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
168 s.Cfi = boolPtr(true)
169 }
170
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000171 if len(globalSanitizers) > 0 {
172 ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
173 }
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700174 }
Colin Cross3c344ef2016-07-18 15:44:56 -0700175
Evgenii Stepanova83fdac2017-01-31 18:37:30 -0800176 // CFI needs gold linker, and mips toolchain does not have one.
177 if !ctx.AConfig().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 {
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800178 s.Cfi = nil
179 s.Diag.Cfi = nil
180 }
181
Vishwath Mohan6d67e6e2017-02-07 20:31:41 -0800182 // Also disable CFI for arm32 until b/35157333 is fixed.
183 if ctx.Arch().ArchType == android.Arm {
184 s.Cfi = nil
185 s.Diag.Cfi = nil
186 }
187
Colin Cross3c344ef2016-07-18 15:44:56 -0700188 if ctx.staticBinary() {
189 s.Address = nil
Colin Cross91169fe2016-08-11 15:54:20 -0700190 s.Coverage = nil
Colin Cross3c344ef2016-07-18 15:44:56 -0700191 s.Thread = nil
Colin Cross16b23492016-01-06 14:41:07 -0800192 }
193
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700194 if Bool(s.All_undefined) {
195 s.Undefined = nil
196 }
197
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700198 if !ctx.toolchain().Is64Bit() {
199 // TSAN and SafeStack are not supported on 32-bit architectures
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700200 s.Thread = nil
201 s.Safestack = nil
Colin Cross16b23492016-01-06 14:41:07 -0800202 // TODO(ccross): error for compile_multilib = "32"?
203 }
204
Colin Cross3c344ef2016-07-18 15:44:56 -0700205 if Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) ||
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700206 Bool(s.Thread) || Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) {
Colin Cross3c344ef2016-07-18 15:44:56 -0700207 sanitize.Properties.SanitizerEnabled = true
208 }
209
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700210 if Bool(s.Coverage) {
211 if !Bool(s.Address) {
Colin Cross16b23492016-01-06 14:41:07 -0800212 ctx.ModuleErrorf(`Use of "coverage" also requires "address"`)
213 }
214 }
215}
216
217func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
218 if !sanitize.Properties.SanitizerEnabled { // || c.static() {
219 return deps
220 }
221
222 if ctx.Device() {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700223 if Bool(sanitize.Properties.Sanitize.Address) {
Dan Willemsencbceaab2016-10-13 16:44:07 -0700224 deps.StaticLibs = append(deps.StaticLibs, asanLibs)
Colin Cross16b23492016-01-06 14:41:07 -0800225 }
Colin Cross263abbd2016-07-15 13:10:48 -0700226 if Bool(sanitize.Properties.Sanitize.Address) || Bool(sanitize.Properties.Sanitize.Thread) {
227 deps.SharedLibs = append(deps.SharedLibs, "libdl")
228 }
Colin Cross16b23492016-01-06 14:41:07 -0800229 }
230
231 return deps
232}
233
234func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
235 if !sanitize.Properties.SanitizerEnabled {
236 return flags
237 }
238
239 if !ctx.clang() {
240 ctx.ModuleErrorf("Use of sanitizers requires clang")
241 }
242
243 var sanitizers []string
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700244 var diagSanitizers []string
Colin Cross16b23492016-01-06 14:41:07 -0800245
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700246 if Bool(sanitize.Properties.Sanitize.All_undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800247 sanitizers = append(sanitizers, "undefined")
248 if ctx.Device() {
249 ctx.ModuleErrorf("ubsan is not yet supported on the device")
250 }
251 } else {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700252 if Bool(sanitize.Properties.Sanitize.Undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800253 sanitizers = append(sanitizers,
254 "bool",
255 "integer-divide-by-zero",
256 "return",
257 "returns-nonnull-attribute",
258 "shift-exponent",
259 "unreachable",
260 "vla-bound",
261 // TODO(danalbert): The following checks currently have compiler performance issues.
262 //"alignment",
263 //"bounds",
264 //"enum",
265 //"float-cast-overflow",
266 //"float-divide-by-zero",
267 //"nonnull-attribute",
268 //"null",
269 //"shift-base",
270 //"signed-integer-overflow",
271 // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
272 // https://llvm.org/PR19302
273 // http://reviews.llvm.org/D6974
274 // "object-size",
275 )
276 }
277 sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...)
278 }
279
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700280 if Bool(sanitize.Properties.Sanitize.Diag.Undefined) &&
281 (Bool(sanitize.Properties.Sanitize.All_undefined) ||
282 Bool(sanitize.Properties.Sanitize.Undefined) ||
283 len(sanitize.Properties.Sanitize.Misc_undefined) > 0) {
284 diagSanitizers = append(diagSanitizers, "undefined")
285 }
286
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700287 if Bool(sanitize.Properties.Sanitize.Address) {
Colin Cross635c3b02016-05-18 15:37:25 -0700288 if ctx.Arch().ArchType == android.Arm {
Colin Cross16b23492016-01-06 14:41:07 -0800289 // Frame pointer based unwinder in ASan requires ARM frame setup.
290 // TODO: put in flags?
291 flags.RequiredInstructionSet = "arm"
292 }
Dan Willemsencbceaab2016-10-13 16:44:07 -0700293 flags.CFlags = append(flags.CFlags, asanCflags)
294 flags.LdFlags = append(flags.LdFlags, asanLdflags)
Colin Cross16b23492016-01-06 14:41:07 -0800295
Colin Cross16b23492016-01-06 14:41:07 -0800296 if ctx.Host() {
297 // -nodefaultlibs (provided with libc++) prevents the driver from linking
298 // libraries needed with -fsanitize=address. http://b/18650275 (WAI)
299 flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
300 flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
Colin Cross46974e22016-10-20 12:41:14 -0700301 // Host ASAN only links symbols in the final executable, so
302 // there will always be undefined symbols in intermediate libraries.
303 _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
Colin Cross16b23492016-01-06 14:41:07 -0800304 } else {
305 flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
306 flags.DynamicLinker = "/system/bin/linker_asan"
307 if flags.Toolchain.Is64Bit() {
308 flags.DynamicLinker += "64"
309 }
310 }
311 sanitizers = append(sanitizers, "address")
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700312 diagSanitizers = append(diagSanitizers, "address")
Colin Cross16b23492016-01-06 14:41:07 -0800313 }
314
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700315 if Bool(sanitize.Properties.Sanitize.Coverage) {
Colin Cross16b23492016-01-06 14:41:07 -0800316 flags.CFlags = append(flags.CFlags, "-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp")
317 }
318
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700319 if Bool(sanitize.Properties.Sanitize.Safestack) {
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700320 sanitizers = append(sanitizers, "safe-stack")
321 }
322
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700323 if Bool(sanitize.Properties.Sanitize.Cfi) {
Evgenii Stepanov7ebf9fa2017-01-20 14:13:06 -0800324 if ctx.Arch().ArchType == android.Arm {
325 // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up
326 // to do this on a function basis, so force Thumb on the entire module.
327 flags.RequiredInstructionSet = "thumb"
Evgenii Stepanova83fdac2017-01-31 18:37:30 -0800328 // Workaround for b/33678192. CFI jumptables need Thumb2 codegen. Revert when
329 // Clang is updated past r290384.
330 flags.LdFlags = append(flags.LdFlags, "-march=armv7-a")
Evgenii Stepanov7ebf9fa2017-01-20 14:13:06 -0800331 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700332 sanitizers = append(sanitizers, "cfi")
Vishwath Mohanf3918d32017-02-14 07:59:33 -0800333 flags.CFlags = append(flags.CFlags, cfiCflags)
334 flags.LdFlags = append(flags.LdFlags, cfiLdflags)
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700335 if Bool(sanitize.Properties.Sanitize.Diag.Cfi) {
336 diagSanitizers = append(diagSanitizers, "cfi")
337 }
338 }
339
Colin Cross16b23492016-01-06 14:41:07 -0800340 if sanitize.Properties.Sanitize.Recover != nil {
341 flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+
342 strings.Join(sanitize.Properties.Sanitize.Recover, ","))
343 }
344
345 if len(sanitizers) > 0 {
346 sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",")
347 flags.CFlags = append(flags.CFlags, sanitizeArg)
348 if ctx.Host() {
349 flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
350 flags.LdFlags = append(flags.LdFlags, sanitizeArg)
351 flags.LdFlags = append(flags.LdFlags, "-lrt", "-ldl")
352 } else {
Colin Cross263abbd2016-07-15 13:10:48 -0700353 flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
Colin Cross16b23492016-01-06 14:41:07 -0800354 }
355 }
356
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700357 if len(diagSanitizers) > 0 {
358 flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ","))
359 }
360 // FIXME: enable RTTI if diag + (cfi or vptr)
361
362 // Link a runtime library if needed.
363 runtimeLibrary := ""
364 if Bool(sanitize.Properties.Sanitize.Address) {
365 runtimeLibrary = config.AddressSanitizerRuntimeLibrary(ctx.toolchain())
366 } else if len(diagSanitizers) > 0 {
367 runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain())
368 }
369
370 // ASan runtime library must be the first in the link order.
371 if runtimeLibrary != "" {
372 flags.libFlags = append([]string{"${config.ClangAsanLibDir}/" + runtimeLibrary}, flags.libFlags...)
373 }
374
Colin Cross635c3b02016-05-18 15:37:25 -0700375 blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist)
Colin Cross16b23492016-01-06 14:41:07 -0800376 if blacklist.Valid() {
377 flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String())
378 flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path())
379 }
380
381 return flags
382}
383
Colin Cross30d5f512016-05-03 18:02:42 -0700384func (sanitize *sanitize) inData() bool {
385 return sanitize.Properties.InData
386}
387
Colin Cross16b23492016-01-06 14:41:07 -0800388func (sanitize *sanitize) Sanitizer(t sanitizerType) bool {
389 if sanitize == nil {
390 return false
391 }
392
393 switch t {
394 case asan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700395 return Bool(sanitize.Properties.Sanitize.Address)
Colin Cross16b23492016-01-06 14:41:07 -0800396 case tsan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700397 return Bool(sanitize.Properties.Sanitize.Thread)
Colin Cross16b23492016-01-06 14:41:07 -0800398 default:
399 panic(fmt.Errorf("unknown sanitizerType %d", t))
400 }
401}
402
403func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) {
404 switch t {
405 case asan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700406 sanitize.Properties.Sanitize.Address = boolPtr(b)
Colin Cross91169fe2016-08-11 15:54:20 -0700407 if !b {
408 sanitize.Properties.Sanitize.Coverage = nil
409 }
Colin Cross16b23492016-01-06 14:41:07 -0800410 case tsan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700411 sanitize.Properties.Sanitize.Thread = boolPtr(b)
Colin Cross16b23492016-01-06 14:41:07 -0800412 default:
413 panic(fmt.Errorf("unknown sanitizerType %d", t))
414 }
415 if b {
416 sanitize.Properties.SanitizerEnabled = true
417 }
418}
419
420// Propagate asan requirements down from binaries
Colin Cross635c3b02016-05-18 15:37:25 -0700421func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) {
422 return func(mctx android.TopDownMutatorContext) {
Colin Cross16b23492016-01-06 14:41:07 -0800423 if c, ok := mctx.Module().(*Module); ok && c.sanitize.Sanitizer(t) {
424 mctx.VisitDepsDepthFirst(func(module blueprint.Module) {
425 if d, ok := mctx.Module().(*Module); ok && c.sanitize != nil &&
426 !c.sanitize.Properties.Sanitize.Never {
427 d.sanitize.Properties.SanitizeDep = true
428 }
429 })
430 }
431 }
432}
433
434// Create asan variants for modules that need them
Colin Cross635c3b02016-05-18 15:37:25 -0700435func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
436 return func(mctx android.BottomUpMutatorContext) {
Colin Cross16b23492016-01-06 14:41:07 -0800437 if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil {
Colin Crossb916a382016-07-29 17:28:03 -0700438 if c.isDependencyRoot() && c.sanitize.Sanitizer(t) {
Colin Cross30d5f512016-05-03 18:02:42 -0700439 modules := mctx.CreateVariations(t.String())
440 modules[0].(*Module).sanitize.SetSanitizer(t, true)
Colin Cross16b23492016-01-06 14:41:07 -0800441 } else if c.sanitize.Properties.SanitizeDep {
Colin Crossb0f28952016-09-19 16:46:53 -0700442 modules := mctx.CreateVariations("", t.String())
443 modules[0].(*Module).sanitize.SetSanitizer(t, false)
444 modules[1].(*Module).sanitize.SetSanitizer(t, true)
445 modules[0].(*Module).sanitize.Properties.SanitizeDep = false
446 modules[1].(*Module).sanitize.Properties.SanitizeDep = false
447 if mctx.Device() {
Colin Crossb36ab1a2016-05-25 12:35:53 -0700448 modules[1].(*Module).sanitize.Properties.InData = true
Colin Crossb0f28952016-09-19 16:46:53 -0700449 } else {
450 modules[0].(*Module).Properties.PreventInstall = true
451 }
452 if mctx.AConfig().EmbeddedInMake() {
453 modules[0].(*Module).Properties.HideFromMake = true
Colin Cross30d5f512016-05-03 18:02:42 -0700454 }
Colin Cross16b23492016-01-06 14:41:07 -0800455 }
456 c.sanitize.Properties.SanitizeDep = false
457 }
458 }
459}