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" |
Jeff Gaston | 7276539 | 2017-11-28 16:37:53 -0800 | [diff] [blame] | 19 | "sort" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 20 | "strings" |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 21 | "sync" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 22 | |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 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" |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 28 | "android/soong/snapshot" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 31 | var ( |
| 32 | // Any C flags added by sanitizer which libTooling tools may not |
| 33 | // understand also need to be added to ClangLibToolingUnknownCflags in |
| 34 | // cc/config/clang.go |
Vishwath Mohan | f3918d3 | 2017-02-14 07:59:33 -0800 | [diff] [blame] | 35 | |
Yi Kong | 20233a4 | 2019-08-21 01:38:40 -0700 | [diff] [blame] | 36 | asanCflags = []string{ |
| 37 | "-fno-omit-frame-pointer", |
Yi Kong | 20233a4 | 2019-08-21 01:38:40 -0700 | [diff] [blame] | 38 | } |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 39 | asanLdflags = []string{"-Wl,-u,__asan_preinit"} |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 40 | |
Florian Mayer | a998446 | 2023-06-16 16:48:51 -0700 | [diff] [blame] | 41 | // DO NOT ADD MLLVM FLAGS HERE! ADD THEM BELOW TO hwasanCommonFlags. |
Yi Kong | 286abc6 | 2021-11-04 16:14:14 +0800 | [diff] [blame] | 42 | hwasanCflags = []string{ |
| 43 | "-fno-omit-frame-pointer", |
| 44 | "-Wno-frame-larger-than=", |
Evgenii Stepanov | 96fa3dd | 2020-03-27 19:38:42 +0000 | [diff] [blame] | 45 | "-fsanitize-hwaddress-abi=platform", |
Yi Kong | 286abc6 | 2021-11-04 16:14:14 +0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | // ThinLTO performs codegen during link time, thus these flags need to |
| 49 | // passed to both CFLAGS and LDFLAGS. |
| 50 | hwasanCommonflags = []string{ |
Evgenii Stepanov | 64bee4d | 2019-11-22 18:37:10 -0800 | [diff] [blame] | 51 | // The following improves debug location information |
| 52 | // availability at the cost of its accuracy. It increases |
| 53 | // the likelihood of a stack variable's frame offset |
| 54 | // to be recorded in the debug info, which is important |
| 55 | // for the quality of hwasan reports. The downside is a |
| 56 | // higher number of "optimized out" stack variables. |
| 57 | // b/112437883. |
Yi Kong | 286abc6 | 2021-11-04 16:14:14 +0800 | [diff] [blame] | 58 | "-instcombine-lower-dbg-declare=0", |
Mitch Phillips | b1c574f | 2020-06-22 13:28:23 -0700 | [diff] [blame] | 59 | // TODO(b/159343917): HWASan and GlobalISel don't play nicely, and |
| 60 | // GlobalISel is the default at -O0 on aarch64. |
Yi Kong | 286abc6 | 2021-11-04 16:14:14 +0800 | [diff] [blame] | 61 | "--aarch64-enable-global-isel-at-O=-1", |
| 62 | "-fast-isel=false", |
Florian Mayer | a998446 | 2023-06-16 16:48:51 -0700 | [diff] [blame] | 63 | "-hwasan-use-after-scope=1", |
Florian Mayer | c746619 | 2023-06-16 16:50:59 -0700 | [diff] [blame^] | 64 | "-dom-tree-reachability-max-bbs-to-explore=128", |
Evgenii Stepanov | 64bee4d | 2019-11-22 18:37:10 -0800 | [diff] [blame] | 65 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 66 | |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 67 | cfiBlocklistPath = "external/compiler-rt/lib/cfi" |
| 68 | cfiBlocklistFilename = "cfi_blocklist.txt" |
Trevor Radcliffe | f1836e4 | 2023-06-01 21:12:08 +0000 | [diff] [blame] | 69 | cfiEnableFlag = "-fsanitize=cfi" |
Trevor Radcliffe | 9f4b476 | 2023-04-04 20:13:42 +0000 | [diff] [blame] | 70 | cfiCrossDsoFlag = "-fsanitize-cfi-cross-dso" |
| 71 | cfiCflags = []string{"-flto", cfiCrossDsoFlag, |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 72 | "-fsanitize-ignorelist=" + cfiBlocklistPath + "/" + cfiBlocklistFilename} |
Evgenii Stepanov | dbf1d4f | 2018-08-31 12:54:33 -0700 | [diff] [blame] | 73 | // -flto and -fvisibility are required by clang when -fsanitize=cfi is |
| 74 | // used, but have no effect on assembly files |
| 75 | cfiAsflags = []string{"-flto", "-fvisibility=default"} |
Trevor Radcliffe | f1836e4 | 2023-06-01 21:12:08 +0000 | [diff] [blame] | 76 | cfiLdflags = []string{"-flto", cfiCrossDsoFlag, cfiEnableFlag, |
Pirama Arumuga Nainar | bdb17f0 | 2017-08-28 21:50:17 -0700 | [diff] [blame] | 77 | "-Wl,-plugin-opt,O1"} |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 78 | cfiExportsMapPath = "build/soong/cc/config" |
| 79 | cfiExportsMapFilename = "cfi_exports.map" |
| 80 | cfiAssemblySupportFlag = "-fno-sanitize-cfi-canonical-jump-tables" |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 81 | |
Pirama Arumuga Nainar | 582fc2d | 2021-08-27 15:12:56 -0700 | [diff] [blame] | 82 | intOverflowCflags = []string{"-fsanitize-ignorelist=build/soong/cc/config/integer_overflow_blocklist.txt"} |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 83 | |
Peter Collingbourne | bd19db0 | 2019-03-06 10:38:48 -0800 | [diff] [blame] | 84 | minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer,undefined", |
Ivan Lozano | ae6ae1d | 2018-10-08 09:29:39 -0700 | [diff] [blame] | 85 | "-fno-sanitize-recover=integer,undefined"} |
Evgenii Stepanov | 2c6484e | 2019-05-15 12:49:54 -0700 | [diff] [blame] | 86 | hwasanGlobalOptions = []string{"heap_history_size=1023", "stack_history_size=512", |
Christopher Ferris | 2fc8e03 | 2023-01-26 14:19:27 -0800 | [diff] [blame] | 87 | "export_memory_stats=0", "max_malloc_fill_size=131072", "malloc_fill_byte=0"} |
Florian Mayer | 1866bbe | 2023-03-11 01:07:40 +0000 | [diff] [blame] | 88 | memtagStackCommonFlags = []string{"-march=armv8-a+memtag", "-mllvm", "-dom-tree-reachability-max-bbs-to-explore=128"} |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 89 | |
| 90 | hostOnlySanitizeFlags = []string{"-fno-sanitize-recover=all"} |
| 91 | deviceOnlySanitizeFlags = []string{"-fsanitize-trap=all", "-ftrap-function=abort"} |
Dan Willemsen | cbceaab | 2016-10-13 16:44:07 -0700 | [diff] [blame] | 92 | ) |
| 93 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 94 | type SanitizerType int |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 95 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 96 | const ( |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 97 | Asan SanitizerType = iota + 1 |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 98 | Hwasan |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 99 | tsan |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 100 | intOverflow |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 101 | scs |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 102 | Fuzzer |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 103 | Memtag_heap |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 104 | Memtag_stack |
Liz Kammer | 75db931 | 2021-07-07 16:41:50 -0400 | [diff] [blame] | 105 | cfi // cfi is last to prevent it running before incompatible mutators |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 106 | ) |
| 107 | |
Liz Kammer | 75db931 | 2021-07-07 16:41:50 -0400 | [diff] [blame] | 108 | var Sanitizers = []SanitizerType{ |
| 109 | Asan, |
| 110 | Hwasan, |
| 111 | tsan, |
| 112 | intOverflow, |
| 113 | scs, |
| 114 | Fuzzer, |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 115 | Memtag_heap, |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 116 | Memtag_stack, |
Liz Kammer | 75db931 | 2021-07-07 16:41:50 -0400 | [diff] [blame] | 117 | cfi, // cfi is last to prevent it running before incompatible mutators |
| 118 | } |
| 119 | |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 120 | // Name of the sanitizer variation for this sanitizer type |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 121 | func (t SanitizerType) variationName() string { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 122 | switch t { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 123 | case Asan: |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 124 | return "asan" |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 125 | case Hwasan: |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 126 | return "hwasan" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 127 | case tsan: |
| 128 | return "tsan" |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 129 | case intOverflow: |
| 130 | return "intOverflow" |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 131 | case cfi: |
| 132 | return "cfi" |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 133 | case scs: |
| 134 | return "scs" |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 135 | case Memtag_heap: |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 136 | return "memtag_heap" |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 137 | case Memtag_stack: |
| 138 | return "memtag_stack" |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 139 | case Fuzzer: |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 140 | return "fuzzer" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 141 | default: |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 142 | panic(fmt.Errorf("unknown SanitizerType %d", t)) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 146 | // This is the sanitizer names in SANITIZE_[TARGET|HOST] |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 147 | func (t SanitizerType) name() string { |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 148 | switch t { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 149 | case Asan: |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 150 | return "address" |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 151 | case Hwasan: |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 152 | return "hwaddress" |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 153 | case Memtag_heap: |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 154 | return "memtag_heap" |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 155 | case Memtag_stack: |
| 156 | return "memtag_stack" |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 157 | case tsan: |
| 158 | return "thread" |
| 159 | case intOverflow: |
| 160 | return "integer_overflow" |
| 161 | case cfi: |
| 162 | return "cfi" |
| 163 | case scs: |
| 164 | return "shadow-call-stack" |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 165 | case Fuzzer: |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 166 | return "fuzzer" |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 167 | default: |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 168 | panic(fmt.Errorf("unknown SanitizerType %d", t)) |
Jiyong Park | 8222663 | 2019-02-01 10:50:50 +0900 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Liz Kammer | 75db931 | 2021-07-07 16:41:50 -0400 | [diff] [blame] | 172 | func (t SanitizerType) registerMutators(ctx android.RegisterMutatorsContext) { |
| 173 | switch t { |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 174 | case cfi, Hwasan, Asan, tsan, Fuzzer, scs: |
| 175 | sanitizer := &sanitizerSplitMutator{t} |
| 176 | ctx.TopDown(t.variationName()+"_markapexes", sanitizer.markSanitizableApexesMutator) |
| 177 | ctx.Transition(t.variationName(), sanitizer) |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 178 | case Memtag_heap, Memtag_stack, intOverflow: |
Liz Kammer | 75db931 | 2021-07-07 16:41:50 -0400 | [diff] [blame] | 179 | // do nothing |
| 180 | default: |
| 181 | panic(fmt.Errorf("unknown SanitizerType %d", t)) |
| 182 | } |
| 183 | } |
| 184 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 185 | // shouldPropagateToSharedLibraryDeps returns whether a sanitizer type should propagate to share |
| 186 | // dependencies. In most cases, sanitizers only propagate to static dependencies; however, some |
| 187 | // sanitizers also must be enabled for shared libraries for linking. |
| 188 | func (t SanitizerType) shouldPropagateToSharedLibraryDeps() bool { |
| 189 | switch t { |
| 190 | case Fuzzer: |
| 191 | // Typically, shared libs are not split. However, for fuzzer, we split even for shared libs |
| 192 | // because a library sanitized for fuzzer can't be linked from a library that isn't sanitized |
| 193 | // for fuzzer. |
| 194 | return true |
| 195 | default: |
| 196 | return false |
| 197 | } |
| 198 | } |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 199 | func (*Module) SanitizerSupported(t SanitizerType) bool { |
| 200 | switch t { |
| 201 | case Asan: |
| 202 | return true |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 203 | case Hwasan: |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 204 | return true |
| 205 | case tsan: |
| 206 | return true |
| 207 | case intOverflow: |
| 208 | return true |
| 209 | case cfi: |
| 210 | return true |
| 211 | case scs: |
| 212 | return true |
| 213 | case Fuzzer: |
| 214 | return true |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 215 | case Memtag_heap: |
| 216 | return true |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 217 | case Memtag_stack: |
| 218 | return true |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 219 | default: |
| 220 | return false |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // incompatibleWithCfi returns true if a sanitizer is incompatible with CFI. |
| 225 | func (t SanitizerType) incompatibleWithCfi() bool { |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 226 | return t == Asan || t == Fuzzer || t == Hwasan |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 227 | } |
| 228 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 229 | type SanitizeUserProps struct { |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 230 | // Prevent use of any sanitizers on this module |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 231 | Never *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 232 | |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 233 | // ASan (Address sanitizer), incompatible with static binaries. |
| 234 | // Always runs in a diagnostic mode. |
| 235 | // Use of address sanitizer disables cfi sanitizer. |
| 236 | // Hwaddress sanitizer takes precedence over this sanitizer. |
| 237 | Address *bool `android:"arch_variant"` |
| 238 | // TSan (Thread sanitizer), incompatible with static binaries and 32 bit architectures. |
| 239 | // Always runs in a diagnostic mode. |
| 240 | // Use of thread sanitizer disables cfi and scudo sanitizers. |
| 241 | // Hwaddress sanitizer takes precedence over this sanitizer. |
| 242 | Thread *bool `android:"arch_variant"` |
| 243 | // HWASan (Hardware Address sanitizer). |
| 244 | // Use of hwasan sanitizer disables cfi, address, thread, and scudo sanitizers. |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 245 | Hwaddress *bool `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 246 | |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 247 | // Undefined behavior sanitizer |
| 248 | All_undefined *bool `android:"arch_variant"` |
| 249 | // Subset of undefined behavior sanitizer |
| 250 | Undefined *bool `android:"arch_variant"` |
| 251 | // List of specific undefined behavior sanitizers to enable |
| 252 | Misc_undefined []string `android:"arch_variant"` |
| 253 | // Fuzzer, incompatible with static binaries. |
| 254 | Fuzzer *bool `android:"arch_variant"` |
| 255 | // safe-stack sanitizer, incompatible with 32-bit architectures. |
| 256 | Safestack *bool `android:"arch_variant"` |
| 257 | // cfi sanitizer, incompatible with asan, hwasan, fuzzer, or Darwin |
| 258 | Cfi *bool `android:"arch_variant"` |
| 259 | // signed/unsigned integer overflow sanitizer, incompatible with Darwin. |
| 260 | Integer_overflow *bool `android:"arch_variant"` |
| 261 | // scudo sanitizer, incompatible with asan, hwasan, tsan |
| 262 | // This should not be used in Android 11+ : https://source.android.com/devices/tech/debug/scudo |
| 263 | // deprecated |
| 264 | Scudo *bool `android:"arch_variant"` |
Elliott Hughes | e4793bc | 2023-02-09 21:15:47 +0000 | [diff] [blame] | 265 | // shadow-call-stack sanitizer, only available on arm64/riscv64. |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 266 | Scs *bool `android:"arch_variant"` |
| 267 | // Memory-tagging, only available on arm64 |
| 268 | // if diag.memtag unset or false, enables async memory tagging |
Florian Mayer | 00ab5cf | 2022-08-31 18:30:18 +0000 | [diff] [blame] | 269 | Memtag_heap *bool `android:"arch_variant"` |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 270 | // Memory-tagging stack instrumentation, only available on arm64 |
| 271 | // Adds instrumentation to detect stack buffer overflows and use-after-scope using MTE. |
| 272 | Memtag_stack *bool `android:"arch_variant"` |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 273 | |
| 274 | // A modifier for ASAN and HWASAN for write only instrumentation |
| 275 | Writeonly *bool `android:"arch_variant"` |
| 276 | |
| 277 | // Sanitizers to run in the diagnostic mode (as opposed to the release mode). |
| 278 | // Replaces abort() on error with a human-readable error message. |
| 279 | // Address and Thread sanitizers always run in diagnostic mode. |
| 280 | Diag struct { |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 281 | // Undefined behavior sanitizer, diagnostic mode |
| 282 | Undefined *bool `android:"arch_variant"` |
| 283 | // cfi sanitizer, diagnostic mode, incompatible with asan, hwasan, fuzzer, or Darwin |
| 284 | Cfi *bool `android:"arch_variant"` |
| 285 | // signed/unsigned integer overflow sanitizer, diagnostic mode, incompatible with Darwin. |
| 286 | Integer_overflow *bool `android:"arch_variant"` |
| 287 | // Memory-tagging, only available on arm64 |
| 288 | // requires sanitizer.memtag: true |
| 289 | // if set, enables sync memory tagging |
| 290 | Memtag_heap *bool `android:"arch_variant"` |
| 291 | // List of specific undefined behavior sanitizers to enable in diagnostic mode |
| 292 | Misc_undefined []string `android:"arch_variant"` |
| 293 | // List of sanitizers to pass to -fno-sanitize-recover |
| 294 | // results in only the first detected error for these sanitizers being reported and program then |
| 295 | // exits with a non-zero exit code. |
| 296 | No_recover []string `android:"arch_variant"` |
Cindy Zhou | d3fe492 | 2020-12-01 11:14:30 -0800 | [diff] [blame] | 297 | } `android:"arch_variant"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 298 | |
Cindy Zhou | 8cd45de | 2020-11-16 08:41:00 -0800 | [diff] [blame] | 299 | // Sanitizers to run with flag configuration specified |
| 300 | Config struct { |
| 301 | // Enables CFI support flags for assembly-heavy libraries |
| 302 | Cfi_assembly_support *bool `android:"arch_variant"` |
Cindy Zhou | d3fe492 | 2020-12-01 11:14:30 -0800 | [diff] [blame] | 303 | } `android:"arch_variant"` |
Cindy Zhou | 8cd45de | 2020-11-16 08:41:00 -0800 | [diff] [blame] | 304 | |
Liz Kammer | 75b9b40 | 2021-06-25 15:19:27 -0400 | [diff] [blame] | 305 | // List of sanitizers to pass to -fsanitize-recover |
| 306 | // allows execution to continue for these sanitizers to detect multiple errors rather than only |
| 307 | // the first one |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 308 | Recover []string |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 309 | |
Pirama Arumuga Nainar | 582fc2d | 2021-08-27 15:12:56 -0700 | [diff] [blame] | 310 | // value to pass to -fsanitize-ignorelist |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 311 | Blocklist *string |
| 312 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 313 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 314 | type sanitizeMutatedProperties struct { |
| 315 | // Whether sanitizers can be enabled on this module |
| 316 | Never *bool `blueprint:"mutated"` |
| 317 | |
| 318 | // Whether ASan (Address sanitizer) is enabled for this module. |
| 319 | // Hwaddress sanitizer takes precedence over this sanitizer. |
| 320 | Address *bool `blueprint:"mutated"` |
| 321 | // Whether TSan (Thread sanitizer) is enabled for this module |
| 322 | Thread *bool `blueprint:"mutated"` |
| 323 | // Whether HWASan (Hardware Address sanitizer) is enabled for this module |
| 324 | Hwaddress *bool `blueprint:"mutated"` |
| 325 | |
| 326 | // Whether Undefined behavior sanitizer is enabled for this module |
| 327 | All_undefined *bool `blueprint:"mutated"` |
| 328 | // Whether undefined behavior sanitizer subset is enabled for this module |
| 329 | Undefined *bool `blueprint:"mutated"` |
| 330 | // List of specific undefined behavior sanitizers enabled for this module |
| 331 | Misc_undefined []string `blueprint:"mutated"` |
| 332 | // Whether Fuzzeris enabled for this module |
| 333 | Fuzzer *bool `blueprint:"mutated"` |
| 334 | // whether safe-stack sanitizer is enabled for this module |
| 335 | Safestack *bool `blueprint:"mutated"` |
| 336 | // Whether cfi sanitizer is enabled for this module |
| 337 | Cfi *bool `blueprint:"mutated"` |
| 338 | // Whether signed/unsigned integer overflow sanitizer is enabled for this module |
| 339 | Integer_overflow *bool `blueprint:"mutated"` |
| 340 | // Whether scudo sanitizer is enabled for this module |
| 341 | Scudo *bool `blueprint:"mutated"` |
| 342 | // Whether shadow-call-stack sanitizer is enabled for this module. |
| 343 | Scs *bool `blueprint:"mutated"` |
| 344 | // Whether Memory-tagging is enabled for this module |
| 345 | Memtag_heap *bool `blueprint:"mutated"` |
| 346 | // Whether Memory-tagging stack instrumentation is enabled for this module |
| 347 | Memtag_stack *bool `blueprint:"mutated"` |
| 348 | |
| 349 | // Whether a modifier for ASAN and HWASAN for write only instrumentation is enabled for this |
| 350 | // module |
| 351 | Writeonly *bool `blueprint:"mutated"` |
| 352 | |
| 353 | // Sanitizers to run in the diagnostic mode (as opposed to the release mode). |
| 354 | Diag struct { |
| 355 | // Whether Undefined behavior sanitizer, diagnostic mode is enabled for this module |
| 356 | Undefined *bool `blueprint:"mutated"` |
| 357 | // Whether cfi sanitizer, diagnostic mode is enabled for this module |
| 358 | Cfi *bool `blueprint:"mutated"` |
| 359 | // Whether signed/unsigned integer overflow sanitizer, diagnostic mode is enabled for this |
| 360 | // module |
| 361 | Integer_overflow *bool `blueprint:"mutated"` |
| 362 | // Whether Memory-tagging, diagnostic mode is enabled for this module |
| 363 | Memtag_heap *bool `blueprint:"mutated"` |
| 364 | // List of specific undefined behavior sanitizers enabled in diagnostic mode |
| 365 | Misc_undefined []string `blueprint:"mutated"` |
| 366 | } `blueprint:"mutated"` |
| 367 | } |
| 368 | |
Martin Stjernholm | b024957 | 2020-09-15 02:32:35 +0100 | [diff] [blame] | 369 | type SanitizeProperties struct { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 370 | Sanitize SanitizeUserProps `android:"arch_variant"` |
| 371 | SanitizeMutated sanitizeMutatedProperties `blueprint:"mutated"` |
| 372 | |
| 373 | SanitizerEnabled bool `blueprint:"mutated"` |
| 374 | MinimalRuntimeDep bool `blueprint:"mutated"` |
| 375 | BuiltinsDep bool `blueprint:"mutated"` |
| 376 | UbsanRuntimeDep bool `blueprint:"mutated"` |
| 377 | InSanitizerDir bool `blueprint:"mutated"` |
| 378 | Sanitizers []string `blueprint:"mutated"` |
| 379 | DiagSanitizers []string `blueprint:"mutated"` |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | type sanitize struct { |
| 383 | Properties SanitizeProperties |
| 384 | } |
| 385 | |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 386 | // Mark this tag with a check to see if apex dependency check should be skipped |
| 387 | func (t libraryDependencyTag) SkipApexAllowedDependenciesCheck() bool { |
| 388 | return t.skipApexAllowedDependenciesCheck |
| 389 | } |
| 390 | |
| 391 | var _ android.SkipApexAllowedDependenciesCheck = (*libraryDependencyTag)(nil) |
| 392 | |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 393 | var exportedVars = android.NewExportedVariables(pctx) |
| 394 | |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 395 | func init() { |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 396 | exportedVars.ExportStringListStaticVariable("HostOnlySanitizeFlags", hostOnlySanitizeFlags) |
| 397 | exportedVars.ExportStringList("DeviceOnlySanitizeFlags", deviceOnlySanitizeFlags) |
| 398 | |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 399 | // Leave out "-flto" from the slices exported to bazel, as we will use the |
Trevor Radcliffe | 9f4b476 | 2023-04-04 20:13:42 +0000 | [diff] [blame] | 400 | // dedicated LTO feature for this. For C Flags and Linker Flags, also leave |
Trevor Radcliffe | f1836e4 | 2023-06-01 21:12:08 +0000 | [diff] [blame] | 401 | // out the cross DSO flag which will be added separately under the correct conditions. |
| 402 | exportedVars.ExportStringList("CfiCFlags", append(cfiCflags[2:], cfiEnableFlag)) |
Trevor Radcliffe | 9f4b476 | 2023-04-04 20:13:42 +0000 | [diff] [blame] | 403 | exportedVars.ExportStringList("CfiLdFlags", cfiLdflags[2:]) |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 404 | exportedVars.ExportStringList("CfiAsFlags", cfiAsflags[1:]) |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 405 | |
Trevor Radcliffe | 9f4b476 | 2023-04-04 20:13:42 +0000 | [diff] [blame] | 406 | exportedVars.ExportString("CfiCrossDsoFlag", cfiCrossDsoFlag) |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 407 | exportedVars.ExportString("CfiBlocklistPath", cfiBlocklistPath) |
| 408 | exportedVars.ExportString("CfiBlocklistFilename", cfiBlocklistFilename) |
| 409 | exportedVars.ExportString("CfiExportsMapPath", cfiExportsMapPath) |
| 410 | exportedVars.ExportString("CfiExportsMapFilename", cfiExportsMapFilename) |
| 411 | exportedVars.ExportString("CfiAssemblySupportFlag", cfiAssemblySupportFlag) |
| 412 | |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 413 | android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider) |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 414 | android.RegisterMakeVarsProvider(pctx, hwasanMakeVarsProvider) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 417 | func (sanitize *sanitize) props() []interface{} { |
| 418 | return []interface{}{&sanitize.Properties} |
| 419 | } |
| 420 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 421 | func (p *sanitizeMutatedProperties) copyUserPropertiesToMutated(userProps *SanitizeUserProps) { |
| 422 | p.Never = userProps.Never |
| 423 | p.Address = userProps.Address |
| 424 | p.All_undefined = userProps.All_undefined |
| 425 | p.Cfi = userProps.Cfi |
| 426 | p.Fuzzer = userProps.Fuzzer |
| 427 | p.Hwaddress = userProps.Hwaddress |
| 428 | p.Integer_overflow = userProps.Integer_overflow |
| 429 | p.Memtag_heap = userProps.Memtag_heap |
| 430 | p.Memtag_stack = userProps.Memtag_stack |
| 431 | p.Safestack = userProps.Safestack |
| 432 | p.Scs = userProps.Scs |
| 433 | p.Scudo = userProps.Scudo |
| 434 | p.Thread = userProps.Thread |
| 435 | p.Undefined = userProps.Undefined |
| 436 | p.Writeonly = userProps.Writeonly |
| 437 | |
| 438 | p.Misc_undefined = make([]string, 0, len(userProps.Misc_undefined)) |
| 439 | for _, v := range userProps.Misc_undefined { |
| 440 | p.Misc_undefined = append(p.Misc_undefined, v) |
| 441 | } |
| 442 | |
| 443 | p.Diag.Cfi = userProps.Diag.Cfi |
| 444 | p.Diag.Integer_overflow = userProps.Diag.Integer_overflow |
| 445 | p.Diag.Memtag_heap = userProps.Diag.Memtag_heap |
| 446 | p.Diag.Undefined = userProps.Diag.Undefined |
| 447 | |
| 448 | p.Diag.Misc_undefined = make([]string, 0, len(userProps.Diag.Misc_undefined)) |
| 449 | for _, v := range userProps.Diag.Misc_undefined { |
| 450 | p.Diag.Misc_undefined = append(p.Diag.Misc_undefined, v) |
| 451 | } |
| 452 | } |
| 453 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 454 | func (sanitize *sanitize) begin(ctx BaseModuleContext) { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 455 | s := &sanitize.Properties.SanitizeMutated |
| 456 | s.copyUserPropertiesToMutated(&sanitize.Properties.Sanitize) |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 457 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 458 | // Don't apply sanitizers to NDK code. |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 459 | if ctx.useSdk() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 460 | s.Never = BoolPtr(true) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // Never always wins. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 464 | if Bool(s.Never) { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 465 | return |
| 466 | } |
| 467 | |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 468 | // cc_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {memtag_heap: false}). |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 469 | if ctx.testBinary() { |
| 470 | if s.Memtag_heap == nil { |
| 471 | s.Memtag_heap = proptools.BoolPtr(true) |
| 472 | } |
| 473 | if s.Diag.Memtag_heap == nil { |
| 474 | s.Diag.Memtag_heap = proptools.BoolPtr(true) |
| 475 | } |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 478 | var globalSanitizers []string |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 479 | var globalSanitizersDiag []string |
| 480 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 481 | if ctx.Host() { |
| 482 | if !ctx.Windows() { |
| 483 | globalSanitizers = ctx.Config().SanitizeHost() |
| 484 | } |
| 485 | } else { |
| 486 | arches := ctx.Config().SanitizeDeviceArch() |
| 487 | if len(arches) == 0 || inList(ctx.Arch().ArchType.Name, arches) { |
| 488 | globalSanitizers = ctx.Config().SanitizeDevice() |
| 489 | globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag() |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 493 | if len(globalSanitizers) > 0 { |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 494 | var found bool |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 495 | if found, globalSanitizers = removeFromList("undefined", globalSanitizers); found && s.All_undefined == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 496 | s.All_undefined = proptools.BoolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 497 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 498 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 499 | if found, globalSanitizers = removeFromList("default-ub", globalSanitizers); found && s.Undefined == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 500 | s.Undefined = proptools.BoolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 503 | if found, globalSanitizers = removeFromList("address", globalSanitizers); found && s.Address == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 504 | s.Address = proptools.BoolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 507 | if found, globalSanitizers = removeFromList("thread", globalSanitizers); found && s.Thread == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 508 | s.Thread = proptools.BoolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 511 | if found, globalSanitizers = removeFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 512 | s.Fuzzer = proptools.BoolPtr(true) |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | if found, globalSanitizers = removeFromList("safe-stack", globalSanitizers); found && s.Safestack == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 516 | s.Safestack = proptools.BoolPtr(true) |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 519 | if found, globalSanitizers = removeFromList("cfi", globalSanitizers); found && s.Cfi == nil { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 520 | if !ctx.Config().CFIDisabledForPath(ctx.ModuleDir()) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 521 | s.Cfi = proptools.BoolPtr(true) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 522 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 525 | // Global integer_overflow builds do not support static libraries. |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 526 | if found, globalSanitizers = removeFromList("integer_overflow", globalSanitizers); found && s.Integer_overflow == nil { |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 527 | if !ctx.Config().IntegerOverflowDisabledForPath(ctx.ModuleDir()) && !ctx.static() { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 528 | s.Integer_overflow = proptools.BoolPtr(true) |
Ivan Lozano | 5f59553 | 2017-07-13 14:46:05 -0700 | [diff] [blame] | 529 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 532 | if found, globalSanitizers = removeFromList("scudo", globalSanitizers); found && s.Scudo == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 533 | s.Scudo = proptools.BoolPtr(true) |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 536 | if found, globalSanitizers = removeFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 537 | s.Hwaddress = proptools.BoolPtr(true) |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 540 | if found, globalSanitizers = removeFromList("writeonly", globalSanitizers); found && s.Writeonly == nil { |
| 541 | // Hwaddress and Address are set before, so we can check them here |
| 542 | // If they aren't explicitly set in the blueprint/SANITIZE_(HOST|TARGET), they would be nil instead of false |
| 543 | if s.Address == nil && s.Hwaddress == nil { |
| 544 | ctx.ModuleErrorf("writeonly modifier cannot be used without 'address' or 'hwaddress'") |
| 545 | } |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 546 | s.Writeonly = proptools.BoolPtr(true) |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 547 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 548 | if found, globalSanitizers = removeFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil { |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 549 | if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 550 | s.Memtag_heap = proptools.BoolPtr(true) |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 551 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 552 | } |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 553 | |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 554 | if found, globalSanitizers = removeFromList("memtag_stack", globalSanitizers); found && s.Memtag_stack == nil { |
| 555 | s.Memtag_stack = proptools.BoolPtr(true) |
| 556 | } |
| 557 | |
Evgenii Stepanov | 05bafd3 | 2016-07-07 17:38:41 +0000 | [diff] [blame] | 558 | if len(globalSanitizers) > 0 { |
| 559 | ctx.ModuleErrorf("unknown global sanitizer option %s", globalSanitizers[0]) |
| 560 | } |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 561 | |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 562 | // Global integer_overflow builds do not support static library diagnostics. |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 563 | if found, globalSanitizersDiag = removeFromList("integer_overflow", globalSanitizersDiag); found && |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 564 | s.Diag.Integer_overflow == nil && Bool(s.Integer_overflow) && !ctx.static() { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 565 | s.Diag.Integer_overflow = proptools.BoolPtr(true) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 568 | if found, globalSanitizersDiag = removeFromList("cfi", globalSanitizersDiag); found && |
| 569 | s.Diag.Cfi == nil && Bool(s.Cfi) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 570 | s.Diag.Cfi = proptools.BoolPtr(true) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 573 | if found, globalSanitizersDiag = removeFromList("memtag_heap", globalSanitizersDiag); found && |
| 574 | s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 575 | s.Diag.Memtag_heap = proptools.BoolPtr(true) |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 578 | if len(globalSanitizersDiag) > 0 { |
| 579 | ctx.ModuleErrorf("unknown global sanitizer diagnostics option %s", globalSanitizersDiag[0]) |
| 580 | } |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 581 | } |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 582 | |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 583 | // Enable Memtag for all components in the include paths (for Aarch64 only) |
Colin Cross | 88a029f | 2022-06-23 14:51:20 -0700 | [diff] [blame] | 584 | if ctx.Arch().ArchType == android.Arm64 && ctx.toolchain().Bionic() { |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 585 | if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 586 | if s.Memtag_heap == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 587 | s.Memtag_heap = proptools.BoolPtr(true) |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 588 | } |
| 589 | if s.Diag.Memtag_heap == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 590 | s.Diag.Memtag_heap = proptools.BoolPtr(true) |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 591 | } |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 592 | } else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) { |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 593 | if s.Memtag_heap == nil { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 594 | s.Memtag_heap = proptools.BoolPtr(true) |
Evgenii Stepanov | 04896ca | 2021-01-12 18:28:33 -0800 | [diff] [blame] | 595 | } |
Evgenii Stepanov | 4beaa0c | 2021-01-05 16:41:26 -0800 | [diff] [blame] | 596 | } |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Hang Lu | a98aab9 | 2023-03-17 13:17:22 +0800 | [diff] [blame] | 599 | // Enable HWASan for all components in the include paths (for Aarch64 only) |
| 600 | if s.Hwaddress == nil && ctx.Config().HWASanEnabledForPath(ctx.ModuleDir()) && |
| 601 | ctx.Arch().ArchType == android.Arm64 && ctx.toolchain().Bionic() { |
| 602 | s.Hwaddress = proptools.BoolPtr(true) |
| 603 | } |
| 604 | |
Elvis Chien | 9c99354 | 2021-06-25 01:15:17 +0800 | [diff] [blame] | 605 | // Enable CFI for non-host components in the include paths |
| 606 | if s.Cfi == nil && ctx.Config().CFIEnabledForPath(ctx.ModuleDir()) && !ctx.Host() { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 607 | s.Cfi = proptools.BoolPtr(true) |
Vishwath Mohan | 3af8ee0 | 2018-03-30 02:55:23 +0000 | [diff] [blame] | 608 | if inList("cfi", ctx.Config().SanitizeDeviceDiag()) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 609 | s.Diag.Cfi = proptools.BoolPtr(true) |
Vishwath Mohan | 1fa3ac5 | 2017-10-31 02:26:14 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Elliott Hughes | da3a071 | 2020-03-06 16:55:28 -0800 | [diff] [blame] | 613 | // Is CFI actually enabled? |
| 614 | if !ctx.Config().EnableCFI() { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 615 | s.Cfi = nil |
| 616 | s.Diag.Cfi = nil |
Vishwath Mohan | 1b017a7 | 2017-01-19 13:54:55 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 619 | // HWASan requires AArch64 hardware feature (top-byte-ignore). |
Colin Cross | 88a029f | 2022-06-23 14:51:20 -0700 | [diff] [blame] | 620 | if ctx.Arch().ArchType != android.Arm64 || !ctx.toolchain().Bionic() { |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 621 | s.Hwaddress = nil |
| 622 | } |
| 623 | |
Elliott Hughes | e4793bc | 2023-02-09 21:15:47 +0000 | [diff] [blame] | 624 | // SCS is only implemented on AArch64/riscv64. |
| 625 | if (ctx.Arch().ArchType != android.Arm64 && ctx.Arch().ArchType != android.Riscv64) || !ctx.toolchain().Bionic() { |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 626 | s.Scs = nil |
| 627 | } |
Elliott Hughes | 5beb42f | 2023-04-12 13:08:58 -0700 | [diff] [blame] | 628 | // ...but temporarily globally disabled on riscv64 (http://b/277909695). |
| 629 | if ctx.Arch().ArchType == android.Riscv64 { |
| 630 | s.Scs = nil |
| 631 | } |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 632 | |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 633 | // Memtag_heap is only implemented on AArch64. |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 634 | // Memtag ABI is Android specific for now, so disable for host. |
| 635 | if ctx.Arch().ArchType != android.Arm64 || !ctx.toolchain().Bionic() || ctx.Host() { |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 636 | s.Memtag_heap = nil |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 637 | s.Memtag_stack = nil |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Vishwath Mohan | 8f4fdd8 | 2017-04-20 07:42:52 -0700 | [diff] [blame] | 640 | // Also disable CFI if ASAN is enabled. |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 641 | if Bool(s.Address) || Bool(s.Hwaddress) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 642 | s.Cfi = nil |
| 643 | s.Diag.Cfi = nil |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 644 | // HWASAN and ASAN win against MTE. |
| 645 | s.Memtag_heap = nil |
| 646 | s.Memtag_stack = nil |
Vishwath Mohan | 8f4fdd8 | 2017-04-20 07:42:52 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Colin Cross | ed12a04 | 2022-02-07 13:55:55 -0800 | [diff] [blame] | 649 | // Disable sanitizers that depend on the UBSan runtime for windows/darwin builds. |
| 650 | if !ctx.Os().Linux() { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 651 | s.Cfi = nil |
| 652 | s.Diag.Cfi = nil |
Ivan Lozano | a9255a8 | 2018-03-13 10:41:07 -0700 | [diff] [blame] | 653 | s.Misc_undefined = nil |
| 654 | s.Undefined = nil |
| 655 | s.All_undefined = nil |
| 656 | s.Integer_overflow = nil |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Aditya Kumar | 1281b99 | 2023-05-16 01:15:24 +0000 | [diff] [blame] | 659 | // TODO(b/254713216): CFI doesn't work for riscv64 yet because LTO doesn't work. |
| 660 | if ctx.Arch().ArchType == android.Riscv64 { |
| 661 | s.Cfi = nil |
| 662 | s.Diag.Cfi = nil |
| 663 | } |
| 664 | |
Colin Cross | ed12a04 | 2022-02-07 13:55:55 -0800 | [diff] [blame] | 665 | // Disable CFI for musl |
| 666 | if ctx.toolchain().Musl() { |
| 667 | s.Cfi = nil |
| 668 | s.Diag.Cfi = nil |
| 669 | } |
| 670 | |
Colin Cross | 390fc74 | 2023-05-02 13:02:51 -0700 | [diff] [blame] | 671 | // TODO(b/280478629): runtimes don't exist for musl arm64 yet. |
| 672 | if ctx.toolchain().Musl() && ctx.Arch().ArchType == android.Arm64 { |
| 673 | s.Address = nil |
| 674 | s.Hwaddress = nil |
| 675 | s.Thread = nil |
| 676 | s.Scudo = nil |
| 677 | s.Fuzzer = nil |
| 678 | s.Cfi = nil |
| 679 | s.Diag.Cfi = nil |
| 680 | s.Misc_undefined = nil |
| 681 | s.Undefined = nil |
| 682 | s.All_undefined = nil |
| 683 | s.Integer_overflow = nil |
| 684 | } |
| 685 | |
Vishwath Mohan | 9ccbba0 | 2018-05-28 13:54:48 -0700 | [diff] [blame] | 686 | // Also disable CFI for VNDK variants of components |
| 687 | if ctx.isVndk() && ctx.useVndk() { |
Justin Yun | 08270c6 | 2022-12-19 17:01:26 +0900 | [diff] [blame] | 688 | s.Cfi = nil |
| 689 | s.Diag.Cfi = nil |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 690 | } |
| 691 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 692 | // HWASan ramdisk (which is built from recovery) goes over some bootloader limit. |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 693 | // Keep libc instrumented so that ramdisk / vendor_ramdisk / recovery can run hwasan-instrumented code if necessary. |
| 694 | if (ctx.inRamdisk() || ctx.inVendorRamdisk() || ctx.inRecovery()) && !strings.HasPrefix(ctx.ModuleDir(), "bionic/libc") { |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 695 | s.Hwaddress = nil |
| 696 | } |
| 697 | |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 698 | if ctx.staticBinary() { |
| 699 | s.Address = nil |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 700 | s.Fuzzer = nil |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 701 | s.Thread = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 704 | if Bool(s.All_undefined) { |
| 705 | s.Undefined = nil |
| 706 | } |
| 707 | |
Evgenii Stepanov | 0a8a0d0 | 2016-05-12 13:54:53 -0700 | [diff] [blame] | 708 | if !ctx.toolchain().Is64Bit() { |
| 709 | // TSAN and SafeStack are not supported on 32-bit architectures |
Evgenii Stepanov | fcfe56d | 2016-07-07 10:54:07 -0700 | [diff] [blame] | 710 | s.Thread = nil |
| 711 | s.Safestack = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 712 | // TODO(ccross): error for compile_multilib = "32"? |
| 713 | } |
| 714 | |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 715 | if ctx.Os() != android.Windows && (Bool(s.All_undefined) || Bool(s.Undefined) || Bool(s.Address) || Bool(s.Thread) || |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 716 | Bool(s.Fuzzer) || Bool(s.Safestack) || Bool(s.Cfi) || Bool(s.Integer_overflow) || len(s.Misc_undefined) > 0 || |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 717 | Bool(s.Scudo) || Bool(s.Hwaddress) || Bool(s.Scs) || Bool(s.Memtag_heap) || Bool(s.Memtag_stack)) { |
Colin Cross | 3c344ef | 2016-07-18 15:44:56 -0700 | [diff] [blame] | 718 | sanitize.Properties.SanitizerEnabled = true |
| 719 | } |
| 720 | |
Kostya Kortchinsky | d5275c8 | 2019-02-01 08:42:56 -0800 | [diff] [blame] | 721 | // Disable Scudo if ASan or TSan is enabled, or if it's disabled globally. |
| 722 | if Bool(s.Address) || Bool(s.Thread) || Bool(s.Hwaddress) || ctx.Config().DisableScudo() { |
Kostya Kortchinsky | d18ae5c | 2018-06-12 14:46:54 -0700 | [diff] [blame] | 723 | s.Scudo = nil |
| 724 | } |
| 725 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 726 | if Bool(s.Hwaddress) { |
| 727 | s.Address = nil |
| 728 | s.Thread = nil |
| 729 | } |
Mitch Phillips | 5007c4a | 2022-03-02 01:25:22 +0000 | [diff] [blame] | 730 | |
| 731 | // TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is |
| 732 | // mutually incompatible. |
| 733 | if Bool(s.Fuzzer) { |
| 734 | s.Cfi = nil |
| 735 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Chih-Hung Hsieh | 3567e62 | 2018-11-15 14:01:36 -0800 | [diff] [blame] | 738 | func toDisableImplicitIntegerChange(flags []string) bool { |
| 739 | // Returns true if any flag is fsanitize*integer, and there is |
| 740 | // no explicit flag about sanitize=implicit-integer-sign-change. |
| 741 | for _, f := range flags { |
| 742 | if strings.Contains(f, "sanitize=implicit-integer-sign-change") { |
| 743 | return false |
| 744 | } |
| 745 | } |
| 746 | for _, f := range flags { |
| 747 | if strings.HasPrefix(f, "-fsanitize") && strings.Contains(f, "integer") { |
| 748 | return true |
| 749 | } |
| 750 | } |
| 751 | return false |
| 752 | } |
| 753 | |
Yabin Cui | db7dda8 | 2020-11-30 15:47:45 -0800 | [diff] [blame] | 754 | func toDisableUnsignedShiftBaseChange(flags []string) bool { |
| 755 | // Returns true if any flag is fsanitize*integer, and there is |
| 756 | // no explicit flag about sanitize=unsigned-shift-base. |
| 757 | for _, f := range flags { |
| 758 | if strings.Contains(f, "sanitize=unsigned-shift-base") { |
| 759 | return false |
| 760 | } |
| 761 | } |
| 762 | for _, f := range flags { |
| 763 | if strings.HasPrefix(f, "-fsanitize") && strings.Contains(f, "integer") { |
| 764 | return true |
| 765 | } |
| 766 | } |
| 767 | return false |
| 768 | } |
| 769 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 770 | func (s *sanitize) flags(ctx ModuleContext, flags Flags) Flags { |
| 771 | if !s.Properties.SanitizerEnabled && !s.Properties.UbsanRuntimeDep { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 772 | return flags |
| 773 | } |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 774 | sanProps := &s.Properties.SanitizeMutated |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 775 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 776 | if Bool(sanProps.Address) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 777 | if ctx.Arch().ArchType == android.Arm { |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 778 | // Frame pointer based unwinder in ASan requires ARM frame setup. |
| 779 | // TODO: put in flags? |
| 780 | flags.RequiredInstructionSet = "arm" |
| 781 | } |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 782 | flags.Local.CFlags = append(flags.Local.CFlags, asanCflags...) |
| 783 | flags.Local.LdFlags = append(flags.Local.LdFlags, asanLdflags...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 784 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 785 | if Bool(sanProps.Writeonly) { |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 786 | flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-asan-instrument-reads=0") |
| 787 | } |
| 788 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 789 | if ctx.Host() { |
| 790 | // -nodefaultlibs (provided with libc++) prevents the driver from linking |
| 791 | // libraries needed with -fsanitize=address. http://b/18650275 (WAI) |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 792 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-as-needed") |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 793 | } else { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 794 | flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-asan-globals=0") |
Jiyong Park | a2aca28 | 2019-02-02 13:13:38 +0900 | [diff] [blame] | 795 | if ctx.bootstrap() { |
| 796 | flags.DynamicLinker = "/system/bin/bootstrap/linker_asan" |
| 797 | } else { |
| 798 | flags.DynamicLinker = "/system/bin/linker_asan" |
| 799 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 800 | if flags.Toolchain.Is64Bit() { |
| 801 | flags.DynamicLinker += "64" |
| 802 | } |
| 803 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 804 | } |
| 805 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 806 | if Bool(sanProps.Hwaddress) { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 807 | flags.Local.CFlags = append(flags.Local.CFlags, hwasanCflags...) |
Yi Kong | 286abc6 | 2021-11-04 16:14:14 +0800 | [diff] [blame] | 808 | |
| 809 | for _, flag := range hwasanCommonflags { |
| 810 | flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", flag) |
| 811 | } |
| 812 | for _, flag := range hwasanCommonflags { |
| 813 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm,"+flag) |
| 814 | } |
| 815 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 816 | if Bool(sanProps.Writeonly) { |
Jasraj Bedi | bb4511d | 2020-07-23 22:58:17 +0000 | [diff] [blame] | 817 | flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-hwasan-instrument-reads=0") |
| 818 | } |
Florian Mayer | 95cd6db | 2023-03-23 17:48:07 -0700 | [diff] [blame] | 819 | if !ctx.staticBinary() && !ctx.Host() { |
| 820 | if ctx.bootstrap() { |
| 821 | flags.DynamicLinker = "/system/bin/bootstrap/linker_hwasan64" |
| 822 | } else { |
| 823 | flags.DynamicLinker = "/system/bin/linker_hwasan64" |
| 824 | } |
| 825 | } |
Yabin Cui | 6be405e | 2017-10-19 15:52:11 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 828 | if Bool(sanProps.Fuzzer) { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 829 | flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize=fuzzer-no-link") |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 830 | |
Mitch Phillips | 5007c4a | 2022-03-02 01:25:22 +0000 | [diff] [blame] | 831 | // TODO(b/131771163): LTO and Fuzzer support is mutually incompatible. |
| 832 | _, flags.Local.LdFlags = removeFromList("-flto", flags.Local.LdFlags) |
| 833 | _, flags.Local.CFlags = removeFromList("-flto", flags.Local.CFlags) |
| 834 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-lto") |
| 835 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-lto") |
| 836 | |
Mitch Phillips | b8e593d | 2019-10-09 17:18:59 -0700 | [diff] [blame] | 837 | // TODO(b/142430592): Upstream linker scripts for sanitizer runtime libraries |
| 838 | // discard the sancov_lowest_stack symbol, because it's emulated TLS (and thus |
| 839 | // doesn't match the linker script due to the "__emutls_v." prefix). |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 840 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-coverage=stack-depth") |
| 841 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-coverage=stack-depth") |
Mitch Phillips | b8e593d | 2019-10-09 17:18:59 -0700 | [diff] [blame] | 842 | |
Mitch Phillips | b9b3e79 | 2019-08-28 12:41:07 -0700 | [diff] [blame] | 843 | // Disable fortify for fuzzing builds. Generally, we'll be building with |
| 844 | // UBSan or ASan here and the fortify checks pollute the stack traces. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 845 | flags.Local.CFlags = append(flags.Local.CFlags, "-U_FORTIFY_SOURCE") |
Mitch Phillips | 734b4cb | 2019-12-10 08:44:52 -0800 | [diff] [blame] | 846 | |
| 847 | // Build fuzzer-sanitized libraries with an $ORIGIN DT_RUNPATH. Android's |
| 848 | // linker uses DT_RUNPATH, not DT_RPATH. When we deploy cc_fuzz targets and |
| 849 | // their libraries to /data/fuzz/<arch>/lib, any transient shared library gets |
| 850 | // the DT_RUNPATH from the shared library above it, and not the executable, |
| 851 | // meaning that the lookup falls back to the system. Adding the $ORIGIN to the |
| 852 | // DT_RUNPATH here means that transient shared libraries can be found |
| 853 | // colocated with their parents. |
| 854 | flags.Local.LdFlags = append(flags.Local.LdFlags, `-Wl,-rpath,\$$ORIGIN`) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 855 | } |
| 856 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 857 | if Bool(sanProps.Cfi) { |
Evgenii Stepanov | 7ebf9fa | 2017-01-20 14:13:06 -0800 | [diff] [blame] | 858 | if ctx.Arch().ArchType == android.Arm { |
| 859 | // __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). LLVM is not set up |
| 860 | // to do this on a function basis, so force Thumb on the entire module. |
| 861 | flags.RequiredInstructionSet = "thumb" |
| 862 | } |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 863 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 864 | flags.Local.CFlags = append(flags.Local.CFlags, cfiCflags...) |
| 865 | flags.Local.AsFlags = append(flags.Local.AsFlags, cfiAsflags...) |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 866 | if Bool(s.Properties.Sanitize.Config.Cfi_assembly_support) { |
Trevor Radcliffe | 391a25d | 2023-03-22 20:22:27 +0000 | [diff] [blame] | 867 | flags.Local.CFlags = append(flags.Local.CFlags, cfiAssemblySupportFlag) |
Cindy Zhou | 8cd45de | 2020-11-16 08:41:00 -0800 | [diff] [blame] | 868 | } |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 869 | // Only append the default visibility flag if -fvisibility has not already been set |
| 870 | // to hidden. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 871 | if !inList("-fvisibility=hidden", flags.Local.CFlags) { |
| 872 | flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default") |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 873 | } |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 874 | flags.Local.LdFlags = append(flags.Local.LdFlags, cfiLdflags...) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 875 | |
| 876 | if ctx.staticBinary() { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 877 | _, flags.Local.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.Local.CFlags) |
| 878 | _, flags.Local.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.Local.LdFlags) |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 879 | } |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 882 | if Bool(sanProps.Memtag_stack) { |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 883 | flags.Local.CFlags = append(flags.Local.CFlags, memtagStackCommonFlags...) |
Florian Mayer | 25cd981 | 2023-03-21 16:13:36 +0000 | [diff] [blame] | 884 | // TODO(fmayer): remove -Wno-error once https://reviews.llvm.org/D127917 is in Android toolchain. |
| 885 | flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-error=frame-larger-than") |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 886 | flags.Local.AsFlags = append(flags.Local.AsFlags, memtagStackCommonFlags...) |
| 887 | flags.Local.LdFlags = append(flags.Local.LdFlags, memtagStackCommonFlags...) |
Florian Mayer | 25cd981 | 2023-03-21 16:13:36 +0000 | [diff] [blame] | 888 | // This works around LLD complaining about the stack frame size. |
| 889 | // TODO(fmayer): remove once https://reviews.llvm.org/D127917 is in Android toolchain. |
| 890 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-fatal-warnings") |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 893 | if (Bool(sanProps.Memtag_heap) || Bool(sanProps.Memtag_stack)) && ctx.binary() { |
| 894 | if Bool(sanProps.Diag.Memtag_heap) { |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 895 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-fsanitize-memtag-mode=sync") |
| 896 | } else { |
| 897 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-fsanitize-memtag-mode=async") |
| 898 | } |
| 899 | } |
| 900 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 901 | if Bool(sanProps.Integer_overflow) { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 902 | flags.Local.CFlags = append(flags.Local.CFlags, intOverflowCflags...) |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 905 | if len(s.Properties.Sanitizers) > 0 { |
| 906 | sanitizeArg := "-fsanitize=" + strings.Join(s.Properties.Sanitizers, ",") |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 907 | flags.Local.CFlags = append(flags.Local.CFlags, sanitizeArg) |
| 908 | flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg) |
Colin Cross | 234b01d | 2022-02-07 13:49:03 -0800 | [diff] [blame] | 909 | flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg) |
| 910 | |
Colin Cross | ed12a04 | 2022-02-07 13:55:55 -0800 | [diff] [blame] | 911 | if ctx.toolchain().Bionic() || ctx.toolchain().Musl() { |
| 912 | // Bionic and musl sanitizer runtimes have already been added as dependencies so that |
| 913 | // the right variant of the runtime will be used (with the "-android" or "-musl" |
| 914 | // suffixes), so don't let clang the runtime library. |
Colin Cross | 234b01d | 2022-02-07 13:49:03 -0800 | [diff] [blame] | 915 | flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-link-runtime") |
| 916 | } else { |
Evgenii Stepanov | 76cee23 | 2017-01-27 15:44:44 -0800 | [diff] [blame] | 917 | // Host sanitizers only link symbols in the final executable, so |
| 918 | // there will always be undefined symbols in intermediate libraries. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 919 | _, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags) |
Colin Cross | 6c18d00 | 2022-06-02 15:11:50 -0700 | [diff] [blame] | 920 | } |
Ivan Lozano | 9ac32c7 | 2020-02-19 15:24:02 -0500 | [diff] [blame] | 921 | |
Colin Cross | 6c18d00 | 2022-06-02 15:11:50 -0700 | [diff] [blame] | 922 | if !ctx.toolchain().Bionic() { |
| 923 | // non-Bionic toolchain prebuilts are missing UBSan's vptr and function san. |
| 924 | // Musl toolchain prebuilts have vptr and function sanitizers, but enabling them |
| 925 | // implicitly enables RTTI which causes RTTI mismatch issues with dependencies. |
| 926 | |
Colin Cross | 234b01d | 2022-02-07 13:49:03 -0800 | [diff] [blame] | 927 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=vptr,function") |
Ivan Lozano | 9ac32c7 | 2020-02-19 15:24:02 -0500 | [diff] [blame] | 928 | } |
| 929 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 930 | if Bool(sanProps.Fuzzer) { |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 931 | // When fuzzing, we wish to crash with diagnostics on any bug. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 932 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-trap=all", "-fno-sanitize-recover=all") |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 933 | } else if ctx.Host() { |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 934 | flags.Local.CFlags = append(flags.Local.CFlags, hostOnlySanitizeFlags...) |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 935 | } else { |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 936 | flags.Local.CFlags = append(flags.Local.CFlags, deviceOnlySanitizeFlags...) |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 937 | } |
Evgenii Stepanov | 5901281 | 2022-06-24 11:09:18 -0700 | [diff] [blame] | 938 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 939 | if enableMinimalRuntime(s) { |
Evgenii Stepanov | 5901281 | 2022-06-24 11:09:18 -0700 | [diff] [blame] | 940 | flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " ")) |
| 941 | } |
| 942 | |
Chih-Hung Hsieh | 3567e62 | 2018-11-15 14:01:36 -0800 | [diff] [blame] | 943 | // http://b/119329758, Android core does not boot up with this sanitizer yet. |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 944 | if toDisableImplicitIntegerChange(flags.Local.CFlags) { |
| 945 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=implicit-integer-sign-change") |
Chih-Hung Hsieh | 3567e62 | 2018-11-15 14:01:36 -0800 | [diff] [blame] | 946 | } |
Yabin Cui | db7dda8 | 2020-11-30 15:47:45 -0800 | [diff] [blame] | 947 | // http://b/171275751, Android doesn't build with this sanitizer yet. |
| 948 | if toDisableUnsignedShiftBaseChange(flags.Local.CFlags) { |
| 949 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=unsigned-shift-base") |
| 950 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 951 | } |
| 952 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 953 | if len(s.Properties.DiagSanitizers) > 0 { |
| 954 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-trap="+strings.Join(s.Properties.DiagSanitizers, ",")) |
Evgenii Stepanov | 1e405e1 | 2016-08-16 15:39:54 -0700 | [diff] [blame] | 955 | } |
| 956 | // FIXME: enable RTTI if diag + (cfi or vptr) |
| 957 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 958 | if s.Properties.Sanitize.Recover != nil { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 959 | flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-recover="+ |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 960 | strings.Join(s.Properties.Sanitize.Recover, ",")) |
Andreas Gampe | 9707116 | 2017-05-08 13:15:23 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 963 | if s.Properties.Sanitize.Diag.No_recover != nil { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 964 | flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-recover="+ |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 965 | strings.Join(s.Properties.Sanitize.Diag.No_recover, ",")) |
Ivan Lozano | 7929bba | 2018-12-12 09:36:31 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 968 | blocklist := android.OptionalPathForModuleSrc(ctx, s.Properties.Sanitize.Blocklist) |
Pirama Arumuga Nainar | 6c4ccca | 2020-07-27 11:49:51 -0700 | [diff] [blame] | 969 | if blocklist.Valid() { |
Pirama Arumuga Nainar | 582fc2d | 2021-08-27 15:12:56 -0700 | [diff] [blame] | 970 | flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-ignorelist="+blocklist.String()) |
Pirama Arumuga Nainar | 6c4ccca | 2020-07-27 11:49:51 -0700 | [diff] [blame] | 971 | flags.CFlagsDeps = append(flags.CFlagsDeps, blocklist.Path()) |
| 972 | } |
| 973 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 974 | return flags |
| 975 | } |
| 976 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 977 | func (s *sanitize) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 978 | // Add a suffix for cfi/hwasan/scs-enabled static/header libraries to allow surfacing |
| 979 | // both the sanitized and non-sanitized variants to make without a name conflict. |
Colin Cross | d80cbca | 2020-02-24 12:01:37 -0800 | [diff] [blame] | 980 | if entries.Class == "STATIC_LIBRARIES" || entries.Class == "HEADER_LIBRARIES" { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 981 | if Bool(s.Properties.SanitizeMutated.Cfi) { |
Colin Cross | d80cbca | 2020-02-24 12:01:37 -0800 | [diff] [blame] | 982 | entries.SubName += ".cfi" |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 983 | } |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 984 | if Bool(s.Properties.SanitizeMutated.Hwaddress) { |
Colin Cross | d80cbca | 2020-02-24 12:01:37 -0800 | [diff] [blame] | 985 | entries.SubName += ".hwasan" |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 986 | } |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 987 | if Bool(s.Properties.SanitizeMutated.Scs) { |
Colin Cross | d80cbca | 2020-02-24 12:01:37 -0800 | [diff] [blame] | 988 | entries.SubName += ".scs" |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 989 | } |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 990 | } |
Colin Cross | 8ff9ef4 | 2017-05-08 13:44:11 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 993 | func (s *sanitize) inSanitizerDir() bool { |
| 994 | return s.Properties.InSanitizerDir |
Colin Cross | 30d5f51 | 2016-05-03 18:02:42 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 997 | // getSanitizerBoolPtr returns the SanitizerTypes associated bool pointer from SanitizeProperties. |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 998 | func (s *sanitize) getSanitizerBoolPtr(t SanitizerType) *bool { |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 999 | switch t { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1000 | case Asan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1001 | return s.Properties.SanitizeMutated.Address |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 1002 | case Hwasan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1003 | return s.Properties.SanitizeMutated.Hwaddress |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 1004 | case tsan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1005 | return s.Properties.SanitizeMutated.Thread |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 1006 | case intOverflow: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1007 | return s.Properties.SanitizeMutated.Integer_overflow |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1008 | case cfi: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1009 | return s.Properties.SanitizeMutated.Cfi |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 1010 | case scs: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1011 | return s.Properties.SanitizeMutated.Scs |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1012 | case Memtag_heap: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1013 | return s.Properties.SanitizeMutated.Memtag_heap |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 1014 | case Memtag_stack: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1015 | return s.Properties.SanitizeMutated.Memtag_stack |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1016 | case Fuzzer: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1017 | return s.Properties.SanitizeMutated.Fuzzer |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 1018 | default: |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1019 | panic(fmt.Errorf("unknown SanitizerType %d", t)) |
Vishwath Mohan | 9522930 | 2017-08-11 00:53:16 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1023 | // isUnsanitizedVariant returns true if no sanitizers are enabled. |
Dan Albert | 7d1eecf | 2018-01-19 12:30:45 -0800 | [diff] [blame] | 1024 | func (sanitize *sanitize) isUnsanitizedVariant() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1025 | return !sanitize.isSanitizerEnabled(Asan) && |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 1026 | !sanitize.isSanitizerEnabled(Hwasan) && |
Dan Albert | 7d1eecf | 2018-01-19 12:30:45 -0800 | [diff] [blame] | 1027 | !sanitize.isSanitizerEnabled(tsan) && |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 1028 | !sanitize.isSanitizerEnabled(cfi) && |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 1029 | !sanitize.isSanitizerEnabled(scs) && |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1030 | !sanitize.isSanitizerEnabled(Memtag_heap) && |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 1031 | !sanitize.isSanitizerEnabled(Memtag_stack) && |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1032 | !sanitize.isSanitizerEnabled(Fuzzer) |
Dan Albert | 7d1eecf | 2018-01-19 12:30:45 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1035 | // isVariantOnProductionDevice returns true if variant is for production devices (no non-production sanitizers enabled). |
Jayant Chowdhary | b7e08ca | 2018-05-10 15:29:24 -0700 | [diff] [blame] | 1036 | func (sanitize *sanitize) isVariantOnProductionDevice() bool { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1037 | return !sanitize.isSanitizerEnabled(Asan) && |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 1038 | !sanitize.isSanitizerEnabled(Hwasan) && |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 1039 | !sanitize.isSanitizerEnabled(tsan) && |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1040 | !sanitize.isSanitizerEnabled(Fuzzer) |
Jayant Chowdhary | b7e08ca | 2018-05-10 15:29:24 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1043 | func (sanitize *sanitize) SetSanitizer(t SanitizerType, b bool) { |
Liz Kammer | b2fc470 | 2021-06-25 14:53:40 -0400 | [diff] [blame] | 1044 | bPtr := proptools.BoolPtr(b) |
| 1045 | if !b { |
| 1046 | bPtr = nil |
| 1047 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1048 | switch t { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1049 | case Asan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1050 | sanitize.Properties.SanitizeMutated.Address = bPtr |
Florian Mayer | 1bda246 | 2022-09-29 15:48:08 -0700 | [diff] [blame] | 1051 | // For ASAN variant, we need to disable Memtag_stack |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1052 | sanitize.Properties.SanitizeMutated.Memtag_stack = nil |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 1053 | case Hwasan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1054 | sanitize.Properties.SanitizeMutated.Hwaddress = bPtr |
Florian Mayer | 1bda246 | 2022-09-29 15:48:08 -0700 | [diff] [blame] | 1055 | // For HWAsan variant, we need to disable Memtag_stack |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1056 | sanitize.Properties.SanitizeMutated.Memtag_stack = nil |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1057 | case tsan: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1058 | sanitize.Properties.SanitizeMutated.Thread = bPtr |
Ivan Lozano | 0c3a1ef | 2017-06-28 09:10:48 -0700 | [diff] [blame] | 1059 | case intOverflow: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1060 | sanitize.Properties.SanitizeMutated.Integer_overflow = bPtr |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1061 | case cfi: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1062 | sanitize.Properties.SanitizeMutated.Cfi = bPtr |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 1063 | case scs: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1064 | sanitize.Properties.SanitizeMutated.Scs = bPtr |
Ivan Lozano | 62cd038 | 2021-11-01 10:27:54 -0400 | [diff] [blame] | 1065 | case Memtag_heap: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1066 | sanitize.Properties.SanitizeMutated.Memtag_heap = bPtr |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 1067 | case Memtag_stack: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1068 | sanitize.Properties.SanitizeMutated.Memtag_stack = bPtr |
Florian Mayer | 1bda246 | 2022-09-29 15:48:08 -0700 | [diff] [blame] | 1069 | // We do not need to disable ASAN or HWASan here, as there is no Memtag_stack variant. |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1070 | case Fuzzer: |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1071 | sanitize.Properties.SanitizeMutated.Fuzzer = bPtr |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1072 | default: |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1073 | panic(fmt.Errorf("unknown SanitizerType %d", t)) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1074 | } |
| 1075 | if b { |
| 1076 | sanitize.Properties.SanitizerEnabled = true |
| 1077 | } |
| 1078 | } |
| 1079 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1080 | // Check if the sanitizer is explicitly disabled (as opposed to nil by |
| 1081 | // virtue of not being set). |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1082 | func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t SanitizerType) bool { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1083 | if sanitize == nil { |
| 1084 | return false |
| 1085 | } |
| 1086 | |
| 1087 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 1088 | return sanitizerVal != nil && *sanitizerVal == false |
| 1089 | } |
| 1090 | |
| 1091 | // There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled) |
| 1092 | // because enabling a sanitizer either directly (via the blueprint) or |
| 1093 | // indirectly (via a mutator) sets the bool ptr to true, and you can't |
| 1094 | // distinguish between the cases. It isn't needed though - both cases can be |
| 1095 | // treated identically. |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1096 | func (sanitize *sanitize) isSanitizerEnabled(t SanitizerType) bool { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1097 | if sanitize == nil { |
| 1098 | return false |
| 1099 | } |
| 1100 | |
| 1101 | sanitizerVal := sanitize.getSanitizerBoolPtr(t) |
| 1102 | return sanitizerVal != nil && *sanitizerVal == true |
| 1103 | } |
| 1104 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1105 | // IsSanitizableDependencyTag returns true if the dependency tag is sanitizable. |
| 1106 | func IsSanitizableDependencyTag(tag blueprint.DependencyTag) bool { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1107 | switch t := tag.(type) { |
| 1108 | case dependencyTag: |
| 1109 | return t == reuseObjTag || t == objDepTag |
| 1110 | case libraryDependencyTag: |
| 1111 | return true |
| 1112 | default: |
| 1113 | return false |
| 1114 | } |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1117 | func (m *Module) SanitizableDepTagChecker() SantizableDependencyTagChecker { |
| 1118 | return IsSanitizableDependencyTag |
| 1119 | } |
| 1120 | |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1121 | // Determines if the current module is a static library going to be captured |
| 1122 | // as vendor snapshot. Such modules must create both cfi and non-cfi variants, |
| 1123 | // except for ones which explicitly disable cfi. |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1124 | func needsCfiForVendorSnapshot(mctx android.BaseModuleContext) bool { |
Justin Yun | 8814fc5 | 2022-12-15 21:45:35 +0900 | [diff] [blame] | 1125 | if inList("hwaddress", mctx.Config().SanitizeDevice()) { |
| 1126 | // cfi will not be built if SANITIZE_TARGET=hwaddress is set |
| 1127 | return false |
| 1128 | } |
| 1129 | |
Kiyoung Kim | 48f3778 | 2021-07-07 12:42:39 +0900 | [diff] [blame] | 1130 | if snapshot.IsVendorProprietaryModule(mctx) { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1131 | return false |
| 1132 | } |
| 1133 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1134 | c := mctx.Module().(PlatformSanitizeable) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1135 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1136 | if !c.InVendor() { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1137 | return false |
| 1138 | } |
| 1139 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1140 | if !c.StaticallyLinked() { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1141 | return false |
| 1142 | } |
| 1143 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1144 | if c.IsPrebuilt() { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1145 | return false |
| 1146 | } |
| 1147 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1148 | if !c.SanitizerSupported(cfi) { |
| 1149 | return false |
| 1150 | } |
| 1151 | |
| 1152 | return c.SanitizePropDefined() && |
| 1153 | !c.SanitizeNever() && |
| 1154 | !c.IsSanitizerExplicitlyDisabled(cfi) |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1155 | } |
| 1156 | |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1157 | type sanitizerSplitMutator struct { |
| 1158 | sanitizer SanitizerType |
| 1159 | } |
| 1160 | |
| 1161 | // If an APEX is sanitized or not depends on whether it contains at least one |
| 1162 | // sanitized module. Transition mutators cannot propagate information up the |
| 1163 | // dependency graph this way, so we need an auxiliary mutator to do so. |
| 1164 | func (s *sanitizerSplitMutator) markSanitizableApexesMutator(ctx android.TopDownMutatorContext) { |
| 1165 | if sanitizeable, ok := ctx.Module().(Sanitizeable); ok { |
| 1166 | enabled := sanitizeable.IsSanitizerEnabled(ctx.Config(), s.sanitizer.name()) |
| 1167 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1168 | if c, ok := dep.(*Module); ok && c.sanitize.isSanitizerEnabled(s.sanitizer) { |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1169 | enabled = true |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1170 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1171 | }) |
| 1172 | |
| 1173 | if enabled { |
| 1174 | sanitizeable.EnableSanitizer(s.sanitizer.name()) |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | func (s *sanitizerSplitMutator) Split(ctx android.BaseModuleContext) []string { |
| 1180 | if c, ok := ctx.Module().(PlatformSanitizeable); ok && c.SanitizePropDefined() { |
| 1181 | if s.sanitizer == cfi && needsCfiForVendorSnapshot(ctx) { |
| 1182 | return []string{"", s.sanitizer.variationName()} |
| 1183 | } |
| 1184 | |
| 1185 | // If the given sanitizer is not requested in the .bp file for a module, it |
| 1186 | // won't automatically build the sanitized variation. |
| 1187 | if !c.IsSanitizerEnabled(s.sanitizer) { |
| 1188 | return []string{""} |
| 1189 | } |
| 1190 | |
| 1191 | if c.Binary() { |
| 1192 | // If a sanitizer is enabled for a binary, we do not build the version |
| 1193 | // without the sanitizer |
| 1194 | return []string{s.sanitizer.variationName()} |
| 1195 | } else if c.StaticallyLinked() || c.Header() { |
| 1196 | // For static libraries, we build both versions. Some Make modules |
| 1197 | // apparently depend on this behavior. |
| 1198 | return []string{"", s.sanitizer.variationName()} |
| 1199 | } else { |
| 1200 | // We only build the requested variation of dynamic libraries |
| 1201 | return []string{s.sanitizer.variationName()} |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if _, ok := ctx.Module().(JniSanitizeable); ok { |
| 1206 | // TODO: this should call into JniSanitizable.IsSanitizerEnabledForJni but |
| 1207 | // that is short-circuited for now |
| 1208 | return []string{""} |
| 1209 | } |
| 1210 | |
| 1211 | // If an APEX has a sanitized dependency, we build the APEX in the sanitized |
| 1212 | // variation. This is useful because such APEXes require extra dependencies. |
| 1213 | if sanitizeable, ok := ctx.Module().(Sanitizeable); ok { |
| 1214 | enabled := sanitizeable.IsSanitizerEnabled(ctx.Config(), s.sanitizer.name()) |
| 1215 | if enabled { |
| 1216 | return []string{s.sanitizer.variationName()} |
| 1217 | } else { |
| 1218 | return []string{""} |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if c, ok := ctx.Module().(*Module); ok { |
| 1223 | //TODO: When Rust modules have vendor support, enable this path for PlatformSanitizeable |
| 1224 | |
| 1225 | // Check if it's a snapshot module supporting sanitizer |
Justin Yun | 08270c6 | 2022-12-19 17:01:26 +0900 | [diff] [blame] | 1226 | if ss, ok := c.linker.(snapshotSanitizer); ok { |
| 1227 | if ss.isSanitizerAvailable(s.sanitizer) { |
| 1228 | return []string{"", s.sanitizer.variationName()} |
| 1229 | } else { |
| 1230 | return []string{""} |
| 1231 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | return []string{""} |
| 1236 | } |
| 1237 | |
| 1238 | func (s *sanitizerSplitMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { |
| 1239 | if c, ok := ctx.Module().(PlatformSanitizeable); ok { |
| 1240 | if !c.SanitizableDepTagChecker()(ctx.DepTag()) { |
| 1241 | // If the dependency is through a non-sanitizable tag, use the |
| 1242 | // non-sanitized variation |
| 1243 | return "" |
| 1244 | } |
| 1245 | |
| 1246 | return sourceVariation |
| 1247 | } else if _, ok := ctx.Module().(JniSanitizeable); ok { |
| 1248 | // TODO: this should call into JniSanitizable.IsSanitizerEnabledForJni but |
| 1249 | // that is short-circuited for now |
| 1250 | return "" |
| 1251 | } else { |
| 1252 | // Otherwise, do not rock the boat. |
| 1253 | return sourceVariation |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | func (s *sanitizerSplitMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { |
| 1258 | if d, ok := ctx.Module().(PlatformSanitizeable); ok { |
| 1259 | if dm, ok := ctx.Module().(*Module); ok { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 1260 | if ss, ok := dm.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) { |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1261 | return incomingVariation |
Inseob Kim | c42f2f2 | 2020-07-29 20:32:10 +0900 | [diff] [blame] | 1262 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | if !d.SanitizePropDefined() || |
| 1266 | d.SanitizeNever() || |
| 1267 | d.IsSanitizerExplicitlyDisabled(s.sanitizer) || |
| 1268 | !d.SanitizerSupported(s.sanitizer) { |
| 1269 | // If a module opts out of a sanitizer, use its non-sanitized variation |
| 1270 | return "" |
| 1271 | } |
| 1272 | |
| 1273 | // Binaries are always built in the variation they requested. |
| 1274 | if d.Binary() { |
| 1275 | if d.IsSanitizerEnabled(s.sanitizer) { |
| 1276 | return s.sanitizer.variationName() |
| 1277 | } else { |
| 1278 | return "" |
Muhammad Haseeb Ahmad | 7e74405 | 2022-03-25 22:50:53 +0000 | [diff] [blame] | 1279 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | // If a shared library requests to be sanitized, it will be built for that |
| 1283 | // sanitizer. Otherwise, some sanitizers propagate through shared library |
| 1284 | // dependency edges, some do not. |
| 1285 | if !d.StaticallyLinked() && !d.Header() { |
| 1286 | if d.IsSanitizerEnabled(s.sanitizer) { |
| 1287 | return s.sanitizer.variationName() |
| 1288 | } |
| 1289 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 1290 | // Some sanitizers do not propagate to shared dependencies |
| 1291 | if !s.sanitizer.shouldPropagateToSharedLibraryDeps() { |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1292 | return "" |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | // Static and header libraries inherit whether they are sanitized from the |
| 1297 | // module they are linked into |
| 1298 | return incomingVariation |
| 1299 | } else if d, ok := ctx.Module().(Sanitizeable); ok { |
| 1300 | // If an APEX contains a sanitized module, it will be built in the variation |
| 1301 | // corresponding to that sanitizer. |
| 1302 | enabled := d.IsSanitizerEnabled(ctx.Config(), s.sanitizer.name()) |
| 1303 | if enabled { |
| 1304 | return s.sanitizer.variationName() |
| 1305 | } |
| 1306 | |
| 1307 | return incomingVariation |
| 1308 | } |
| 1309 | |
| 1310 | return "" |
| 1311 | } |
| 1312 | |
| 1313 | func (s *sanitizerSplitMutator) Mutate(mctx android.BottomUpMutatorContext, variationName string) { |
| 1314 | sanitizerVariation := variationName == s.sanitizer.variationName() |
| 1315 | |
| 1316 | if c, ok := mctx.Module().(PlatformSanitizeable); ok && c.SanitizePropDefined() { |
| 1317 | sanitizerEnabled := c.IsSanitizerEnabled(s.sanitizer) |
| 1318 | |
| 1319 | oneMakeVariation := false |
| 1320 | if c.StaticallyLinked() || c.Header() { |
| 1321 | if s.sanitizer != cfi && s.sanitizer != scs && s.sanitizer != Hwasan { |
| 1322 | // These sanitizers export only one variation to Make. For the rest, |
| 1323 | // Make targets can depend on both the sanitized and non-sanitized |
| 1324 | // versions. |
| 1325 | oneMakeVariation = true |
| 1326 | } |
| 1327 | } else if !c.Binary() { |
| 1328 | // Shared library. These are the sanitizers that do propagate through shared |
| 1329 | // library dependencies and therefore can cause multiple variations of a |
| 1330 | // shared library to be built. |
| 1331 | if s.sanitizer != cfi && s.sanitizer != Hwasan && s.sanitizer != scs && s.sanitizer != Asan { |
| 1332 | oneMakeVariation = true |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | if oneMakeVariation { |
| 1337 | if sanitizerEnabled != sanitizerVariation { |
| 1338 | c.SetPreventInstall() |
| 1339 | c.SetHideFromMake() |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | if sanitizerVariation { |
| 1344 | c.SetSanitizer(s.sanitizer, true) |
| 1345 | |
| 1346 | // CFI is incompatible with ASAN so disable it in ASAN variations |
| 1347 | if s.sanitizer.incompatibleWithCfi() { |
| 1348 | cfiSupported := mctx.Module().(PlatformSanitizeable).SanitizerSupported(cfi) |
| 1349 | if mctx.Device() && cfiSupported { |
| 1350 | c.SetSanitizer(cfi, false) |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1351 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | // locate the asan libraries under /data/asan |
| 1355 | if !c.Binary() && !c.StaticallyLinked() && !c.Header() && mctx.Device() && s.sanitizer == Asan && sanitizerEnabled { |
| 1356 | c.SetInSanitizerDir() |
| 1357 | } |
| 1358 | |
| 1359 | if c.StaticallyLinked() && c.ExportedToMake() { |
| 1360 | if s.sanitizer == Hwasan { |
| 1361 | hwasanStaticLibs(mctx.Config()).add(c, c.Module().Name()) |
| 1362 | } else if s.sanitizer == cfi { |
| 1363 | cfiStaticLibs(mctx.Config()).add(c, c.Module().Name()) |
| 1364 | } |
| 1365 | } |
| 1366 | } else if c.IsSanitizerEnabled(s.sanitizer) { |
| 1367 | // Disable the sanitizer for the non-sanitized variation |
| 1368 | c.SetSanitizer(s.sanitizer, false) |
| 1369 | } |
| 1370 | } else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok { |
| 1371 | // If an APEX has sanitized dependencies, it gets a few more dependencies |
| 1372 | if sanitizerVariation { |
| 1373 | sanitizeable.AddSanitizerDependencies(mctx, s.sanitizer.name()) |
| 1374 | } |
| 1375 | } else if c, ok := mctx.Module().(*Module); ok { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 1376 | if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) { |
| 1377 | if !ss.isUnsanitizedVariant() { |
| 1378 | // Snapshot sanitizer may have only one variantion. |
| 1379 | // Skip exporting the module if it already has a sanitizer variation. |
| 1380 | c.SetPreventInstall() |
| 1381 | c.SetHideFromMake() |
| 1382 | return |
| 1383 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1384 | c.linker.(snapshotSanitizer).setSanitizerVariation(s.sanitizer, sanitizerVariation) |
| 1385 | |
| 1386 | // Export the static lib name to make |
| 1387 | if c.static() && c.ExportedToMake() { |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 1388 | // use BaseModuleName which is the name for Make. |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1389 | if s.sanitizer == cfi { |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1390 | cfiStaticLibs(mctx.Config()).add(c, c.BaseModuleName()) |
Justin Yun | 39c3031 | 2022-11-23 16:20:12 +0900 | [diff] [blame] | 1391 | } else if s.sanitizer == Hwasan { |
| 1392 | hwasanStaticLibs(mctx.Config()).add(c, c.BaseModuleName()) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 1393 | } |
| 1394 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1399 | func (c *Module) SanitizeNever() bool { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1400 | return Bool(c.sanitize.Properties.SanitizeMutated.Never) |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | func (c *Module) IsSanitizerExplicitlyDisabled(t SanitizerType) bool { |
| 1404 | return c.sanitize.isSanitizerExplicitlyDisabled(t) |
| 1405 | } |
| 1406 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1407 | // 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] | 1408 | func sanitizerRuntimeDepsMutator(mctx android.TopDownMutatorContext) { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1409 | // Change this to PlatformSanitizable when/if non-cc modules support ubsan sanitizers. |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1410 | if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1411 | isSanitizableDependencyTag := c.SanitizableDepTagChecker() |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1412 | mctx.WalkDeps(func(child, parent android.Module) bool { |
| 1413 | if !isSanitizableDependencyTag(mctx.OtherModuleDependencyTag(child)) { |
| 1414 | return false |
| 1415 | } |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1416 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1417 | d, ok := child.(*Module) |
| 1418 | if !ok || !d.static() { |
| 1419 | return false |
| 1420 | } |
| 1421 | if d.sanitize != nil { |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1422 | if enableMinimalRuntime(d.sanitize) { |
| 1423 | // If a static dependency is built with the minimal runtime, |
| 1424 | // make sure we include the ubsan minimal runtime. |
| 1425 | c.sanitize.Properties.MinimalRuntimeDep = true |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1426 | } else if enableUbsanRuntime(d.sanitize) { |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1427 | // If a static dependency runs with full ubsan diagnostics, |
| 1428 | // make sure we include the ubsan runtime. |
| 1429 | c.sanitize.Properties.UbsanRuntimeDep = true |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1430 | } |
Colin Cross | 0b90833 | 2019-06-19 23:00:20 -0700 | [diff] [blame] | 1431 | |
| 1432 | if c.sanitize.Properties.MinimalRuntimeDep && |
| 1433 | c.sanitize.Properties.UbsanRuntimeDep { |
| 1434 | // both flags that this mutator might set are true, so don't bother recursing |
| 1435 | return false |
| 1436 | } |
| 1437 | |
Ivan Lozano | 9ac32c7 | 2020-02-19 15:24:02 -0500 | [diff] [blame] | 1438 | if c.Os() == android.Linux { |
| 1439 | c.sanitize.Properties.BuiltinsDep = true |
| 1440 | } |
| 1441 | |
Colin Cross | 0b90833 | 2019-06-19 23:00:20 -0700 | [diff] [blame] | 1442 | return true |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1443 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1444 | |
Jose Galmes | f729458 | 2020-11-13 12:07:36 -0800 | [diff] [blame] | 1445 | if p, ok := d.linker.(*snapshotLibraryDecorator); ok { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1446 | if Bool(p.properties.Sanitize_minimal_dep) { |
| 1447 | c.sanitize.Properties.MinimalRuntimeDep = true |
| 1448 | } |
| 1449 | if Bool(p.properties.Sanitize_ubsan_dep) { |
| 1450 | c.sanitize.Properties.UbsanRuntimeDep = true |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | return false |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 1455 | }) |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1459 | // Add the dependency to the runtime library for each of the sanitizer variants |
| 1460 | func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1461 | if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { |
Pirama Arumuga Nainar | 6aa2102 | 2019-01-25 00:20:35 +0000 | [diff] [blame] | 1462 | if !c.Enabled() { |
| 1463 | return |
| 1464 | } |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1465 | var sanitizers []string |
| 1466 | var diagSanitizers []string |
| 1467 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1468 | sanProps := &c.sanitize.Properties.SanitizeMutated |
| 1469 | |
| 1470 | if Bool(sanProps.All_undefined) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1471 | sanitizers = append(sanitizers, "undefined") |
| 1472 | } else { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1473 | if Bool(sanProps.Undefined) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1474 | sanitizers = append(sanitizers, |
| 1475 | "bool", |
| 1476 | "integer-divide-by-zero", |
| 1477 | "return", |
| 1478 | "returns-nonnull-attribute", |
| 1479 | "shift-exponent", |
| 1480 | "unreachable", |
| 1481 | "vla-bound", |
| 1482 | // TODO(danalbert): The following checks currently have compiler performance issues. |
| 1483 | //"alignment", |
| 1484 | //"bounds", |
| 1485 | //"enum", |
| 1486 | //"float-cast-overflow", |
| 1487 | //"float-divide-by-zero", |
| 1488 | //"nonnull-attribute", |
| 1489 | //"null", |
| 1490 | //"shift-base", |
| 1491 | //"signed-integer-overflow", |
| 1492 | // TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on. |
| 1493 | // https://llvm.org/PR19302 |
| 1494 | // http://reviews.llvm.org/D6974 |
| 1495 | // "object-size", |
| 1496 | ) |
| 1497 | } |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1498 | sanitizers = append(sanitizers, sanProps.Misc_undefined...) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1499 | } |
| 1500 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1501 | if Bool(sanProps.Diag.Undefined) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1502 | diagSanitizers = append(diagSanitizers, "undefined") |
| 1503 | } |
| 1504 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1505 | diagSanitizers = append(diagSanitizers, sanProps.Diag.Misc_undefined...) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1506 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1507 | if Bool(sanProps.Address) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1508 | sanitizers = append(sanitizers, "address") |
| 1509 | diagSanitizers = append(diagSanitizers, "address") |
| 1510 | } |
| 1511 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1512 | if Bool(sanProps.Hwaddress) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1513 | sanitizers = append(sanitizers, "hwaddress") |
| 1514 | } |
| 1515 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1516 | if Bool(sanProps.Thread) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1517 | sanitizers = append(sanitizers, "thread") |
| 1518 | } |
| 1519 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1520 | if Bool(sanProps.Safestack) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1521 | sanitizers = append(sanitizers, "safe-stack") |
| 1522 | } |
| 1523 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1524 | if Bool(sanProps.Cfi) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1525 | sanitizers = append(sanitizers, "cfi") |
| 1526 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1527 | if Bool(sanProps.Diag.Cfi) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1528 | diagSanitizers = append(diagSanitizers, "cfi") |
| 1529 | } |
| 1530 | } |
| 1531 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1532 | if Bool(sanProps.Integer_overflow) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1533 | sanitizers = append(sanitizers, "unsigned-integer-overflow") |
| 1534 | sanitizers = append(sanitizers, "signed-integer-overflow") |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1535 | if Bool(sanProps.Diag.Integer_overflow) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1536 | diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow") |
| 1537 | diagSanitizers = append(diagSanitizers, "signed-integer-overflow") |
| 1538 | } |
| 1539 | } |
| 1540 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1541 | if Bool(sanProps.Scudo) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1542 | sanitizers = append(sanitizers, "scudo") |
| 1543 | } |
| 1544 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1545 | if Bool(sanProps.Scs) { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1546 | sanitizers = append(sanitizers, "shadow-call-stack") |
| 1547 | } |
| 1548 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1549 | if Bool(sanProps.Memtag_heap) && c.Binary() { |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 1550 | sanitizers = append(sanitizers, "memtag-heap") |
| 1551 | } |
| 1552 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1553 | if Bool(sanProps.Memtag_stack) { |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 1554 | sanitizers = append(sanitizers, "memtag-stack") |
Evgenii Stepanov | 193ac2e | 2020-04-28 15:09:12 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1557 | if Bool(sanProps.Fuzzer) { |
Mitch Phillips | 5a6ea6c | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 1558 | sanitizers = append(sanitizers, "fuzzer-no-link") |
| 1559 | } |
| 1560 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1561 | // Save the list of sanitizers. These will be used again when generating |
| 1562 | // the build rules (for Cflags, etc.) |
| 1563 | c.sanitize.Properties.Sanitizers = sanitizers |
| 1564 | c.sanitize.Properties.DiagSanitizers = diagSanitizers |
| 1565 | |
Ivan Lozano | f3b190f | 2020-03-06 12:01:21 -0500 | [diff] [blame] | 1566 | // TODO(b/150822854) Hosts have a different default behavior and assume the runtime library is used. |
| 1567 | if c.Host() { |
| 1568 | diagSanitizers = sanitizers |
| 1569 | } |
| 1570 | |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1571 | addStaticDeps := func(dep string, hideSymbols bool) { |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1572 | // If we're using snapshots, redirect to snapshot whenever possible |
| 1573 | snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo) |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1574 | if lib, ok := snapshot.StaticLibs[dep]; ok { |
| 1575 | dep = lib |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | // static executable gets static runtime libs |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1579 | depTag := libraryDependencyTag{Kind: staticLibraryDependency, unexportedSymbols: hideSymbols} |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1580 | variations := append(mctx.Target().Variations(), |
| 1581 | blueprint.Variation{Mutator: "link", Variation: "static"}) |
| 1582 | if c.Device() { |
| 1583 | variations = append(variations, c.ImageVariation()) |
| 1584 | } |
| 1585 | if c.UseSdk() { |
| 1586 | variations = append(variations, |
| 1587 | blueprint.Variation{Mutator: "sdk", Variation: "sdk"}) |
| 1588 | } |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1589 | mctx.AddFarVariationDependencies(variations, depTag, dep) |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1590 | } |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1591 | |
| 1592 | // Determine the runtime library required |
| 1593 | runtimeSharedLibrary := "" |
| 1594 | toolchain := c.toolchain(mctx) |
| 1595 | if Bool(sanProps.Address) { |
Colin Cross | b781d23 | 2023-02-15 12:40:20 -0800 | [diff] [blame] | 1596 | if toolchain.Musl() || (c.staticBinary() && toolchain.Bionic()) { |
| 1597 | // Use a static runtime for musl to match what clang does for glibc. |
| 1598 | addStaticDeps(config.AddressSanitizerStaticRuntimeLibrary(toolchain), false) |
| 1599 | addStaticDeps(config.AddressSanitizerCXXStaticRuntimeLibrary(toolchain), false) |
| 1600 | } else { |
| 1601 | runtimeSharedLibrary = config.AddressSanitizerRuntimeLibrary(toolchain) |
| 1602 | } |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1603 | } else if Bool(sanProps.Hwaddress) { |
| 1604 | if c.staticBinary() { |
| 1605 | addStaticDeps(config.HWAddressSanitizerStaticLibrary(toolchain), true) |
| 1606 | addStaticDeps("libdl", false) |
| 1607 | } else { |
| 1608 | runtimeSharedLibrary = config.HWAddressSanitizerRuntimeLibrary(toolchain) |
| 1609 | } |
| 1610 | } else if Bool(sanProps.Thread) { |
| 1611 | runtimeSharedLibrary = config.ThreadSanitizerRuntimeLibrary(toolchain) |
| 1612 | } else if Bool(sanProps.Scudo) { |
| 1613 | if len(diagSanitizers) == 0 && !c.sanitize.Properties.UbsanRuntimeDep { |
| 1614 | runtimeSharedLibrary = config.ScudoMinimalRuntimeLibrary(toolchain) |
| 1615 | } else { |
| 1616 | runtimeSharedLibrary = config.ScudoRuntimeLibrary(toolchain) |
| 1617 | } |
| 1618 | } else if len(diagSanitizers) > 0 || c.sanitize.Properties.UbsanRuntimeDep || |
| 1619 | Bool(sanProps.Fuzzer) || |
| 1620 | Bool(sanProps.Undefined) || |
| 1621 | Bool(sanProps.All_undefined) { |
| 1622 | if toolchain.Musl() || (c.staticBinary() && toolchain.Bionic()) { |
| 1623 | // Use a static runtime for static binaries. |
| 1624 | // Also use a static runtime for musl to match |
| 1625 | // what clang does for glibc. Otherwise dlopening |
| 1626 | // libraries that depend on libclang_rt.ubsan_standalone.so |
| 1627 | // fails with: |
| 1628 | // Error relocating ...: initial-exec TLS resolves to dynamic definition |
| 1629 | addStaticDeps(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)+".static", true) |
| 1630 | } else { |
| 1631 | runtimeSharedLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain) |
| 1632 | } |
| 1633 | } |
| 1634 | |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1635 | if enableMinimalRuntime(c.sanitize) || c.sanitize.Properties.MinimalRuntimeDep { |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1636 | addStaticDeps(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), true) |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1637 | } |
| 1638 | if c.sanitize.Properties.BuiltinsDep { |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1639 | addStaticDeps(config.BuiltinsRuntimeLibrary(toolchain), true) |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1642 | if runtimeSharedLibrary != "" && (toolchain.Bionic() || toolchain.Musl() || c.sanitize.Properties.UbsanRuntimeDep) { |
Ivan Lozano | 9ac32c7 | 2020-02-19 15:24:02 -0500 | [diff] [blame] | 1643 | // UBSan is supported on non-bionic linux host builds as well |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1644 | |
| 1645 | // Adding dependency to the runtime library. We are using *FarVariation* |
| 1646 | // because the runtime libraries themselves are not mutated by sanitizer |
| 1647 | // mutators and thus don't have sanitizer variants whereas this module |
| 1648 | // has been already mutated. |
| 1649 | // |
| 1650 | // Note that by adding dependency with {static|shared}DepTag, the lib is |
| 1651 | // added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1652 | if c.staticBinary() { |
| 1653 | // Most sanitizers are either disabled for static binaries or have already |
| 1654 | // handled the static binary case above through a direct call to addStaticDeps. |
| 1655 | // If not, treat the runtime shared library as a static library and hope for |
| 1656 | // the best. |
| 1657 | addStaticDeps(runtimeSharedLibrary, true) |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1658 | } else if !c.static() && !c.Header() { |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 1659 | // If we're using snapshots, redirect to snapshot whenever possible |
| 1660 | snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo) |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1661 | if lib, ok := snapshot.SharedLibs[runtimeSharedLibrary]; ok { |
| 1662 | runtimeSharedLibrary = lib |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1663 | } |
Colin Cross | e0edaf9 | 2021-01-11 17:31:17 -0800 | [diff] [blame] | 1664 | |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 1665 | // Skip apex dependency check for sharedLibraryDependency |
| 1666 | // when sanitizer diags are enabled. Skipping the check will allow |
| 1667 | // building with diag libraries without having to list the |
| 1668 | // dependency in Apex's allowed_deps file. |
| 1669 | diagEnabled := len(diagSanitizers) > 0 |
Jiyong Park | 3b1746a | 2019-01-29 11:15:04 +0900 | [diff] [blame] | 1670 | // dynamic executable and shared libs get shared runtime libs |
Cindy Zhou | 18417cb | 2020-12-10 07:12:38 -0800 | [diff] [blame] | 1671 | depTag := libraryDependencyTag{ |
| 1672 | Kind: sharedLibraryDependency, |
| 1673 | Order: earlyLibraryDependency, |
| 1674 | |
| 1675 | skipApexAllowedDependenciesCheck: diagEnabled, |
| 1676 | } |
Colin Cross | 4250733 | 2020-08-21 16:15:23 -0700 | [diff] [blame] | 1677 | variations := append(mctx.Target().Variations(), |
| 1678 | blueprint.Variation{Mutator: "link", Variation: "shared"}) |
| 1679 | if c.Device() { |
| 1680 | variations = append(variations, c.ImageVariation()) |
| 1681 | } |
Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 1682 | if c.UseSdk() { |
| 1683 | variations = append(variations, |
| 1684 | blueprint.Variation{Mutator: "sdk", Variation: "sdk"}) |
| 1685 | } |
Colin Cross | e323a79 | 2023-02-15 13:57:57 -0800 | [diff] [blame] | 1686 | AddSharedLibDependenciesWithVersions(mctx, c, variations, depTag, runtimeSharedLibrary, "", true) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1687 | } |
| 1688 | // static lib does not have dependency to the runtime library. The |
| 1689 | // dependency will be added to the executables or shared libs using |
| 1690 | // the static lib. |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | type Sanitizeable interface { |
| 1696 | android.Module |
Lukacs T. Berki | 01a648a | 2022-06-17 08:59:37 +0200 | [diff] [blame] | 1697 | IsSanitizerEnabled(config android.Config, sanitizerName string) bool |
Jiyong Park | f97782b | 2019-02-13 20:28:58 +0900 | [diff] [blame] | 1698 | EnableSanitizer(sanitizerName string) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1699 | AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1700 | } |
| 1701 | |
Muhammad Haseeb Ahmad | 7e74405 | 2022-03-25 22:50:53 +0000 | [diff] [blame] | 1702 | type JniSanitizeable interface { |
| 1703 | android.Module |
| 1704 | IsSanitizerEnabledForJni(ctx android.BaseModuleContext, sanitizerName string) bool |
| 1705 | } |
| 1706 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1707 | func (c *Module) MinimalRuntimeDep() bool { |
| 1708 | return c.sanitize.Properties.MinimalRuntimeDep |
| 1709 | } |
| 1710 | |
| 1711 | func (c *Module) UbsanRuntimeDep() bool { |
| 1712 | return c.sanitize.Properties.UbsanRuntimeDep |
| 1713 | } |
| 1714 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1715 | func (c *Module) SanitizePropDefined() bool { |
| 1716 | return c.sanitize != nil |
| 1717 | } |
| 1718 | |
| 1719 | func (c *Module) IsSanitizerEnabled(t SanitizerType) bool { |
| 1720 | return c.sanitize.isSanitizerEnabled(t) |
| 1721 | } |
| 1722 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1723 | func (c *Module) StaticallyLinked() bool { |
| 1724 | return c.static() |
| 1725 | } |
| 1726 | |
| 1727 | func (c *Module) SetInSanitizerDir() { |
| 1728 | if c.sanitize != nil { |
| 1729 | c.sanitize.Properties.InSanitizerDir = true |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | func (c *Module) SetSanitizer(t SanitizerType, b bool) { |
| 1734 | if c.sanitize != nil { |
| 1735 | c.sanitize.SetSanitizer(t, b) |
| 1736 | } |
| 1737 | } |
| 1738 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1739 | var _ PlatformSanitizeable = (*Module)(nil) |
| 1740 | |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1741 | type sanitizerStaticLibsMap struct { |
| 1742 | // libsMap contains one list of modules per each image and each arch. |
| 1743 | // e.g. libs[vendor]["arm"] contains arm modules installed to vendor |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1744 | libsMap map[ImageVariantType]map[string][]string |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1745 | libsMapLock sync.Mutex |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1746 | sanitizerType SanitizerType |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1747 | } |
| 1748 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1749 | func newSanitizerStaticLibsMap(t SanitizerType) *sanitizerStaticLibsMap { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1750 | return &sanitizerStaticLibsMap{ |
| 1751 | sanitizerType: t, |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1752 | libsMap: make(map[ImageVariantType]map[string][]string), |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | // Add the current module to sanitizer static libs maps |
| 1757 | // Each module should pass its exported name as names of Make and Soong can differ. |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1758 | func (s *sanitizerStaticLibsMap) add(c LinkableInterface, name string) { |
| 1759 | image := GetImageVariantType(c) |
| 1760 | arch := c.Module().Target().Arch.ArchType.String() |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1761 | |
| 1762 | s.libsMapLock.Lock() |
| 1763 | defer s.libsMapLock.Unlock() |
| 1764 | |
| 1765 | if _, ok := s.libsMap[image]; !ok { |
| 1766 | s.libsMap[image] = make(map[string][]string) |
| 1767 | } |
| 1768 | |
| 1769 | s.libsMap[image][arch] = append(s.libsMap[image][arch], name) |
| 1770 | } |
| 1771 | |
| 1772 | // Exports makefile variables in the following format: |
| 1773 | // SOONG_{sanitizer}_{image}_{arch}_STATIC_LIBRARIES |
| 1774 | // e.g. SOONG_cfi_core_x86_STATIC_LIBRARIES |
| 1775 | // These are to be used by use_soong_sanitized_static_libraries. |
| 1776 | // See build/make/core/binary.mk for more details. |
| 1777 | func (s *sanitizerStaticLibsMap) exportToMake(ctx android.MakeVarsContext) { |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1778 | for _, image := range android.SortedKeys(s.libsMap) { |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 1779 | archMap := s.libsMap[ImageVariantType(image)] |
Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1780 | for _, arch := range android.SortedKeys(archMap) { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1781 | libs := archMap[arch] |
| 1782 | sort.Strings(libs) |
| 1783 | |
| 1784 | key := fmt.Sprintf( |
| 1785 | "SOONG_%s_%s_%s_STATIC_LIBRARIES", |
| 1786 | s.sanitizerType.variationName(), |
| 1787 | image, // already upper |
| 1788 | arch) |
| 1789 | |
| 1790 | ctx.Strict(key, strings.Join(libs, " ")) |
| 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1795 | var cfiStaticLibsKey = android.NewOnceKey("cfiStaticLibs") |
| 1796 | |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1797 | func cfiStaticLibs(config android.Config) *sanitizerStaticLibsMap { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1798 | return config.Once(cfiStaticLibsKey, func() interface{} { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1799 | return newSanitizerStaticLibsMap(cfi) |
| 1800 | }).(*sanitizerStaticLibsMap) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1803 | var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs") |
| 1804 | |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1805 | func hwasanStaticLibs(config android.Config) *sanitizerStaticLibsMap { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1806 | return config.Once(hwasanStaticLibsKey, func() interface{} { |
Tri Vo | 6eafc36 | 2021-04-01 11:29:09 -0700 | [diff] [blame] | 1807 | return newSanitizerStaticLibsMap(Hwasan) |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1808 | }).(*sanitizerStaticLibsMap) |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 1809 | } |
| 1810 | |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1811 | func enableMinimalRuntime(sanitize *sanitize) bool { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1812 | if sanitize.isSanitizerEnabled(Asan) { |
| 1813 | return false |
| 1814 | } else if sanitize.isSanitizerEnabled(Hwasan) { |
| 1815 | return false |
| 1816 | } else if sanitize.isSanitizerEnabled(Fuzzer) { |
| 1817 | return false |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1818 | } |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1819 | |
| 1820 | if enableUbsanRuntime(sanitize) { |
| 1821 | return false |
| 1822 | } |
| 1823 | |
| 1824 | sanitizeProps := &sanitize.Properties.SanitizeMutated |
| 1825 | if Bool(sanitizeProps.Diag.Cfi) { |
| 1826 | return false |
| 1827 | } |
| 1828 | |
| 1829 | return Bool(sanitizeProps.Integer_overflow) || |
| 1830 | len(sanitizeProps.Misc_undefined) > 0 || |
| 1831 | Bool(sanitizeProps.Undefined) || |
| 1832 | Bool(sanitizeProps.All_undefined) |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1835 | func (m *Module) UbsanRuntimeNeeded() bool { |
| 1836 | return enableUbsanRuntime(m.sanitize) |
| 1837 | } |
| 1838 | |
| 1839 | func (m *Module) MinimalRuntimeNeeded() bool { |
| 1840 | return enableMinimalRuntime(m.sanitize) |
| 1841 | } |
| 1842 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1843 | func enableUbsanRuntime(sanitize *sanitize) bool { |
Liz Kammer | 2c1d6aa | 2022-10-03 15:07:37 -0400 | [diff] [blame] | 1844 | sanitizeProps := &sanitize.Properties.SanitizeMutated |
| 1845 | return Bool(sanitizeProps.Diag.Integer_overflow) || |
| 1846 | Bool(sanitizeProps.Diag.Undefined) || |
| 1847 | len(sanitizeProps.Diag.Misc_undefined) > 0 |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1848 | } |
| 1849 | |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 1850 | func cfiMakeVarsProvider(ctx android.MakeVarsContext) { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1851 | cfiStaticLibs(ctx.Config()).exportToMake(ctx) |
Vishwath Mohan | e712879 | 2017-11-17 11:08:10 -0800 | [diff] [blame] | 1852 | } |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 1853 | |
| 1854 | func hwasanMakeVarsProvider(ctx android.MakeVarsContext) { |
Inseob Kim | 74d2556 | 2020-08-04 00:41:38 +0900 | [diff] [blame] | 1855 | hwasanStaticLibs(ctx.Config()).exportToMake(ctx) |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 1856 | } |
Trevor Radcliffe | 4f95ee9 | 2023-01-19 16:02:47 +0000 | [diff] [blame] | 1857 | |
| 1858 | func BazelCcSanitizerToolchainVars(config android.Config) string { |
| 1859 | return android.BazelToolchainVars(config, exportedVars) |
| 1860 | } |