Skip to content

Commit 0a0e9ce

Browse files
authored
Reactivate function and vptr UBSan checks (#35812)
* Reactivate ubsan checks * omit the sanitization of vptr when the -fno-rtti flag is set * grouping all declare_args at the top BUILD.gn file
1 parent f509f67 commit 0a0e9ce

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

build/config/compiler/BUILD.gn

+35-25
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,40 @@ if (current_os == "mac" || current_os == "ios") {
2424
import("${build_root}/config/mac/mac_sdk.gni")
2525
}
2626

27+
# To use different sanitizer options, use `gn args .` in the out folder and
28+
# use settings like:
29+
#
30+
# is_clang=true
31+
# is_debug=true
32+
# optimize_for_size=false
33+
# is_asan=true
34+
# is_sanitize_fatal=false
35+
#
36+
2737
declare_args() {
2838
# Enable -Werror. This can be disabled if using a different compiler
2939
# with unfixed or unsupported wanings.
3040
treat_warnings_as_errors = true
41+
42+
# Enable Thread sanitizer
43+
is_tsan = false
44+
45+
# Enable memory sanitizer
46+
is_msan = false
47+
48+
# enable undefined behavior sanitizer
49+
is_ubsan = false
50+
51+
# Exit on sanitize error. Generally standard libraries may get errors
52+
# so not stopping on the first error is often useful
53+
is_sanitize_fatal = true
54+
55+
# Enable or disable Runtime Type Information (RTTI).
56+
# Defaults true on darwin because Darwin.framework uses it.
57+
enable_rtti = current_os == "mac" || current_os == "ios"
58+
59+
# Enable or disable support for C++ exceptions.
60+
enable_exceptions = false
3161
}
3262

3363
if (current_cpu == "arm" || current_cpu == "arm64") {
@@ -397,21 +427,6 @@ config("runtime_default") {
397427
# is_sanitize_fatal=false
398428
#
399429

400-
declare_args() {
401-
# Enable Thread sanitizer
402-
is_tsan = false
403-
404-
# Enable memory sanitizer
405-
is_msan = false
406-
407-
# enable undefined behavior sanitizer
408-
is_ubsan = false
409-
410-
# Exit on sanitize error. Generally standard libraries may get errors
411-
# so not stopping on the first error is often useful
412-
is_sanitize_fatal = true
413-
}
414-
415430
config("sanitize_address") {
416431
defines = []
417432
cflags = [
@@ -452,10 +467,14 @@ config("sanitize_undefined_behavior") {
452467
"-fsanitize=unsigned-integer-overflow",
453468
"-fsanitize=implicit-conversion",
454469
"-fsanitize=nullability",
455-
"-fno-sanitize=vptr,function",
456470
]
457471
}
458472

473+
#According to the LLVM UBSan documentation, sanitizing vptr is incompatible with the -fno-rtti flag.
474+
if (!enable_rtti) {
475+
cflags += [ "-fno-sanitize=vptr" ]
476+
}
477+
459478
ldflags = cflags
460479
}
461480

@@ -522,15 +541,6 @@ config("coverage_default") {
522541
}
523542
}
524543

525-
declare_args() {
526-
# Enable or disable Runtime Type Information (RTTI).
527-
# Defaults true on darwin because Darwin.framework uses it.
528-
enable_rtti = current_os == "mac" || current_os == "ios"
529-
530-
# Enable or disable support for C++ exceptions.
531-
enable_exceptions = false
532-
}
533-
534544
config("no_rtti") {
535545
cflags_cc = [ "-fno-rtti" ]
536546
}

0 commit comments

Comments
 (0)