blob: 2f5afd74db4daf47e65609aa73d3101ca87daa8b [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 Lozano62cd0382021-11-01 10:27:54 -040035
36 // Memory-tagging, only available on arm64
37 // if diag.memtag unset or false, enables async memory tagging
38 Memtag_heap *bool `android:"arch_variant"`
39 Fuzzer *bool `android:"arch_variant"`
40 Never *bool `android:"arch_variant"`
41
42 // Sanitizers to run in the diagnostic mode (as opposed to the release mode).
43 // Replaces abort() on error with a human-readable error message.
44 // Address and Thread sanitizers always run in diagnostic mode.
45 Diag struct {
46 // Memory-tagging, only available on arm64
47 // requires sanitizer.memtag: true
48 // if set, enables sync memory tagging
49 Memtag_heap *bool `android:"arch_variant"`
50 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -050051 }
Lukacs T. Berki6c716762022-06-13 20:50:39 +020052 SanitizerEnabled bool `blueprint:"mutated"`
Ivan Lozano6cd99e62020-02-11 08:24:25 -050053
54 // Used when we need to place libraries in their own directory, such as ASAN.
55 InSanitizerDir bool `blueprint:"mutated"`
56}
57
58var fuzzerFlags = []string{
Charisee5ddec432022-03-01 03:02:51 +000059 "-C passes='sancov-module'",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050060
61 "--cfg fuzzing",
Ivan Lozanoc044f5b2021-04-02 12:43:28 -040062 "-C llvm-args=-sanitizer-coverage-level=3",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050063 "-C llvm-args=-sanitizer-coverage-trace-compares",
64 "-C llvm-args=-sanitizer-coverage-inline-8bit-counters",
Ivan Lozano1247b3c2023-06-12 14:57:44 -040065 "-C llvm-args=-sanitizer-coverage-pc-table",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050066
Ivan Lozanoaa7c9802021-08-02 09:43:46 -040067 // See https://github.com/rust-fuzz/cargo-fuzz/pull/193
68 "-C link-dead-code",
69
Ivan Lozano6cd99e62020-02-11 08:24:25 -050070 // Sancov breaks with lto
Charisee5ddec432022-03-01 03:02:51 +000071 // 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 -050072 "-C lto=no",
73}
74
75var asanFlags = []string{
76 "-Z sanitizer=address",
77}
78
Ivan Lozano5482d6a2021-11-01 10:13:25 -040079// See cc/sanitize.go's hwasanGlobalOptions for global hwasan options.
Tri Vo0a74c3e2021-04-01 13:59:27 -070080var hwasanFlags = []string{
81 "-Z sanitizer=hwaddress",
82 "-C target-feature=+tagged-globals",
Ivan Lozano5482d6a2021-11-01 10:13:25 -040083
84 // Flags from cc/sanitize.go hwasanFlags
85 "-C llvm-args=--aarch64-enable-global-isel-at-O=-1",
86 "-C llvm-args=-fast-isel=false",
87 "-C llvm-args=-instcombine-lower-dbg-declare=0",
88
89 // Additional flags for HWASAN-ified Rust/C interop
90 "-C llvm-args=--hwasan-with-ifunc",
Tri Vo0a74c3e2021-04-01 13:59:27 -070091}
92
Ivan Lozano6cd99e62020-02-11 08:24:25 -050093func boolPtr(v bool) *bool {
94 if v {
95 return &v
96 } else {
97 return nil
98 }
99}
100
101func init() {
102}
103func (sanitize *sanitize) props() []interface{} {
104 return []interface{}{&sanitize.Properties}
105}
106
107func (sanitize *sanitize) begin(ctx BaseModuleContext) {
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400108 s := &sanitize.Properties.Sanitize
109
110 // Never always wins.
111 if Bool(s.Never) {
112 return
113 }
114
Ivan Lozano62cd0382021-11-01 10:27:54 -0400115 // rust_test targets default to SYNC MemTag unless explicitly set to ASYNC (via diag: {Memtag_heap}).
116 if binary, ok := ctx.RustModule().compiler.(binaryInterface); ok && binary.testBinary() {
117 if s.Memtag_heap == nil {
118 s.Memtag_heap = proptools.BoolPtr(true)
119 }
120 if s.Diag.Memtag_heap == nil {
121 s.Diag.Memtag_heap = proptools.BoolPtr(true)
122 }
123 }
124
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400125 var globalSanitizers []string
Ivan Lozano62cd0382021-11-01 10:27:54 -0400126 var globalSanitizersDiag []string
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400127
128 if ctx.Host() {
129 if !ctx.Windows() {
130 globalSanitizers = ctx.Config().SanitizeHost()
131 }
132 } else {
133 arches := ctx.Config().SanitizeDeviceArch()
134 if len(arches) == 0 || android.InList(ctx.Arch().ArchType.Name, arches) {
135 globalSanitizers = ctx.Config().SanitizeDevice()
Ivan Lozano62cd0382021-11-01 10:27:54 -0400136 globalSanitizersDiag = ctx.Config().SanitizeDeviceDiag()
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400137 }
138 }
139
140 if len(globalSanitizers) > 0 {
141 var found bool
142
143 // Global Sanitizers
144 if found, globalSanitizers = android.RemoveFromList("hwaddress", globalSanitizers); found && s.Hwaddress == nil {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500145 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400146 if !ctx.RustModule().StaticExecutable() {
147 s.Hwaddress = proptools.BoolPtr(true)
148 }
149 }
150
Ivan Lozano62cd0382021-11-01 10:27:54 -0400151 if found, globalSanitizers = android.RemoveFromList("memtag_heap", globalSanitizers); found && s.Memtag_heap == nil {
152 if !ctx.Config().MemtagHeapDisabledForPath(ctx.ModuleDir()) {
153 s.Memtag_heap = proptools.BoolPtr(true)
154 }
155 }
156
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400157 if found, globalSanitizers = android.RemoveFromList("address", globalSanitizers); found && s.Address == nil {
158 s.Address = proptools.BoolPtr(true)
159 }
160
161 if found, globalSanitizers = android.RemoveFromList("fuzzer", globalSanitizers); found && s.Fuzzer == nil {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500162 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet, and fuzzer enables HWAsan
163 if !ctx.RustModule().StaticExecutable() {
164 s.Fuzzer = proptools.BoolPtr(true)
165 }
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400166 }
167
Ivan Lozano62cd0382021-11-01 10:27:54 -0400168 // Global Diag Sanitizers
169 if found, globalSanitizersDiag = android.RemoveFromList("memtag_heap", globalSanitizersDiag); found &&
170 s.Diag.Memtag_heap == nil && Bool(s.Memtag_heap) {
171 s.Diag.Memtag_heap = proptools.BoolPtr(true)
172 }
173 }
174
175 // Enable Memtag for all components in the include paths (for Aarch64 only)
Colin Cross1faf8232022-06-24 18:42:32 -0700176 if ctx.Arch().ArchType == android.Arm64 && ctx.Os().Bionic() {
Ivan Lozano62cd0382021-11-01 10:27:54 -0400177 if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
178 if s.Memtag_heap == nil {
179 s.Memtag_heap = proptools.BoolPtr(true)
180 }
181 if s.Diag.Memtag_heap == nil {
182 s.Diag.Memtag_heap = proptools.BoolPtr(true)
183 }
184 } else if ctx.Config().MemtagHeapAsyncEnabledForPath(ctx.ModuleDir()) {
185 if s.Memtag_heap == nil {
186 s.Memtag_heap = proptools.BoolPtr(true)
187 }
188 }
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400189 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500190
Tri Vo0a74c3e2021-04-01 13:59:27 -0700191 // HWASan requires AArch64 hardware feature (top-byte-ignore).
Colin Cross1faf8232022-06-24 18:42:32 -0700192 if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700193 s.Hwaddress = nil
194 }
195
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400196 // HWASan ramdisk (which is built from recovery) goes over some bootloader limit.
197 // Keep libc instrumented so that ramdisk / vendor_ramdisk / recovery can run hwasan-instrumented code if necessary.
198 if (ctx.RustModule().InRamdisk() || ctx.RustModule().InVendorRamdisk() || ctx.RustModule().InRecovery()) && !strings.HasPrefix(ctx.ModuleDir(), "bionic/libc") {
199 s.Hwaddress = nil
200 }
201
202 if Bool(s.Hwaddress) {
203 s.Address = nil
204 }
205
Ivan Lozano62cd0382021-11-01 10:27:54 -0400206 // Memtag_heap is only implemented on AArch64.
Colin Cross1faf8232022-06-24 18:42:32 -0700207 if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
Ivan Lozano62cd0382021-11-01 10:27:54 -0400208 s.Memtag_heap = nil
209 }
210
Colin Cross3ef92852023-09-05 12:09:30 -0700211 // Disable sanitizers for musl x86 modules, rustc does not support any sanitizers.
212 if ctx.Os() == android.LinuxMusl && ctx.Arch().ArchType == android.X86 {
213 s.Never = boolPtr(true)
214 }
215
Florian Mayer296d5952022-10-12 19:30:14 +0000216 // TODO:(b/178369775)
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400217 // For now sanitizing is only supported on non-windows targets
218 if ctx.Os() != android.Windows && (Bool(s.Hwaddress) || Bool(s.Address) || Bool(s.Memtag_heap) || Bool(s.Fuzzer)) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700219 sanitize.Properties.SanitizerEnabled = true
220 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500221}
222
223type sanitize struct {
224 Properties SanitizeProperties
225}
226
227func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) {
228 if !sanitize.Properties.SanitizerEnabled {
229 return flags, deps
230 }
Ivan Lozano408d3732023-07-27 13:28:08 -0400231
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500232 if Bool(sanitize.Properties.Sanitize.Fuzzer) {
233 flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
Ivan Lozano408d3732023-07-27 13:28:08 -0400234 }
235
236 if Bool(sanitize.Properties.Sanitize.Hwaddress) {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700237 flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
Ivan Lozano408d3732023-07-27 13:28:08 -0400238 }
239
240 if Bool(sanitize.Properties.Sanitize.Address) {
Ivan Lozanof3e8fc32021-11-13 07:43:54 -0500241 flags.RustFlags = append(flags.RustFlags, asanFlags...)
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400242 if ctx.Host() {
243 // -nodefaultlibs (provided with libc++) prevents the driver from linking
244 // libraries needed with -fsanitize=address. http://b/18650275 (WAI)
245 flags.LinkFlags = append(flags.LinkFlags, []string{"-Wl,--no-as-needed"}...)
246 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700247 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500248 return flags, deps
249}
250
251func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
252 return deps
253}
254
255func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
256 if mod, ok := mctx.Module().(*Module); ok && mod.sanitize != nil {
257 if !mod.Enabled() {
258 return
259 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700260
Ivan Lozano62cd0382021-11-01 10:27:54 -0400261 if Bool(mod.sanitize.Properties.Sanitize.Memtag_heap) && mod.Binary() {
262 noteDep := "note_memtag_heap_async"
263 if Bool(mod.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
264 noteDep = "note_memtag_heap_sync"
265 }
266 // If we're using snapshots, redirect to snapshot whenever possible
267 // TODO(b/178470649): clean manual snapshot redirections
268 snapshot := mctx.Provider(cc.SnapshotInfoProvider).(cc.SnapshotInfo)
269 if lib, ok := snapshot.StaticLibs[noteDep]; ok {
270 noteDep = lib
271 }
272 depTag := cc.StaticDepTag(true)
273 variations := append(mctx.Target().Variations(),
274 blueprint.Variation{Mutator: "link", Variation: "static"})
275 if mod.Device() {
276 variations = append(variations, mod.ImageVariation())
277 }
278 mctx.AddFarVariationDependencies(variations, depTag, noteDep)
279 }
280
Tri Vo0a74c3e2021-04-01 13:59:27 -0700281 variations := mctx.Target().Variations()
282 var depTag blueprint.DependencyTag
283 var deps []string
284
Ivan Lozano408d3732023-07-27 13:28:08 -0400285 if mod.IsSanitizerEnabled(cc.Asan) {
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400286 if mod.Host() {
287 variations = append(variations,
288 blueprint.Variation{Mutator: "link", Variation: "static"})
289 depTag = cc.StaticDepTag(false)
290 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan.static")}
291 } else {
292 variations = append(variations,
293 blueprint.Variation{Mutator: "link", Variation: "shared"})
294 depTag = cc.SharedDepTag()
295 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
296 }
Ivan Lozano408d3732023-07-27 13:28:08 -0400297 } else if mod.IsSanitizerEnabled(cc.Hwasan) {
Ivan Lozano6c5b8f42021-11-15 09:35:12 -0500298 // TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400299 if binary, ok := mod.compiler.(binaryInterface); ok {
300 if binary.staticallyLinked() {
Tri Vo0a74c3e2021-04-01 13:59:27 -0700301 mctx.ModuleErrorf("HWASan is not supported for static Rust executables yet.")
302 }
303 }
304
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400305 // Always link against the shared library -- static binaries will pull in the static
306 // library during final link if necessary
307 variations = append(variations,
308 blueprint.Variation{Mutator: "link", Variation: "shared"})
309 depTag = cc.SharedDepTag()
310 deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "hwasan")}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500311 }
Tri Vo0a74c3e2021-04-01 13:59:27 -0700312
Ivan Lozano62cd0382021-11-01 10:27:54 -0400313 if len(deps) > 0 {
314 mctx.AddFarVariationDependencies(variations, depTag, deps...)
315 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500316 }
317}
318
319func (sanitize *sanitize) SetSanitizer(t cc.SanitizerType, b bool) {
320 sanitizerSet := false
321 switch t {
322 case cc.Fuzzer:
323 sanitize.Properties.Sanitize.Fuzzer = boolPtr(b)
324 sanitizerSet = true
325 case cc.Asan:
326 sanitize.Properties.Sanitize.Address = boolPtr(b)
327 sanitizerSet = true
Tri Vo0a74c3e2021-04-01 13:59:27 -0700328 case cc.Hwasan:
329 sanitize.Properties.Sanitize.Hwaddress = boolPtr(b)
330 sanitizerSet = true
Ivan Lozano62cd0382021-11-01 10:27:54 -0400331 case cc.Memtag_heap:
332 sanitize.Properties.Sanitize.Memtag_heap = boolPtr(b)
333 sanitizerSet = true
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500334 default:
335 panic(fmt.Errorf("setting unsupported sanitizerType %d", t))
336 }
337 if b && sanitizerSet {
338 sanitize.Properties.SanitizerEnabled = true
339 }
340}
341
Ivan Lozanod7586b62021-04-01 09:49:36 -0400342func (m *Module) UbsanRuntimeNeeded() bool {
343 return false
344}
345
346func (m *Module) MinimalRuntimeNeeded() bool {
347 return false
348}
349
350func (m *Module) UbsanRuntimeDep() bool {
351 return false
352}
353
354func (m *Module) MinimalRuntimeDep() bool {
355 return false
356}
357
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500358// Check if the sanitizer is explicitly disabled (as opposed to nil by
359// virtue of not being set).
360func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
361 if sanitize == nil {
362 return false
363 }
364 if Bool(sanitize.Properties.Sanitize.Never) {
365 return true
366 }
367 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
368 return sanitizerVal != nil && *sanitizerVal == false
369}
370
371// There isn't an analog of the method above (ie:isSanitizerExplicitlyEnabled)
372// because enabling a sanitizer either directly (via the blueprint) or
373// indirectly (via a mutator) sets the bool ptr to true, and you can't
374// distinguish between the cases. It isn't needed though - both cases can be
375// treated identically.
376func (sanitize *sanitize) isSanitizerEnabled(t cc.SanitizerType) bool {
377 if sanitize == nil || !sanitize.Properties.SanitizerEnabled {
378 return false
379 }
380
381 sanitizerVal := sanitize.getSanitizerBoolPtr(t)
382 return sanitizerVal != nil && *sanitizerVal == true
383}
384
385func (sanitize *sanitize) getSanitizerBoolPtr(t cc.SanitizerType) *bool {
386 switch t {
387 case cc.Fuzzer:
388 return sanitize.Properties.Sanitize.Fuzzer
389 case cc.Asan:
390 return sanitize.Properties.Sanitize.Address
Tri Vo0a74c3e2021-04-01 13:59:27 -0700391 case cc.Hwasan:
392 return sanitize.Properties.Sanitize.Hwaddress
Ivan Lozano62cd0382021-11-01 10:27:54 -0400393 case cc.Memtag_heap:
394 return sanitize.Properties.Sanitize.Memtag_heap
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500395 default:
396 return nil
397 }
398}
399
Tri Vo0a74c3e2021-04-01 13:59:27 -0700400func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
401 // Add a suffix for hwasan rlib libraries to allow surfacing both the sanitized and
402 // non-sanitized variants to make without a name conflict.
403 if entries.Class == "RLIB_LIBRARIES" || entries.Class == "STATIC_LIBRARIES" {
404 if sanitize.isSanitizerEnabled(cc.Hwasan) {
405 entries.SubName += ".hwasan"
406 }
407 }
408}
409
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500410func (mod *Module) SanitizerSupported(t cc.SanitizerType) bool {
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400411 // Sanitizers are not supported on Windows targets.
412 if mod.Os() == android.Windows {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500413 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 Lozano6cd99e62020-02-11 08:24:25 -0500428 default:
429 return false
430 }
431}
432
433func (mod *Module) IsSanitizerEnabled(t cc.SanitizerType) bool {
434 return mod.sanitize.isSanitizerEnabled(t)
435}
436
437func (mod *Module) IsSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400438 // Sanitizers are not supported on Windows targets.
439 if mod.Os() == android.Windows {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500440 return true
441 }
442
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500443 return mod.sanitize.isSanitizerExplicitlyDisabled(t)
444}
445
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500446func (mod *Module) SetSanitizer(t cc.SanitizerType, b bool) {
447 if !Bool(mod.sanitize.Properties.Sanitize.Never) {
448 mod.sanitize.SetSanitizer(t, b)
449 }
450}
451
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500452func (mod *Module) StaticallyLinked() bool {
453 if lib, ok := mod.compiler.(libraryInterface); ok {
Tri Vo505b0e82021-04-08 15:50:48 -0700454 return lib.rlib() || lib.static()
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400455 } else if binary, ok := mod.compiler.(binaryInterface); ok {
456 return binary.staticallyLinked()
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500457 }
458 return false
459}
460
461func (mod *Module) SetInSanitizerDir() {
462 mod.sanitize.Properties.InSanitizerDir = true
463}
464
465func (mod *Module) SanitizeNever() bool {
466 return Bool(mod.sanitize.Properties.Sanitize.Never)
467}
468
469var _ cc.PlatformSanitizeable = (*Module)(nil)
470
471func IsSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
472 switch t := tag.(type) {
473 case dependencyTag:
474 return t.library
475 default:
476 return cc.IsSanitizableDependencyTag(tag)
477 }
478}
479
480func (m *Module) SanitizableDepTagChecker() cc.SantizableDependencyTagChecker {
481 return IsSanitizableDependencyTag
482}