Merge "Fix libdl inclusion for default-ub."
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 48cedce..21b8294 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -151,6 +151,7 @@
 LOCAL_CTS_TEST_RUNNER:=
 LOCAL_CLANG:=
 LOCAL_ADDRESS_SANITIZER:=
+LOCAL_DETECT_INTEGER_OVERFLOWS:=
 LOCAL_JAR_EXCLUDE_FILES:=
 LOCAL_JAR_PACKAGES:=
 LOCAL_JAR_EXCLUDE_PACKAGES:=
diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk
index 87cf65c..bb18695 100644
--- a/core/config_sanitizers.mk
+++ b/core/config_sanitizers.mk
@@ -106,3 +106,13 @@
   recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)),
   my_cflags += -fsanitize-recover=$(recover_arg)
 endif
+
+ifeq ($(strip $(LOCAL_DETECT_INTEGER_OVERFLOWS)),true)
+  ifeq ($(my_clang),true)
+    my_cflags += -fsanitize=signed-integer-overflow,unsigned-integer-overflow
+    my_cflags += -ftrap-function=abort
+    my_cflags += -fsanitize-undefined-trap-on-error
+  else
+    $(error $(LOCAL_MODULE): You must enable LOCAL_CLANG:=true to use LOCAL_DETECT_INTEGER_OVERFLOWS)
+  endif
+endif