summaryrefslogtreecommitdiffstats
path: root/build/config/sanitizers/sanitizers.gni
blob: 2d6fb1e682654ad98314d4e451593c0b6987f636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
  # Compile for Address Sanitizer to find memory bugs.
  is_asan = false

  # Compile for Leak Sanitizer to find leaks.
  is_lsan = false

  # Compile for Memory Sanitizer to find uninitialized reads.
  is_msan = false

  # Compile for Thread Sanitizer to find threading bugs.
  is_tsan = false

  # Compile for Undefined Behaviour Sanitizer to find various types of
  # undefined behaviour (excludes vptr checks).
  is_ubsan = false

  # Compile for Undefined Behaviour Sanitizer's vptr checks.
  is_ubsan_vptr = false

  # Track where uninitialized memory originates from. From fastest to slowest:
  # 0 - no tracking, 1 - track only the initial allocation site, 2 - track the
  # chain of stores leading from allocation site to use site.
  msan_track_origins = 2

  # Use dynamic libraries instrumented by one of the sanitizers instead of the
  # standard system libraries. Set this flag to download prebuilt binaries from
  # GCS.
  use_prebuilt_instrumented_libraries = false

  # Enable building with SyzyAsan which can find certain types of memory
  # errors. Only works on Windows. See
  # https://github.com/google/syzygy/wiki/SyzyASanHowTo
  is_syzyasan = false

  # Compile with Control Flow Integrity to protect virtual calls and casts.
  # See http://clang.llvm.org/docs/ControlFlowIntegrity.html
  is_cfi = false

  # By default, Control Flow Integrity will crash the program if it detects a
  # violation. Set this to true to print detailed diagnostics instead.
  use_cfi_diag = false

  # Compile for fuzzing with LLVM LibFuzzer.
  # See http://www.chromium.org/developers/testing/libfuzzer
  use_libfuzzer = false

  # Enables core ubsan security features. Will later be removed once it matches
  # is_ubsan.
  is_ubsan_security = false

  # Compile for fuzzing with Dr. Fuzz
  # See http://www.chromium.org/developers/testing/dr-fuzz
  use_drfuzz = false

  # Helper variable for testing builds with disabled libfuzzer.
  # Not for client use.
  disable_libfuzzer = false
}

# Args that are in turn dependent on other args must be in a separate
# declare_args block. User overrides are only applied at the end of a
# declare_args block.
declare_args() {
  # Use libc++ (buildtools/third_party/libc++ and
  # buildtools/third_party/libc++abi) instead of stdlibc++ as standard library.
  # This is intended to be used for instrumented builds.
  use_custom_libcxx = (is_asan && (is_linux || is_mac)) || is_tsan || is_msan ||
                      is_ubsan || use_libfuzzer

  # Enable Link Time Optimization (output programs runs faster,
  # but linking is up to 5-20x slower.
  is_lto = is_cfi

  use_sanitizer_coverage = use_libfuzzer
}

using_sanitizer =
    is_asan || is_lsan || is_tsan || is_msan || is_ubsan || is_ubsan_vptr

assert(!using_sanitizer || is_clang,
       "Sanitizers (is_*san) require setting is_clang = true in 'gn args'")

# MSan only links Chrome properly in release builds (brettw -- 9/1/2015). The
# same is possibly true for the other non-ASan sanitizers. But regardless of
# whether it links, one would normally never run a sanitizer in debug mode.
# Running in debug mode probably indicates you forgot to set the "is_debug =
# false" flag in the build args. ASan seems to run fine in debug mode.
#
# If you find a use-case where you want to compile a sanitizer in debug mode
# and have verified it works, ask brettw and we can consider removing it from
# this condition. We may also be able to find another way to enable your case
# without having people accidentally get broken builds by compiling an
# unsupported or unadvisable configurations.
#
# For one-off testing, just comment this assertion out.
assert(
    !is_debug || !(is_msan || is_lsan || is_tsan || is_ubsan || is_ubsan_vptr),
    "Sanitizers should generally be used in release (set is_debug=false).")