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" |
Jeff Gaston | 7276539 | 2017-11-28 16:37:53 -0800 | [diff] [blame] | 20 | "sort" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 21 | "strings" |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 22 | "sync" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 23 | |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint" |
| 25 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 26 | "android/soong/android" |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 27 | "android/soong/cc/config" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 30 | var ( |
| 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 Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 34 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 35 | asanCflags = []string{"-fno-omit-frame-pointer"} |
| 36 | asanLdflags = []string{"-Wl,-u,__asan_preinit"} |
| 37 | asanLibs = []string{"libasan"} |
| 38 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 39 | hwasanCflags = []string{"-mllvm", "-hwasan-with-ifunc=0", "-fno-omit-frame-pointer", "-Wno-frame-larger-than="} |
| 40 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 41 | cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso", |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 42 | "-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"} |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 43 | // -flto and -fvisibility are required by clang when -fsanitize=cfi is |
| 44 | // used, but have no effect on assembly files |
| 45 | cfiAsflags = []string{"-flto", "-fvisibility=default"} |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 46 | cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi", |
Pirama Arumuga Nainar | bdb17f0 | 2017-08-28 21:50:17 -0700 | [diff] [blame] | 47 | "-Wl,-plugin-opt,O1"} |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 48 | cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map" |
| 49 | cfiStaticLibsMutex sync.Mutex |
| 50 | hwasanStaticLibsMutex sync.Mutex |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 51 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 52 | intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"} |
Ivan Lozano | ae6ae1d | 2018-10-08 09:29:39 -0700 | [diff] [blame^] | 53 | minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer,undefined", |
| 54 | "-fno-sanitize-recover=integer,undefined"} |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 55 | ) |
| 56 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 57 | type sanitizerType int |
| 58 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 59 | func boolPtr(v bool) *bool { |
| 60 | if v { |
| 61 | return &v |
| 62 | } else { |
| 63 | return nil |
| 64 | } |
| 65 | } |
| 66 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 67 | const ( |
| 68 | asan sanitizerType = iota + 1 |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 69 | hwasan |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 70 | tsan |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 71 | intOverflow |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 72 | cfi |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 73 | ) |
| 74 | |
| 75 | func (t sanitizerType) String() string { |
| 76 | switch t { |
| 77 | case asan: |
| 78 | return "asan" |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 79 | case hwasan: |
| 80 | return "hwasan" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 81 | case tsan: |
| 82 | return "tsan" |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 83 | case intOverflow: |
| 84 | return "intOverflow" |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 85 | case cfi: |
| 86 | return "cfi" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 87 | default: |
| 88 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | type SanitizeProperties struct { |
| 93 | // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer |
| 94 | Sanitize struct { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 95 | Never *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 96 | |
| 97 | // main sanitizers |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 98 | Address *bool `android:"arch_variant"` |
| 99 | Thread *bool `android:"arch_variant"` |
| 100 | Hwaddress *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 101 | |
| 102 | // local sanitizers |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 103 | Undefined *bool `android:"arch_variant"` |
| 104 | All_undefined *bool `android:"arch_variant"` |
| 105 | Misc_undefined []string `android:"arch_variant"` |
| 106 | Coverage *bool `android:"arch_variant"` |
| 107 | Safestack *bool `android:"arch_variant"` |
| 108 | Cfi *bool `android:"arch_variant"` |
| 109 | Integer_overflow *bool `android:"arch_variant"` |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 110 | Scudo *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 111 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 112 | // Sanitizers to run in the diagnostic mode (as opposed to the release mode). |
| 113 | // Replaces abort() on error with a human-readable error message. |
| 114 | // Address and Thread sanitizers always run in diagnostic mode. |
| 115 | Diag struct { |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 116 | Undefined *bool `android:"arch_variant"` |
| 117 | Cfi *bool `android:"arch_variant"` |
| 118 | Integer_overflow *bool `android:"arch_variant"` |
| 119 | Misc_undefined []string `android:"arch_variant"` |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // value to pass to -fsanitize-recover= |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 123 | Recover []string |
| 124 | |
| 125 | // value to pass to -fsanitize-blacklist |
| 126 | Blacklist *string |
| 127 | } `android:"arch_variant"` |
| 128 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 129 | SanitizerEnabled bool `blueprint:"mutated"` |
| 130 | SanitizeDep bool `blueprint:"mutated"` |
| 131 | MinimalRuntimeDep bool `blueprint:"mutated"` |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 132 | UbsanRuntimeDep bool `blueprint:"mutated"` |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 133 | InSanitizerDir bool `blueprint:"mutated"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | type sanitize struct { |
| 137 | Properties SanitizeProperties |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 138 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 139 | runtimeLibrary string |
| 140 | androidMkRuntimeLibrary string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 143 | func init() { |
| 144 | android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider) |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 145 | android.RegisterMakeVarsProvider(pctx, hwasanMakeVarsProvider) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 148 | func (sanitize *sanitize) props() []interface{} { |
| 149 | return []interface{}{&sanitize.Properties} |
| 150 | } |
| 151 | |
| 152 | func (sanitize *sanitize) begin(ctx BaseModuleContext) { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 153 | s := &sanitize.Properties.Sanitize |
| 154 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 155 | // Don't apply sanitizers to NDK code. |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 156 | if ctx.useSdk() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 157 | s.Never = BoolPtr(true) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Never always wins. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 161 | if Bool(s.Never) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 162 | return |
| 163 | } |
| 164 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 165 | var globalSanitizers []string |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 166 | var globalSanitizersDiag []string |
| 167 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 168 | if ctx.Host() { |
| 169 | if !ctx.Windows() { |
| 170 | globalSanitizers = ctx.Config().SanitizeHost() |
| 171 | } |
| 172 | } else { |
| 173 | arches := ctx.Config().SanitizeDeviceArch() |
| 174 | if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) { |
| 175 | globalSanitizers = ctx.Config().SanitizeDevice() |
| 176 | globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag() |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 180 | if len(globalSanitizers) > 0 { |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 181 | var found bool |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 182 | if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil { |
| 183 | s.All_undefined = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 184 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 185 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 186 | if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil { |
| 187 | s.Undefined = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Evgenii Stepanov | 774cb81 | 2016-12-28 15:52:54 -0800 | [diff] [blame] | 190 | if found, globalSanitizers = removeFromList("address", globalSanitizers); found { |
| 191 | if s.Address == nil { |
| 192 | s.Address = boolPtr(true) |
| 193 | } else if *s.Address == false { |
| 194 | // Coverage w/o address is an error. If globalSanitizers includes both, and the module |
| 195 | // disables address, then disable coverage as well. |
| 196 | _, globalSanitizers = removeFromList("coverage", globalSanitizers) |
| 197 | } |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 200 | if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil { |
| 201 | s.Thread = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 204 | if found, globalSanitizers = removeFromList("coverage", globalSanitizers); found && s.Coverage == nil { |
| 205 | s.Coverage = boolPtr(true) |
| 206 | } |
| 207 | |
| 208 | if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil { |
| 209 | s.Safestack = boolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 212 | if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 213 | if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) { |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 214 | s.Cfi = boolPtr(true) |
| 215 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 218 | // Global integer_overflow builds do not support static libraries. |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 219 | if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil { |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 220 | if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() { |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 221 | s.Integer_overflow = boolPtr(true) |
| 222 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 225 | if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil { |
| 226 | s.Scudo = boolPtr(true) |
| 227 | } |
| 228 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 229 | if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil { |
| 230 | s.Hwaddress = boolPtr(true) |
| 231 | } |
| 232 | |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 233 | if len(globalSanitizers) > 0 { |
| 234 | ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0]) |
| 235 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 236 | |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 237 | // Global integer_overflow builds do not support static library diagnostics. |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 238 | if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found && |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 239 | s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() { |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 240 | s.Diag.Integer_overflow = boolPtr(true) |
| 241 | } |
| 242 | |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 243 | if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found && |
| 244 | s.Diag.Cfi == nil && Bool(s.Cfi) { |
| 245 | s.Diag.Cfi = boolPtr(true) |
| 246 | } |
| 247 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 248 | if len(globalSanitizersDiag) > 0 { |
| 249 | ctx.ModuleErrorf("unknown global sanitizer diagnostics option %s", globalSanitizersDiag[0]) |
| 250 | } |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 251 | } |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 252 | |
Vishwath Mohan | 1c54f66 | 2018-05-24 18:36:18 -0700 | [diff] [blame] | 253 | // Enable CFI for all components in the include paths (for Aarch64 only) |
| 254 | if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && ctx.Arch().ArchType == android.Arm64 { |
Vishwath Mohan | 3af8ee0 | 2018-03-30 02:55:23 +0000 | [diff] [blame] | 255 | s.Cfi = boolPtr(true) |
| 256 | if inList("cfi", ctx.Config().SanitizeDeviceDiag()) { |
| 257 | s.Diag.Cfi = boolPtr(true) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Evgenii Stepanov | a83fdac | 2017-01-31 18:37:30 -0800 | [diff] [blame] | 261 | // CFI needs gold linker, and mips toolchain does not have one. |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 262 | if !ctx.Config().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 { |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 263 | s.Cfi = nil |
| 264 | s.Diag.Cfi = nil |
| 265 | } |
| 266 | |
Vishwath Mohan | 6d67e6e | 2017-02-07 20:31:41 -0800 | [diff] [blame] | 267 | // Also disable CFI for arm32 until b/35157333 is fixed. |
| 268 | if ctx.Arch().ArchType == android.Arm { |
| 269 | s.Cfi = nil |
| 270 | s.Diag.Cfi = nil |
| 271 | } |
| 272 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 273 | // HWASan requires AArch64 hardware feature (top-byte-ignore). |
| 274 | if ctx.Arch().ArchType != android.Arm64 { |
| 275 | s.Hwaddress = nil |
| 276 | } |
| 277 | |
Vishwath Mohan | 8f4fdd8 | 2017-04-20 07:42:52 -0700 | [diff] [blame] | 278 | // Also disable CFI if ASAN is enabled. |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 279 | if Bool(s.Address) || Bool(s.Hwaddress) { |
Vishwath Mohan | 8f4fdd8 | 2017-04-20 07:42:52 -0700 | [diff] [blame] | 280 | s.Cfi = nil |
| 281 | s.Diag.Cfi = nil |
| 282 | } |
| 283 | |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 284 | // Disable sanitizers that depend on the UBSan runtime for host builds. |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 285 | if ctx.Host() { |
| 286 | s.Cfi = nil |
| 287 | s.Diag.Cfi = nil |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 288 | s.Misc_undefined = nil |
| 289 | s.Undefined = nil |
| 290 | s.All_undefined = nil |
| 291 | s.Integer_overflow = nil |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Vishwath Mohan | 9ccbba0 | 2018-05-28 13:54:48 -0700 | [diff] [blame] | 294 | // Also disable CFI for VNDK variants of components |
| 295 | if ctx.isVndk() && ctx.useVndk() { |
Vishwath Mohan | 7589c82 | 2018-05-23 19:29:55 -0700 | [diff] [blame] | 296 | s.Cfi = nil |
| 297 | s.Diag.Cfi = nil |
| 298 | } |
| 299 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 300 | // HWASan ramdisk (which is built from recovery) goes over some bootloader limit. |
| 301 | if ctx.inRecovery() { |
| 302 | s.Hwaddress = nil |
| 303 | } |
| 304 | |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 305 | if ctx.staticBinary() { |
| 306 | s.Address = nil |
Colin Cross | 91169fe | 2016-08-11 15:54:20 -0700 | [diff] [blame] | 307 | s.Coverage = nil |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 308 | s.Thread = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 311 | if Bool(s.All_undefined) { |
| 312 | s.Undefined = nil |
| 313 | } |
| 314 | |
Evgenii Stepanov | 0a8a0d0 | 2016-05-12 13:54:53 -0700 | [diff] [blame] | 315 | if !ctx.toolchain().Is64Bit() { |
| 316 | // TSAN and SafeStack are not supported on 32-bit architectures |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 317 | s.Thread = nil |
| 318 | s.Safestack = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 319 | // TODO(ccross): error for compile_multilib = "32"? |
| 320 | } |
| 321 | |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 322 | if ctx.Os() != android.Windows && (Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) || Bool(s.Thread) || |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 323 | Bool(s.Coverage) || Bool(s.Safestack) || Bool(s.Cfi) || Bool(s.Integer_overflow) || len(s.Misc_undefined) > 0 || |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 324 | Bool(s.Scudo) || Bool(s.Hwaddress)) { |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 325 | sanitize.Properties.SanitizerEnabled = true |
| 326 | } |
| 327 | |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 328 | // Disable Scudo if ASan or TSan is enabled. |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 329 | if Bool(s.Address) || Bool(s.Thread) || Bool(s.Hwaddress) { |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 330 | s.Scudo = nil |
| 331 | } |
| 332 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 333 | if Bool(s.Hwaddress) { |
| 334 | s.Address = nil |
| 335 | s.Thread = nil |
| 336 | } |
| 337 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 338 | if Bool(s.Coverage) { |
| 339 | if !Bool(s.Address) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 340 | ctx.ModuleErrorf(`Use of "coverage" also requires "address"`) |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps { |
| 346 | if !sanitize.Properties.SanitizerEnabled { // || c.static() { |
| 347 | return deps |
| 348 | } |
| 349 | |
| 350 | if ctx.Device() { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 351 | if Bool(sanitize.Properties.Sanitize.Address) { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 352 | deps.StaticLibs = append(deps.StaticLibs, asanLibs...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | return deps |
| 357 | } |
| 358 | |
| 359 | func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { |
Ivan Lozano | 59fdea2 | 2018-05-10 14:17:22 -0700 | [diff] [blame] | 360 | minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a" |
| 361 | minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 362 | |
| 363 | if ctx.Device() && sanitize.Properties.MinimalRuntimeDep { |
| 364 | flags.LdFlags = append(flags.LdFlags, minimalRuntimePath) |
Ivan Lozano | 59fdea2 | 2018-05-10 14:17:22 -0700 | [diff] [blame] | 365 | flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib) |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 366 | } |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 367 | if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 368 | return flags |
| 369 | } |
| 370 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 371 | var sanitizers []string |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 372 | var diagSanitizers []string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 373 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 374 | if Bool(sanitize.Properties.Sanitize.All_undefined) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 375 | sanitizers = append(sanitizers, "undefined") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 376 | } else { |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 377 | if Bool(sanitize.Properties.Sanitize.Undefined) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 378 | sanitizers = append(sanitizers, |
| 379 | "bool", |
| 380 | "integer-divide-by-zero", |
| 381 | "return", |
| 382 | "returns-nonnull-attribute", |
| 383 | "shift-exponent", |
| 384 | "unreachable", |
| 385 | "vla-bound", |
| 386 | // TODO(danalbert): The following checks currently have compiler performance issues. |
| 387 | //"alignment", |
| 388 | //"bounds", |
| 389 | //"enum", |
| 390 | //"float-cast-overflow", |
| 391 | //"float-divide-by-zero", |
| 392 | //"nonnull-attribute", |
| 393 | //"null", |
| 394 | //"shift-base", |
| 395 | //"signed-integer-overflow", |
| 396 | // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on. |
| 397 | // https://llvm.org/PR19302 |
| 398 | // http://reviews.llvm.org/D6974 |
| 399 | // "object-size", |
| 400 | ) |
| 401 | } |
| 402 | sanitizers = append(sanitizers, sanitize.Properties.Sanitize.Misc_undefined...) |
| 403 | } |
| 404 | |
Ivan Lozano | 651275b | 2017-06-13 10:24:34 -0700 | [diff] [blame] | 405 | if Bool(sanitize.Properties.Sanitize.Diag.Undefined) { |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 406 | diagSanitizers = append(diagSanitizers, "undefined") |
| 407 | } |
| 408 | |
Ivan Lozano | 651275b | 2017-06-13 10:24:34 -0700 | [diff] [blame] | 409 | diagSanitizers = append(diagSanitizers, sanitize.Properties.Sanitize.Diag.Misc_undefined...) |
| 410 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 411 | if Bool(sanitize.Properties.Sanitize.Address) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 412 | if ctx.Arch().ArchType == android.Arm { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 413 | // Frame pointer based unwinder in ASan requires ARM frame setup. |
| 414 | // TODO: put in flags? |
| 415 | flags.RequiredInstructionSet = "arm" |
| 416 | } |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 417 | flags.CFlags = append(flags.CFlags, asanCflags...) |
| 418 | flags.LdFlags = append(flags.LdFlags, asanLdflags...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 419 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 420 | if ctx.Host() { |
| 421 | // -nodefaultlibs (provided with libc++) prevents the driver from linking |
| 422 | // libraries needed with -fsanitize=address. http://b/18650275 (WAI) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 423 | flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed") |
| 424 | } else { |
| 425 | flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0") |
| 426 | flags.DynamicLinker = "/system/bin/linker_asan" |
| 427 | if flags.Toolchain.Is64Bit() { |
| 428 | flags.DynamicLinker += "64" |
| 429 | } |
| 430 | } |
| 431 | sanitizers = append(sanitizers, "address") |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 432 | diagSanitizers = append(diagSanitizers, "address") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 435 | if Bool(sanitize.Properties.Sanitize.Hwaddress) { |
| 436 | flags.CFlags = append(flags.CFlags, hwasanCflags...) |
| 437 | sanitizers = append(sanitizers, "hwaddress") |
| 438 | } |
| 439 | |
Yabin Cui | 6be405e | 2017-10-19 15:52:11 -0700 | [diff] [blame] | 440 | if Bool(sanitize.Properties.Sanitize.Thread) { |
| 441 | sanitizers = append(sanitizers, "thread") |
| 442 | } |
| 443 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 444 | if Bool(sanitize.Properties.Sanitize.Coverage) { |
Zach Riggle | 06bbd89 | 2017-08-21 17:12:32 -0400 | [diff] [blame] | 445 | 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] | 446 | } |
| 447 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 448 | if Bool(sanitize.Properties.Sanitize.Safestack) { |
Evgenii Stepanov | 0a8a0d0 | 2016-05-12 13:54:53 -0700 | [diff] [blame] | 449 | sanitizers = append(sanitizers, "safe-stack") |
| 450 | } |
| 451 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 452 | if Bool(sanitize.Properties.Sanitize.Cfi) { |
Evgenii Stepanov | 7ebf9fa | 2017-01-20 14:13:06 -0800 | [diff] [blame] | 453 | if ctx.Arch().ArchType == android.Arm { |
| 454 | // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up |
| 455 | // to do this on a function basis, so force Thumb on the entire module. |
| 456 | flags.RequiredInstructionSet = "thumb" |
| 457 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 458 | sanitizers = append(sanitizers, "cfi") |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 459 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 460 | flags.CFlags = append(flags.CFlags, cfiCflags...) |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 461 | flags.AsFlags = append(flags.AsFlags, cfiAsflags...) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 462 | // Only append the default visibility flag if -fvisibility has not already been set |
| 463 | // to hidden. |
| 464 | if !inList("-fvisibility=hidden", flags.CFlags) { |
| 465 | flags.CFlags = append(flags.CFlags, "-fvisibility=default") |
| 466 | } |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 467 | flags.LdFlags = append(flags.LdFlags, cfiLdflags...) |
Zhizhou Yang | 51be632 | 2018-02-08 18:32:11 -0800 | [diff] [blame] | 468 | flags.ArGoldPlugin = true |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 469 | if Bool(sanitize.Properties.Sanitize.Diag.Cfi) { |
| 470 | diagSanitizers = append(diagSanitizers, "cfi") |
| 471 | } |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 472 | |
| 473 | if ctx.staticBinary() { |
| 474 | _, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags) |
| 475 | _, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags) |
| 476 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 479 | if Bool(sanitize.Properties.Sanitize.Integer_overflow) { |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 480 | sanitizers = append(sanitizers, "unsigned-integer-overflow") |
| 481 | sanitizers = append(sanitizers, "signed-integer-overflow") |
| 482 | flags.CFlags = append(flags.CFlags, intOverflowCflags...) |
| 483 | if Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) { |
| 484 | diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow") |
| 485 | diagSanitizers = append(diagSanitizers, "signed-integer-overflow") |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 489 | if Bool(sanitize.Properties.Sanitize.Scudo) { |
| 490 | sanitizers = append(sanitizers, "scudo") |
| 491 | } |
| 492 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 493 | if len(sanitizers) > 0 { |
| 494 | sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",") |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 495 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 496 | flags.CFlags = append(flags.CFlags, sanitizeArg) |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 497 | flags.AsFlags = append(flags.AsFlags, sanitizeArg) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 498 | if ctx.Host() { |
| 499 | flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all") |
| 500 | flags.LdFlags = append(flags.LdFlags, sanitizeArg) |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 501 | // Host sanitizers only link symbols in the final executable, so |
| 502 | // there will always be undefined symbols in intermediate libraries. |
| 503 | _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 504 | } else { |
Colin Cross | 263abbd | 2016-07-15 13:10:48 -0700 | [diff] [blame] | 505 | flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort") |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 506 | |
| 507 | if enableMinimalRuntime(sanitize) { |
| 508 | flags.CFlags = append(flags.CFlags, strings.Join(minimalRuntimeFlags, " ")) |
| 509 | flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...) |
Ivan Lozano | 59fdea2 | 2018-05-10 14:17:22 -0700 | [diff] [blame] | 510 | flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib) |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 511 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 515 | if len(diagSanitizers) > 0 { |
Ivan Lozano | b7d0f52 | 2018-01-20 01:44:38 +0000 | [diff] [blame] | 516 | flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ",")) |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 517 | } |
| 518 | // FIXME: enable RTTI if diag + (cfi or vptr) |
| 519 | |
Andreas Gampe | 9707116 | 2017-05-08 13:15:23 -0700 | [diff] [blame] | 520 | if sanitize.Properties.Sanitize.Recover != nil { |
| 521 | flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+ |
| 522 | strings.Join(sanitize.Properties.Sanitize.Recover, ",")) |
| 523 | } |
| 524 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 525 | // Link a runtime library if needed. |
| 526 | runtimeLibrary := "" |
| 527 | if Bool(sanitize.Properties.Sanitize.Address) { |
| 528 | runtimeLibrary = config.AddressSanitizerRuntimeLibrary(ctx.toolchain()) |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 529 | } else if Bool(sanitize.Properties.Sanitize.Hwaddress) { |
| 530 | runtimeLibrary = config.HWAddressSanitizerRuntimeLibrary(ctx.toolchain()) |
Yabin Cui | 6be405e | 2017-10-19 15:52:11 -0700 | [diff] [blame] | 531 | } else if Bool(sanitize.Properties.Sanitize.Thread) { |
| 532 | runtimeLibrary = config.ThreadSanitizerRuntimeLibrary(ctx.toolchain()) |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 533 | } else if Bool(sanitize.Properties.Sanitize.Scudo) { |
| 534 | runtimeLibrary = config.ScudoRuntimeLibrary(ctx.toolchain()) |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 535 | } else if len(diagSanitizers) > 0 || sanitize.Properties.UbsanRuntimeDep { |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 536 | runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(ctx.toolchain()) |
| 537 | } |
| 538 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 539 | if runtimeLibrary != "" { |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 540 | runtimeLibraryPath := "${config.ClangAsanLibDir}/" + runtimeLibrary |
| 541 | if !ctx.static() { |
| 542 | runtimeLibraryPath = runtimeLibraryPath + ctx.toolchain().ShlibSuffix() |
| 543 | } else { |
| 544 | runtimeLibraryPath = runtimeLibraryPath + ".a" |
| 545 | } |
| 546 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 547 | // ASan runtime library must be the first in the link order. |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 548 | flags.libFlags = append([]string{runtimeLibraryPath}, flags.libFlags...) |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 549 | sanitize.runtimeLibrary = runtimeLibrary |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 550 | |
| 551 | // When linking against VNDK, use the vendor variant of the runtime lib |
| 552 | sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 553 | if ctx.useVndk() { |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 554 | sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix |
| 555 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 558 | blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 559 | if blacklist.Valid() { |
| 560 | flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String()) |
| 561 | flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path()) |
| 562 | } |
| 563 | |
| 564 | return flags |
| 565 | } |
| 566 | |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 567 | func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { |
Colin Cross | 27a4b05 | 2017-08-10 16:32:23 -0700 | [diff] [blame] | 568 | ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 569 | if sanitize.androidMkRuntimeLibrary != "" { |
| 570 | fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES += "+sanitize.androidMkRuntimeLibrary) |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 571 | } |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 572 | }) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 573 | |
| 574 | // Add a suffix for CFI-enabled static libraries to allow surfacing both to make without a |
| 575 | // name conflict. |
| 576 | if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Cfi) { |
| 577 | ret.SubName += ".cfi" |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 578 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 579 | if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Hwaddress) { |
| 580 | ret.SubName += ".hwasan" |
| 581 | } |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 584 | func (sanitize *sanitize) inSanitizerDir() bool { |
| 585 | return sanitize.Properties.InSanitizerDir |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 588 | func (sanitize *sanitize) getSanitizerBoolPtr(t sanitizerType) *bool { |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 589 | switch t { |
| 590 | case asan: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 591 | return sanitize.Properties.Sanitize.Address |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 592 | case hwasan: |
| 593 | return sanitize.Properties.Sanitize.Hwaddress |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 594 | case tsan: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 595 | return sanitize.Properties.Sanitize.Thread |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 596 | case intOverflow: |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 597 | return sanitize.Properties.Sanitize.Integer_overflow |
| 598 | case cfi: |
| 599 | return sanitize.Properties.Sanitize.Cfi |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 600 | default: |
| 601 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 602 | } |
| 603 | } |
| 604 | |
Dan Albert | 7d1eecf | 2018-01-19 12:30:45 -0800 | [diff] [blame] | 605 | func (sanitize *sanitize) isUnsanitizedVariant() bool { |
| 606 | return !sanitize.isSanitizerEnabled(asan) && |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 607 | !sanitize.isSanitizerEnabled(hwasan) && |
Dan Albert | 7d1eecf | 2018-01-19 12:30:45 -0800 | [diff] [blame] | 608 | !sanitize.isSanitizerEnabled(tsan) && |
| 609 | !sanitize.isSanitizerEnabled(cfi) |
| 610 | } |
| 611 | |
Jayant Chowdhary | b7e08ca | 2018-05-10 15:29:24 -0700 | [diff] [blame] | 612 | func (sanitize *sanitize) isVariantOnProductionDevice() bool { |
| 613 | return !sanitize.isSanitizerEnabled(asan) && |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 614 | !sanitize.isSanitizerEnabled(hwasan) && |
Jayant Chowdhary | b7e08ca | 2018-05-10 15:29:24 -0700 | [diff] [blame] | 615 | !sanitize.isSanitizerEnabled(tsan) |
| 616 | } |
| 617 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 618 | func (sanitize *sanitize) SetSanitizer(t sanitizerType, b bool) { |
| 619 | switch t { |
| 620 | case asan: |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 621 | sanitize.Properties.Sanitize.Address = boolPtr(b) |
Colin Cross | 91169fe | 2016-08-11 15:54:20 -0700 | [diff] [blame] | 622 | if !b { |
| 623 | sanitize.Properties.Sanitize.Coverage = nil |
| 624 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 625 | case hwasan: |
| 626 | sanitize.Properties.Sanitize.Hwaddress = boolPtr(b) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 627 | case tsan: |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 628 | sanitize.Properties.Sanitize.Thread = boolPtr(b) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 629 | case intOverflow: |
| 630 | sanitize.Properties.Sanitize.Integer_overflow = boolPtr(b) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 631 | case cfi: |
| 632 | sanitize.Properties.Sanitize.Cfi = boolPtr(b) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 633 | default: |
| 634 | panic(fmt.Errorf("unknown sanitizerType %d", t)) |
| 635 | } |
| 636 | if b { |
| 637 | sanitize.Properties.SanitizerEnabled = true |
| 638 | } |
| 639 | } |
| 640 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 641 | // Check if the sanitizer is explicitly disabled (as opposed to nil by |
| 642 | // virtue of not being set). |
| 643 | func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t sanitizerType) bool { |
| 644 | if sanitize == nil { |
| 645 | return false |
| 646 | } |
| 647 | |
| 648 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 649 | return sanitizerVal != nil && *sanitizerVal == false |
| 650 | } |
| 651 | |
| 652 | // There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled) |
| 653 | // because enabling a sanitizer either directly (via the blueprint) or |
| 654 | // indirectly (via a mutator) sets the bool ptr to true, and you can't |
| 655 | // distinguish between the cases. It isn't needed though - both cases can be |
| 656 | // treated identically. |
| 657 | func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool { |
| 658 | if sanitize == nil { |
| 659 | return false |
| 660 | } |
| 661 | |
| 662 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 663 | return sanitizerVal != nil && *sanitizerVal == true |
| 664 | } |
| 665 | |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 666 | func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool { |
| 667 | t, ok := tag.(dependencyTag) |
| 668 | return ok && t.library || t == reuseObjTag |
| 669 | } |
| 670 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 671 | // Propagate sanitizer requirements down from binaries |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 672 | func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) { |
| 673 | return func(mctx android.TopDownMutatorContext) { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 674 | if c, ok := mctx.Module().(*Module); ok && c.sanitize.isSanitizerEnabled(t) { |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 675 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 676 | if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) { |
| 677 | return false |
| 678 | } |
| 679 | if d, ok := child.(*Module); ok && d.sanitize != nil && |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 680 | !Bool(d.sanitize.Properties.Sanitize.Never) && |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 681 | !d.sanitize.isSanitizerExplicitlyDisabled(t) { |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 682 | if t == cfi || t == hwasan { |
| 683 | if d.static() { |
| 684 | d.sanitize.Properties.SanitizeDep = true |
| 685 | } |
| 686 | } else { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 687 | d.sanitize.Properties.SanitizeDep = true |
| 688 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 689 | } |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 690 | return true |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 691 | }) |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 696 | // Propagate the ubsan minimal runtime dependency when there are integer overflow sanitized static dependencies. |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 697 | func sanitizerRuntimeDepsMutator(mctx android.TopDownMutatorContext) { |
| 698 | if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { |
| 699 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 700 | if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) { |
| 701 | return false |
| 702 | } |
| 703 | if d, ok := child.(*Module); ok && d.static() && d.sanitize != nil { |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 704 | |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 705 | if enableMinimalRuntime(d.sanitize) { |
| 706 | // If a static dependency is built with the minimal runtime, |
| 707 | // make sure we include the ubsan minimal runtime. |
| 708 | c.sanitize.Properties.MinimalRuntimeDep = true |
| 709 | } else if Bool(d.sanitize.Properties.Sanitize.Diag.Integer_overflow) || |
| 710 | len(d.sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0 { |
| 711 | // If a static dependency runs with full ubsan diagnostics, |
| 712 | // make sure we include the ubsan runtime. |
| 713 | c.sanitize.Properties.UbsanRuntimeDep = true |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 714 | } |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 715 | } |
| 716 | return true |
| 717 | }) |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 721 | // Create sanitized variants for modules that need them |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 722 | func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { |
| 723 | return func(mctx android.BottomUpMutatorContext) { |
Vishwath Mohan | e615345 | 2017-08-11 00:52:44 +0000 | [diff] [blame] | 724 | if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 725 | if c.isDependencyRoot() && c.sanitize.isSanitizerEnabled(t) { |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 726 | modules := mctx.CreateVariations(t.String()) |
| 727 | modules[0].(*Module).sanitize.SetSanitizer(t, true) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 728 | } else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep { |
| 729 | // Save original sanitizer status before we assign values to variant |
| 730 | // 0 as that overwrites the original. |
| 731 | isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t) |
| 732 | |
Colin Cross | b0f2895 | 2016-09-19 16:46:53 -0700 | [diff] [blame] | 733 | modules := mctx.CreateVariations("", t.String()) |
| 734 | modules[0].(*Module).sanitize.SetSanitizer(t, false) |
| 735 | modules[1].(*Module).sanitize.SetSanitizer(t, true) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 736 | |
Colin Cross | b0f2895 | 2016-09-19 16:46:53 -0700 | [diff] [blame] | 737 | modules[0].(*Module).sanitize.Properties.SanitizeDep = false |
| 738 | modules[1].(*Module).sanitize.Properties.SanitizeDep = false |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 739 | |
| 740 | // We don't need both variants active for anything but CFI-enabled |
| 741 | // target static libraries, so suppress the appropriate variant in |
| 742 | // all other cases. |
| 743 | if t == cfi { |
| 744 | if c.static() { |
| 745 | if !mctx.Device() { |
| 746 | if isSanitizerEnabled { |
| 747 | modules[0].(*Module).Properties.PreventInstall = true |
| 748 | modules[0].(*Module).Properties.HideFromMake = true |
| 749 | } else { |
| 750 | modules[1].(*Module).Properties.PreventInstall = true |
| 751 | modules[1].(*Module).Properties.HideFromMake = true |
| 752 | } |
| 753 | } else { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 754 | cfiStaticLibs := cfiStaticLibs(mctx.Config()) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 755 | |
| 756 | cfiStaticLibsMutex.Lock() |
| 757 | *cfiStaticLibs = append(*cfiStaticLibs, c.Name()) |
| 758 | cfiStaticLibsMutex.Unlock() |
| 759 | } |
| 760 | } else { |
| 761 | modules[0].(*Module).Properties.PreventInstall = true |
| 762 | modules[0].(*Module).Properties.HideFromMake = true |
| 763 | } |
| 764 | } else if t == asan { |
| 765 | if mctx.Device() { |
| 766 | // CFI and ASAN are currently mutually exclusive so disable |
| 767 | // CFI if this is an ASAN variant. |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 768 | modules[1].(*Module).sanitize.Properties.InSanitizerDir = true |
| 769 | modules[1].(*Module).sanitize.SetSanitizer(cfi, false) |
| 770 | } |
Vishwath Mohan | e21fe42 | 2017-11-01 19:42:45 -0700 | [diff] [blame] | 771 | if isSanitizerEnabled { |
| 772 | modules[0].(*Module).Properties.PreventInstall = true |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 773 | modules[0].(*Module).Properties.HideFromMake = true |
Vishwath Mohan | e21fe42 | 2017-11-01 19:42:45 -0700 | [diff] [blame] | 774 | } else { |
| 775 | modules[1].(*Module).Properties.PreventInstall = true |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 776 | modules[1].(*Module).Properties.HideFromMake = true |
Vishwath Mohan | e21fe42 | 2017-11-01 19:42:45 -0700 | [diff] [blame] | 777 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 778 | } else if t == hwasan { |
| 779 | if mctx.Device() { |
| 780 | // CFI and HWASAN are currently mutually exclusive so disable |
| 781 | // CFI if this is an HWASAN variant. |
| 782 | modules[1].(*Module).sanitize.SetSanitizer(cfi, false) |
| 783 | } |
| 784 | |
| 785 | if c.static() { |
| 786 | if c.useVndk() { |
| 787 | hwasanVendorStaticLibs := hwasanVendorStaticLibs(mctx.Config()) |
| 788 | hwasanStaticLibsMutex.Lock() |
| 789 | *hwasanVendorStaticLibs = append(*hwasanVendorStaticLibs, c.Name()) |
| 790 | hwasanStaticLibsMutex.Unlock() |
| 791 | } else { |
| 792 | hwasanStaticLibs := hwasanStaticLibs(mctx.Config()) |
| 793 | hwasanStaticLibsMutex.Lock() |
| 794 | *hwasanStaticLibs = append(*hwasanStaticLibs, c.Name()) |
| 795 | hwasanStaticLibsMutex.Unlock() |
| 796 | } |
| 797 | } else { |
| 798 | if isSanitizerEnabled { |
| 799 | modules[0].(*Module).Properties.PreventInstall = true |
| 800 | modules[0].(*Module).Properties.HideFromMake = true |
| 801 | } else { |
| 802 | modules[1].(*Module).Properties.PreventInstall = true |
| 803 | modules[1].(*Module).Properties.HideFromMake = true |
| 804 | } |
| 805 | } |
Vishwath Mohan | e21fe42 | 2017-11-01 19:42:45 -0700 | [diff] [blame] | 806 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 807 | } |
| 808 | c.sanitize.Properties.SanitizeDep = false |
| 809 | } |
| 810 | } |
| 811 | } |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 812 | |
| 813 | func cfiStaticLibs(config android.Config) *[]string { |
| 814 | return config.Once("cfiStaticLibs", func() interface{} { |
| 815 | return &[]string{} |
| 816 | }).(*[]string) |
| 817 | } |
| 818 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 819 | func hwasanStaticLibs(config android.Config) *[]string { |
| 820 | return config.Once("hwasanStaticLibs", func() interface{} { |
| 821 | return &[]string{} |
| 822 | }).(*[]string) |
| 823 | } |
| 824 | |
| 825 | func hwasanVendorStaticLibs(config android.Config) *[]string { |
| 826 | return config.Once("hwasanVendorStaticLibs", func() interface{} { |
| 827 | return &[]string{} |
| 828 | }).(*[]string) |
| 829 | } |
| 830 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 831 | func enableMinimalRuntime(sanitize *sanitize) bool { |
| 832 | if !Bool(sanitize.Properties.Sanitize.Address) && |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 833 | !Bool(sanitize.Properties.Sanitize.Hwaddress) && |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 834 | !Bool(sanitize.Properties.Sanitize.Scudo) && |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 835 | (Bool(sanitize.Properties.Sanitize.Integer_overflow) || |
| 836 | len(sanitize.Properties.Sanitize.Misc_undefined) > 0) && |
| 837 | !(Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) || |
| 838 | Bool(sanitize.Properties.Sanitize.Diag.Cfi) || |
| 839 | len(sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0) { |
| 840 | return true |
| 841 | } |
| 842 | return false |
| 843 | } |
| 844 | |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 845 | func cfiMakeVarsProvider(ctx android.MakeVarsContext) { |
| 846 | cfiStaticLibs := cfiStaticLibs(ctx.Config()) |
Jeff Gaston | 7276539 | 2017-11-28 16:37:53 -0800 | [diff] [blame] | 847 | sort.Strings(*cfiStaticLibs) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 848 | ctx.Strict("SOONG_CFI_STATIC_LIBRARIES", strings.Join(*cfiStaticLibs, " ")) |
| 849 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 850 | |
| 851 | func hwasanMakeVarsProvider(ctx android.MakeVarsContext) { |
| 852 | hwasanStaticLibs := hwasanStaticLibs(ctx.Config()) |
| 853 | sort.Strings(*hwasanStaticLibs) |
| 854 | ctx.Strict("SOONG_HWASAN_STATIC_LIBRARIES", strings.Join(*hwasanStaticLibs, " ")) |
| 855 | |
| 856 | hwasanVendorStaticLibs := hwasanVendorStaticLibs(ctx.Config()) |
| 857 | sort.Strings(*hwasanVendorStaticLibs) |
| 858 | ctx.Strict("SOONG_HWASAN_VENDOR_STATIC_LIBRARIES", strings.Join(*hwasanVendorStaticLibs, " ")) |
| 859 | } |