blob: 080ac094bd6c32f1e98080e7c0269e9ba59a573b [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() {
Colin Cross6510f912017-11-29 00:27:14 -0800158 globalSanitizers = ctx.Config().SanitizeHost()
Colin Cross16b23492016-01-06 14:41:07 -0800159 } else {
Colin Cross6510f912017-11-29 00:27:14 -0800160 arches := ctx.Config().SanitizeDeviceArch()
Colin Cross23ae82a2016-11-02 14:34:39 -0700161 if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) {
Colin Cross6510f912017-11-29 00:27:14 -0800162 globalSanitizers = ctx.Config().SanitizeDevice()
163 globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag()
Colin Cross23ae82a2016-11-02 14:34:39 -0700164 }
Colin Cross16b23492016-01-06 14:41:07 -0800165 }
166 }
167
Colin Cross16b23492016-01-06 14:41:07 -0800168 if len(globalSanitizers) > 0 {
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000169 var found bool
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700170 if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil {
171 s.All_undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000172 }
Colin Cross16b23492016-01-06 14:41:07 -0800173
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700174 if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil {
175 s.Undefined = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000176 }
177
Evgenii Stepanov774cb812016-12-28 15:52:54 -0800178 if found, globalSanitizers = removeFromList("address", globalSanitizers); found {
179 if s.Address == nil {
180 s.Address = boolPtr(true)
181 } else if *s.Address == false {
182 // Coverage w/o address is an error. If globalSanitizers includes both, and the module
183 // disables address, then disable coverage as well.
184 _, globalSanitizers = removeFromList("coverage", globalSanitizers)
185 }
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000186 }
187
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700188 if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil {
189 s.Thread = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000190 }
191
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700192 if found, globalSanitizers = removeFromList("coverage", globalSanitizers); found && s.Coverage == nil {
193 s.Coverage = boolPtr(true)
194 }
195
196 if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil {
197 s.Safestack = boolPtr(true)
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000198 }
199
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700200 if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil {
Colin Cross6510f912017-11-29 00:27:14 -0800201 if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) {
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700202 s.Cfi = boolPtr(true)
203 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700204 }
205
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700206 // Global integer_overflow builds do not support static libraries.
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700207 if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700208 if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() {
Ivan Lozano5f595532017-07-13 14:46:05 -0700209 s.Integer_overflow = boolPtr(true)
210 }
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700211 }
212
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700213 if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil {
214 s.Scudo = boolPtr(true)
215 }
216
Evgenii Stepanov05bafd32016-07-07 17:38:41 +0000217 if len(globalSanitizers) > 0 {
218 ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0])
219 }
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700220
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700221 // Global integer_overflow builds do not support static library diagnostics.
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700222 if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found &&
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700223 s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() {
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700224 s.Diag.Integer_overflow = boolPtr(true)
225 }
226
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700227 if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found &&
228 s.Diag.Cfi == nil && Bool(s.Cfi) {
229 s.Diag.Cfi = boolPtr(true)
230 }
231
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700232 if len(globalSanitizersDiag) > 0 {
233 ctx.ModuleErrorf("unknown global sanitizer diagnostics option %s", globalSanitizersDiag[0])
234 }
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700235 }
Colin Cross3c344ef2016-07-18 15:44:56 -0700236
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700237 // Enable CFI for all components in the include paths
Colin Cross6510f912017-11-29 00:27:14 -0800238 if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) {
Vishwath Mohan3af8ee02018-03-30 02:55:23 +0000239 s.Cfi = boolPtr(true)
240 if inList("cfi", ctx.Config().SanitizeDeviceDiag()) {
241 s.Diag.Cfi = boolPtr(true)
Vishwath Mohan1fa3ac52017-10-31 02:26:14 -0700242 }
243 }
244
Evgenii Stepanova83fdac2017-01-31 18:37:30 -0800245 // CFI needs gold linker, and mips toolchain does not have one.
Colin Cross6510f912017-11-29 00:27:14 -0800246 if !ctx.Config().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 {
Vishwath Mohan1b017a72017-01-19 13:54:55 -0800247 s.Cfi = nil
248 s.Diag.Cfi = nil
249 }
250
Vishwath Mohan6d67e6e2017-02-07 20:31:41 -0800251 // Also disable CFI for arm32 until b/35157333 is fixed.
252 if ctx.Arch().ArchType == android.Arm {
253 s.Cfi = nil
254 s.Diag.Cfi = nil
255 }
256
Vishwath Mohan8f4fdd82017-04-20 07:42:52 -0700257 // Also disable CFI if ASAN is enabled.
258 if Bool(s.Address) {
259 s.Cfi = nil
260 s.Diag.Cfi = nil
261 }
262
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700263 // Disable sanitizers that depend on the UBSan runtime for host builds.
Vishwath Mohane7128792017-11-17 11:08:10 -0800264 if ctx.Host() {
265 s.Cfi = nil
266 s.Diag.Cfi = nil
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700267 s.Misc_undefined = nil
268 s.Undefined = nil
269 s.All_undefined = nil
270 s.Integer_overflow = nil
Vishwath Mohane7128792017-11-17 11:08:10 -0800271 }
272
Colin Cross3c344ef2016-07-18 15:44:56 -0700273 if ctx.staticBinary() {
274 s.Address = nil
Colin Cross91169fe2016-08-11 15:54:20 -0700275 s.Coverage = nil
Colin Cross3c344ef2016-07-18 15:44:56 -0700276 s.Thread = nil
Colin Cross16b23492016-01-06 14:41:07 -0800277 }
278
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700279 if Bool(s.All_undefined) {
280 s.Undefined = nil
281 }
282
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700283 if !ctx.toolchain().Is64Bit() {
284 // TSAN and SafeStack are not supported on 32-bit architectures
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700285 s.Thread = nil
286 s.Safestack = nil
Colin Cross16b23492016-01-06 14:41:07 -0800287 // TODO(ccross): error for compile_multilib = "32"?
288 }
289
Evgenii Stepanov76cee232017-01-27 15:44:44 -0800290 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 -0700291 Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) || Bool(s.Integer_overflow) || len(s.Misc_undefined) > 0 ||
292 Bool(s.Scudo)) {
Colin Cross3c344ef2016-07-18 15:44:56 -0700293 sanitize.Properties.SanitizerEnabled = true
294 }
295
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700296 // Disable Scudo if ASan or TSan is enabled.
297 if Bool(s.Address) || Bool(s.Thread) {
298 s.Scudo = nil
299 }
300
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700301 if Bool(s.Coverage) {
302 if !Bool(s.Address) {
Colin Cross16b23492016-01-06 14:41:07 -0800303 ctx.ModuleErrorf(`Use of "coverage" also requires "address"`)
304 }
305 }
306}
307
308func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
309 if !sanitize.Properties.SanitizerEnabled { // || c.static() {
310 return deps
311 }
312
313 if ctx.Device() {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700314 if Bool(sanitize.Properties.Sanitize.Address) {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700315 deps.StaticLibs = append(deps.StaticLibs, asanLibs...)
Colin Cross16b23492016-01-06 14:41:07 -0800316 }
317 }
318
319 return deps
320}
321
322func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
Ivan Lozano59fdea22018-05-10 14:17:22 -0700323 minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a"
324 minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib
Ivan Lozano30c5db22018-02-21 15:49:20 -0800325
326 if ctx.Device() && sanitize.Properties.MinimalRuntimeDep {
327 flags.LdFlags = append(flags.LdFlags, minimalRuntimePath)
Ivan Lozano59fdea22018-05-10 14:17:22 -0700328 flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800329 }
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700330 if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
Colin Cross16b23492016-01-06 14:41:07 -0800331 return flags
332 }
333
334 if !ctx.clang() {
335 ctx.ModuleErrorf("Use of sanitizers requires clang")
336 }
337
338 var sanitizers []string
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700339 var diagSanitizers []string
Colin Cross16b23492016-01-06 14:41:07 -0800340
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700341 if Bool(sanitize.Properties.Sanitize.All_undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800342 sanitizers = append(sanitizers, "undefined")
Colin Cross16b23492016-01-06 14:41:07 -0800343 } else {
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700344 if Bool(sanitize.Properties.Sanitize.Undefined) {
Colin Cross16b23492016-01-06 14:41:07 -0800345 sanitizers = append(sanitizers,
346 "bool",
347 "integer-divide-by-zero",
348 "return",
349 "returns-nonnull-attribute",
350 "shift-exponent",
351 "unreachable",
352 "vla-bound",
353 // TODO(danalbert): The following checks currently have compiler performance issues.
354 //"alignment",
355 //"bounds",
356 //"enum",
357 //"float-cast-overflow",
358 //"float-divide-by-zero",
359 //"nonnull-attribute",
360 //"null",
361 //"shift-base",
362 //"signed-integer-overflow",
363 // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
364 // https://llvm.org/PR19302
365 // http://reviews.llvm.org/D6974
366 // "object-size",
367 )
368 }
369 sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...)
370 }
371
Ivan Lozano651275b2017-06-13 10:24:34 -0700372 if Bool(sanitize.Properties.Sanitize.Diag.Undefined) {
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700373 diagSanitizers = append(diagSanitizers, "undefined")
374 }
375
Ivan Lozano651275b2017-06-13 10:24:34 -0700376 diagSanitizers = append(diagSanitizers, sanitize.Properties.Sanitize.Diag.Misc_undefined...)
377
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700378 if Bool(sanitize.Properties.Sanitize.Address) {
Colin Cross635c3b02016-05-18 15:37:25 -0700379 if ctx.Arch().ArchType == android.Arm {
Colin Cross16b23492016-01-06 14:41:07 -0800380 // Frame pointer based unwinder in ASan requires ARM frame setup.
381 // TODO: put in flags?
382 flags.RequiredInstructionSet = "arm"
383 }
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700384 flags.CFlags = append(flags.CFlags, asanCflags...)
385 flags.LdFlags = append(flags.LdFlags, asanLdflags...)
Colin Cross16b23492016-01-06 14:41:07 -0800386
Colin Cross16b23492016-01-06 14:41:07 -0800387 if ctx.Host() {
388 // -nodefaultlibs (provided with libc++) prevents the driver from linking
389 // libraries needed with -fsanitize=address. http://b/18650275 (WAI)
Colin Cross16b23492016-01-06 14:41:07 -0800390 flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
391 } else {
392 flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
393 flags.DynamicLinker = "/system/bin/linker_asan"
394 if flags.Toolchain.Is64Bit() {
395 flags.DynamicLinker += "64"
396 }
397 }
398 sanitizers = append(sanitizers, "address")
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700399 diagSanitizers = append(diagSanitizers, "address")
Colin Cross16b23492016-01-06 14:41:07 -0800400 }
401
Yabin Cui6be405e2017-10-19 15:52:11 -0700402 if Bool(sanitize.Properties.Sanitize.Thread) {
403 sanitizers = append(sanitizers, "thread")
404 }
405
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700406 if Bool(sanitize.Properties.Sanitize.Coverage) {
Zach Riggle06bbd892017-08-21 17:12:32 -0400407 flags.CFlags = append(flags.CFlags, "-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp")
Colin Cross16b23492016-01-06 14:41:07 -0800408 }
409
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700410 if Bool(sanitize.Properties.Sanitize.Safestack) {
Evgenii Stepanov0a8a0d02016-05-12 13:54:53 -0700411 sanitizers = append(sanitizers, "safe-stack")
412 }
413
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700414 if Bool(sanitize.Properties.Sanitize.Cfi) {
Evgenii Stepanov7ebf9fa2017-01-20 14:13:06 -0800415 if ctx.Arch().ArchType == android.Arm {
416 // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up
417 // to do this on a function basis, so force Thumb on the entire module.
418 flags.RequiredInstructionSet = "thumb"
419 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700420 sanitizers = append(sanitizers, "cfi")
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000421
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700422 flags.CFlags = append(flags.CFlags, cfiCflags...)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000423 // Only append the default visibility flag if -fvisibility has not already been set
424 // to hidden.
425 if !inList("-fvisibility=hidden", flags.CFlags) {
426 flags.CFlags = append(flags.CFlags, "-fvisibility=default")
427 }
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700428 flags.LdFlags = append(flags.LdFlags, cfiLdflags...)
Zhizhou Yang51be6322018-02-08 18:32:11 -0800429 flags.ArGoldPlugin = true
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700430 if Bool(sanitize.Properties.Sanitize.Diag.Cfi) {
431 diagSanitizers = append(diagSanitizers, "cfi")
432 }
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000433
434 if ctx.staticBinary() {
435 _, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags)
436 _, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags)
437 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700438 }
439
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700440 if Bool(sanitize.Properties.Sanitize.Integer_overflow) {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700441 sanitizers = append(sanitizers, "unsigned-integer-overflow")
442 sanitizers = append(sanitizers, "signed-integer-overflow")
443 flags.CFlags = append(flags.CFlags, intOverflowCflags...)
444 if Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) {
445 diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow")
446 diagSanitizers = append(diagSanitizers, "signed-integer-overflow")
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700447 }
448 }
449
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700450 if Bool(sanitize.Properties.Sanitize.Scudo) {
451 sanitizers = append(sanitizers, "scudo")
452 }
453
Colin Cross16b23492016-01-06 14:41:07 -0800454 if len(sanitizers) > 0 {
455 sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",")
Ivan Lozano30c5db22018-02-21 15:49:20 -0800456
Colin Cross16b23492016-01-06 14:41:07 -0800457 flags.CFlags = append(flags.CFlags, sanitizeArg)
458 if ctx.Host() {
459 flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
460 flags.LdFlags = append(flags.LdFlags, sanitizeArg)
Evgenii Stepanov76cee232017-01-27 15:44:44 -0800461 // Host sanitizers only link symbols in the final executable, so
462 // there will always be undefined symbols in intermediate libraries.
463 _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
Colin Cross16b23492016-01-06 14:41:07 -0800464 } else {
Colin Cross263abbd2016-07-15 13:10:48 -0700465 flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
Ivan Lozano30c5db22018-02-21 15:49:20 -0800466
467 if enableMinimalRuntime(sanitize) {
468 flags.CFlags = append(flags.CFlags, strings.Join(minimalRuntimeFlags, " "))
469 flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...)
Ivan Lozano59fdea22018-05-10 14:17:22 -0700470 flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800471 }
Colin Cross16b23492016-01-06 14:41:07 -0800472 }
473 }
474
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700475 if len(diagSanitizers) > 0 {
Ivan Lozanob7d0f522018-01-20 01:44:38 +0000476 flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ","))
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700477 }
478 // FIXME: enable RTTI if diag + (cfi or vptr)
479
Andreas Gampe97071162017-05-08 13:15:23 -0700480 if sanitize.Properties.Sanitize.Recover != nil {
481 flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+
482 strings.Join(sanitize.Properties.Sanitize.Recover, ","))
483 }
484
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700485 // Link a runtime library if needed.
486 runtimeLibrary := ""
487 if Bool(sanitize.Properties.Sanitize.Address) {
488 runtimeLibrary = config.AddressSanitizerRuntimeLibrary(ctx.toolchain())
Yabin Cui6be405e2017-10-19 15:52:11 -0700489 } else if Bool(sanitize.Properties.Sanitize.Thread) {
490 runtimeLibrary = config.ThreadSanitizerRuntimeLibrary(ctx.toolchain())
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700491 } else if Bool(sanitize.Properties.Sanitize.Scudo) {
492 runtimeLibrary = config.ScudoRuntimeLibrary(ctx.toolchain())
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700493 } else if len(diagSanitizers) > 0 || sanitize.Properties.UbsanRuntimeDep {
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700494 runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain())
495 }
496
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700497 if runtimeLibrary != "" {
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700498 runtimeLibraryPath := "${config.ClangAsanLibDir}/" + runtimeLibrary
499 if !ctx.static() {
500 runtimeLibraryPath = runtimeLibraryPath + ctx.toolchain().ShlibSuffix()
501 } else {
502 runtimeLibraryPath = runtimeLibraryPath + ".a"
503 }
504
Jiyong Park27b188b2017-07-18 13:23:39 +0900505 // ASan runtime library must be the first in the link order.
Ivan Lozanoa9255a82018-03-13 10:41:07 -0700506 flags.libFlags = append([]string{runtimeLibraryPath}, flags.libFlags...)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700507 sanitize.runtimeLibrary = runtimeLibrary
Jiyong Park27b188b2017-07-18 13:23:39 +0900508
509 // When linking against VNDK, use the vendor variant of the runtime lib
510 sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700511 if ctx.useVndk() {
Jiyong Park27b188b2017-07-18 13:23:39 +0900512 sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix
513 }
Evgenii Stepanov1e405e12016-08-16 15:39:54 -0700514 }
515
Colin Cross635c3b02016-05-18 15:37:25 -0700516 blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist)
Colin Cross16b23492016-01-06 14:41:07 -0800517 if blacklist.Valid() {
518 flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String())
519 flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path())
520 }
521
522 return flags
523}
524
Colin Cross8ff9ef42017-05-08 13:44:11 -0700525func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
Colin Cross27a4b052017-08-10 16:32:23 -0700526 ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
Jiyong Park27b188b2017-07-18 13:23:39 +0900527 if sanitize.androidMkRuntimeLibrary != "" {
528 fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary)
Colin Cross8ff9ef42017-05-08 13:44:11 -0700529 }
Colin Cross8ff9ef42017-05-08 13:44:11 -0700530 })
Vishwath Mohane7128792017-11-17 11:08:10 -0800531
532 // Add a suffix for CFI-enabled static libraries to allow surfacing both to make without a
533 // name conflict.
534 if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Cfi) {
535 ret.SubName += ".cfi"
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000536 }
Colin Cross8ff9ef42017-05-08 13:44:11 -0700537}
538
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700539func (sanitize *sanitize) inSanitizerDir() bool {
540 return sanitize.Properties.InSanitizerDir
Colin Cross30d5f512016-05-03 18:02:42 -0700541}
542
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000543func (sanitize *sanitize) getSanitizerBoolPtr(t sanitizerType) *bool {
Vishwath Mohan95229302017-08-11 00:53:16 +0000544 switch t {
545 case asan:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000546 return sanitize.Properties.Sanitize.Address
Vishwath Mohan95229302017-08-11 00:53:16 +0000547 case tsan:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000548 return sanitize.Properties.Sanitize.Thread
Vishwath Mohan95229302017-08-11 00:53:16 +0000549 case intOverflow:
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000550 return sanitize.Properties.Sanitize.Integer_overflow
551 case cfi:
552 return sanitize.Properties.Sanitize.Cfi
Vishwath Mohan95229302017-08-11 00:53:16 +0000553 default:
554 panic(fmt.Errorf("unknown sanitizerType %d", t))
555 }
556}
557
Dan Albert7d1eecf2018-01-19 12:30:45 -0800558func (sanitize *sanitize) isUnsanitizedVariant() bool {
559 return !sanitize.isSanitizerEnabled(asan) &&
560 !sanitize.isSanitizerEnabled(tsan) &&
561 !sanitize.isSanitizerEnabled(cfi)
562}
563
Jayant Chowdharyb7e08ca2018-05-10 15:29:24 -0700564func (sanitize *sanitize) isVariantOnProductionDevice() bool {
565 return !sanitize.isSanitizerEnabled(asan) &&
566 !sanitize.isSanitizerEnabled(tsan)
567}
568
Colin Cross16b23492016-01-06 14:41:07 -0800569func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) {
570 switch t {
571 case asan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700572 sanitize.Properties.Sanitize.Address = boolPtr(b)
Colin Cross91169fe2016-08-11 15:54:20 -0700573 if !b {
574 sanitize.Properties.Sanitize.Coverage = nil
575 }
Colin Cross16b23492016-01-06 14:41:07 -0800576 case tsan:
Evgenii Stepanovfcfe56d2016-07-07 10:54:07 -0700577 sanitize.Properties.Sanitize.Thread = boolPtr(b)
Ivan Lozano0c3a1ef2017-06-28 09:10:48 -0700578 case intOverflow:
579 sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000580 case cfi:
581 sanitize.Properties.Sanitize.Cfi = boolPtr(b)
Colin Cross16b23492016-01-06 14:41:07 -0800582 default:
583 panic(fmt.Errorf("unknown sanitizerType %d", t))
584 }
585 if b {
586 sanitize.Properties.SanitizerEnabled = true
587 }
588}
589
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000590// Check if the sanitizer is explicitly disabled (as opposed to nil by
591// virtue of not being set).
592func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t sanitizerType) bool {
593 if sanitize == nil {
594 return false
595 }
596
597 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
598 return sanitizerVal != nil && *sanitizerVal == false
599}
600
601// There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled)
602// because enabling a sanitizer either directly (via the blueprint) or
603// indirectly (via a mutator) sets the bool ptr to true, and you can't
604// distinguish between the cases. It isn't needed though - both cases can be
605// treated identically.
606func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool {
607 if sanitize == nil {
608 return false
609 }
610
611 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
612 return sanitizerVal != nil && *sanitizerVal == true
613}
614
Colin Cross6b753602018-06-21 13:03:07 -0700615func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
616 t, ok := tag.(dependencyTag)
617 return ok && t.library || t == reuseObjTag
618}
619
Colin Cross16b23492016-01-06 14:41:07 -0800620// Propagate asan requirements down from binaries
Colin Cross635c3b02016-05-18 15:37:25 -0700621func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) {
622 return func(mctx android.TopDownMutatorContext) {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000623 if c, ok := mctx.Module().(*Module); ok && c.sanitize.isSanitizerEnabled(t) {
Colin Cross6b753602018-06-21 13:03:07 -0700624 mctx.WalkDeps(func(child, parent android.Module) bool {
625 if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) {
626 return false
627 }
628 if d, ok := child.(*Module); ok && d.sanitize != nil &&
Nan Zhang0007d812017-11-07 10:57:05 -0800629 !Bool(d.sanitize.Properties.Sanitize.Never) &&
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000630 !d.sanitize.isSanitizerExplicitlyDisabled(t) {
631 if (t == cfi && d.static()) || t != cfi {
632 d.sanitize.Properties.SanitizeDep = true
633 }
Colin Cross16b23492016-01-06 14:41:07 -0800634 }
Colin Cross6b753602018-06-21 13:03:07 -0700635 return true
Colin Cross16b23492016-01-06 14:41:07 -0800636 })
637 }
638 }
639}
640
Ivan Lozano30c5db22018-02-21 15:49:20 -0800641// Propagate the ubsan minimal runtime dependency when there are integer overflow sanitized static dependencies.
Colin Cross6b753602018-06-21 13:03:07 -0700642func sanitizerRuntimeDepsMutator(mctx android.TopDownMutatorContext) {
643 if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil {
644 mctx.WalkDeps(func(child, parent android.Module) bool {
645 if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) {
646 return false
647 }
648 if d, ok := child.(*Module); ok && d.static() && d.sanitize != nil {
Ivan Lozano30c5db22018-02-21 15:49:20 -0800649
Colin Cross6b753602018-06-21 13:03:07 -0700650 if enableMinimalRuntime(d.sanitize) {
651 // If a static dependency is built with the minimal runtime,
652 // make sure we include the ubsan minimal runtime.
653 c.sanitize.Properties.MinimalRuntimeDep = true
654 } else if Bool(d.sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
655 len(d.sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0 {
656 // If a static dependency runs with full ubsan diagnostics,
657 // make sure we include the ubsan runtime.
658 c.sanitize.Properties.UbsanRuntimeDep = true
Ivan Lozano30c5db22018-02-21 15:49:20 -0800659 }
Colin Cross6b753602018-06-21 13:03:07 -0700660 }
661 return true
662 })
Ivan Lozano30c5db22018-02-21 15:49:20 -0800663 }
664}
665
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000666// Create sanitized variants for modules that need them
Colin Cross635c3b02016-05-18 15:37:25 -0700667func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
668 return func(mctx android.BottomUpMutatorContext) {
Vishwath Mohane6153452017-08-11 00:52:44 +0000669 if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000670 if c.isDependencyRoot() && c.sanitize.isSanitizerEnabled(t) {
Colin Cross30d5f512016-05-03 18:02:42 -0700671 modules := mctx.CreateVariations(t.String())
672 modules[0].(*Module).sanitize.SetSanitizer(t, true)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000673 } else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep {
674 // Save original sanitizer status before we assign values to variant
675 // 0 as that overwrites the original.
676 isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t)
677
Colin Crossb0f28952016-09-19 16:46:53 -0700678 modules := mctx.CreateVariations("", t.String())
679 modules[0].(*Module).sanitize.SetSanitizer(t, false)
680 modules[1].(*Module).sanitize.SetSanitizer(t, true)
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000681
Colin Crossb0f28952016-09-19 16:46:53 -0700682 modules[0].(*Module).sanitize.Properties.SanitizeDep = false
683 modules[1].(*Module).sanitize.Properties.SanitizeDep = false
Vishwath Mohane7128792017-11-17 11:08:10 -0800684
685 // We don't need both variants active for anything but CFI-enabled
686 // target static libraries, so suppress the appropriate variant in
687 // all other cases.
688 if t == cfi {
689 if c.static() {
690 if !mctx.Device() {
691 if isSanitizerEnabled {
692 modules[0].(*Module).Properties.PreventInstall = true
693 modules[0].(*Module).Properties.HideFromMake = true
694 } else {
695 modules[1].(*Module).Properties.PreventInstall = true
696 modules[1].(*Module).Properties.HideFromMake = true
697 }
698 } else {
Colin Cross6510f912017-11-29 00:27:14 -0800699 cfiStaticLibs := cfiStaticLibs(mctx.Config())
Vishwath Mohane7128792017-11-17 11:08:10 -0800700
701 cfiStaticLibsMutex.Lock()
702 *cfiStaticLibs = append(*cfiStaticLibs, c.Name())
703 cfiStaticLibsMutex.Unlock()
704 }
705 } else {
706 modules[0].(*Module).Properties.PreventInstall = true
707 modules[0].(*Module).Properties.HideFromMake = true
708 }
709 } else if t == asan {
710 if mctx.Device() {
711 // CFI and ASAN are currently mutually exclusive so disable
712 // CFI if this is an ASAN variant.
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000713 modules[1].(*Module).sanitize.Properties.InSanitizerDir = true
714 modules[1].(*Module).sanitize.SetSanitizer(cfi, false)
715 }
Vishwath Mohane21fe422017-11-01 19:42:45 -0700716 if isSanitizerEnabled {
717 modules[0].(*Module).Properties.PreventInstall = true
Vishwath Mohane7128792017-11-17 11:08:10 -0800718 modules[0].(*Module).Properties.HideFromMake = true
Vishwath Mohane21fe422017-11-01 19:42:45 -0700719 } else {
720 modules[1].(*Module).Properties.PreventInstall = true
Vishwath Mohane7128792017-11-17 11:08:10 -0800721 modules[1].(*Module).Properties.HideFromMake = true
Vishwath Mohane21fe422017-11-01 19:42:45 -0700722 }
723 }
Colin Cross16b23492016-01-06 14:41:07 -0800724 }
725 c.sanitize.Properties.SanitizeDep = false
726 }
727 }
728}
Vishwath Mohane7128792017-11-17 11:08:10 -0800729
730func cfiStaticLibs(config android.Config) *[]string {
731 return config.Once("cfiStaticLibs", func() interface{} {
732 return &[]string{}
733 }).(*[]string)
734}
735
Ivan Lozano30c5db22018-02-21 15:49:20 -0800736func enableMinimalRuntime(sanitize *sanitize) bool {
737 if !Bool(sanitize.Properties.Sanitize.Address) &&
Kostya Kortchinskyd18ae5c2018-06-12 14:46:54 -0700738 !Bool(sanitize.Properties.Sanitize.Scudo) &&
Ivan Lozano30c5db22018-02-21 15:49:20 -0800739 (Bool(sanitize.Properties.Sanitize.Integer_overflow) ||
740 len(sanitize.Properties.Sanitize.Misc_undefined) > 0) &&
741 !(Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) ||
742 Bool(sanitize.Properties.Sanitize.Diag.Cfi) ||
743 len(sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0) {
744 return true
745 }
746 return false
747}
748
Vishwath Mohane7128792017-11-17 11:08:10 -0800749func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
750 cfiStaticLibs := cfiStaticLibs(ctx.Config())
Jeff Gaston72765392017-11-28 16:37:53 -0800751 sort.Strings(*cfiStaticLibs)
Vishwath Mohane7128792017-11-17 11:08:10 -0800752 ctx.Strict("SOONG_CFI_STATIC_LIBRARIES", strings.Join(*cfiStaticLibs, " "))
753}