Skip to content

Commit e132653

Browse files
chiragramanicopybara-github
authored andcommitted
Remove O1 from sanitizer feature flag defaults
This PR removes `-O1` from the current set of sanitizer related feature flags defaults. **Context and Repro** 1. Heap buffer overflow in the following code block is not caught by asan. example.cc ``` #include <cstdlib> int main(int argc, char **argv) { int *array = new int[100]; array[0] = 0; int res = array[argc + 100]; // BOOM delete [] array; return res; } ``` BUILD ``` cc_binary( name = 'example', srcs = ['example.cc'], features = ['asan'], ) ``` execute: ``` bazel run :example ``` **Expectation:** Address sanitizer should detect and report heap buffer overflow. But this doesn't happen in the above case. It is because of O1 being applied by default and since this is added at the last, it also overrides explicit copts passed(O0). It would be nice if the optimization level is a bit de-coupled from the default group here. Closes #17355. PiperOrigin-RevId: 507658773 Change-Id: I3aa4fb92a2dc271cbbedfc6f05e72a8a9b2aba09
1 parent 6b853e6 commit e132653

File tree

2 files changed

+0
-2
lines changed

2 files changed

+0
-2
lines changed

tools/cpp/unix_cc_toolchain_config.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_fla
151151
actions = all_compile_actions,
152152
flag_groups = [
153153
flag_group(flags = [
154-
"-O1",
155154
"-fno-omit-frame-pointer",
156155
"-fno-sanitize-recover=all",
157156
] + specific_compile_flags),

tools/osx/crosstool/cc_toolchain_config.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,6 @@ def _impl(ctx):
25662566
flag_groups = [
25672567
flag_group(
25682568
flags = [
2569-
"-O1",
25702569
"-gline-tables-only",
25712570
"-fno-omit-frame-pointer",
25722571
"-fno-sanitize-recover=all",

0 commit comments

Comments
 (0)