Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 19 | "io" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 20 | "strings" |
| 21 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 22 | "android/soong/android" |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 23 | "android/soong/cc/config" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 26 | var ( |
| 27 | // Any C flags added by sanitizer which libTooling tools may not |
| 28 | // understand also need to be added to ClangLibToolingUnknownCflags in |
| 29 | // cc/config/clang.go |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 30 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 31 | asanCflags = []string{"-fno-omit-frame-pointer"} |
| 32 | asanLdflags = []string{"-Wl,-u,__asan_preinit"} |
| 33 | asanLibs = []string{"libasan"} |
| 34 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 35 | cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso", |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 36 | "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"} |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 37 | cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi", |
Pirama Arumuga Nainar | bdb17f0 | 2017-08-28 21:50:17 -0700 | [diff] [blame] | 38 | "-Wl,-plugin-opt,O1"} |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 39 | cfiArflags = []string{"--plugin ${config.ClangBin}/../lib64/LLVMgold.so"} |
| 40 | cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map" |
| 41 | cfiExportsMap android.Path |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 42 | |
| 43 | intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"} |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 44 | ) |
| 45 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 46 | type sanitizerType int |
| 47 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 48 | func boolPtr(v bool) *bool { |
| 49 | if v { |
| 50 | return &v |
| 51 | } else { |
| 52 | return nil |
| 53 | } |
| 54 | } |
| 55 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 56 | const ( |
| 57 | asan sanitizerType = iota + 1 |
| 58 | tsan |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 59 | intOverflow |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 60 | cfi |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 61 | ) |
| 62 | |
| 63 | func (t sanitizerType) String() string { |
| 64 | switch t { |
| 65 | case asan: |
| 66 | return "asan" |
| 67 | case tsan: |
| 68 | return "tsan" |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 69 | case intOverflow: |
| 70 | return "intOverflow" |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 71 | case cfi: |
| 72 | return "cfi" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 73 | default: |
| 74 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | type SanitizeProperties struct { |
| 79 | // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer |
| 80 | Sanitize struct { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 81 | Never *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 82 | |
| 83 | // main sanitizers |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 84 | Address *bool `android:"arch_variant"` |
| 85 | Thread *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 86 | |
| 87 | // local sanitizers |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 88 | Undefined *bool `android:"arch_variant"` |
| 89 | All_undefined *bool `android:"arch_variant"` |
| 90 | Misc_undefined []string `android:"arch_variant"` |
| 91 | Coverage *bool `android:"arch_variant"` |
| 92 | Safestack *bool `android:"arch_variant"` |
| 93 | Cfi *bool `android:"arch_variant"` |
| 94 | Integer_overflow *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 95 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 96 | // Sanitizers to run in the diagnostic mode (as opposed to the release mode). |
| 97 | // Replaces abort() on error with a human-readable error message. |
| 98 | // Address and Thread sanitizers always run in diagnostic mode. |
| 99 | Diag struct { |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 100 | Undefined *bool `android:"arch_variant"` |
| 101 | Cfi *bool `android:"arch_variant"` |
| 102 | Integer_overflow *bool `android:"arch_variant"` |
| 103 | Misc_undefined []string `android:"arch_variant"` |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // value to pass to -fsanitize-recover= |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 107 | Recover []string |
| 108 | |
| 109 | // value to pass to -fsanitize-blacklist |
| 110 | Blacklist *string |
| 111 | } `android:"arch_variant"` |
| 112 | |
| 113 | SanitizerEnabled bool `blueprint:"mutated"` |
| 114 | SanitizeDep bool `blueprint:"mutated"` |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 115 | InSanitizerDir bool `blueprint:"mutated"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | type sanitize struct { |
| 119 | Properties SanitizeProperties |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 120 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 121 | runtimeLibrary string |
| 122 | androidMkRuntimeLibrary string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | func (sanitize *sanitize) props() []interface{} { |
| 126 | return []interface{}{&sanitize.Properties} |
| 127 | } |
| 128 | |
| 129 | func (sanitize *sanitize) begin(ctx BaseModuleContext) { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 130 | s := &sanitize.Properties.Sanitize |
| 131 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 132 | // Don't apply sanitizers to NDK code. |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 133 | if ctx.useSdk() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 134 | s.Never = BoolPtr(true) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // Never always wins. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 138 | if Bool(s.Never) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 139 | return |
| 140 | } |
| 141 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 142 | var globalSanitizers []string |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 143 | var globalSanitizersDiag []string |
| 144 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 145 | if ctx.clang() { |
| 146 | if ctx.Host() { |
| 147 | globalSanitizers = ctx.AConfig().SanitizeHost() |
| 148 | } else { |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 149 | arches := ctx.AConfig().SanitizeDeviceArch() |
| 150 | if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) { |
| 151 | globalSanitizers = ctx.AConfig().SanitizeDevice() |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 152 | globalSanitizersDiag = ctx.AConfig().SanitizeDeviceDiag() |
Colin Cross | 23ae82a | 2016-11-02 14:34:39 -0700 | [diff] [blame] | 153 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 157 | if len(globalSanitizers) > 0 { |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 158 | var found bool |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 159 | if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil { |
| 160 | s.All_undefined = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 161 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 162 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 163 | if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil { |
| 164 | s.Undefined = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Evgenii Stepanov | 774cb81 | 2016-12-28 15:52:54 -0800 | [diff] [blame] | 167 | if found, globalSanitizers = removeFromList("address", globalSanitizers); found { |
| 168 | if s.Address == nil { |
| 169 | s.Address = boolPtr(true) |
| 170 | } else if *s.Address == false { |
| 171 | // Coverage w/o address is an error. If globalSanitizers includes both, and the module |
| 172 | // disables address, then disable coverage as well. |
| 173 | _, globalSanitizers = removeFromList("coverage", globalSanitizers) |
| 174 | } |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 177 | if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil { |
| 178 | s.Thread = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 181 | if found, globalSanitizers = removeFromList("coverage", globalSanitizers); found && s.Coverage == nil { |
| 182 | s.Coverage = boolPtr(true) |
| 183 | } |
| 184 | |
| 185 | if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil { |
| 186 | s.Safestack = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 189 | if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame^] | 190 | if !ctx.AConfig().CFIDisabledForPath(ctx.ModuleDir()) { |
| 191 | s.Cfi = boolPtr(true) |
| 192 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 195 | if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 196 | if !ctx.AConfig().IntegerOverflowDisabledForPath(ctx.ModuleDir()) { |
| 197 | s.Integer_overflow = boolPtr(true) |
| 198 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 201 | if len(globalSanitizers) > 0 { |
| 202 | ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0]) |
| 203 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 204 | |
| 205 | if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found && |
| 206 | s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) { |
| 207 | s.Diag.Integer_overflow = boolPtr(true) |
| 208 | } |
| 209 | |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame^] | 210 | if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found && |
| 211 | s.Diag.Cfi == nil && Bool(s.Cfi) { |
| 212 | s.Diag.Cfi = boolPtr(true) |
| 213 | } |
| 214 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 215 | if len(globalSanitizersDiag) > 0 { |
| 216 | ctx.ModuleErrorf("unknown global sanitizer diagnostics option %s", globalSanitizersDiag[0]) |
| 217 | } |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 218 | } |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 219 | |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame^] | 220 | // Enable CFI for all components in the include paths |
| 221 | if s.Cfi == nil && ctx.AConfig().CFIEnabledForPath(ctx.ModuleDir()) { |
| 222 | s.Cfi = boolPtr(true) |
| 223 | if inList("cfi", ctx.AConfig().SanitizeDeviceDiag()) { |
| 224 | s.Diag.Cfi = boolPtr(true) |
| 225 | } |
| 226 | } |
| 227 | |
Evgenii Stepanov | a83fdac | 2017-01-31 18:37:30 -0800 | [diff] [blame] | 228 | // CFI needs gold linker, and mips toolchain does not have one. |
| 229 | if !ctx.AConfig().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 { |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 230 | s.Cfi = nil |
| 231 | s.Diag.Cfi = nil |
| 232 | } |
| 233 | |
Vishwath Mohan | 6d67e6e | 2017-02-07 20:31:41 -0800 | [diff] [blame] | 234 | // Also disable CFI for arm32 until b/35157333 is fixed. |
| 235 | if ctx.Arch().ArchType == android.Arm { |
| 236 | s.Cfi = nil |
| 237 | s.Diag.Cfi = nil |
| 238 | } |
| 239 | |
Vishwath Mohan | 8f4fdd8 | 2017-04-20 07:42:52 -0700 | [diff] [blame] | 240 | // Also disable CFI if ASAN is enabled. |
| 241 | if Bool(s.Address) { |
| 242 | s.Cfi = nil |
| 243 | s.Diag.Cfi = nil |
| 244 | } |
| 245 | |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 246 | if ctx.staticBinary() { |
| 247 | s.Address = nil |
Colin Cross | 91169fe | 2016-08-11 15:54:20 -0700 | [diff] [blame] | 248 | s.Coverage = nil |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 249 | s.Thread = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 252 | if Bool(s.All_undefined) { |
| 253 | s.Undefined = nil |
| 254 | } |
| 255 | |
Evgenii Stepanov | 0a8a0d0 | 2016-05-12 13:54:53 -0700 | [diff] [blame] | 256 | if !ctx.toolchain().Is64Bit() { |
| 257 | // TSAN and SafeStack are not supported on 32-bit architectures |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 258 | s.Thread = nil |
| 259 | s.Safestack = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 260 | // TODO(ccross): error for compile_multilib = "32"? |
| 261 | } |
| 262 | |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 263 | if ctx.Os() != android.Windows && (Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) || Bool(s.Thread) || |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 264 | Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) || Bool(s.Integer_overflow) || len(s.Misc_undefined) > 0) { |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 265 | sanitize.Properties.SanitizerEnabled = true |
| 266 | } |
| 267 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 268 | if Bool(s.Coverage) { |
| 269 | if !Bool(s.Address) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 270 | ctx.ModuleErrorf(`Use of "coverage" also requires "address"`) |
| 271 | } |
| 272 | } |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 273 | |
| 274 | cfiExportsMap = android.PathForSource(ctx, cfiExportsMapPath) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 278 | if !sanitize.Properties.SanitizerEnabled { // || c.static() { |
| 279 | return deps |
| 280 | } |
| 281 | |
| 282 | if ctx.Device() { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 283 | if Bool(sanitize.Properties.Sanitize.Address) { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 284 | deps.StaticLibs = append(deps.StaticLibs, asanLibs...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | return deps |
| 289 | } |
| 290 | |
| 291 | func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { |
| 292 | if !sanitize.Properties.SanitizerEnabled { |
| 293 | return flags |
| 294 | } |
| 295 | |
| 296 | if !ctx.clang() { |
| 297 | ctx.ModuleErrorf("Use of sanitizers requires clang") |
| 298 | } |
| 299 | |
| 300 | var sanitizers []string |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 301 | var diagSanitizers []string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 302 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 303 | if Bool(sanitize.Properties.Sanitize.All_undefined) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 304 | sanitizers = append(sanitizers, "undefined") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 305 | } else { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 306 | if Bool(sanitize.Properties.Sanitize.Undefined) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 307 | sanitizers = append(sanitizers, |
| 308 | "bool", |
| 309 | "integer-divide-by-zero", |
| 310 | "return", |
| 311 | "returns-nonnull-attribute", |
| 312 | "shift-exponent", |
| 313 | "unreachable", |
| 314 | "vla-bound", |
| 315 | // TODO(danalbert): The following checks currently have compiler performance issues. |
| 316 | //"alignment", |
| 317 | //"bounds", |
| 318 | //"enum", |
| 319 | //"float-cast-overflow", |
| 320 | //"float-divide-by-zero", |
| 321 | //"nonnull-attribute", |
| 322 | //"null", |
| 323 | //"shift-base", |
| 324 | //"signed-integer-overflow", |
| 325 | // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on. |
| 326 | // https://llvm.org/PR19302 |
| 327 | // http://reviews.llvm.org/D6974 |
| 328 | // "object-size", |
| 329 | ) |
| 330 | } |
| 331 | sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...) |
| 332 | } |
| 333 | |
Ivan Lozano | 651275b | 2017-06-13 10:24:34 -0700 | [diff] [blame] | 334 | if Bool(sanitize.Properties.Sanitize.Diag.Undefined) { |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 335 | diagSanitizers = append(diagSanitizers, "undefined") |
| 336 | } |
| 337 | |
Ivan Lozano | 651275b | 2017-06-13 10:24:34 -0700 | [diff] [blame] | 338 | diagSanitizers = append(diagSanitizers, sanitize.Properties.Sanitize.Diag.Misc_undefined...) |
| 339 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 340 | if Bool(sanitize.Properties.Sanitize.Address) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 341 | if ctx.Arch().ArchType == android.Arm { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 342 | // Frame pointer based unwinder in ASan requires ARM frame setup. |
| 343 | // TODO: put in flags? |
| 344 | flags.RequiredInstructionSet = "arm" |
| 345 | } |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 346 | flags.CFlags = append(flags.CFlags, asanCflags...) |
| 347 | flags.LdFlags = append(flags.LdFlags, asanLdflags...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 348 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 349 | if ctx.Host() { |
| 350 | // -nodefaultlibs (provided with libc++) prevents the driver from linking |
| 351 | // libraries needed with -fsanitize=address. http://b/18650275 (WAI) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 352 | flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed") |
| 353 | } else { |
| 354 | flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0") |
| 355 | flags.DynamicLinker = "/system/bin/linker_asan" |
| 356 | if flags.Toolchain.Is64Bit() { |
| 357 | flags.DynamicLinker += "64" |
| 358 | } |
| 359 | } |
| 360 | sanitizers = append(sanitizers, "address") |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 361 | diagSanitizers = append(diagSanitizers, "address") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Yabin Cui | 6be405e | 2017-10-19 15:52:11 -0700 | [diff] [blame] | 364 | if Bool(sanitize.Properties.Sanitize.Thread) { |
| 365 | sanitizers = append(sanitizers, "thread") |
| 366 | } |
| 367 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 368 | if Bool(sanitize.Properties.Sanitize.Coverage) { |
Zach Riggle | 06bbd89 | 2017-08-21 17:12:32 -0400 | [diff] [blame] | 369 | flags.CFlags = append(flags.CFlags, "-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 372 | if Bool(sanitize.Properties.Sanitize.Safestack) { |
Evgenii Stepanov | 0a8a0d0 | 2016-05-12 13:54:53 -0700 | [diff] [blame] | 373 | sanitizers = append(sanitizers, "safe-stack") |
| 374 | } |
| 375 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 376 | if Bool(sanitize.Properties.Sanitize.Cfi) { |
Evgenii Stepanov | 7ebf9fa | 2017-01-20 14:13:06 -0800 | [diff] [blame] | 377 | if ctx.Arch().ArchType == android.Arm { |
| 378 | // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up |
| 379 | // to do this on a function basis, so force Thumb on the entire module. |
| 380 | flags.RequiredInstructionSet = "thumb" |
| 381 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 382 | sanitizers = append(sanitizers, "cfi") |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 383 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 384 | flags.CFlags = append(flags.CFlags, cfiCflags...) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 385 | // Only append the default visibility flag if -fvisibility has not already been set |
| 386 | // to hidden. |
| 387 | if !inList("-fvisibility=hidden", flags.CFlags) { |
| 388 | flags.CFlags = append(flags.CFlags, "-fvisibility=default") |
| 389 | } |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 390 | flags.LdFlags = append(flags.LdFlags, cfiLdflags...) |
| 391 | flags.ArFlags = append(flags.ArFlags, cfiArflags...) |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 392 | if Bool(sanitize.Properties.Sanitize.Diag.Cfi) { |
| 393 | diagSanitizers = append(diagSanitizers, "cfi") |
| 394 | } |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 395 | |
| 396 | if ctx.staticBinary() { |
| 397 | _, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags) |
| 398 | _, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags) |
| 399 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 402 | if Bool(sanitize.Properties.Sanitize.Integer_overflow) { |
| 403 | if !ctx.static() { |
| 404 | sanitizers = append(sanitizers, "unsigned-integer-overflow") |
| 405 | sanitizers = append(sanitizers, "signed-integer-overflow") |
| 406 | flags.CFlags = append(flags.CFlags, intOverflowCflags...) |
| 407 | if Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) { |
| 408 | diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow") |
| 409 | diagSanitizers = append(diagSanitizers, "signed-integer-overflow") |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 414 | if len(sanitizers) > 0 { |
| 415 | sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",") |
| 416 | flags.CFlags = append(flags.CFlags, sanitizeArg) |
| 417 | if ctx.Host() { |
| 418 | flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all") |
| 419 | flags.LdFlags = append(flags.LdFlags, sanitizeArg) |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 420 | // Host sanitizers only link symbols in the final executable, so |
| 421 | // there will always be undefined symbols in intermediate libraries. |
| 422 | _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 423 | } else { |
Colin Cross | 263abbd | 2016-07-15 13:10:48 -0700 | [diff] [blame] | 424 | flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 428 | if len(diagSanitizers) > 0 { |
| 429 | flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ",")) |
| 430 | } |
| 431 | // FIXME: enable RTTI if diag + (cfi or vptr) |
| 432 | |
Andreas Gampe | 9707116 | 2017-05-08 13:15:23 -0700 | [diff] [blame] | 433 | if sanitize.Properties.Sanitize.Recover != nil { |
| 434 | flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+ |
| 435 | strings.Join(sanitize.Properties.Sanitize.Recover, ",")) |
| 436 | } |
| 437 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 438 | // Link a runtime library if needed. |
| 439 | runtimeLibrary := "" |
| 440 | if Bool(sanitize.Properties.Sanitize.Address) { |
| 441 | runtimeLibrary = config.AddressSanitizerRuntimeLibrary(ctx.toolchain()) |
Yabin Cui | 6be405e | 2017-10-19 15:52:11 -0700 | [diff] [blame] | 442 | } else if Bool(sanitize.Properties.Sanitize.Thread) { |
| 443 | runtimeLibrary = config.ThreadSanitizerRuntimeLibrary(ctx.toolchain()) |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 444 | } else if len(diagSanitizers) > 0 { |
| 445 | runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain()) |
| 446 | } |
| 447 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 448 | if runtimeLibrary != "" { |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 449 | // ASan runtime library must be the first in the link order. |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 450 | flags.libFlags = append([]string{ |
| 451 | "${config.ClangAsanLibDir}/" + runtimeLibrary + ctx.toolchain().ShlibSuffix(), |
| 452 | }, flags.libFlags...) |
| 453 | sanitize.runtimeLibrary = runtimeLibrary |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 454 | |
| 455 | // When linking against VNDK, use the vendor variant of the runtime lib |
| 456 | sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 457 | if ctx.useVndk() { |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 458 | sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix |
| 459 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 462 | blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 463 | if blacklist.Valid() { |
| 464 | flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String()) |
| 465 | flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path()) |
| 466 | } |
| 467 | |
| 468 | return flags |
| 469 | } |
| 470 | |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 471 | func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 472 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 473 | if sanitize.androidMkRuntimeLibrary != "" { |
| 474 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary) |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 475 | } |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 476 | }) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 477 | if ctx.Target().Os.Class == android.Device { |
| 478 | if Bool(sanitize.Properties.Sanitize.Cfi) { |
| 479 | ret.SubName += ".cfi" |
| 480 | } else if Bool(sanitize.Properties.Sanitize.Address) { |
| 481 | ret.SubName += ".asan" |
| 482 | } |
| 483 | } |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 486 | func (sanitize *sanitize) inSanitizerDir() bool { |
| 487 | return sanitize.Properties.InSanitizerDir |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 490 | func (sanitize *sanitize) getSanitizerBoolPtr(t sanitizerType) *bool { |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 491 | switch t { |
| 492 | case asan: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 493 | return sanitize.Properties.Sanitize.Address |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 494 | case tsan: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 495 | return sanitize.Properties.Sanitize.Thread |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 496 | case intOverflow: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 497 | return sanitize.Properties.Sanitize.Integer_overflow |
| 498 | case cfi: |
| 499 | return sanitize.Properties.Sanitize.Cfi |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 500 | default: |
| 501 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 502 | } |
| 503 | } |
| 504 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 505 | func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) { |
| 506 | switch t { |
| 507 | case asan: |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 508 | sanitize.Properties.Sanitize.Address = boolPtr(b) |
Colin Cross | 91169fe | 2016-08-11 15:54:20 -0700 | [diff] [blame] | 509 | if !b { |
| 510 | sanitize.Properties.Sanitize.Coverage = nil |
| 511 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 512 | case tsan: |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 513 | sanitize.Properties.Sanitize.Thread = boolPtr(b) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 514 | case intOverflow: |
| 515 | sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 516 | case cfi: |
| 517 | sanitize.Properties.Sanitize.Cfi = boolPtr(b) |
| 518 | sanitize.Properties.Sanitize.Diag.Cfi = boolPtr(b) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 519 | default: |
| 520 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 521 | } |
| 522 | if b { |
| 523 | sanitize.Properties.SanitizerEnabled = true |
| 524 | } |
| 525 | } |
| 526 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 527 | // Check if the sanitizer is explicitly disabled (as opposed to nil by |
| 528 | // virtue of not being set). |
| 529 | func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t sanitizerType) bool { |
| 530 | if sanitize == nil { |
| 531 | return false |
| 532 | } |
| 533 | |
| 534 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 535 | return sanitizerVal != nil && *sanitizerVal == false |
| 536 | } |
| 537 | |
| 538 | // There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled) |
| 539 | // because enabling a sanitizer either directly (via the blueprint) or |
| 540 | // indirectly (via a mutator) sets the bool ptr to true, and you can't |
| 541 | // distinguish between the cases. It isn't needed though - both cases can be |
| 542 | // treated identically. |
| 543 | func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool { |
| 544 | if sanitize == nil { |
| 545 | return false |
| 546 | } |
| 547 | |
| 548 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 549 | return sanitizerVal != nil && *sanitizerVal == true |
| 550 | } |
| 551 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 552 | // Propagate asan requirements down from binaries |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 553 | func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) { |
| 554 | return func(mctx android.TopDownMutatorContext) { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 555 | if c, ok := mctx.Module().(*Module); ok && c.sanitize.isSanitizerEnabled(t) { |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 556 | mctx.VisitDepsDepthFirst(func(module android.Module) { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 557 | if d, ok := module.(*Module); ok && d.sanitize != nil && |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 558 | !Bool(d.sanitize.Properties.Sanitize.Never) && |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 559 | !d.sanitize.isSanitizerExplicitlyDisabled(t) { |
| 560 | if (t == cfi && d.static()) || t != cfi { |
| 561 | d.sanitize.Properties.SanitizeDep = true |
| 562 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 563 | } |
| 564 | }) |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 569 | // Create sanitized variants for modules that need them |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 570 | func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { |
| 571 | return func(mctx android.BottomUpMutatorContext) { |
Vishwath Mohan | e615345 | 2017-08-11 00:52:44 +0000 | [diff] [blame] | 572 | if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 573 | if c.isDependencyRoot() && c.sanitize.isSanitizerEnabled(t) { |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 574 | modules := mctx.CreateVariations(t.String()) |
| 575 | modules[0].(*Module).sanitize.SetSanitizer(t, true) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 576 | } else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep { |
| 577 | // Save original sanitizer status before we assign values to variant |
| 578 | // 0 as that overwrites the original. |
| 579 | isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t) |
| 580 | |
Colin Cross | b0f2895 | 2016-09-19 16:46:53 -0700 | [diff] [blame] | 581 | modules := mctx.CreateVariations("", t.String()) |
| 582 | modules[0].(*Module).sanitize.SetSanitizer(t, false) |
| 583 | modules[1].(*Module).sanitize.SetSanitizer(t, true) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 584 | |
Colin Cross | b0f2895 | 2016-09-19 16:46:53 -0700 | [diff] [blame] | 585 | modules[0].(*Module).sanitize.Properties.SanitizeDep = false |
| 586 | modules[1].(*Module).sanitize.Properties.SanitizeDep = false |
Vishwath Mohan | e615345 | 2017-08-11 00:52:44 +0000 | [diff] [blame] | 587 | if mctx.Device() { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 588 | // CFI and ASAN are currently mutually exclusive so disable |
| 589 | // CFI if this is an ASAN variant. |
| 590 | if t == asan { |
| 591 | modules[1].(*Module).sanitize.Properties.InSanitizerDir = true |
| 592 | modules[1].(*Module).sanitize.SetSanitizer(cfi, false) |
| 593 | } |
Orion Hodson | da11d74 | 2017-10-31 17:31:00 +0000 | [diff] [blame] | 594 | } else { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 595 | if mctx.AConfig().EmbeddedInMake() { |
| 596 | if isSanitizerEnabled { |
| 597 | modules[0].(*Module).Properties.HideFromMake = true |
| 598 | } else { |
| 599 | modules[1].(*Module).Properties.HideFromMake = true |
| 600 | } |
| 601 | } |
Orion Hodson | da11d74 | 2017-10-31 17:31:00 +0000 | [diff] [blame] | 602 | } |
Vishwath Mohan | e21fe42 | 2017-11-01 19:42:45 -0700 | [diff] [blame] | 603 | if !mctx.AConfig().EmbeddedInMake() || !mctx.Device() { |
| 604 | if isSanitizerEnabled { |
| 605 | modules[0].(*Module).Properties.PreventInstall = true |
| 606 | } else { |
| 607 | modules[1].(*Module).Properties.PreventInstall = true |
| 608 | } |
| 609 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 610 | } |
| 611 | c.sanitize.Properties.SanitizeDep = false |
| 612 | } |
| 613 | } |
| 614 | } |