blob: e232b53e738023e9598ca56d895dff3800b8b137 [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 Lozano88271132023-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 Lozano88271132023-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 Lozano88271132023-07-26 13:34:55 -0400215 // SCS is only supported on AArch64 in Rust.
216 // TODO: Add riscv when riscv supported.
217 if (ctx.Arch().ArchType != android.Arm64) || !ctx.toolchain().Bionic() {
218 s.Scs = nil
219 }
220
Florian Mayer296d5952022-10-12 19:30:14 +0000221 // TODO:(b/178369775)
222 // For now sanitizing is only supported on devices
Ivan Lozano88271132023-07-26 13:34:55 -0400223 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 -0700224 sanitize.Properties.SanitizerEnabled = true
225 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500226}
227
228type sanitize struct {
229 Properties SanitizeProperties
230}
231
232func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
233 if !sanitize.Properties.SanitizerEnabled {
234 return flags, deps
235 }
236 if Bool(sanitize.Properties.Sanitize.Fuzzer) {
237 flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
Ivan Lozanof3e8fc32021-11-13 07:43:54 -0500238 } else if Bool(sanitize.Properties.Sanitize.Hwaddress) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700239 flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
Ivan Lozanof3e8fc32021-11-13 07:43:54 -0500240 } else if Bool(sanitize.Properties.Sanitize.Address) {
241 flags.RustFlags = append(flags.RustFlags, asanFlags...)
Ivan Lozano88271132023-07-26 13:34:55 -0400242 } else if Bool(sanitize.Properties.Sanitize.Scs) {
243 flags.RustFlags = append(flags.RustFlags, scsFlags...)
Tri Vo0a74c3e2021-04-01 13:59:27 -0700244 }
Ivan Lozano88271132023-07-26 13:34:55 -0400245
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500246 return flags, deps
247}
248
249func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
250 return deps
251}
252
253func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
254 if mod, ok := mctx.Module().(*Module); ok && mod.sanitize != nil {
255 if !mod.Enabled() {
256 return
257 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700258
Ivan Lozano62cd0382021-11-01 10:27:54 -0400259 if Bool(mod.sanitize.Properties.Sanitize.Memtag_heap) && mod.Binary() {
260 noteDep := "note_memtag_heap_async"
261 if Bool(mod.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
262 noteDep = "note_memtag_heap_sync"
263 }
264 // If we're using snapshots, redirect to snapshot whenever possible
265 // TODO(b/178470649): clean manual snapshot redirections
266 snapshot := mctx.Provider(cc.SnapshotInfoProvider).(cc.SnapshotInfo)
267 if lib, ok := snapshot.StaticLibs[noteDep]; ok {
268 noteDep = lib
269 }
270 depTag := cc.StaticDepTag(true)
271 variations := append(mctx.Target().Variations(),
272 blueprint.Variation{Mutator: "link", Variation: "static"})
273 if mod.Device() {
274 variations = append(variations, mod.ImageVariation())
275 }
276 mctx.AddFarVariationDependencies(variations, depTag, noteDep)
277 }
278
Tri Vo0a74c3e2021-04-01 13:59:27 -0700279 variations := mctx.Target().Variations()
280 var depTag blueprint.DependencyTag
281 var deps []string
282
Tri Vo505b0e82021-04-08 15:50:48 -0700283 if mod.IsSanitizerEnabled(cc.Asan) ||
Colin Cross1faf8232022-06-24 18:42:32 -0700284 (mod.IsSanitizerEnabled(cc.Fuzzer) && (mctx.Arch().ArchType != android.Arm64 || !mctx.Os().Bionic())) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700285 variations = append(variations,
286 blueprint.Variation{Mutator: "link", Variation: "shared"})
287 depTag = cc.SharedDepTag()
288 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
Tri Vo505b0e82021-04-08 15:50:48 -0700289 } else if mod.IsSanitizerEnabled(cc.Hwasan) ||
Colin Cross1faf8232022-06-24 18:42:32 -0700290 (mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64 && mctx.Os().Bionic()) {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500291 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400292 if binary, ok := mod.compiler.(binaryInterface); ok {
293 if binary.staticallyLinked() {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700294 mctx.ModuleErrorf("HWASan is not supported for static Rust executables yet.")
295 }
296 }
297
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400298 // Always link against the shared library -- static binaries will pull in the static
299 // library during final link if necessary
300 variations = append(variations,
301 blueprint.Variation{Mutator: "link", Variation: "shared"})
302 depTag = cc.SharedDepTag()
303 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "hwasan")}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500304 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700305
Ivan Lozano62cd0382021-11-01 10:27:54 -0400306 if len(deps) > 0 {
307 mctx.AddFarVariationDependencies(variations, depTag, deps...)
308 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500309 }
310}
311
312func (sanitize *sanitize) SetSanitizer(t cc.SanitizerType, b bool) {
313 sanitizerSet := false
314 switch t {
315 case cc.Fuzzer:
316 sanitize.Properties.Sanitize.Fuzzer = boolPtr(b)
317 sanitizerSet = true
318 case cc.Asan:
319 sanitize.Properties.Sanitize.Address = boolPtr(b)
320 sanitizerSet = true
Tri Vo0a74c3e2021-04-01 13:59:27 -0700321 case cc.Hwasan:
322 sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
323 sanitizerSet = true
Ivan Lozano62cd0382021-11-01 10:27:54 -0400324 case cc.Memtag_heap:
325 sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
326 sanitizerSet = true
Ivan Lozano88271132023-07-26 13:34:55 -0400327 case cc.Scs:
328 sanitize.Properties.Sanitize.Scs = boolPtr(b)
329 sanitizerSet = true
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500330 default:
331 panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
332 }
333 if b && sanitizerSet {
334 sanitize.Properties.SanitizerEnabled = true
335 }
336}
337
Ivan Lozanod7586b62021-04-01 09:49:36 -0400338func (m *Module) UbsanRuntimeNeeded() bool {
339 return false
340}
341
342func (m *Module) MinimalRuntimeNeeded() bool {
343 return false
344}
345
346func (m *Module) UbsanRuntimeDep() bool {
347 return false
348}
349
350func (m *Module) MinimalRuntimeDep() bool {
351 return false
352}
353
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500354// Check if the sanitizer is explicitly disabled (as opposed to nil by
355// virtue of not being set).
356func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
357 if sanitize == nil {
358 return false
359 }
360 if Bool(sanitize.Properties.Sanitize.Never) {
361 return true
362 }
363 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
364 return sanitizerVal != nil && *sanitizerVal == false
365}
366
367// There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled)
368// because enabling a sanitizer either directly (via the blueprint) or
369// indirectly (via a mutator) sets the bool ptr to true, and you can't
370// distinguish between the cases. It isn't needed though - both cases can be
371// treated identically.
372func (sanitize *sanitize) isSanitizerEnabled(t cc.SanitizerType) bool {
373 if sanitize == nil || !sanitize.Properties.SanitizerEnabled {
374 return false
375 }
376
377 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
378 return sanitizerVal != nil && *sanitizerVal == true
379}
380
381func (sanitize *sanitize) getSanitizerBoolPtr(t cc.SanitizerType) *bool {
382 switch t {
383 case cc.Fuzzer:
384 return sanitize.Properties.Sanitize.Fuzzer
385 case cc.Asan:
386 return sanitize.Properties.Sanitize.Address
Tri Vo0a74c3e2021-04-01 13:59:27 -0700387 case cc.Hwasan:
388 return sanitize.Properties.Sanitize.Hwaddress
Ivan Lozano62cd0382021-11-01 10:27:54 -0400389 case cc.Memtag_heap:
390 return sanitize.Properties.Sanitize.Memtag_heap
Ivan Lozano88271132023-07-26 13:34:55 -0400391 case cc.Scs:
392 return sanitize.Properties.Sanitize.Scs
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500393 default:
394 return nil
395 }
396}
397
Tri Vo0a74c3e2021-04-01 13:59:27 -0700398func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
399 // Add a suffix for hwasan rlib libraries to allow surfacing both the sanitized and
400 // non-sanitized variants to make without a name conflict.
401 if entries.Class == "RLIB_LIBRARIES" || entries.Class == "STATIC_LIBRARIES" {
402 if sanitize.isSanitizerEnabled(cc.Hwasan) {
403 entries.SubName += ".hwasan"
404 }
Ivan Lozano88271132023-07-26 13:34:55 -0400405 if sanitize.isSanitizerEnabled(cc.Scs) {
406 entries.SubName += ".scs"
407 }
408
Tri Vo0a74c3e2021-04-01 13:59:27 -0700409 }
410}
411
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500412func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
413 if mod.Host() {
414 return false
415 }
416 switch t {
417 case cc.Fuzzer:
418 return true
419 case cc.Asan:
420 return true
Tri Vo0a74c3e2021-04-01 13:59:27 -0700421 case cc.Hwasan:
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400422 // TODO(b/180495975): HWASan for static Rust binaries isn't supported yet.
423 if mod.StaticExecutable() {
424 return false
425 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700426 return true
Ivan Lozano62cd0382021-11-01 10:27:54 -0400427 case cc.Memtag_heap:
428 return true
Ivan Lozano88271132023-07-26 13:34:55 -0400429 case cc.Scs:
430 // SCS is only supported on AArch64 in Rust.
431 // TODO: Add riscv when riscv supported.
432 if mod.Target().Arch.ArchType == android.Arm64 {
433 return true
434 }
435 return false
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500436 default:
437 return false
438 }
439}
440
441func (mod *Module) IsSanitizerEnabled(t cc.SanitizerType) bool {
442 return mod.sanitize.isSanitizerEnabled(t)
443}
444
445func (mod *Module) IsSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
446 if mod.Host() {
447 return true
448 }
449
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500450 return mod.sanitize.isSanitizerExplicitlyDisabled(t)
451}
452
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500453func (mod *Module) SetSanitizer(t cc.SanitizerType, b bool) {
454 if !Bool(mod.sanitize.Properties.Sanitize.Never) {
455 mod.sanitize.SetSanitizer(t, b)
456 }
457}
458
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500459func (mod *Module) StaticallyLinked() bool {
460 if lib, ok := mod.compiler.(libraryInterface); ok {
Tri Vo505b0e82021-04-08 15:50:48 -0700461 return lib.rlib() || lib.static()
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400462 } else if binary, ok := mod.compiler.(binaryInterface); ok {
463 return binary.staticallyLinked()
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500464 }
465 return false
466}
467
468func (mod *Module) SetInSanitizerDir() {
469 mod.sanitize.Properties.InSanitizerDir = true
470}
471
472func (mod *Module) SanitizeNever() bool {
473 return Bool(mod.sanitize.Properties.Sanitize.Never)
474}
475
476var _ cc.PlatformSanitizeable = (*Module)(nil)
477
478func IsSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
479 switch t := tag.(type) {
480 case dependencyTag:
481 return t.library
482 default:
483 return cc.IsSanitizableDependencyTag(tag)
484 }
485}
486
487func (m *Module) SanitizableDepTagChecker() cc.SantizableDependencyTagChecker {
488 return IsSanitizableDependencyTag
489}