OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/chrome_build.gni") | 5 import("//build/config/chrome_build.gni") |
6 import("//build/config/chromecast_build.gni") | 6 import("//build/config/chromecast_build.gni") |
7 import("//build/config/sanitizers/sanitizers.gni") | 7 import("//build/config/sanitizers/sanitizers.gni") |
8 | 8 |
9 # Contains the dependencies needed for sanitizers to link into executables and | 9 # Contains the dependencies needed for sanitizers to link into executables and |
10 # shared_libraries. Unconditionally depend upon this target as it is empty if | 10 # shared_libraries. Unconditionally depend upon this target as it is empty if |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 if (is_msan) { | 86 if (is_msan) { |
87 ldflags += [ "-fsanitize=memory" ] | 87 ldflags += [ "-fsanitize=memory" ] |
88 } | 88 } |
89 if (is_ubsan) { | 89 if (is_ubsan) { |
90 ldflags += [ "-fsanitize=undefined" ] | 90 ldflags += [ "-fsanitize=undefined" ] |
91 } | 91 } |
92 if (is_ubsan_vptr) { | 92 if (is_ubsan_vptr) { |
93 ldflags += [ "-fsanitize=vptr" ] | 93 ldflags += [ "-fsanitize=vptr" ] |
94 } | 94 } |
95 if (is_cfi && !is_nacl) { | 95 if (is_lto && !is_nacl) { |
96 ldflags += [ | 96 ldflags += [ "-flto" ] |
97 "-flto", | |
98 "-fsanitize=cfi-vcall", | |
99 "-fsanitize=cfi-derived-cast", | |
100 "-fsanitize=cfi-unrelated-cast", | |
101 ] | |
102 | 97 |
103 # Apply a lower LTO optimization level as the default is too slow. | 98 # Apply a lower LTO optimization level as the default is too slow. |
104 if (is_linux) { | 99 if (is_linux) { |
105 ldflags += [ "-Wl,-plugin-opt,O1" ] | 100 ldflags += [ "-Wl,-plugin-opt,O1" ] |
106 } else if (is_mac) { | 101 } else if (is_mac) { |
107 ldflags += [ "-Wl,-mllvm,-O1" ] | 102 ldflags += [ "-Wl,-mllvm,-O1" ] |
108 } | 103 } |
109 | 104 |
110 # Work-around for http://openradar.appspot.com/20356002 | 105 # Work-around for http://openradar.appspot.com/20356002 |
111 if (is_mac) { | 106 if (is_mac) { |
112 ldflags += [ "-Wl,-all_load" ] | 107 ldflags += [ "-Wl,-all_load" ] |
113 } | 108 } |
114 | 109 |
115 # Without this flag, LTO produces a .text section that is larger | 110 # Without this flag, LTO produces a .text section that is larger |
116 # than the maximum call displacement, preventing the linker from | 111 # than the maximum call displacement, preventing the linker from |
117 # relocating calls (http://llvm.org/PR22999). | 112 # relocating calls (http://llvm.org/PR22999). |
118 if (current_cpu == "arm") { | 113 if (current_cpu == "arm") { |
119 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] | 114 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] |
120 } | 115 } |
121 | 116 |
| 117 if (is_cfi) { |
| 118 ldflags += [ |
| 119 "-fsanitize=cfi-vcall", |
| 120 "-fsanitize=cfi-derived-cast", |
| 121 "-fsanitize=cfi-unrelated-cast", |
| 122 ] |
| 123 } |
| 124 |
122 if (use_cfi_diag) { | 125 if (use_cfi_diag) { |
123 ldflags += [ | 126 ldflags += [ |
124 "-fno-sanitize-trap=cfi", | 127 "-fno-sanitize-trap=cfi", |
125 "-fsanitize-recover=cfi", | 128 "-fsanitize-recover=cfi", |
126 ] | 129 ] |
127 } | 130 } |
128 } | 131 } |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 # This config is applied by default to all targets. It sets the compiler flags | 135 # This config is applied by default to all targets. It sets the compiler flags |
133 # for sanitizer usage, or, if no sanitizer is set, does nothing. | 136 # for sanitizer usage, or, if no sanitizer is set, does nothing. |
134 # | 137 # |
135 # This needs to be in a separate config so that targets can opt out of | 138 # This needs to be in a separate config so that targets can opt out of |
136 # sanitizers (by removing the config) if they desire. Even if a target | 139 # sanitizers (by removing the config) if they desire. Even if a target |
137 # removes this config, executables & shared libraries should still depend on | 140 # removes this config, executables & shared libraries should still depend on |
138 # :deps if any of their dependencies have not opted out of sanitizers. | 141 # :deps if any of their dependencies have not opted out of sanitizers. |
139 config("default_sanitizer_flags") { | 142 config("default_sanitizer_flags") { |
140 cflags = [] | 143 cflags = [] |
141 cflags_cc = [] | 144 cflags_cc = [] |
142 defines = [] | 145 defines = [] |
143 configs = [ ":default_sanitizer_ldflags" ] | 146 configs = [ ":default_sanitizer_ldflags" ] |
144 | 147 |
145 # Only works on Posix-like platforms. | 148 # Only works on Posix-like platforms. |
146 # FIXME: this is not true, remove the conditional. | 149 # FIXME: this is not true, remove the conditional. |
147 if (is_posix) { | 150 if (is_posix) { |
148 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, | 151 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, |
149 # MemorySanitizer and non-official CFI builds. | 152 # MemorySanitizer and non-official CFI builds. |
150 if (using_sanitizer || (is_cfi && !is_official_build)) { | 153 if (using_sanitizer || (is_lto && !is_official_build)) { |
151 cflags += [ | 154 cflags += [ |
152 "-fno-omit-frame-pointer", | 155 "-fno-omit-frame-pointer", |
153 "-gline-tables-only", | 156 "-gline-tables-only", |
154 ] | 157 ] |
155 } | 158 } |
156 if (is_asan) { | 159 if (is_asan) { |
157 asan_blacklist_path = | 160 asan_blacklist_path = |
158 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) | 161 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) |
159 cflags += [ | 162 cflags += [ |
160 "-fsanitize=address", | 163 "-fsanitize=address", |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 239 } |
237 } | 240 } |
238 if (is_ubsan_vptr) { | 241 if (is_ubsan_vptr) { |
239 ubsan_vptr_blacklist_path = | 242 ubsan_vptr_blacklist_path = |
240 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir) | 243 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir) |
241 cflags += [ | 244 cflags += [ |
242 "-fsanitize=vptr", | 245 "-fsanitize=vptr", |
243 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path", | 246 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path", |
244 ] | 247 ] |
245 } | 248 } |
246 if (is_cfi && !is_nacl) { | 249 if (is_lto && !is_nacl) { |
247 cfi_blacklist_path = | 250 cflags += [ "-flto" ] |
248 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) | 251 |
249 cflags += [ | 252 if (is_cfi) { |
250 "-flto", | 253 cfi_blacklist_path = |
251 "-fsanitize=cfi-vcall", | 254 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) |
252 "-fsanitize=cfi-derived-cast", | 255 cflags += [ |
253 "-fsanitize=cfi-unrelated-cast", | 256 "-fsanitize=cfi-vcall", |
254 "-fsanitize-blacklist=$cfi_blacklist_path", | 257 "-fsanitize=cfi-derived-cast", |
255 ] | 258 "-fsanitize=cfi-unrelated-cast", |
| 259 "-fsanitize-blacklist=$cfi_blacklist_path", |
| 260 ] |
| 261 } |
256 | 262 |
257 if (use_cfi_diag) { | 263 if (use_cfi_diag) { |
258 cflags += [ | 264 cflags += [ |
259 "-fno-sanitize-trap=cfi", | 265 "-fno-sanitize-trap=cfi", |
260 "-fsanitize-recover=cfi", | 266 "-fsanitize-recover=cfi", |
261 "-fno-inline-functions", | 267 "-fno-inline-functions", |
262 "-fno-inline", | 268 "-fno-inline", |
263 "-fno-omit-frame-pointer", | 269 "-fno-omit-frame-pointer", |
264 "-O1", | 270 "-O1", |
265 ] | 271 ] |
(...skipping 16 matching lines...) Expand all Loading... |
282 | 288 |
283 config("default_sanitizer_coverage_flags") { | 289 config("default_sanitizer_coverage_flags") { |
284 cflags = [] | 290 cflags = [] |
285 | 291 |
286 if (use_sanitizer_coverage) { | 292 if (use_sanitizer_coverage) { |
287 # FIXME: make this configurable. | 293 # FIXME: make this configurable. |
288 cflags += | 294 cflags += |
289 [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp" ] | 295 [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp" ] |
290 } | 296 } |
291 } | 297 } |
OLD | NEW |