Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 410e1f83 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

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 911cb99b)
parent ff413b1c
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -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)