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
56sanitizer = {
57    Sanitizer.address: [
58        "-Zsanitizer=address",
59        "-Cllvm-args=-asan-use-after-scope",
60        "-Cllvm-args=-asan-use-after-return=always",
61        # "-Cllvm-args=-asan-stack=false",  # Remove when database-issues#7468 is fixed
62        "-Cdebug-assertions=on",
63        "-Clink-arg=-fuse-ld=lld",  # access beyond end of merged section
64        "-Clinker=clang++",
65    ],
66    Sanitizer.hwaddress: [
67        "-Zsanitizer=hwaddress",
68        "-Ctarget-feature=+tagged-globals",
69        "-Clink-arg=-fuse-ld=lld",  # access beyond end of merged section
70        "-Clinker=clang++",
71    ],
72    Sanitizer.cfi: [
73        "-Zsanitizer=cfi",
74        "-Clto",  # error: `-Zsanitizer=cfi` requires `-Clto` or `-Clinker-plugin-lto`
75        "-Clink-arg=-fuse-ld=lld",  # access beyond end of merged section
76        "-Clinker=clang++",
77    ],
78    Sanitizer.thread: [
79        "-Zsanitizer=thread",
80        "-Clink-arg=-fuse-ld=lld",  # access beyond end of merged section
81        "-Clinker=clang++",
82    ],
83    Sanitizer.leak: [
84        "-Zsanitizer=leak",
85        "-Clink-arg=-fuse-ld=lld",  # access beyond end of merged section
86        "-Clinker=clang++",
87    ],
88    Sanitizer.undefined: ["-Clink-arg=-fsanitize=undefined", "-Clinker=clang++"],
89}
90
91sanitizer_cflags = {
92    Sanitizer.address: ["-fsanitize=address"],
93    Sanitizer.hwaddress: ["-fsanitize=hwaddress"],
94    Sanitizer.cfi: ["-fsanitize=cfi"],
95    Sanitizer.thread: ["-fsanitize=thread"],
96    Sanitizer.leak: ["-fsanitize=leak"],
97    Sanitizer.undefined: ["-fsanitize=undefined"],
98}
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

What sanitizer to use

address = <Sanitizer.address: 'address'>
cfi = <Sanitizer.cfi: 'cfi'>
thread = <Sanitizer.thread: 'thread'>
leak = <Sanitizer.leak: 'leak'>
undefined = <Sanitizer.undefined: 'undefined'>
none = <Sanitizer.none: 'none'>

No 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']}