Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 ( |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 19 | "runtime" |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 20 | "strings" |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint" |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(` |
| 29 | cc_library_shared { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 30 | name: "libclang_rt.asan", |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 31 | host_supported: true, |
| 32 | } |
| 33 | cc_library_static { |
| 34 | name: "libclang_rt.asan.static", |
| 35 | host_supported: true, |
| 36 | } |
| 37 | cc_library_static { |
| 38 | name: "libclang_rt.asan_cxx.static", |
| 39 | host_supported: true, |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 40 | } |
| 41 | `)) |
| 42 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 43 | var prepareForTsanTest = android.FixtureAddFile("tsan/Android.bp", []byte(` |
| 44 | cc_library_shared { |
| 45 | name: "libclang_rt.tsan", |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 46 | host_supported: true, |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 47 | } |
| 48 | `)) |
| 49 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 50 | type providerInterface interface { |
| 51 | ModuleProvider(blueprint.Module, blueprint.ProviderKey) interface{} |
| 52 | } |
| 53 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 54 | // expectSharedLinkDep verifies that the from module links against the to module as a |
| 55 | // shared library. |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 56 | func expectSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 57 | t.Helper() |
| 58 | fromLink := from.Description("link") |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 59 | toInfo := ctx.ModuleProvider(to.Module(), SharedLibraryInfoProvider).(SharedLibraryInfo) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 60 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 61 | if g, w := fromLink.OrderOnly.Strings(), toInfo.SharedLibrary.RelativeToTop().String(); !android.InList(w, g) { |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 62 | t.Errorf("%s should link against %s, expected %q, got %q", |
| 63 | from.Module(), to.Module(), w, g) |
| 64 | } |
| 65 | } |
| 66 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 67 | // expectNoSharedLinkDep verifies that the from module links against the to module as a |
| 68 | // shared library. |
| 69 | func expectNoSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { |
| 70 | t.Helper() |
| 71 | fromLink := from.Description("link") |
| 72 | toInfo := ctx.ModuleProvider(to.Module(), SharedLibraryInfoProvider).(SharedLibraryInfo) |
| 73 | |
| 74 | if g, w := fromLink.OrderOnly.Strings(), toInfo.SharedLibrary.RelativeToTop().String(); android.InList(w, g) { |
| 75 | t.Errorf("%s should not link against %s, expected %q, got %q", |
| 76 | from.Module(), to.Module(), w, g) |
| 77 | } |
| 78 | } |
| 79 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 80 | // expectStaticLinkDep verifies that the from module links against the to module as a |
| 81 | // static library. |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 82 | func expectStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 83 | t.Helper() |
| 84 | fromLink := from.Description("link") |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 85 | toInfo := ctx.ModuleProvider(to.Module(), StaticLibraryInfoProvider).(StaticLibraryInfo) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 86 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 87 | if g, w := fromLink.Implicits.Strings(), toInfo.StaticLibrary.RelativeToTop().String(); !android.InList(w, g) { |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 88 | t.Errorf("%s should link against %s, expected %q, got %q", |
| 89 | from.Module(), to.Module(), w, g) |
| 90 | } |
| 91 | |
| 92 | } |
| 93 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 94 | // expectNoStaticLinkDep verifies that the from module links against the to module as a |
| 95 | // static library. |
| 96 | func expectNoStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { |
| 97 | t.Helper() |
| 98 | fromLink := from.Description("link") |
| 99 | toInfo := ctx.ModuleProvider(to.Module(), StaticLibraryInfoProvider).(StaticLibraryInfo) |
| 100 | |
| 101 | if g, w := fromLink.Implicits.Strings(), toInfo.StaticLibrary.RelativeToTop().String(); android.InList(w, g) { |
| 102 | t.Errorf("%s should not link against %s, expected %q, got %q", |
| 103 | from.Module(), to.Module(), w, g) |
| 104 | } |
| 105 | |
| 106 | } |
| 107 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 108 | // expectInstallDep verifies that the install rule of the from module depends on the |
| 109 | // install rule of the to module. |
| 110 | func expectInstallDep(t *testing.T, from, to android.TestingModule) { |
| 111 | t.Helper() |
| 112 | fromInstalled := from.Description("install") |
| 113 | toInstalled := to.Description("install") |
| 114 | |
| 115 | // combine implicits and order-only dependencies, host uses implicit but device uses |
| 116 | // order-only. |
| 117 | got := append(fromInstalled.Implicits.Strings(), fromInstalled.OrderOnly.Strings()...) |
| 118 | want := toInstalled.Output.String() |
| 119 | if !android.InList(want, got) { |
| 120 | t.Errorf("%s installation should depend on %s, expected %q, got %q", |
| 121 | from.Module(), to.Module(), want, got) |
| 122 | } |
| 123 | } |
| 124 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 125 | type expectedRuntimeLinkage int |
| 126 | |
| 127 | const ( |
| 128 | RUNTIME_LINKAGE_NONE = expectedRuntimeLinkage(0) |
| 129 | RUNTIME_LINKAGE_SHARED = iota |
Colin Cross | b781d23 | 2023-02-15 12:40:20 -0800 | [diff] [blame] | 130 | RUNTIME_LINKAGE_STATIC |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 131 | ) |
| 132 | |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 133 | func TestAsan(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 134 | t.Parallel() |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 135 | bp := ` |
| 136 | cc_binary { |
| 137 | name: "bin_with_asan", |
| 138 | host_supported: true, |
| 139 | shared_libs: [ |
| 140 | "libshared", |
| 141 | "libasan", |
| 142 | ], |
| 143 | static_libs: [ |
| 144 | "libstatic", |
| 145 | "libnoasan", |
Liz Kammer | ecc659c | 2022-10-28 16:27:13 -0400 | [diff] [blame] | 146 | "libstatic_asan", |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 147 | ], |
| 148 | sanitize: { |
| 149 | address: true, |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | cc_binary { |
| 154 | name: "bin_no_asan", |
| 155 | host_supported: true, |
| 156 | shared_libs: [ |
| 157 | "libshared", |
| 158 | "libasan", |
| 159 | ], |
| 160 | static_libs: [ |
| 161 | "libstatic", |
| 162 | "libnoasan", |
Liz Kammer | ecc659c | 2022-10-28 16:27:13 -0400 | [diff] [blame] | 163 | "libstatic_asan", |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 164 | ], |
| 165 | } |
| 166 | |
| 167 | cc_library_shared { |
| 168 | name: "libshared", |
| 169 | host_supported: true, |
| 170 | shared_libs: ["libtransitive"], |
| 171 | } |
| 172 | |
| 173 | cc_library_shared { |
| 174 | name: "libasan", |
| 175 | host_supported: true, |
| 176 | shared_libs: ["libtransitive"], |
| 177 | sanitize: { |
| 178 | address: true, |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | cc_library_shared { |
| 183 | name: "libtransitive", |
| 184 | host_supported: true, |
| 185 | } |
| 186 | |
| 187 | cc_library_static { |
| 188 | name: "libstatic", |
| 189 | host_supported: true, |
| 190 | } |
| 191 | |
| 192 | cc_library_static { |
| 193 | name: "libnoasan", |
| 194 | host_supported: true, |
| 195 | sanitize: { |
| 196 | address: false, |
| 197 | } |
| 198 | } |
Liz Kammer | ecc659c | 2022-10-28 16:27:13 -0400 | [diff] [blame] | 199 | |
| 200 | cc_library_static { |
| 201 | name: "libstatic_asan", |
| 202 | host_supported: true, |
| 203 | sanitize: { |
| 204 | address: true, |
| 205 | } |
| 206 | } |
| 207 | |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 208 | ` |
| 209 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 210 | preparer := android.GroupFixturePreparers( |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 211 | prepareForCcTest, |
| 212 | prepareForAsanTest, |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 213 | ) |
| 214 | buildOS := preparer.RunTestWithBp(t, bp).Config.BuildOSTarget.String() |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 215 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 216 | check := func(t *testing.T, variant string, runtimeLinkage expectedRuntimeLinkage, preparer android.FixturePreparer) { |
| 217 | result := preparer.RunTestWithBp(t, bp) |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 218 | ctx := result.TestContext |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 219 | asanVariant := variant + "_asan" |
| 220 | sharedVariant := variant + "_shared" |
| 221 | sharedAsanVariant := sharedVariant + "_asan" |
| 222 | staticVariant := variant + "_static" |
| 223 | staticAsanVariant := staticVariant + "_asan" |
| 224 | |
| 225 | // The binaries, one with asan and one without |
| 226 | binWithAsan := result.ModuleForTests("bin_with_asan", asanVariant) |
| 227 | binNoAsan := result.ModuleForTests("bin_no_asan", variant) |
| 228 | |
| 229 | // Shared libraries that don't request asan |
| 230 | libShared := result.ModuleForTests("libshared", sharedVariant) |
| 231 | libTransitive := result.ModuleForTests("libtransitive", sharedVariant) |
| 232 | |
| 233 | // Shared library that requests asan |
| 234 | libAsan := result.ModuleForTests("libasan", sharedAsanVariant) |
| 235 | |
| 236 | // Static library that uses an asan variant for bin_with_asan and a non-asan variant |
| 237 | // for bin_no_asan. |
| 238 | libStaticAsanVariant := result.ModuleForTests("libstatic", staticAsanVariant) |
| 239 | libStaticNoAsanVariant := result.ModuleForTests("libstatic", staticVariant) |
| 240 | |
| 241 | // Static library that never uses asan. |
| 242 | libNoAsan := result.ModuleForTests("libnoasan", staticVariant) |
| 243 | |
Liz Kammer | ecc659c | 2022-10-28 16:27:13 -0400 | [diff] [blame] | 244 | // Static library that specifies asan |
| 245 | libStaticAsan := result.ModuleForTests("libstatic_asan", staticAsanVariant) |
| 246 | libStaticAsanNoAsanVariant := result.ModuleForTests("libstatic_asan", staticVariant) |
| 247 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 248 | libAsanSharedRuntime := result.ModuleForTests("libclang_rt.asan", sharedVariant) |
Colin Cross | b781d23 | 2023-02-15 12:40:20 -0800 | [diff] [blame] | 249 | libAsanStaticRuntime := result.ModuleForTests("libclang_rt.asan.static", staticVariant) |
| 250 | libAsanStaticCxxRuntime := result.ModuleForTests("libclang_rt.asan_cxx.static", staticVariant) |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 251 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 252 | expectSharedLinkDep(t, ctx, binWithAsan, libShared) |
| 253 | expectSharedLinkDep(t, ctx, binWithAsan, libAsan) |
| 254 | expectSharedLinkDep(t, ctx, libShared, libTransitive) |
| 255 | expectSharedLinkDep(t, ctx, libAsan, libTransitive) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 256 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 257 | expectStaticLinkDep(t, ctx, binWithAsan, libStaticAsanVariant) |
| 258 | expectStaticLinkDep(t, ctx, binWithAsan, libNoAsan) |
| 259 | expectStaticLinkDep(t, ctx, binWithAsan, libStaticAsan) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 260 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 261 | expectInstallDep(t, binWithAsan, libShared) |
| 262 | expectInstallDep(t, binWithAsan, libAsan) |
| 263 | expectInstallDep(t, binWithAsan, libTransitive) |
| 264 | expectInstallDep(t, libShared, libTransitive) |
| 265 | expectInstallDep(t, libAsan, libTransitive) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 266 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 267 | expectSharedLinkDep(t, ctx, binNoAsan, libShared) |
| 268 | expectSharedLinkDep(t, ctx, binNoAsan, libAsan) |
| 269 | expectSharedLinkDep(t, ctx, libShared, libTransitive) |
| 270 | expectSharedLinkDep(t, ctx, libAsan, libTransitive) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 271 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 272 | expectStaticLinkDep(t, ctx, binNoAsan, libStaticNoAsanVariant) |
| 273 | expectStaticLinkDep(t, ctx, binNoAsan, libNoAsan) |
| 274 | expectStaticLinkDep(t, ctx, binNoAsan, libStaticAsanNoAsanVariant) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 275 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 276 | expectInstallDep(t, binNoAsan, libShared) |
| 277 | expectInstallDep(t, binNoAsan, libAsan) |
| 278 | expectInstallDep(t, binNoAsan, libTransitive) |
| 279 | expectInstallDep(t, libShared, libTransitive) |
| 280 | expectInstallDep(t, libAsan, libTransitive) |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 281 | |
| 282 | if runtimeLinkage == RUNTIME_LINKAGE_SHARED { |
| 283 | expectSharedLinkDep(t, ctx, binWithAsan, libAsanSharedRuntime) |
| 284 | expectNoSharedLinkDep(t, ctx, binNoAsan, libAsanSharedRuntime) |
| 285 | expectSharedLinkDep(t, ctx, libAsan, libAsanSharedRuntime) |
| 286 | expectNoSharedLinkDep(t, ctx, libShared, libAsanSharedRuntime) |
| 287 | expectNoSharedLinkDep(t, ctx, libTransitive, libAsanSharedRuntime) |
| 288 | } else { |
| 289 | expectNoSharedLinkDep(t, ctx, binWithAsan, libAsanSharedRuntime) |
| 290 | expectNoSharedLinkDep(t, ctx, binNoAsan, libAsanSharedRuntime) |
| 291 | expectNoSharedLinkDep(t, ctx, libAsan, libAsanSharedRuntime) |
| 292 | expectNoSharedLinkDep(t, ctx, libShared, libAsanSharedRuntime) |
| 293 | expectNoSharedLinkDep(t, ctx, libTransitive, libAsanSharedRuntime) |
| 294 | } |
Colin Cross | b781d23 | 2023-02-15 12:40:20 -0800 | [diff] [blame] | 295 | |
| 296 | if runtimeLinkage == RUNTIME_LINKAGE_STATIC { |
| 297 | expectStaticLinkDep(t, ctx, binWithAsan, libAsanStaticRuntime) |
| 298 | expectNoStaticLinkDep(t, ctx, binNoAsan, libAsanStaticRuntime) |
| 299 | expectStaticLinkDep(t, ctx, libAsan, libAsanStaticRuntime) |
| 300 | expectNoStaticLinkDep(t, ctx, libShared, libAsanStaticRuntime) |
| 301 | expectNoStaticLinkDep(t, ctx, libTransitive, libAsanStaticRuntime) |
| 302 | |
| 303 | expectStaticLinkDep(t, ctx, binWithAsan, libAsanStaticCxxRuntime) |
| 304 | expectNoStaticLinkDep(t, ctx, binNoAsan, libAsanStaticCxxRuntime) |
| 305 | expectStaticLinkDep(t, ctx, libAsan, libAsanStaticCxxRuntime) |
| 306 | expectNoStaticLinkDep(t, ctx, libShared, libAsanStaticCxxRuntime) |
| 307 | expectNoStaticLinkDep(t, ctx, libTransitive, libAsanStaticCxxRuntime) |
| 308 | } else { |
| 309 | expectNoStaticLinkDep(t, ctx, binWithAsan, libAsanStaticRuntime) |
| 310 | expectNoStaticLinkDep(t, ctx, binNoAsan, libAsanStaticRuntime) |
| 311 | expectNoStaticLinkDep(t, ctx, libAsan, libAsanStaticRuntime) |
| 312 | expectNoStaticLinkDep(t, ctx, libShared, libAsanStaticRuntime) |
| 313 | expectNoStaticLinkDep(t, ctx, libTransitive, libAsanStaticRuntime) |
| 314 | |
| 315 | expectNoStaticLinkDep(t, ctx, binWithAsan, libAsanStaticCxxRuntime) |
| 316 | expectNoStaticLinkDep(t, ctx, binNoAsan, libAsanStaticCxxRuntime) |
| 317 | expectNoStaticLinkDep(t, ctx, libAsan, libAsanStaticCxxRuntime) |
| 318 | expectNoStaticLinkDep(t, ctx, libShared, libAsanStaticCxxRuntime) |
| 319 | expectNoStaticLinkDep(t, ctx, libTransitive, libAsanStaticCxxRuntime) |
| 320 | } |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 323 | t.Run("host", func(t *testing.T) { check(t, buildOS, RUNTIME_LINKAGE_NONE, preparer) }) |
| 324 | t.Run("device", func(t *testing.T) { check(t, "android_arm64_armv8-a", RUNTIME_LINKAGE_SHARED, preparer) }) |
| 325 | t.Run("host musl", func(t *testing.T) { |
Colin Cross | b781d23 | 2023-02-15 12:40:20 -0800 | [diff] [blame] | 326 | check(t, "linux_musl_x86_64", RUNTIME_LINKAGE_STATIC, |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 327 | android.GroupFixturePreparers(preparer, PrepareForTestWithHostMusl)) |
| 328 | }) |
Colin Cross | af98f58 | 2021-05-12 17:27:32 -0700 | [diff] [blame] | 329 | } |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 330 | |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 331 | func TestTsan(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 332 | t.Parallel() |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 333 | bp := ` |
| 334 | cc_binary { |
| 335 | name: "bin_with_tsan", |
| 336 | host_supported: true, |
| 337 | shared_libs: [ |
| 338 | "libshared", |
| 339 | "libtsan", |
| 340 | ], |
| 341 | sanitize: { |
| 342 | thread: true, |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | cc_binary { |
| 347 | name: "bin_no_tsan", |
| 348 | host_supported: true, |
| 349 | shared_libs: [ |
| 350 | "libshared", |
| 351 | "libtsan", |
| 352 | ], |
| 353 | } |
| 354 | |
| 355 | cc_library_shared { |
| 356 | name: "libshared", |
| 357 | host_supported: true, |
| 358 | shared_libs: ["libtransitive"], |
| 359 | } |
| 360 | |
| 361 | cc_library_shared { |
| 362 | name: "libtsan", |
| 363 | host_supported: true, |
| 364 | shared_libs: ["libtransitive"], |
| 365 | sanitize: { |
| 366 | thread: true, |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | cc_library_shared { |
| 371 | name: "libtransitive", |
| 372 | host_supported: true, |
| 373 | } |
| 374 | ` |
| 375 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 376 | preparer := android.GroupFixturePreparers( |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 377 | prepareForCcTest, |
| 378 | prepareForTsanTest, |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 379 | ) |
| 380 | buildOS := preparer.RunTestWithBp(t, bp).Config.BuildOSTarget.String() |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 381 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 382 | check := func(t *testing.T, variant string, preparer android.FixturePreparer) { |
| 383 | result := preparer.RunTestWithBp(t, bp) |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 384 | ctx := result.TestContext |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 385 | tsanVariant := variant + "_tsan" |
| 386 | sharedVariant := variant + "_shared" |
| 387 | sharedTsanVariant := sharedVariant + "_tsan" |
| 388 | |
| 389 | // The binaries, one with tsan and one without |
| 390 | binWithTsan := result.ModuleForTests("bin_with_tsan", tsanVariant) |
| 391 | binNoTsan := result.ModuleForTests("bin_no_tsan", variant) |
| 392 | |
| 393 | // Shared libraries that don't request tsan |
| 394 | libShared := result.ModuleForTests("libshared", sharedVariant) |
| 395 | libTransitive := result.ModuleForTests("libtransitive", sharedVariant) |
| 396 | |
| 397 | // Shared library that requests tsan |
| 398 | libTsan := result.ModuleForTests("libtsan", sharedTsanVariant) |
| 399 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 400 | expectSharedLinkDep(t, ctx, binWithTsan, libShared) |
| 401 | expectSharedLinkDep(t, ctx, binWithTsan, libTsan) |
| 402 | expectSharedLinkDep(t, ctx, libShared, libTransitive) |
| 403 | expectSharedLinkDep(t, ctx, libTsan, libTransitive) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 404 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 405 | expectSharedLinkDep(t, ctx, binNoTsan, libShared) |
| 406 | expectSharedLinkDep(t, ctx, binNoTsan, libTsan) |
| 407 | expectSharedLinkDep(t, ctx, libShared, libTransitive) |
| 408 | expectSharedLinkDep(t, ctx, libTsan, libTransitive) |
| 409 | } |
| 410 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 411 | t.Run("host", func(t *testing.T) { check(t, buildOS, preparer) }) |
| 412 | t.Run("device", func(t *testing.T) { check(t, "android_arm64_armv8-a", preparer) }) |
| 413 | t.Run("host musl", func(t *testing.T) { |
| 414 | check(t, "linux_musl_x86_64", android.GroupFixturePreparers(preparer, PrepareForTestWithHostMusl)) |
| 415 | }) |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | func TestMiscUndefined(t *testing.T) { |
Liz Kammer | 2a109bc | 2022-12-02 09:36:01 -0500 | [diff] [blame] | 419 | if runtime.GOOS != "linux" { |
| 420 | t.Skip("requires linux") |
| 421 | } |
| 422 | |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 423 | t.Parallel() |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 424 | bp := ` |
| 425 | cc_binary { |
| 426 | name: "bin_with_ubsan", |
| 427 | srcs: ["src.cc"], |
| 428 | host_supported: true, |
| 429 | static_libs: [ |
| 430 | "libstatic", |
| 431 | "libubsan", |
| 432 | ], |
| 433 | sanitize: { |
| 434 | misc_undefined: ["integer"], |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | cc_binary { |
| 439 | name: "bin_no_ubsan", |
| 440 | host_supported: true, |
| 441 | srcs: ["src.cc"], |
| 442 | static_libs: [ |
| 443 | "libstatic", |
| 444 | "libubsan", |
| 445 | ], |
| 446 | } |
| 447 | |
| 448 | cc_library_static { |
| 449 | name: "libstatic", |
| 450 | host_supported: true, |
| 451 | srcs: ["src.cc"], |
| 452 | static_libs: ["libtransitive"], |
| 453 | } |
| 454 | |
| 455 | cc_library_static { |
| 456 | name: "libubsan", |
| 457 | host_supported: true, |
| 458 | srcs: ["src.cc"], |
| 459 | whole_static_libs: ["libtransitive"], |
| 460 | sanitize: { |
| 461 | misc_undefined: ["integer"], |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | cc_library_static { |
| 466 | name: "libtransitive", |
| 467 | host_supported: true, |
| 468 | srcs: ["src.cc"], |
| 469 | } |
| 470 | ` |
| 471 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 472 | preparer := android.GroupFixturePreparers( |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 473 | prepareForCcTest, |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 474 | ) |
| 475 | buildOS := preparer.RunTestWithBp(t, bp).Config.BuildOSTarget.String() |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 476 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 477 | check := func(t *testing.T, variant string, preparer android.FixturePreparer) { |
| 478 | result := preparer.RunTestWithBp(t, bp) |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 479 | ctx := result.TestContext |
| 480 | staticVariant := variant + "_static" |
| 481 | |
| 482 | // The binaries, one with ubsan and one without |
| 483 | binWithUbsan := result.ModuleForTests("bin_with_ubsan", variant) |
| 484 | binNoUbsan := result.ModuleForTests("bin_no_ubsan", variant) |
| 485 | |
| 486 | // Static libraries that don't request ubsan |
| 487 | libStatic := result.ModuleForTests("libstatic", staticVariant) |
| 488 | libTransitive := result.ModuleForTests("libtransitive", staticVariant) |
| 489 | |
| 490 | libUbsan := result.ModuleForTests("libubsan", staticVariant) |
| 491 | |
| 492 | libUbsanMinimal := result.ModuleForTests("libclang_rt.ubsan_minimal", staticVariant) |
| 493 | |
| 494 | expectStaticLinkDep(t, ctx, binWithUbsan, libStatic) |
| 495 | expectStaticLinkDep(t, ctx, binWithUbsan, libUbsan) |
| 496 | expectStaticLinkDep(t, ctx, binWithUbsan, libUbsanMinimal) |
| 497 | |
| 498 | miscUndefinedSanFlag := "-fsanitize=integer" |
| 499 | binWithUbsanCflags := binWithUbsan.Rule("cc").Args["cFlags"] |
| 500 | if !strings.Contains(binWithUbsanCflags, miscUndefinedSanFlag) { |
| 501 | t.Errorf("'bin_with_ubsan' Expected %q to be in flags %q, was not", miscUndefinedSanFlag, binWithUbsanCflags) |
| 502 | } |
| 503 | libStaticCflags := libStatic.Rule("cc").Args["cFlags"] |
| 504 | if strings.Contains(libStaticCflags, miscUndefinedSanFlag) { |
| 505 | t.Errorf("'libstatic' Expected %q to NOT be in flags %q, was", miscUndefinedSanFlag, binWithUbsanCflags) |
| 506 | } |
| 507 | libUbsanCflags := libUbsan.Rule("cc").Args["cFlags"] |
| 508 | if !strings.Contains(libUbsanCflags, miscUndefinedSanFlag) { |
| 509 | t.Errorf("'libubsan' Expected %q to be in flags %q, was not", miscUndefinedSanFlag, binWithUbsanCflags) |
| 510 | } |
| 511 | libTransitiveCflags := libTransitive.Rule("cc").Args["cFlags"] |
| 512 | if strings.Contains(libTransitiveCflags, miscUndefinedSanFlag) { |
| 513 | t.Errorf("'libtransitive': Expected %q to NOT be in flags %q, was", miscUndefinedSanFlag, binWithUbsanCflags) |
| 514 | } |
| 515 | |
| 516 | expectStaticLinkDep(t, ctx, binNoUbsan, libStatic) |
| 517 | expectStaticLinkDep(t, ctx, binNoUbsan, libUbsan) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 520 | t.Run("host", func(t *testing.T) { check(t, buildOS, preparer) }) |
| 521 | t.Run("device", func(t *testing.T) { check(t, "android_arm64_armv8-a", preparer) }) |
| 522 | t.Run("host musl", func(t *testing.T) { |
| 523 | check(t, "linux_musl_x86_64", android.GroupFixturePreparers(preparer, PrepareForTestWithHostMusl)) |
| 524 | }) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | func TestFuzz(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 528 | t.Parallel() |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 529 | bp := ` |
| 530 | cc_binary { |
| 531 | name: "bin_with_fuzzer", |
| 532 | host_supported: true, |
| 533 | shared_libs: [ |
| 534 | "libshared", |
| 535 | "libfuzzer", |
| 536 | ], |
| 537 | static_libs: [ |
| 538 | "libstatic", |
| 539 | "libnofuzzer", |
| 540 | "libstatic_fuzzer", |
| 541 | ], |
| 542 | sanitize: { |
| 543 | fuzzer: true, |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | cc_binary { |
| 548 | name: "bin_no_fuzzer", |
| 549 | host_supported: true, |
| 550 | shared_libs: [ |
| 551 | "libshared", |
| 552 | "libfuzzer", |
| 553 | ], |
| 554 | static_libs: [ |
| 555 | "libstatic", |
| 556 | "libnofuzzer", |
| 557 | "libstatic_fuzzer", |
| 558 | ], |
| 559 | } |
| 560 | |
| 561 | cc_library_shared { |
| 562 | name: "libshared", |
| 563 | host_supported: true, |
| 564 | shared_libs: ["libtransitive"], |
| 565 | } |
| 566 | |
| 567 | cc_library_shared { |
| 568 | name: "libfuzzer", |
| 569 | host_supported: true, |
| 570 | shared_libs: ["libtransitive"], |
| 571 | sanitize: { |
| 572 | fuzzer: true, |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | cc_library_shared { |
| 577 | name: "libtransitive", |
| 578 | host_supported: true, |
| 579 | } |
| 580 | |
| 581 | cc_library_static { |
| 582 | name: "libstatic", |
| 583 | host_supported: true, |
| 584 | } |
| 585 | |
| 586 | cc_library_static { |
| 587 | name: "libnofuzzer", |
| 588 | host_supported: true, |
| 589 | sanitize: { |
| 590 | fuzzer: false, |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | cc_library_static { |
| 595 | name: "libstatic_fuzzer", |
| 596 | host_supported: true, |
| 597 | } |
| 598 | |
| 599 | ` |
| 600 | |
| 601 | result := android.GroupFixturePreparers( |
| 602 | prepareForCcTest, |
| 603 | ).RunTestWithBp(t, bp) |
| 604 | |
| 605 | check := func(t *testing.T, result *android.TestResult, variant string) { |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 606 | ctx := result.TestContext |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 607 | fuzzerVariant := variant + "_fuzzer" |
| 608 | sharedVariant := variant + "_shared" |
| 609 | sharedFuzzerVariant := sharedVariant + "_fuzzer" |
| 610 | staticVariant := variant + "_static" |
| 611 | staticFuzzerVariant := staticVariant + "_fuzzer" |
| 612 | |
| 613 | // The binaries, one with fuzzer and one without |
| 614 | binWithFuzzer := result.ModuleForTests("bin_with_fuzzer", fuzzerVariant) |
| 615 | binNoFuzzer := result.ModuleForTests("bin_no_fuzzer", variant) |
| 616 | |
| 617 | // Shared libraries that don't request fuzzer |
| 618 | libShared := result.ModuleForTests("libshared", sharedVariant) |
| 619 | libTransitive := result.ModuleForTests("libtransitive", sharedVariant) |
| 620 | |
| 621 | // Shared libraries that don't request fuzzer |
| 622 | libSharedFuzzer := result.ModuleForTests("libshared", sharedFuzzerVariant) |
| 623 | libTransitiveFuzzer := result.ModuleForTests("libtransitive", sharedFuzzerVariant) |
| 624 | |
| 625 | // Shared library that requests fuzzer |
| 626 | libFuzzer := result.ModuleForTests("libfuzzer", sharedFuzzerVariant) |
| 627 | |
| 628 | // Static library that uses an fuzzer variant for bin_with_fuzzer and a non-fuzzer variant |
| 629 | // for bin_no_fuzzer. |
| 630 | libStaticFuzzerVariant := result.ModuleForTests("libstatic", staticFuzzerVariant) |
| 631 | libStaticNoFuzzerVariant := result.ModuleForTests("libstatic", staticVariant) |
| 632 | |
| 633 | // Static library that never uses fuzzer. |
| 634 | libNoFuzzer := result.ModuleForTests("libnofuzzer", staticVariant) |
| 635 | |
| 636 | // Static library that specifies fuzzer |
| 637 | libStaticFuzzer := result.ModuleForTests("libstatic_fuzzer", staticFuzzerVariant) |
| 638 | libStaticFuzzerNoFuzzerVariant := result.ModuleForTests("libstatic_fuzzer", staticVariant) |
| 639 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 640 | expectSharedLinkDep(t, ctx, binWithFuzzer, libSharedFuzzer) |
| 641 | expectSharedLinkDep(t, ctx, binWithFuzzer, libFuzzer) |
| 642 | expectSharedLinkDep(t, ctx, libSharedFuzzer, libTransitiveFuzzer) |
| 643 | expectSharedLinkDep(t, ctx, libFuzzer, libTransitiveFuzzer) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 644 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 645 | expectStaticLinkDep(t, ctx, binWithFuzzer, libStaticFuzzerVariant) |
| 646 | expectStaticLinkDep(t, ctx, binWithFuzzer, libNoFuzzer) |
| 647 | expectStaticLinkDep(t, ctx, binWithFuzzer, libStaticFuzzer) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 648 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 649 | expectSharedLinkDep(t, ctx, binNoFuzzer, libShared) |
| 650 | expectSharedLinkDep(t, ctx, binNoFuzzer, libFuzzer) |
| 651 | expectSharedLinkDep(t, ctx, libShared, libTransitive) |
| 652 | expectSharedLinkDep(t, ctx, libFuzzer, libTransitiveFuzzer) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 653 | |
Liz Kammer | 92c7259 | 2022-10-31 14:44:28 -0400 | [diff] [blame] | 654 | expectStaticLinkDep(t, ctx, binNoFuzzer, libStaticNoFuzzerVariant) |
| 655 | expectStaticLinkDep(t, ctx, binNoFuzzer, libNoFuzzer) |
| 656 | expectStaticLinkDep(t, ctx, binNoFuzzer, libStaticFuzzerNoFuzzerVariant) |
Liz Kammer | fd8a49f | 2022-10-31 10:31:11 -0400 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | t.Run("device", func(t *testing.T) { check(t, result, "android_arm64_armv8-a") }) |
| 660 | } |
| 661 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 662 | func TestUbsan(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 663 | t.Parallel() |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 664 | if runtime.GOOS != "linux" { |
| 665 | t.Skip("requires linux") |
| 666 | } |
| 667 | |
| 668 | bp := ` |
| 669 | cc_binary { |
| 670 | name: "bin_with_ubsan", |
| 671 | host_supported: true, |
| 672 | shared_libs: [ |
| 673 | "libshared", |
| 674 | ], |
| 675 | static_libs: [ |
| 676 | "libstatic", |
| 677 | "libnoubsan", |
| 678 | ], |
| 679 | sanitize: { |
| 680 | undefined: true, |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | cc_binary { |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 685 | name: "bin_depends_ubsan_static", |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 686 | host_supported: true, |
| 687 | shared_libs: [ |
| 688 | "libshared", |
| 689 | ], |
| 690 | static_libs: [ |
| 691 | "libstatic", |
| 692 | "libubsan", |
| 693 | "libnoubsan", |
| 694 | ], |
| 695 | } |
| 696 | |
| 697 | cc_binary { |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 698 | name: "bin_depends_ubsan_shared", |
| 699 | host_supported: true, |
| 700 | shared_libs: [ |
| 701 | "libsharedubsan", |
| 702 | ], |
| 703 | } |
| 704 | |
| 705 | cc_binary { |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 706 | name: "bin_no_ubsan", |
| 707 | host_supported: true, |
| 708 | shared_libs: [ |
| 709 | "libshared", |
| 710 | ], |
| 711 | static_libs: [ |
| 712 | "libstatic", |
| 713 | "libnoubsan", |
| 714 | ], |
| 715 | } |
| 716 | |
Colin Cross | 0df8153 | 2023-08-23 22:20:51 -0700 | [diff] [blame] | 717 | cc_binary { |
| 718 | name: "static_bin_with_ubsan_dep", |
| 719 | static_executable: true, |
| 720 | host_supported: true, |
| 721 | static_libs: [ |
| 722 | "libubsan_diag", |
| 723 | ], |
| 724 | } |
| 725 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 726 | cc_library_shared { |
| 727 | name: "libshared", |
| 728 | host_supported: true, |
| 729 | shared_libs: ["libtransitive"], |
| 730 | } |
| 731 | |
| 732 | cc_library_shared { |
| 733 | name: "libtransitive", |
| 734 | host_supported: true, |
| 735 | } |
| 736 | |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 737 | cc_library_shared { |
| 738 | name: "libsharedubsan", |
| 739 | host_supported: true, |
| 740 | sanitize: { |
| 741 | undefined: true, |
| 742 | } |
| 743 | } |
| 744 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 745 | cc_library_static { |
| 746 | name: "libubsan", |
| 747 | host_supported: true, |
| 748 | sanitize: { |
| 749 | undefined: true, |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | cc_library_static { |
Colin Cross | 0df8153 | 2023-08-23 22:20:51 -0700 | [diff] [blame] | 754 | name: "libubsan_diag", |
| 755 | host_supported: true, |
| 756 | sanitize: { |
| 757 | undefined: true, |
| 758 | diag: { |
| 759 | undefined: true, |
| 760 | }, |
| 761 | }, |
| 762 | } |
| 763 | |
| 764 | cc_library_static { |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 765 | name: "libstatic", |
| 766 | host_supported: true, |
| 767 | } |
| 768 | |
| 769 | cc_library_static { |
| 770 | name: "libnoubsan", |
| 771 | host_supported: true, |
| 772 | } |
| 773 | ` |
| 774 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 775 | preparer := android.GroupFixturePreparers( |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 776 | prepareForCcTest, |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 777 | ) |
| 778 | buildOS := preparer.RunTestWithBp(t, bp).Config.BuildOSTarget.String() |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 779 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 780 | check := func(t *testing.T, variant string, preparer android.FixturePreparer) { |
| 781 | result := preparer.RunTestWithBp(t, bp) |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 782 | staticVariant := variant + "_static" |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 783 | sharedVariant := variant + "_shared" |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 784 | |
| 785 | minimalRuntime := result.ModuleForTests("libclang_rt.ubsan_minimal", staticVariant) |
Colin Cross | 0df8153 | 2023-08-23 22:20:51 -0700 | [diff] [blame] | 786 | standaloneRuntime := result.ModuleForTests("libclang_rt.ubsan_standalone.static", staticVariant) |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 787 | |
| 788 | // The binaries, one with ubsan and one without |
| 789 | binWithUbsan := result.ModuleForTests("bin_with_ubsan", variant) |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 790 | binDependsUbsan := result.ModuleForTests("bin_depends_ubsan_static", variant) |
| 791 | libSharedUbsan := result.ModuleForTests("libsharedubsan", sharedVariant) |
| 792 | binDependsUbsanShared := result.ModuleForTests("bin_depends_ubsan_shared", variant) |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 793 | binNoUbsan := result.ModuleForTests("bin_no_ubsan", variant) |
Colin Cross | 0df8153 | 2023-08-23 22:20:51 -0700 | [diff] [blame] | 794 | staticBin := result.ModuleForTests("static_bin_with_ubsan_dep", variant) |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 795 | |
| 796 | android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_with_ubsan static libs", |
| 797 | strings.Split(binWithUbsan.Rule("ld").Args["libFlags"], " "), |
| 798 | minimalRuntime.OutputFiles(t, "")[0].String()) |
| 799 | |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 800 | android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_depends_ubsan_static static libs", |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 801 | strings.Split(binDependsUbsan.Rule("ld").Args["libFlags"], " "), |
| 802 | minimalRuntime.OutputFiles(t, "")[0].String()) |
| 803 | |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 804 | android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in libsharedubsan static libs", |
| 805 | strings.Split(libSharedUbsan.Rule("ld").Args["libFlags"], " "), |
| 806 | minimalRuntime.OutputFiles(t, "")[0].String()) |
| 807 | |
| 808 | android.AssertStringListDoesNotContain(t, "unexpected libclang_rt.ubsan_minimal in bin_depends_ubsan_shared static libs", |
| 809 | strings.Split(binDependsUbsanShared.Rule("ld").Args["libFlags"], " "), |
| 810 | minimalRuntime.OutputFiles(t, "")[0].String()) |
| 811 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 812 | android.AssertStringListDoesNotContain(t, "unexpected libclang_rt.ubsan_minimal in bin_no_ubsan static libs", |
| 813 | strings.Split(binNoUbsan.Rule("ld").Args["libFlags"], " "), |
| 814 | minimalRuntime.OutputFiles(t, "")[0].String()) |
| 815 | |
| 816 | android.AssertStringListContains(t, "missing -Wl,--exclude-libs for minimal runtime in bin_with_ubsan", |
| 817 | strings.Split(binWithUbsan.Rule("ld").Args["ldFlags"], " "), |
| 818 | "-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base()) |
| 819 | |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 820 | android.AssertStringListContains(t, "missing -Wl,--exclude-libs for minimal runtime in bin_depends_ubsan_static static libs", |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 821 | strings.Split(binDependsUbsan.Rule("ld").Args["ldFlags"], " "), |
| 822 | "-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base()) |
| 823 | |
Trevor Radcliffe | 9981555 | 2022-11-14 21:35:05 +0000 | [diff] [blame] | 824 | android.AssertStringListContains(t, "missing -Wl,--exclude-libs for minimal runtime in libsharedubsan static libs", |
| 825 | strings.Split(libSharedUbsan.Rule("ld").Args["ldFlags"], " "), |
| 826 | "-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base()) |
| 827 | |
| 828 | android.AssertStringListDoesNotContain(t, "unexpected -Wl,--exclude-libs for minimal runtime in bin_depends_ubsan_shared static libs", |
| 829 | strings.Split(binDependsUbsanShared.Rule("ld").Args["ldFlags"], " "), |
| 830 | "-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base()) |
| 831 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 832 | android.AssertStringListDoesNotContain(t, "unexpected -Wl,--exclude-libs for minimal runtime in bin_no_ubsan static libs", |
| 833 | strings.Split(binNoUbsan.Rule("ld").Args["ldFlags"], " "), |
| 834 | "-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base()) |
Colin Cross | 0df8153 | 2023-08-23 22:20:51 -0700 | [diff] [blame] | 835 | |
| 836 | android.AssertStringListContains(t, "missing libclang_rt.ubsan_standalone.static in static_bin_with_ubsan_dep static libs", |
| 837 | strings.Split(staticBin.Rule("ld").Args["libFlags"], " "), |
| 838 | standaloneRuntime.OutputFiles(t, "")[0].String()) |
| 839 | |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Colin Cross | 5dc62c9 | 2023-02-15 12:20:19 -0800 | [diff] [blame] | 842 | t.Run("host", func(t *testing.T) { check(t, buildOS, preparer) }) |
| 843 | t.Run("device", func(t *testing.T) { check(t, "android_arm64_armv8-a", preparer) }) |
| 844 | t.Run("host musl", func(t *testing.T) { |
| 845 | check(t, "linux_musl_x86_64", android.GroupFixturePreparers(preparer, PrepareForTestWithHostMusl)) |
| 846 | }) |
Colin Cross | 3e5e778 | 2022-06-17 22:17:05 +0000 | [diff] [blame] | 847 | } |
| 848 | |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 849 | type MemtagNoteType int |
| 850 | |
| 851 | const ( |
| 852 | None MemtagNoteType = iota + 1 |
| 853 | Sync |
| 854 | Async |
| 855 | ) |
| 856 | |
| 857 | func (t MemtagNoteType) str() string { |
| 858 | switch t { |
| 859 | case None: |
| 860 | return "none" |
| 861 | case Sync: |
| 862 | return "sync" |
| 863 | case Async: |
| 864 | return "async" |
| 865 | default: |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 866 | panic("type_note_invalid") |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | |
| 870 | func checkHasMemtagNote(t *testing.T, m android.TestingModule, expected MemtagNoteType) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 871 | t.Helper() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 872 | |
| 873 | found := None |
Florian Mayer | d8434a4 | 2022-08-31 20:57:03 +0000 | [diff] [blame] | 874 | ldFlags := m.Rule("ld").Args["ldFlags"] |
| 875 | if strings.Contains(ldFlags, "-fsanitize-memtag-mode=async") { |
| 876 | found = Async |
| 877 | } else if strings.Contains(ldFlags, "-fsanitize-memtag-mode=sync") { |
| 878 | found = Sync |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | if found != expected { |
| 882 | t.Errorf("Wrong Memtag note in target %q: found %q, expected %q", m.Module().(*Module).Name(), found.str(), expected.str()) |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | var prepareForTestWithMemtagHeap = android.GroupFixturePreparers( |
| 887 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 888 | templateBp := ` |
| 889 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 890 | name: "unset_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 891 | gtest: false, |
| 892 | } |
| 893 | |
| 894 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 895 | name: "no_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 896 | gtest: false, |
| 897 | sanitize: { memtag_heap: false }, |
| 898 | } |
| 899 | |
| 900 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 901 | name: "set_memtag_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 902 | gtest: false, |
| 903 | sanitize: { memtag_heap: true }, |
| 904 | } |
| 905 | |
| 906 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 907 | name: "set_memtag_set_async_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 908 | gtest: false, |
| 909 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 910 | } |
| 911 | |
| 912 | cc_test { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 913 | name: "set_memtag_set_sync_test_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 914 | gtest: false, |
| 915 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 916 | } |
| 917 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 918 | cc_test { |
| 919 | name: "unset_memtag_set_sync_test_%[1]s", |
| 920 | gtest: false, |
| 921 | sanitize: { diag: { memtag_heap: true } }, |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 925 | name: "unset_binary_%[1]s", |
| 926 | } |
| 927 | |
| 928 | cc_binary { |
| 929 | name: "no_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 930 | sanitize: { memtag_heap: false }, |
| 931 | } |
| 932 | |
| 933 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 934 | name: "set_memtag_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 935 | sanitize: { memtag_heap: true }, |
| 936 | } |
| 937 | |
| 938 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 939 | name: "set_memtag_set_async_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 940 | sanitize: { memtag_heap: true, diag: { memtag_heap: false } }, |
| 941 | } |
| 942 | |
| 943 | cc_binary { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 944 | name: "set_memtag_set_sync_binary_%[1]s", |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 945 | sanitize: { memtag_heap: true, diag: { memtag_heap: true } }, |
| 946 | } |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 947 | |
| 948 | cc_binary { |
| 949 | name: "unset_memtag_set_sync_binary_%[1]s", |
| 950 | sanitize: { diag: { memtag_heap: true } }, |
| 951 | } |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 952 | ` |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 953 | subdirNoOverrideBp := fmt.Sprintf(templateBp, "no_override") |
| 954 | subdirOverrideDefaultDisableBp := fmt.Sprintf(templateBp, "override_default_disable") |
| 955 | subdirSyncBp := fmt.Sprintf(templateBp, "override_default_sync") |
| 956 | subdirAsyncBp := fmt.Sprintf(templateBp, "override_default_async") |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 957 | |
| 958 | fs.Merge(android.MockFS{ |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 959 | "subdir_no_override/Android.bp": []byte(subdirNoOverrideBp), |
| 960 | "subdir_override_default_disable/Android.bp": []byte(subdirOverrideDefaultDisableBp), |
| 961 | "subdir_sync/Android.bp": []byte(subdirSyncBp), |
| 962 | "subdir_async/Android.bp": []byte(subdirAsyncBp), |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 963 | }) |
| 964 | }), |
| 965 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 966 | variables.MemtagHeapExcludePaths = []string{"subdir_override_default_disable"} |
| 967 | // "subdir_override_default_disable" is covered by both include and override_default_disable paths. override_default_disable wins. |
| 968 | variables.MemtagHeapSyncIncludePaths = []string{"subdir_sync", "subdir_override_default_disable"} |
| 969 | variables.MemtagHeapAsyncIncludePaths = []string{"subdir_async", "subdir_override_default_disable"} |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 970 | }), |
| 971 | ) |
| 972 | |
| 973 | func TestSanitizeMemtagHeap(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 974 | t.Parallel() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 975 | variant := "android_arm64_armv8-a" |
| 976 | |
| 977 | result := android.GroupFixturePreparers( |
| 978 | prepareForCcTest, |
| 979 | prepareForTestWithMemtagHeap, |
| 980 | ).RunTest(t) |
| 981 | ctx := result.TestContext |
| 982 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 983 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 984 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 985 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 986 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 987 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 988 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 989 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 990 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 991 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 992 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 993 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async) |
| 994 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async) |
| 995 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async) |
| 996 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 997 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 998 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 999 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 1000 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1001 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1002 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1003 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 1004 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 1005 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 1006 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1007 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1008 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 1009 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 1010 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 1011 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1012 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1013 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 1014 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1015 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 1016 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1017 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1018 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 1019 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1020 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1021 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1022 | |
| 1023 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 1024 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), None) |
| 1025 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1026 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 1027 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 1028 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 1029 | |
| 1030 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 1031 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1032 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1033 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1034 | |
| 1035 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), None) |
| 1036 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async) |
| 1037 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 1038 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 1039 | |
| 1040 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 1041 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 1042 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 1043 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | func TestSanitizeMemtagHeapWithSanitizeDevice(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1047 | t.Parallel() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1048 | variant := "android_arm64_armv8-a" |
| 1049 | |
| 1050 | result := android.GroupFixturePreparers( |
| 1051 | prepareForCcTest, |
| 1052 | prepareForTestWithMemtagHeap, |
| 1053 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1054 | variables.SanitizeDevice = []string{"memtag_heap"} |
| 1055 | }), |
| 1056 | ).RunTest(t) |
| 1057 | ctx := result.TestContext |
| 1058 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1059 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 1060 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 1061 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 1062 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1063 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1064 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 1065 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 1066 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 1067 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1068 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1069 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Async) |
| 1070 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Async) |
| 1071 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Async) |
| 1072 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1073 | |
Liz Kammer | 7b920b4 | 2021-06-22 16:57:27 -0400 | [diff] [blame] | 1074 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 1075 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 1076 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1077 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1078 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1079 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 1080 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 1081 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 1082 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1083 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1084 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 1085 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 1086 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 1087 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1088 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1089 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 1090 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1091 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 1092 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1093 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1094 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 1095 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1096 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1097 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1098 | |
| 1099 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync) |
| 1100 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1101 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 1102 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 1103 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 1104 | |
| 1105 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 1106 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1107 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1108 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1109 | |
| 1110 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Async) |
| 1111 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Async) |
| 1112 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 1113 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 1114 | |
| 1115 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 1116 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 1117 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 1118 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | func TestSanitizeMemtagHeapWithSanitizeDeviceDiag(t *testing.T) { |
Liz Kammer | 7c5d159 | 2022-10-31 16:27:38 -0400 | [diff] [blame] | 1122 | t.Parallel() |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1123 | variant := "android_arm64_armv8-a" |
| 1124 | |
| 1125 | result := android.GroupFixturePreparers( |
| 1126 | prepareForCcTest, |
| 1127 | prepareForTestWithMemtagHeap, |
| 1128 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1129 | variables.SanitizeDevice = []string{"memtag_heap"} |
| 1130 | variables.SanitizeDeviceDiag = []string{"memtag_heap"} |
| 1131 | }), |
| 1132 | ).RunTest(t) |
| 1133 | ctx := result.TestContext |
| 1134 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1135 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_no_override", variant), None) |
| 1136 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_async", variant), None) |
| 1137 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_disable", variant), None) |
| 1138 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_binary_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1139 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1140 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_no_override", variant), None) |
| 1141 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_async", variant), None) |
| 1142 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_disable", variant), None) |
| 1143 | checkHasMemtagNote(t, ctx.ModuleForTests("no_memtag_test_override_default_sync", variant), None) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1144 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1145 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_no_override", variant), Sync) |
| 1146 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_async", variant), Sync) |
| 1147 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_disable", variant), Sync) |
| 1148 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1149 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1150 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_no_override", variant), Sync) |
| 1151 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_async", variant), Sync) |
| 1152 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_disable", variant), Sync) |
| 1153 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1154 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1155 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_no_override", variant), Async) |
| 1156 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_async", variant), Async) |
| 1157 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_disable", variant), Async) |
| 1158 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_binary_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1159 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1160 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_no_override", variant), Async) |
| 1161 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_async", variant), Async) |
| 1162 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_disable", variant), Async) |
| 1163 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_async_test_override_default_sync", variant), Async) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1164 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1165 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_no_override", variant), Sync) |
| 1166 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1167 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_disable", variant), Sync) |
| 1168 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_binary_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1169 | |
Liz Kammer | d56ddb5 | 2021-06-21 17:37:39 -0400 | [diff] [blame] | 1170 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_no_override", variant), Sync) |
| 1171 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1172 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1173 | checkHasMemtagNote(t, ctx.ModuleForTests("set_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1174 | |
| 1175 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_no_override", variant), Sync) |
| 1176 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_async", variant), Sync) |
| 1177 | // should sanitize: { diag: { memtag: true } } result in Sync instead of None here? |
| 1178 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_disable", variant), None) |
| 1179 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_binary_override_default_sync", variant), Sync) |
| 1180 | |
| 1181 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_no_override", variant), Sync) |
| 1182 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_async", variant), Sync) |
| 1183 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_disable", variant), Sync) |
| 1184 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_memtag_set_sync_test_override_default_sync", variant), Sync) |
| 1185 | |
| 1186 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_no_override", variant), Sync) |
| 1187 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_async", variant), Sync) |
| 1188 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_disable", variant), None) |
| 1189 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_binary_override_default_sync", variant), Sync) |
| 1190 | |
| 1191 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_no_override", variant), Sync) |
| 1192 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_async", variant), Sync) |
| 1193 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_disable", variant), Sync) |
| 1194 | checkHasMemtagNote(t, ctx.ModuleForTests("unset_test_override_default_sync", variant), Sync) |
Liz Kammer | bb8d84f | 2021-06-21 12:53:03 -0400 | [diff] [blame] | 1195 | } |
Trevor Radcliffe | bc65f63 | 2023-04-12 21:51:08 +0000 | [diff] [blame] | 1196 | |
| 1197 | func TestCfi(t *testing.T) { |
| 1198 | t.Parallel() |
| 1199 | |
| 1200 | bp := ` |
| 1201 | cc_library_shared { |
| 1202 | name: "shared_with_cfi", |
| 1203 | static_libs: [ |
| 1204 | "static_dep_with_cfi", |
| 1205 | "static_dep_no_cfi", |
| 1206 | ], |
| 1207 | sanitize: { |
| 1208 | cfi: true, |
| 1209 | }, |
| 1210 | } |
| 1211 | |
| 1212 | cc_library_shared { |
| 1213 | name: "shared_no_cfi", |
| 1214 | static_libs: [ |
| 1215 | "static_dep_with_cfi", |
| 1216 | "static_dep_no_cfi", |
| 1217 | ], |
| 1218 | } |
| 1219 | |
| 1220 | cc_library_static { |
| 1221 | name: "static_dep_with_cfi", |
| 1222 | sanitize: { |
| 1223 | cfi: true, |
| 1224 | }, |
| 1225 | } |
| 1226 | |
| 1227 | cc_library_static { |
| 1228 | name: "static_dep_no_cfi", |
| 1229 | } |
| 1230 | |
| 1231 | cc_library_shared { |
| 1232 | name: "shared_rdep_no_cfi", |
| 1233 | static_libs: ["static_dep_with_cfi_2"], |
| 1234 | } |
| 1235 | |
| 1236 | cc_library_static { |
| 1237 | name: "static_dep_with_cfi_2", |
| 1238 | sanitize: { |
| 1239 | cfi: true, |
| 1240 | }, |
| 1241 | } |
| 1242 | ` |
| 1243 | preparer := android.GroupFixturePreparers( |
| 1244 | prepareForCcTest, |
| 1245 | ) |
| 1246 | result := preparer.RunTestWithBp(t, bp) |
| 1247 | ctx := result.TestContext |
| 1248 | |
| 1249 | buildOs := "android_arm64_armv8-a" |
| 1250 | shared_suffix := "_shared" |
| 1251 | cfi_suffix := "_cfi" |
| 1252 | static_suffix := "_static" |
| 1253 | |
| 1254 | sharedWithCfiLib := result.ModuleForTests("shared_with_cfi", buildOs+shared_suffix+cfi_suffix) |
| 1255 | sharedNoCfiLib := result.ModuleForTests("shared_no_cfi", buildOs+shared_suffix) |
| 1256 | staticWithCfiLib := result.ModuleForTests("static_dep_with_cfi", buildOs+static_suffix) |
| 1257 | staticWithCfiLibCfiVariant := result.ModuleForTests("static_dep_with_cfi", buildOs+static_suffix+cfi_suffix) |
| 1258 | staticNoCfiLib := result.ModuleForTests("static_dep_no_cfi", buildOs+static_suffix) |
| 1259 | staticNoCfiLibCfiVariant := result.ModuleForTests("static_dep_no_cfi", buildOs+static_suffix+cfi_suffix) |
| 1260 | sharedRdepNoCfi := result.ModuleForTests("shared_rdep_no_cfi", buildOs+shared_suffix) |
| 1261 | staticDepWithCfi2Lib := result.ModuleForTests("static_dep_with_cfi_2", buildOs+static_suffix) |
| 1262 | |
| 1263 | // Confirm assumptions about propagation of CFI enablement |
| 1264 | expectStaticLinkDep(t, ctx, sharedWithCfiLib, staticWithCfiLibCfiVariant) |
| 1265 | expectStaticLinkDep(t, ctx, sharedNoCfiLib, staticWithCfiLib) |
| 1266 | expectStaticLinkDep(t, ctx, sharedWithCfiLib, staticNoCfiLibCfiVariant) |
| 1267 | expectStaticLinkDep(t, ctx, sharedNoCfiLib, staticNoCfiLib) |
| 1268 | expectStaticLinkDep(t, ctx, sharedRdepNoCfi, staticDepWithCfi2Lib) |
| 1269 | |
| 1270 | // Confirm that non-CFI variants do not add CFI flags |
| 1271 | bazLibCflags := staticWithCfiLib.Rule("cc").Args["cFlags"] |
| 1272 | if strings.Contains(bazLibCflags, "-fsanitize-cfi-cross-dso") { |
| 1273 | t.Errorf("non-CFI variant of baz not expected to contain CFI flags ") |
| 1274 | } |
| 1275 | } |