-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use of GCC with UBSan and the null, returns-nonnull-attribute, nonnull-attribute checks will cause the compiler to reject valid code due to use of the underlying GCC option -fno-delete-null-pointer-checks. This commit patches rules_cc to disable these checks if a GCC compiler is used with the ubsan feature. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67762#c2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962 This change is needed by #89. Change-Id: Ic0e5224850d8478aa92806a8f21248e979acce04
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
diff --git a/cc/defs.bzl b/cc/defs.bzl | ||
index a3acac7..53ee96e 100644 | ||
--- a/cc/defs.bzl | ||
+++ b/cc/defs.bzl | ||
@@ -46,6 +46,18 @@ def _add_tags(attrs, is_binary = False): | ||
|
||
return attrs | ||
|
||
+def _gcc_no_sanitize_null(attrs): | ||
+ attrs["copts"] = ( | ||
+ attrs.get("copts", []) + | ||
+ select({ | ||
+ "@starflate//toolchain:gcc_with_ubsan": [ | ||
+ "-fno-sanitize=null,returns-nonnull-attribute,nonnull-attribute", | ||
+ ], | ||
+ "//conditions:default": [], | ||
+ }) | ||
+ ) | ||
+ return attrs | ||
+ | ||
def cc_binary(**attrs): | ||
"""Bazel cc_binary rule. | ||
|
||
@@ -56,7 +68,7 @@ def cc_binary(**attrs): | ||
""" | ||
|
||
# buildifier: disable=native-cc | ||
- native.cc_binary(**_add_tags(attrs, True)) | ||
+ native.cc_binary(**_add_tags(_gcc_no_sanitize_null(attrs), True)) | ||
|
||
def cc_test(**attrs): | ||
"""Bazel cc_test rule. | ||
@@ -68,7 +80,7 @@ def cc_test(**attrs): | ||
""" | ||
|
||
# buildifier: disable=native-cc | ||
- native.cc_test(**_add_tags(attrs, True)) | ||
+ native.cc_test(**_add_tags(_gcc_no_sanitize_null(attrs), True)) | ||
|
||
def cc_library(**attrs): | ||
"""Bazel cc_library rule. | ||
@@ -80,7 +92,7 @@ def cc_library(**attrs): | ||
""" | ||
|
||
# buildifier: disable=native-cc | ||
- native.cc_library(**_add_tags(attrs)) | ||
+ native.cc_library(**_add_tags(_gcc_no_sanitize_null(attrs))) | ||
|
||
def cc_import(**attrs): | ||
"""Bazel cc_import rule. |