From 410e1f8389f28e52b11cbf811a1f909da8fa9ec2 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Wed, 21 Feb 2018 13:41:05 -0800 Subject: [PATCH] Add minimal-runtime support for integer overflows. Adds Make support for -fsanitze-minimal-runtime when using the integer overflow sanitizers. This makes the crashes due to these sanitizers less mysterious. This also cleans up the handling of the integer_overflow flag. Bug: 64091660 Test: Compiled and checked the generated compiler commands Test: Checked program that overflows for the abort reason Test: Checked integer_overflow flag still emits overflow checks Change-Id: I11012ed0cbbf51935f549a08bd17109b5ce6f330 Merged-In: I11012ed0cbbf51935f549a08bd17109b5ce6f330 (cherry picked from commit 911cb99bc115ba059e3033c00ca89b559300907d) --- core/config_sanitizers.mk | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index 94151430f..35d077ca6 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -217,19 +217,17 @@ ifneq ($(filter integer_overflow,$(my_sanitize)),) # Respect LOCAL_NOSANITIZE for integer-overflow flags. ifeq ($(filter signed-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) - my_cflags += -fsanitize=signed-integer-overflow + my_sanitize += signed-integer-overflow endif ifeq ($(filter unsigned-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) - my_cflags += -fsanitize=unsigned-integer-overflow + my_sanitize += unsigned-integer-overflow endif - my_cflags += -fsanitize-trap=all - my_cflags += -ftrap-function=abort my_cflags += $(INTEGER_OVERFLOW_EXTRA_CFLAGS) # Check for diagnostics mode (on by default). ifneq ($(filter integer_overflow,$(my_sanitize_diag)),) - my_cflags += -fno-sanitize-trap=signed-integer-overflow,unsigned-integer-overflow - my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY) $(my_shared_libraries) + my_sanitize_diag += signed-integer-overflow + my_sanitize_diag += unsigned-integer-overflow endif endif endif @@ -326,6 +324,27 @@ ifneq ($(filter address,$(my_sanitize)),) endif endif +# Use minimal diagnostics when integer overflow is enabled +ifndef LOCAL_IS_HOST_MODULE + # Pre-emptively add UBSAN minimal runtime incase a static library dependency requires it + ifeq ($(filter STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),) + ifndef LOCAL_SDK_VERSION + my_static_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_MINIMAL_RUNTIME_LIBRARY) + endif + endif + ifneq ($(filter unsigned-integer-overflow signed-integer-overflow integer,$(my_sanitize)),) + ifeq ($(filter unsigned-integer-overflow signed-integer overflow integer,$(my_sanitize_diag)),) + ifeq ($(filter cfi,$(my_sanitize_diag)),) + ifeq ($(filter address,$(my_sanitize)),) + my_cflags += -fsanitize-minimal-runtime + my_cflags += -fno-sanitize-trap=integer + my_cflags += -fno-sanitize-recover=integer + endif + endif + endif + endif +endif + ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),) recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)), my_cflags += -fsanitize-recover=$(recover_arg)