From 05eefa12e24cd1bdc50f4a002c461bd2df810276 Mon Sep 17 00:00:00 2001 From: kshyanashree <109167932+kshyanashree@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:38:54 -0800 Subject: [PATCH] Remove O1 from sanitizer feature flag defaults (#17439) 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 Co-authored-by: Chirag Ramani --- 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 7849348ac4be45..1a825f1fe17115 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 276c3ceb6797d7..a27068f446a90a 100644 --- a/tools/osx/crosstool/cc_toolchain_config.bzl +++ b/tools/osx/crosstool/cc_toolchain_config.bzl @@ -2674,7 +2674,6 @@ def _impl(ctx): flag_groups = [ flag_group( flags = [ - "-O1", "-gline-tables-only", "-fno-omit-frame-pointer", "-fno-sanitize-recover=all",