blob: fd67bc41907bdce095e878875cb320f8ecca5045 [file] [log] [blame]
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
Ivan Lozano5482d6a2021-11-01 10:13:25 -040018 "fmt"
19 "strings"
20
21 "github.com/google/blueprint"
22 "github.com/google/blueprint/proptools"
23
Ivan Lozano6cd99e62020-02-11 08:24:25 -050024 "android/soong/android"
25 "android/soong/cc"
26 "android/soong/rust/config"
Ivan Lozano6cd99e62020-02-11 08:24:25 -050027)
28
Ivan Lozano62cd0382021-11-01 10:27:54 -040029// TODO: When Rust has sanitizer-parity with CC, deduplicate this struct
Ivan Lozano6cd99e62020-02-11 08:24:25 -050030type SanitizeProperties struct {
Tri Vo0a74c3e2021-04-01 13:59:27 -070031 // enable AddressSanitizer, HWAddressSanitizer, and others.
Ivan Lozano6cd99e62020-02-11 08:24:25 -050032 Sanitize struct {
Tri Vo0a74c3e2021-04-01 13:59:27 -070033 Address *bool `android:"arch_variant"`
34 Hwaddress *bool `android:"arch_variant"`
Ivan Lozano447f5b12023-07-26 13:34:55 -040035 Scs *bool `android:"arch_variant"`
Ivan Lozano62cd0382021-11-01 10:27:54 -040036
37 // Memory-tagging, only available on arm64
38 // if diag.memtag unset or false, enables async memory tagging
39 Memtag_heap *bool `android:"arch_variant"`
40 Fuzzer *bool `android:"arch_variant"`
41 Never *bool `android:"arch_variant"`
42
43 // Sanitizers to run in the diagnostic mode (as opposed to the release mode).
44 // Replaces abort() on error with a human-readable error message.
45 // Address and Thread sanitizers always run in diagnostic mode.
46 Diag struct {
47 // Memory-tagging, only available on arm64
48 // requires sanitizer.memtag: true
49 // if set, enables sync memory tagging
50 Memtag_heap *bool `android:"arch_variant"`
51 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -050052 }
Lukacs T. Berki6c716762022-06-13 20:50:39 +020053 SanitizerEnabled bool `blueprint:"mutated"`
Ivan Lozano6cd99e62020-02-11 08:24:25 -050054
55 // Used when we need to place libraries in their own directory, such as ASAN.
56 InSanitizerDir bool `blueprint:"mutated"`
57}
58
59var fuzzerFlags = []string{
Charisee5ddec432022-03-01 03:02:51 +000060 "-C passes='sancov-module'",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050061
62 "--cfg fuzzing",
Ivan Lozanoc044f5b2021-04-02 12:43:28 -040063 "-C llvm-args=-sanitizer-coverage-level=3",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050064 "-C llvm-args=-sanitizer-coverage-trace-compares",
65 "-C llvm-args=-sanitizer-coverage-inline-8bit-counters",
Ivan Lozano1247b3c2023-06-12 14:57:44 -040066 "-C llvm-args=-sanitizer-coverage-pc-table",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050067
Ivan Lozanoaa7c9802021-08-02 09:43:46 -040068 // See https://github.com/rust-fuzz/cargo-fuzz/pull/193
69 "-C link-dead-code",
70
Ivan Lozano6cd99e62020-02-11 08:24:25 -050071 // Sancov breaks with lto
Charisee5ddec432022-03-01 03:02:51 +000072 // TODO: Remove when https://bugs.llvm.org/show_bug.cgi?id=41734 is resolved and sancov-module works with LTO
Ivan Lozano6cd99e62020-02-11 08:24:25 -050073 "-C lto=no",
74}
75
76var asanFlags = []string{
77 "-Z sanitizer=address",
78}
Ivan Lozano447f5b12023-07-26 13:34:55 -040079var scsFlags = []string{
80 "-Z sanitizer=shadow-call-stack",
81}
Ivan Lozano6cd99e62020-02-11 08:24:25 -050082
Ivan Lozano5482d6a2021-11-01 10:13:25 -040083// See cc/sanitize.go's hwasanGlobalOptions for global hwasan options.
Tri Vo0a74c3e2021-04-01 13:59:27 -070084var hwasanFlags = []string{
85 "-Z sanitizer=hwaddress",
86 "-C target-feature=+tagged-globals",
Ivan Lozano5482d6a2021-11-01 10:13:25 -040087
88 // Flags from cc/sanitize.go hwasanFlags
89 "-C llvm-args=--aarch64-enable-global-isel-at-O=-1",
90 "-C llvm-args=-fast-isel=false",
91 "-C llvm-args=-instcombine-lower-dbg-declare=0",
92
93 // Additional flags for HWASAN-ified Rust/C interop
94 "-C llvm-args=--hwasan-with-ifunc",
Tri Vo0a74c3e2021-04-01 13:59:27 -070095}
96
Ivan Lozano6cd99e62020-02-11 08:24:25 -050097func boolPtr(v bool) *bool {
98 if v {
99 return &v
100 } else {
101 return nil
102 }
103}
104
105func init() {
106}
107func (sanitize *sanitize) props() []interface{} {
108 return []interface{}{&sanitize.Properties}
109}
110
111func (sanitize *sanitize) begin(ctx BaseModuleContext) {
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400112 s := &sanitize.Properties.Sanitize
113
114 // Never always wins.
115 if Bool(s.Never) {
116 return
117 }
118
Ivan Lozano62cd0382021-11-01 10:27:54 -0400119 // rust_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {Memtag_heap}).
120 if binary, ok := ctx.RustModule().compiler.(binaryInterface); ok && binary.testBinary() {
121 if s.Memtag_heap == nil {
122 s.Memtag_heap = proptools.BoolPtr(true)
123 }
124 if s.Diag.Memtag_heap == nil {
125 s.Diag.Memtag_heap = proptools.BoolPtr(true)
126 }
127 }
128
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400129 var globalSanitizers []string
Ivan Lozano62cd0382021-11-01 10:27:54 -0400130 var globalSanitizersDiag []string
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400131
132 if ctx.Host() {
133 if !ctx.Windows() {
134 globalSanitizers = ctx.Config().SanitizeHost()
135 }
136 } else {
137 arches := ctx.Config().SanitizeDeviceArch()
138 if len(arches) == 0 || android.InList(ctx.Arch().ArchType.Name, arches) {
139 globalSanitizers = ctx.Config().SanitizeDevice()
Ivan Lozano62cd0382021-11-01 10:27:54 -0400140 globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag()
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400141 }
142 }
143
144 if len(globalSanitizers) > 0 {
145 var found bool
146
147 // Global Sanitizers
148 if found, globalSanitizers = android.RemoveFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500149 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400150 if !ctx.RustModule().StaticExecutable() {
151 s.Hwaddress = proptools.BoolPtr(true)
152 }
153 }
154
Ivan Lozano62cd0382021-11-01 10:27:54 -0400155 if found, globalSanitizers = android.RemoveFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil {
156 if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) {
157 s.Memtag_heap = proptools.BoolPtr(true)
158 }
159 }
160
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400161 if found, globalSanitizers = android.RemoveFromList("address", globalSanitizers); found && s.Address == nil {
162 s.Address = proptools.BoolPtr(true)
163 }
164
165 if found, globalSanitizers = android.RemoveFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500166 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet, and fuzzer enables HWAsan
167 if !ctx.RustModule().StaticExecutable() {
168 s.Fuzzer = proptools.BoolPtr(true)
169 }
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400170 }
171
Ivan Lozano62cd0382021-11-01 10:27:54 -0400172 // Global Diag Sanitizers
173 if found, globalSanitizersDiag = android.RemoveFromList("memtag_heap", globalSanitizersDiag); found &&
174 s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) {
175 s.Diag.Memtag_heap = proptools.BoolPtr(true)
176 }
177 }
178
179 // Enable Memtag for all components in the include paths (for Aarch64 only)
Colin Cross1faf8232022-06-24 18:42:32 -0700180 if ctx.Arch().ArchType == android.Arm64 && ctx.Os().Bionic() {
Ivan Lozano62cd0382021-11-01 10:27:54 -0400181 if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
182 if s.Memtag_heap == nil {
183 s.Memtag_heap = proptools.BoolPtr(true)
184 }
185 if s.Diag.Memtag_heap == nil {
186 s.Diag.Memtag_heap = proptools.BoolPtr(true)
187 }
188 } else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) {
189 if s.Memtag_heap == nil {
190 s.Memtag_heap = proptools.BoolPtr(true)
191 }
192 }
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400193 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500194
Tri Vo0a74c3e2021-04-01 13:59:27 -0700195 // HWASan requires AArch64 hardware feature (top-byte-ignore).
Colin Cross1faf8232022-06-24 18:42:32 -0700196 if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700197 s.Hwaddress = nil
198 }
199
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400200 // HWASan ramdisk (which is built from recovery) goes over some bootloader limit.
201 // Keep libc instrumented so that ramdisk / vendor_ramdisk / recovery can run hwasan-instrumented code if necessary.
202 if (ctx.RustModule().InRamdisk() || ctx.RustModule().InVendorRamdisk() || ctx.RustModule().InRecovery()) && !strings.HasPrefix(ctx.ModuleDir(), "bionic/libc") {
203 s.Hwaddress = nil
204 }
205
206 if Bool(s.Hwaddress) {
207 s.Address = nil
208 }
209
Ivan Lozano62cd0382021-11-01 10:27:54 -0400210 // Memtag_heap is only implemented on AArch64.
Colin Cross1faf8232022-06-24 18:42:32 -0700211 if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
Ivan Lozano62cd0382021-11-01 10:27:54 -0400212 s.Memtag_heap = nil
213 }
214
Ivan Lozano447f5b12023-07-26 13:34:55 -0400215 // SCS is only implemented on AArch64/riscv64.
216 if (ctx.Arch().ArchType != android.Arm64 && ctx.Arch().ArchType != android.Riscv64) || !ctx.toolchain().Bionic() {
217 s.Scs = nil
218 }
219
Florian Mayer296d5952022-10-12 19:30:14 +0000220 // TODO:(b/178369775)
221 // For now sanitizing is only supported on devices
Ivan Lozano447f5b12023-07-26 13:34:55 -0400222 if ctx.Os() == android.Android && (Bool(s.Hwaddress) || Bool(s.Address) || Bool(s.Memtag_heap) || Bool(s.Fuzzer) || Bool(s.Scs)) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700223 sanitize.Properties.SanitizerEnabled = true
224 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500225}
226
227type sanitize struct {
228 Properties SanitizeProperties
229}
230
231func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
232 if !sanitize.Properties.SanitizerEnabled {
233 return flags, deps
234 }
235 if Bool(sanitize.Properties.Sanitize.Fuzzer) {
236 flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
Ivan Lozanof3e8fc32021-11-13 07:43:54 -0500237 } else if Bool(sanitize.Properties.Sanitize.Hwaddress) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700238 flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
Ivan Lozanof3e8fc32021-11-13 07:43:54 -0500239 } else if Bool(sanitize.Properties.Sanitize.Address) {
240 flags.RustFlags = append(flags.RustFlags, asanFlags...)
Ivan Lozano447f5b12023-07-26 13:34:55 -0400241 } else if Bool(sanitize.Properties.Sanitize.Scs) {
242 flags.RustFlags = append(flags.RustFlags, scsFlags...)
Tri Vo0a74c3e2021-04-01 13:59:27 -0700243 }
Ivan Lozano447f5b12023-07-26 13:34:55 -0400244
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500245 return flags, deps
246}
247
248func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
249 return deps
250}
251
252func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
253 if mod, ok := mctx.Module().(*Module); ok && mod.sanitize != nil {
254 if !mod.Enabled() {
255 return
256 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700257
Ivan Lozano62cd0382021-11-01 10:27:54 -0400258 if Bool(mod.sanitize.Properties.Sanitize.Memtag_heap) && mod.Binary() {
259 noteDep := "note_memtag_heap_async"
260 if Bool(mod.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
261 noteDep = "note_memtag_heap_sync"
262 }
263 // If we're using snapshots, redirect to snapshot whenever possible
264 // TODO(b/178470649): clean manual snapshot redirections
265 snapshot := mctx.Provider(cc.SnapshotInfoProvider).(cc.SnapshotInfo)
266 if lib, ok := snapshot.StaticLibs[noteDep]; ok {
267 noteDep = lib
268 }
269 depTag := cc.StaticDepTag(true)
270 variations := append(mctx.Target().Variations(),
271 blueprint.Variation{Mutator: "link", Variation: "static"})
272 if mod.Device() {
273 variations = append(variations, mod.ImageVariation())
274 }
275 mctx.AddFarVariationDependencies(variations, depTag, noteDep)
276 }
277
Tri Vo0a74c3e2021-04-01 13:59:27 -0700278 variations := mctx.Target().Variations()
279 var depTag blueprint.DependencyTag
280 var deps []string
281
Tri Vo505b0e82021-04-08 15:50:48 -0700282 if mod.IsSanitizerEnabled(cc.Asan) ||
Colin Cross1faf8232022-06-24 18:42:32 -0700283 (mod.IsSanitizerEnabled(cc.Fuzzer) && (mctx.Arch().ArchType != android.Arm64 || !mctx.Os().Bionic())) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700284 variations = append(variations,
285 blueprint.Variation{Mutator: "link", Variation: "shared"})
286 depTag = cc.SharedDepTag()
287 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
Tri Vo505b0e82021-04-08 15:50:48 -0700288 } else if mod.IsSanitizerEnabled(cc.Hwasan) ||
Colin Cross1faf8232022-06-24 18:42:32 -0700289 (mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64 && mctx.Os().Bionic()) {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500290 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400291 if binary, ok := mod.compiler.(binaryInterface); ok {
292 if binary.staticallyLinked() {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700293 mctx.ModuleErrorf("HWASan is not supported for static Rust executables yet.")
294 }
295 }
296
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400297 // Always link against the shared library -- static binaries will pull in the static
298 // library during final link if necessary
299 variations = append(variations,
300 blueprint.Variation{Mutator: "link", Variation: "shared"})
301 depTag = cc.SharedDepTag()
302 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "hwasan")}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500303 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700304
Ivan Lozano62cd0382021-11-01 10:27:54 -0400305 if len(deps) > 0 {
306 mctx.AddFarVariationDependencies(variations, depTag, deps...)
307 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500308 }
309}
310
311func (sanitize *sanitize) SetSanitizer(t cc.SanitizerType, b bool) {
312 sanitizerSet := false
313 switch t {
314 case cc.Fuzzer:
315 sanitize.Properties.Sanitize.Fuzzer = boolPtr(b)
316 sanitizerSet = true
317 case cc.Asan:
318 sanitize.Properties.Sanitize.Address = boolPtr(b)
319 sanitizerSet = true
Tri Vo0a74c3e2021-04-01 13:59:27 -0700320 case cc.Hwasan:
321 sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
322 sanitizerSet = true
Ivan Lozano62cd0382021-11-01 10:27:54 -0400323 case cc.Memtag_heap:
324 sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
325 sanitizerSet = true
Ivan Lozano447f5b12023-07-26 13:34:55 -0400326 case cc.Scs:
327 sanitize.Properties.Sanitize.Scs = boolPtr(b)
328 sanitizerSet = true
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500329 default:
330 panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
331 }
332 if b && sanitizerSet {
333 sanitize.Properties.SanitizerEnabled = true
334 }
335}
336
Ivan Lozanod7586b62021-04-01 09:49:36 -0400337func (m *Module) UbsanRuntimeNeeded() bool {
338 return false
339}
340
341func (m *Module) MinimalRuntimeNeeded() bool {
342 return false
343}
344
345func (m *Module) UbsanRuntimeDep() bool {
346 return false
347}
348
349func (m *Module) MinimalRuntimeDep() bool {
350 return false
351}
352
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500353// Check if the sanitizer is explicitly disabled (as opposed to nil by
354// virtue of not being set).
355func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
356 if sanitize == nil {
357 return false
358 }
359 if Bool(sanitize.Properties.Sanitize.Never) {
360 return true
361 }
362 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
363 return sanitizerVal != nil && *sanitizerVal == false
364}
365
366// There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled)
367// because enabling a sanitizer either directly (via the blueprint) or
368// indirectly (via a mutator) sets the bool ptr to true, and you can't
369// distinguish between the cases. It isn't needed though - both cases can be
370// treated identically.
371func (sanitize *sanitize) isSanitizerEnabled(t cc.SanitizerType) bool {
372 if sanitize == nil || !sanitize.Properties.SanitizerEnabled {
373 return false
374 }
375
376 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
377 return sanitizerVal != nil && *sanitizerVal == true
378}
379
380func (sanitize *sanitize) getSanitizerBoolPtr(t cc.SanitizerType) *bool {
381 switch t {
382 case cc.Fuzzer:
383 return sanitize.Properties.Sanitize.Fuzzer
384 case cc.Asan:
385 return sanitize.Properties.Sanitize.Address
Tri Vo0a74c3e2021-04-01 13:59:27 -0700386 case cc.Hwasan:
387 return sanitize.Properties.Sanitize.Hwaddress
Ivan Lozano62cd0382021-11-01 10:27:54 -0400388 case cc.Memtag_heap:
389 return sanitize.Properties.Sanitize.Memtag_heap
Ivan Lozano447f5b12023-07-26 13:34:55 -0400390 case cc.Scs:
391 return sanitize.Properties.Sanitize.Scs
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500392 default:
393 return nil
394 }
395}
396
Tri Vo0a74c3e2021-04-01 13:59:27 -0700397func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
398 // Add a suffix for hwasan rlib libraries to allow surfacing both the sanitized and
399 // non-sanitized variants to make without a name conflict.
400 if entries.Class == "RLIB_LIBRARIES" || entries.Class == "STATIC_LIBRARIES" {
401 if sanitize.isSanitizerEnabled(cc.Hwasan) {
402 entries.SubName += ".hwasan"
403 }
Ivan Lozano447f5b12023-07-26 13:34:55 -0400404 if sanitize.isSanitizerEnabled(cc.Scs) {
405 entries.SubName += ".scs"
406 }
407
Tri Vo0a74c3e2021-04-01 13:59:27 -0700408 }
409}
410
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500411func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
412 if mod.Host() {
413 return false
414 }
415 switch t {
416 case cc.Fuzzer:
417 return true
418 case cc.Asan:
419 return true
Tri Vo0a74c3e2021-04-01 13:59:27 -0700420 case cc.Hwasan:
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400421 // TODO(b/180495975): HWASan for static Rust binaries isn't supported yet.
422 if mod.StaticExecutable() {
423 return false
424 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700425 return true
Ivan Lozano62cd0382021-11-01 10:27:54 -0400426 case cc.Memtag_heap:
427 return true
Ivan Lozano447f5b12023-07-26 13:34:55 -0400428 case cc.Scs:
429 return true
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500430 default:
431 return false
432 }
433}
434
435func (mod *Module) IsSanitizerEnabled(t cc.SanitizerType) bool {
436 return mod.sanitize.isSanitizerEnabled(t)
437}
438
439func (mod *Module) IsSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
440 if mod.Host() {
441 return true
442 }
443
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500444 return mod.sanitize.isSanitizerExplicitlyDisabled(t)
445}
446
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500447func (mod *Module) SetSanitizer(t cc.SanitizerType, b bool) {
448 if !Bool(mod.sanitize.Properties.Sanitize.Never) {
449 mod.sanitize.SetSanitizer(t, b)
450 }
451}
452
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500453func (mod *Module) StaticallyLinked() bool {
454 if lib, ok := mod.compiler.(libraryInterface); ok {
Tri Vo505b0e82021-04-08 15:50:48 -0700455 return lib.rlib() || lib.static()
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400456 } else if binary, ok := mod.compiler.(binaryInterface); ok {
457 return binary.staticallyLinked()
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500458 }
459 return false
460}
461
462func (mod *Module) SetInSanitizerDir() {
463 mod.sanitize.Properties.InSanitizerDir = true
464}
465
466func (mod *Module) SanitizeNever() bool {
467 return Bool(mod.sanitize.Properties.Sanitize.Never)
468}
469
470var _ cc.PlatformSanitizeable = (*Module)(nil)
471
472func IsSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
473 switch t := tag.(type) {
474 case dependencyTag:
475 return t.library
476 default:
477 return cc.IsSanitizableDependencyTag(tag)
478 }
479}
480
481func (m *Module) SanitizableDepTagChecker() cc.SantizableDependencyTagChecker {
482 return IsSanitizableDependencyTag
483}