1# 2# Copyright (C) 2012 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16# 17 18LOCAL_PATH:= $(call my-dir) 19 20ASAN_NEEDS_SEGV=0 21ASAN_HAS_EXCEPTIONS=1 22ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 23 24asan_rtl_files := \ 25 asan_activation.cc \ 26 asan_allocator.cc \ 27 asan_fake_stack.cc \ 28 asan_flags.cc \ 29 asan_globals.cc \ 30 asan_interceptors.cc \ 31 asan_linux.cc \ 32 asan_mac.cc \ 33 asan_malloc_linux.cc \ 34 asan_malloc_mac.cc \ 35 asan_malloc_win.cc \ 36 asan_poisoning.cc \ 37 asan_posix.cc \ 38 asan_report.cc \ 39 asan_rtl.cc \ 40 asan_stack.cc \ 41 asan_stats.cc \ 42 asan_suppressions.cc \ 43 asan_thread.cc \ 44 asan_win.cc \ 45 ../interception/interception_linux.cc \ 46 ../lsan/lsan_common.cc \ 47 ../lsan/lsan_common_linux.cc \ 48 ../sanitizer_common/sanitizer_allocator.cc \ 49 ../sanitizer_common/sanitizer_common.cc \ 50 ../sanitizer_common/sanitizer_common_libcdep.cc \ 51 ../sanitizer_common/sanitizer_coverage_libcdep.cc \ 52 ../sanitizer_common/sanitizer_coverage_mapping_libcdep.cc \ 53 ../sanitizer_common/sanitizer_deadlock_detector1.cc \ 54 ../sanitizer_common/sanitizer_deadlock_detector2.cc \ 55 ../sanitizer_common/sanitizer_flags.cc \ 56 ../sanitizer_common/sanitizer_flag_parser.cc \ 57 ../sanitizer_common/sanitizer_libc.cc \ 58 ../sanitizer_common/sanitizer_libignore.cc \ 59 ../sanitizer_common/sanitizer_linux.cc \ 60 ../sanitizer_common/sanitizer_linux_libcdep.cc \ 61 ../sanitizer_common/sanitizer_mac.cc \ 62 ../sanitizer_common/sanitizer_persistent_allocator.cc \ 63 ../sanitizer_common/sanitizer_platform_limits_linux.cc \ 64 ../sanitizer_common/sanitizer_platform_limits_posix.cc \ 65 ../sanitizer_common/sanitizer_posix.cc \ 66 ../sanitizer_common/sanitizer_posix_libcdep.cc \ 67 ../sanitizer_common/sanitizer_printf.cc \ 68 ../sanitizer_common/sanitizer_procmaps_common.cc \ 69 ../sanitizer_common/sanitizer_procmaps_freebsd.cc \ 70 ../sanitizer_common/sanitizer_procmaps_linux.cc \ 71 ../sanitizer_common/sanitizer_procmaps_mac.cc \ 72 ../sanitizer_common/sanitizer_stackdepot.cc \ 73 ../sanitizer_common/sanitizer_stacktrace.cc \ 74 ../sanitizer_common/sanitizer_stacktrace_libcdep.cc \ 75 ../sanitizer_common/sanitizer_stacktrace_printer.cc \ 76 ../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc \ 77 ../sanitizer_common/sanitizer_suppressions.cc \ 78 ../sanitizer_common/sanitizer_symbolizer.cc \ 79 ../sanitizer_common/sanitizer_symbolizer_libbacktrace.cc \ 80 ../sanitizer_common/sanitizer_symbolizer_libcdep.cc \ 81 ../sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc \ 82 ../sanitizer_common/sanitizer_symbolizer_process_libcdep.cc \ 83 ../sanitizer_common/sanitizer_symbolizer_win.cc \ 84 ../sanitizer_common/sanitizer_thread_registry.cc \ 85 ../sanitizer_common/sanitizer_tls_get_addr.cc \ 86 ../sanitizer_common/sanitizer_unwind_posix_libcdep.cc \ 87 ../sanitizer_common/sanitizer_win.cc \ 88 89asan_rtl_cxx_files := \ 90 asan_new_delete.cc \ 91 92asan_rtl_cflags := \ 93 -fvisibility=hidden \ 94 -fno-exceptions \ 95 -DASAN_LOW_MEMORY=1 \ 96 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 97 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 98 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=$(ASAN_FLEXIBLE_MAPPING_AND_OFFSET) \ 99 -Wno-covered-switch-default \ 100 -Wno-non-virtual-dtor \ 101 -Wno-sign-compare \ 102 -Wno-unused-parameter \ 103 -std=c++11 \ 104 -fno-rtti \ 105 -fno-builtin 106 107asan_test_files := \ 108 tests/asan_globals_test.cc \ 109 tests/asan_test.cc 110 111#tests/asan_noinst_test.cc \ 112#tests/asan_test_main.cc \ 113 114asan_test_cflags := \ 115 -fsanitize-blacklist=external/compiler-rt/lib/asan/tests/asan_test.ignore \ 116 -DASAN_LOW_MEMORY=1 \ 117 -DASAN_UAR=0 \ 118 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 119 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 120 -DASAN_HAS_BLACKLIST=1 \ 121 -Wno-covered-switch-default \ 122 -Wno-non-virtual-dtor \ 123 -Wno-sign-compare \ 124 -Wno-unused-parameter \ 125 -std=c++11 126 127 128ifeq ($(TARGET_ARCH),arm) 129 130include $(CLEAR_VARS) 131 132LOCAL_MODULE := libasan 133LOCAL_C_INCLUDES := \ 134 external/compiler-rt/lib \ 135 external/compiler-rt/include 136LOCAL_CFLAGS += $(asan_rtl_cflags) 137LOCAL_SRC_FILES := asan_preinit.cc 138#LOCAL_SRC_FILES := asan_android_stub.cc asan_preinit.cc 139LOCAL_CPP_EXTENSION := .cc 140LOCAL_CLANG := true 141LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 142LOCAL_ADDRESS_SANITIZER := false 143include $(BUILD_STATIC_LIBRARY) 144 145define build-asan-rt-shared-library 146 147include $(CLEAR_VARS) 148LOCAL_MODULE := $(1) 149LOCAL_MULTILIB := $(2) 150# We need to unwind by frame pointers through a small portion of ASan runtime library code, 151# and that only works with ARM, not with Thumb. 152LOCAL_ARM_MODE := arm 153LOCAL_C_INCLUDES := \ 154 external/compiler-rt/lib \ 155 external/compiler-rt/include 156LOCAL_CFLAGS += $(asan_rtl_cflags) 157LOCAL_SRC_FILES := $(asan_rtl_files) $(asan_rtl_cxx_files) 158LOCAL_CPP_EXTENSION := .cc 159LOCAL_SHARED_LIBRARIES := liblog libc libdl 160LOCAL_STATIC_LIBRARIES := libcompiler_rt libubsan 161# MacOS toolchain is out-of-date and does not support -z global. 162# TODO: re-enable once the toolchain issue is fixed. 163ifneq ($(HOST_OS),darwin) 164 LOCAL_LDFLAGS += -Wl,-z,global 165endif 166LOCAL_CLANG := true 167LOCAL_ADDRESS_SANITIZER := false 168LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 169include $(BUILD_SHARED_LIBRARY) 170 171endef 172 173ifdef 2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY 174 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),64)) 175 $(eval $(call build-asan-rt-shared-library,$(2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY),32)) 176else 177 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),32)) 178endif 179 180include $(CLEAR_VARS) 181 182LOCAL_MODULE := asanwrapper 183LOCAL_SRC_FILES := asanwrapper.cc 184LOCAL_CPP_EXTENSION := .cc 185LOCAL_CPPFLAGS := -std=c++11 186LOCAL_SHARED_LIBRARIES += libc 187LOCAL_ADDRESS_SANITIZER := false 188LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 189LOCAL_CXX_STL := libc++ 190 191include $(BUILD_EXECUTABLE) 192 193 194include $(CLEAR_VARS) 195 196LOCAL_MODULE := libasan_noinst_test 197LOCAL_MODULE_TAGS := tests 198LOCAL_C_INCLUDES := \ 199 external/gtest/include \ 200 external/compiler-rt/include \ 201 external/compiler-rt/lib \ 202 external/compiler-rt/lib/asan/tests \ 203 external/compiler-rt/lib/sanitizer_common/tests 204LOCAL_CFLAGS += \ 205 -Wno-non-virtual-dtor \ 206 -Wno-unused-parameter \ 207 -Wno-sign-compare \ 208 -DASAN_UAR=0 \ 209 -DASAN_HAS_BLACKLIST=1 \ 210 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 211 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 212 -std=c++11 213LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc 214LOCAL_CPP_EXTENSION := .cc 215LOCAL_CLANG := true 216LOCAL_ADDRESS_SANITIZER := false 217LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 218LOCAL_CXX_STL := libc++ 219 220include $(BUILD_STATIC_LIBRARY) 221 222 223include $(CLEAR_VARS) 224 225LOCAL_MODULE := asan_test 226LOCAL_MODULE_TAGS := tests 227LOCAL_C_INCLUDES := \ 228 external/gtest/include \ 229 external/compiler-rt/lib \ 230 external/compiler-rt/lib/asan/tests \ 231 external/compiler-rt/lib/sanitizer_common/tests 232LOCAL_CFLAGS += $(asan_test_cflags) 233LOCAL_SRC_FILES := $(asan_test_files) 234LOCAL_CPP_EXTENSION := .cc 235LOCAL_STATIC_LIBRARIES := libgtest libasan_noinst_test 236LOCAL_SHARED_LIBRARIES := libc 237LOCAL_ADDRESS_SANITIZER := true 238LOCAL_CLANG := true 239LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 240LOCAL_CXX_STL := libc++ 241 242include $(BUILD_EXECUTABLE) 243 244endif # ifeq($(TARGET_ARCH),arm) 245 246################################################################################ 247# Host modules 248 249ifneq ($(HOST_OS),darwin) 250include $(CLEAR_VARS) 251LOCAL_MODULE := libasan 252LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include 253LOCAL_CFLAGS += $(asan_rtl_cflags) 254LOCAL_SRC_FILES := $(asan_rtl_files) 255LOCAL_CPP_EXTENSION := .cc 256LOCAL_CLANG := true 257LOCAL_MULTILIB := both 258LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 259LOCAL_ADDRESS_SANITIZER := false 260LOCAL_WHOLE_STATIC_LIBRARIES := libubsan 261include $(BUILD_HOST_STATIC_LIBRARY) 262 263include $(CLEAR_VARS) 264LOCAL_MODULE := libasan_cxx 265LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include 266LOCAL_CFLAGS += $(asan_rtl_cflags) 267LOCAL_SRC_FILES := $(asan_rtl_cxx_files) 268LOCAL_CPP_EXTENSION := .cc 269LOCAL_CLANG := true 270LOCAL_MULTILIB := both 271LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 272LOCAL_ADDRESS_SANITIZER := false 273include $(BUILD_HOST_STATIC_LIBRARY) 274 275include $(CLEAR_VARS) 276LOCAL_MODULE := libasan_noinst_test 277LOCAL_MODULE_TAGS := tests 278LOCAL_C_INCLUDES := \ 279 external/gtest/include \ 280 external/compiler-rt/include \ 281 external/compiler-rt/lib \ 282 external/compiler-rt/lib/asan/tests \ 283 external/compiler-rt/lib/sanitizer_common/tests 284LOCAL_CFLAGS += \ 285 -Wno-unused-parameter \ 286 -Wno-sign-compare \ 287 -DASAN_UAR=0 \ 288 -DASAN_HAS_BLACKLIST=1 \ 289 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 290 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 291 -std=c++11 292LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc 293LOCAL_CPP_EXTENSION := .cc 294LOCAL_CLANG := true 295LOCAL_CXX_STL := libc++ 296LOCAL_MULTILIB := both 297LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 298LOCAL_ADDRESS_SANITIZER := false 299include $(BUILD_HOST_STATIC_LIBRARY) 300 301include $(CLEAR_VARS) 302LOCAL_MODULE := asan_test 303LOCAL_MODULE_TAGS := tests 304LOCAL_C_INCLUDES := \ 305 external/compiler-rt/lib \ 306 external/compiler-rt/lib/asan/tests \ 307 external/compiler-rt/lib/sanitizer_common/tests 308LOCAL_CFLAGS += $(asan_test_cflags) 309LOCAL_SRC_FILES := $(asan_test_files) 310LOCAL_CPP_EXTENSION := .cc 311LOCAL_STATIC_LIBRARIES := libasan_noinst_test 312LOCAL_ADDRESS_SANITIZER := true 313LOCAL_CLANG := true 314LOCAL_CXX_STL := libc++ 315LOCAL_MULTILIB := both 316LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 317LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 318LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 319include $(BUILD_HOST_NATIVE_TEST) 320endif 321