misc.python.materialize.rustc_flags
1# Copyright Materialize, Inc. and contributors. All rights reserved. 2# 3# Use of this software is governed by the Business Source License 4# included in the LICENSE file at the root of this repository. 5# 6# As of the Change Date specified in that file, in accordance with 7# the Business Source License, use of this software will be governed 8# by the Apache License, Version 2.0. 9 10from enum import Enum 11 12"""rustc flags.""" 13 14# Flags to enable code coverage. 15# 16# Note that because clusterd gets terminated by a signal in most 17# cases, it needs to use LLVM's continuous profiling mode, and though 18# the documentation is contradictory about this, on Linux this 19# requires the additional -runtime-counter-relocation flag or you'll 20# get errors of the form "__llvm_profile_counter_bias is undefined" 21# and no profiles will be written. 22coverage = [ 23 "-Cinstrument-coverage", 24 "-Cllvm-args=-runtime-counter-relocation", 25] 26 27 28class Sanitizer(Enum): 29 """What sanitizer to use""" 30 31 address = "address" 32 """The AddressSanitizer, see https://clang.llvm.org/docs/AddressSanitizer.html""" 33 34 hwaddress = "hwaddress" 35 """The HWAddressSanitizer, see https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html""" 36 37 cfi = "cfi" 38 """Control Flow Integrity, see https://clang.llvm.org/docs/ControlFlowIntegrity.html""" 39 40 thread = "thread" 41 """The ThreadSanitizer, see https://clang.llvm.org/docs/ThreadSanitizer.html""" 42 43 leak = "leak" 44 """The LeakSanitizer, see https://clang.llvm.org/docs/LeakSanitizer.html""" 45 46 undefined = "undefined" 47 """The UndefinedBehavior, see https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html""" 48 49 none = "none" 50 """No sanitizer""" 51 52 def __str__(self) -> str: 53 return self.value 54 55 def bazel_flags(self) -> list[str]: 56 """Return a set of Bazel flags to enable the sanitizer.""" 57 if self == Sanitizer.address: 58 return ["--config=asan"] 59 elif self == Sanitizer.hwaddress: 60 return ["--config=hwasan"] 61 elif self == Sanitizer.cfi: 62 return ["--config=cfi"] 63 elif self == Sanitizer.thread: 64 return ["--config=tsan"] 65 elif self == Sanitizer.leak: 66 return ["--config=leak"] 67 elif self == Sanitizer.undefined: 68 return ["--config=undefined"] 69 else: 70 return [] 71 72 73sanitizer = { 74 Sanitizer.address: [ 75 "-Zsanitizer=address", 76 "-Cllvm-args=-asan-use-after-scope", 77 "-Cllvm-args=-asan-use-after-return=always", 78 # "-Cllvm-args=-asan-stack=false", # Remove when database-issues#7468 is fixed 79 "-Cdebug-assertions=on", 80 "-Clink-arg=-fuse-ld=lld", # access beyond end of merged section 81 "-Clinker=clang++", 82 ], 83 Sanitizer.hwaddress: [ 84 "-Zsanitizer=hwaddress", 85 "-Ctarget-feature=+tagged-globals", 86 "-Clink-arg=-fuse-ld=lld", # access beyond end of merged section 87 "-Clinker=clang++", 88 ], 89 Sanitizer.cfi: [ 90 "-Zsanitizer=cfi", 91 "-Clto", # error: `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto` 92 "-Clink-arg=-fuse-ld=lld", # access beyond end of merged section 93 "-Clinker=clang++", 94 ], 95 Sanitizer.thread: [ 96 "-Zsanitizer=thread", 97 "-Clink-arg=-fuse-ld=lld", # access beyond end of merged section 98 "-Clinker=clang++", 99 ], 100 Sanitizer.leak: [ 101 "-Zsanitizer=leak", 102 "-Clink-arg=-fuse-ld=lld", # access beyond end of merged section 103 "-Clinker=clang++", 104 ], 105 Sanitizer.undefined: ["-Clink-arg=-fsanitize=undefined", "-Clinker=clang++"], 106} 107 108sanitizer_cflags = { 109 Sanitizer.address: ["-fsanitize=address"], 110 Sanitizer.hwaddress: ["-fsanitize=hwaddress"], 111 Sanitizer.cfi: ["-fsanitize=cfi"], 112 Sanitizer.thread: ["-fsanitize=thread"], 113 Sanitizer.leak: ["-fsanitize=leak"], 114 Sanitizer.undefined: ["-fsanitize=undefined"], 115}
coverage =
['-Cinstrument-coverage', '-Cllvm-args=-runtime-counter-relocation']
class
Sanitizer(enum.Enum):
29class Sanitizer(Enum): 30 """What sanitizer to use""" 31 32 address = "address" 33 """The AddressSanitizer, see https://clang.llvm.org/docs/AddressSanitizer.html""" 34 35 hwaddress = "hwaddress" 36 """The HWAddressSanitizer, see https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html""" 37 38 cfi = "cfi" 39 """Control Flow Integrity, see https://clang.llvm.org/docs/ControlFlowIntegrity.html""" 40 41 thread = "thread" 42 """The ThreadSanitizer, see https://clang.llvm.org/docs/ThreadSanitizer.html""" 43 44 leak = "leak" 45 """The LeakSanitizer, see https://clang.llvm.org/docs/LeakSanitizer.html""" 46 47 undefined = "undefined" 48 """The UndefinedBehavior, see https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html""" 49 50 none = "none" 51 """No sanitizer""" 52 53 def __str__(self) -> str: 54 return self.value 55 56 def bazel_flags(self) -> list[str]: 57 """Return a set of Bazel flags to enable the sanitizer.""" 58 if self == Sanitizer.address: 59 return ["--config=asan"] 60 elif self == Sanitizer.hwaddress: 61 return ["--config=hwasan"] 62 elif self == Sanitizer.cfi: 63 return ["--config=cfi"] 64 elif self == Sanitizer.thread: 65 return ["--config=tsan"] 66 elif self == Sanitizer.leak: 67 return ["--config=leak"] 68 elif self == Sanitizer.undefined: 69 return ["--config=undefined"] 70 else: 71 return []
What sanitizer to use
address =
<Sanitizer.address: 'address'>
The AddressSanitizer, see https://clang.llvm.org/docs/AddressSanitizer.html
hwaddress =
<Sanitizer.hwaddress: 'hwaddress'>
The HWAddressSanitizer, see https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
cfi =
<Sanitizer.cfi: 'cfi'>
Control Flow Integrity, see https://clang.llvm.org/docs/ControlFlowIntegrity.html
thread =
<Sanitizer.thread: 'thread'>
The ThreadSanitizer, see https://clang.llvm.org/docs/ThreadSanitizer.html
leak =
<Sanitizer.leak: 'leak'>
The LeakSanitizer, see https://clang.llvm.org/docs/LeakSanitizer.html
undefined =
<Sanitizer.undefined: 'undefined'>
The UndefinedBehavior, see https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
def
bazel_flags(self) -> list[str]:
56 def bazel_flags(self) -> list[str]: 57 """Return a set of Bazel flags to enable the sanitizer.""" 58 if self == Sanitizer.address: 59 return ["--config=asan"] 60 elif self == Sanitizer.hwaddress: 61 return ["--config=hwasan"] 62 elif self == Sanitizer.cfi: 63 return ["--config=cfi"] 64 elif self == Sanitizer.thread: 65 return ["--config=tsan"] 66 elif self == Sanitizer.leak: 67 return ["--config=leak"] 68 elif self == Sanitizer.undefined: 69 return ["--config=undefined"] 70 else: 71 return []
Return a set of Bazel flags to enable the sanitizer.
sanitizer =
{<Sanitizer.address: 'address'>: ['-Zsanitizer=address', '-Cllvm-args=-asan-use-after-scope', '-Cllvm-args=-asan-use-after-return=always', '-Cdebug-assertions=on', '-Clink-arg=-fuse-ld=lld', '-Clinker=clang++'], <Sanitizer.hwaddress: 'hwaddress'>: ['-Zsanitizer=hwaddress', '-Ctarget-feature=+tagged-globals', '-Clink-arg=-fuse-ld=lld', '-Clinker=clang++'], <Sanitizer.cfi: 'cfi'>: ['-Zsanitizer=cfi', '-Clto', '-Clink-arg=-fuse-ld=lld', '-Clinker=clang++'], <Sanitizer.thread: 'thread'>: ['-Zsanitizer=thread', '-Clink-arg=-fuse-ld=lld', '-Clinker=clang++'], <Sanitizer.leak: 'leak'>: ['-Zsanitizer=leak', '-Clink-arg=-fuse-ld=lld', '-Clinker=clang++'], <Sanitizer.undefined: 'undefined'>: ['-Clink-arg=-fsanitize=undefined', '-Clinker=clang++']}
sanitizer_cflags =
{<Sanitizer.address: 'address'>: ['-fsanitize=address'], <Sanitizer.hwaddress: 'hwaddress'>: ['-fsanitize=hwaddress'], <Sanitizer.cfi: 'cfi'>: ['-fsanitize=cfi'], <Sanitizer.thread: 'thread'>: ['-fsanitize=thread'], <Sanitizer.leak: 'leak'>: ['-fsanitize=leak'], <Sanitizer.undefined: 'undefined'>: ['-fsanitize=undefined']}