From e132653ead5e50f4226dbff7776466fef1918f49 Mon Sep 17 00:00:00 2001 From: Chirag Ramani Date: Mon, 6 Feb 2023 20:15:09 -0800 Subject: [PATCH] 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 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 --- tools/cpp/unix_cc_toolchain_config.bzl | 1 - tools/osx/crosstool/cc_toolchain_config.bzl | 1 - 2 files changed, 2 deletions(-) diff --git a/tools/cpp/unix_cc_toolchain_config.bzl b/tools/cpp/unix_cc_toolchain_config.bzl index 867013473927ee..4dd7c7d2ed2015 100644 --- a/tools/cpp/unix_cc_toolchain_config.bzl +++ b/tools/cpp/unix_cc_toolchain_config.bzl @@ -151,7 +151,6 @@ def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_fla actions = all_compile_actions, flag_groups = [ flag_group(flags = [ - "-O1", "-fno-omit-frame-pointer", "-fno-sanitize-recover=all", ] + specific_compile_flags), diff --git a/tools/osx/crosstool/cc_toolchain_config.bzl b/tools/osx/crosstool/cc_toolchain_config.bzl index 8e7356ac375b27..9a1527d2d7bafa 100644 --- a/tools/osx/crosstool/cc_toolchain_config.bzl +++ b/tools/osx/crosstool/cc_toolchain_config.bzl @@ -2566,7 +2566,6 @@ def _impl(ctx): flag_groups = [ flag_group( flags = [ - "-O1", "-gline-tables-only", "-fno-omit-frame-pointer", "-fno-sanitize-recover=all",