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_win.cc \ 83 ../sanitizer_common/sanitizer_thread_registry.cc \ 84 ../sanitizer_common/sanitizer_tls_get_addr.cc \ 85 ../sanitizer_common/sanitizer_unwind_linux_libcdep.cc \ 86 ../sanitizer_common/sanitizer_win.cc \ 87 88asan_rtl_cxx_files := \ 89 asan_new_delete.cc \ 90 91asan_rtl_cflags := \ 92 -fvisibility=hidden \ 93 -fno-exceptions \ 94 -DASAN_LOW_MEMORY=1 \ 95 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 96 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 97 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=$(ASAN_FLEXIBLE_MAPPING_AND_OFFSET) \ 98 -Wno-covered-switch-default \ 99 -Wno-non-virtual-dtor \ 100 -Wno-sign-compare \ 101 -Wno-unused-parameter \ 102 -std=c++11 \ 103 -fno-rtti \ 104 -fno-builtin 105 106asan_test_files := \ 107 tests/asan_globals_test.cc \ 108 tests/asan_test.cc 109 110#tests/asan_noinst_test.cc \ 111#tests/asan_test_main.cc \ 112 113asan_test_cflags := \ 114 -fsanitize-blacklist=external/compiler-rt/lib/asan/tests/asan_test.ignore \ 115 -DASAN_LOW_MEMORY=1 \ 116 -DASAN_UAR=0 \ 117 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 118 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 119 -DASAN_HAS_BLACKLIST=1 \ 120 -Wno-covered-switch-default \ 121 -Wno-non-virtual-dtor \ 122 -Wno-sign-compare \ 123 -Wno-unused-parameter \ 124 -std=c++11 125 126 127include $(CLEAR_VARS) 128 129LOCAL_MODULE := libasan 130LOCAL_C_INCLUDES := \ 131 external/compiler-rt/lib \ 132 external/compiler-rt/include 133LOCAL_CFLAGS += $(asan_rtl_cflags) 134LOCAL_SRC_FILES := asan_preinit.cc 135LOCAL_CPP_EXTENSION := .cc 136LOCAL_CLANG := true 137LOCAL_SANITIZE := never 138LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 139LOCAL_NDK_STL_VARIANT := none 140LOCAL_SDK_VERSION := 19 141include $(BUILD_STATIC_LIBRARY) 142 143define build-asan-rt-shared-library 144 145include $(CLEAR_VARS) 146LOCAL_MODULE := $(1) 147LOCAL_MULTILIB := $(2) 148# This library must go on /system partition, even in SANITIZE_TARGET mode (when all libraries are 149# installed on /data). That's because /data may not be available until vold does some magic and 150# vold itself depends on this library. 151LOCAL_MODULE_PATH_32 := $(TARGET_OUT)/lib 152LOCAL_MODULE_PATH_64 := $(TARGET_OUT)/lib64 153# We need to unwind by frame pointers through a small portion of ASan runtime library code, 154# and that only works with ARM, not with Thumb. 155LOCAL_ARM_MODE := arm 156LOCAL_C_INCLUDES := \ 157 external/compiler-rt/lib \ 158 external/compiler-rt/include 159LOCAL_CFLAGS += $(asan_rtl_cflags) 160LOCAL_SRC_FILES := $(asan_rtl_files) $(asan_rtl_cxx_files) 161LOCAL_CPP_EXTENSION := .cc 162LOCAL_LDLIBS := -llog -ldl 163LOCAL_STATIC_LIBRARIES := libubsan 164# MacOS toolchain is out-of-date and does not support -z global. 165# TODO: re-enable once the toolchain issue is fixed. 166ifneq ($(HOST_OS),darwin) 167 LOCAL_LDFLAGS += -Wl,-z,global 168endif 169LOCAL_CLANG := true 170LOCAL_SANITIZE := never 171LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 172LOCAL_NDK_STL_VARIANT := none 173LOCAL_SDK_VERSION := 19 174include $(BUILD_SHARED_LIBRARY) 175 176endef 177 178ifeq (true,$(FORCE_BUILD_SANITIZER_SHARED_OBJECTS)) 179ifdef 2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY 180 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),64)) 181 $(eval $(call build-asan-rt-shared-library,$(2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY),32)) 182else 183 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),32)) 184endif 185endif 186 187include $(CLEAR_VARS) 188 189LOCAL_MODULE := asanwrapper 190LOCAL_SRC_FILES := asanwrapper.cc 191LOCAL_CPP_EXTENSION := .cc 192LOCAL_CPPFLAGS := -std=c++11 193LOCAL_SANITIZE := never 194LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 195LOCAL_CXX_STL := libc++ 196 197include $(BUILD_EXECUTABLE) 198 199ifneq (true,$(SKIP_LLVM_TESTS)) 200 201include $(CLEAR_VARS) 202 203LOCAL_MODULE := libasan_noinst_test 204LOCAL_MODULE_TAGS := tests 205LOCAL_C_INCLUDES := \ 206 external/gtest/include \ 207 external/compiler-rt/include \ 208 external/compiler-rt/lib \ 209 external/compiler-rt/lib/asan/tests \ 210 external/compiler-rt/lib/sanitizer_common/tests 211LOCAL_CFLAGS += \ 212 -Wno-non-virtual-dtor \ 213 -Wno-unused-parameter \ 214 -Wno-sign-compare \ 215 -DASAN_UAR=0 \ 216 -DASAN_HAS_BLACKLIST=1 \ 217 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 218 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 219 -std=c++11 220LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc 221LOCAL_CPP_EXTENSION := .cc 222LOCAL_CLANG := true 223LOCAL_SANITIZE := never 224LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 225LOCAL_CXX_STL := libc++ 226 227include $(BUILD_STATIC_LIBRARY) 228 229 230include $(CLEAR_VARS) 231 232LOCAL_MODULE := asan_test 233LOCAL_MODULE_TAGS := tests 234LOCAL_C_INCLUDES := \ 235 external/gtest/include \ 236 external/compiler-rt/lib \ 237 external/compiler-rt/lib/asan/tests \ 238 external/compiler-rt/lib/sanitizer_common/tests 239LOCAL_CFLAGS += $(asan_test_cflags) 240LOCAL_SRC_FILES := $(asan_test_files) 241LOCAL_CPP_EXTENSION := .cc 242LOCAL_STATIC_LIBRARIES := libgtest libasan_noinst_test 243LOCAL_SHARED_LIBRARIES := libc 244LOCAL_SANITIZE := address 245LOCAL_CLANG := true 246LOCAL_MODULE_TARGET_ARCH := arm arm64 x86 247LOCAL_CXX_STL := libc++ 248 249include $(BUILD_EXECUTABLE) 250 251endif # SKIP_LLVM_TESTS 252 253################################################################################ 254# Host modules 255 256ifneq ($(HOST_OS),darwin) 257include $(CLEAR_VARS) 258LOCAL_MODULE := libasan 259LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include 260LOCAL_CFLAGS += $(asan_rtl_cflags) 261LOCAL_SRC_FILES := $(asan_rtl_files) 262LOCAL_CPP_EXTENSION := .cc 263LOCAL_CLANG := true 264LOCAL_MULTILIB := both 265LOCAL_SANITIZE := never 266LOCAL_WHOLE_STATIC_LIBRARIES := libubsan 267include $(BUILD_HOST_STATIC_LIBRARY) 268 269include $(CLEAR_VARS) 270LOCAL_MODULE := libasan_cxx 271LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include 272LOCAL_CFLAGS += $(asan_rtl_cflags) 273LOCAL_SRC_FILES := $(asan_rtl_cxx_files) 274LOCAL_CPP_EXTENSION := .cc 275LOCAL_CLANG := true 276LOCAL_MULTILIB := both 277LOCAL_SANITIZE := never 278include $(BUILD_HOST_STATIC_LIBRARY) 279 280ifneq (true,$(SKIP_LLVM_TESTS)) 281 282include $(CLEAR_VARS) 283LOCAL_MODULE := libasan_noinst_test 284LOCAL_MODULE_TAGS := tests 285LOCAL_C_INCLUDES := \ 286 external/gtest/include \ 287 external/compiler-rt/include \ 288 external/compiler-rt/lib \ 289 external/compiler-rt/lib/asan/tests \ 290 external/compiler-rt/lib/sanitizer_common/tests 291LOCAL_CFLAGS += \ 292 -Wno-unused-parameter \ 293 -Wno-sign-compare \ 294 -DASAN_UAR=0 \ 295 -DASAN_HAS_BLACKLIST=1 \ 296 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 297 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 298 -std=c++11 299LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc 300LOCAL_CPP_EXTENSION := .cc 301LOCAL_CLANG := true 302LOCAL_CXX_STL := libc++ 303LOCAL_MULTILIB := both 304LOCAL_SANITIZE := never 305include $(BUILD_HOST_STATIC_LIBRARY) 306 307include $(CLEAR_VARS) 308LOCAL_MODULE := asan_test 309LOCAL_MODULE_TAGS := tests 310LOCAL_C_INCLUDES := \ 311 external/compiler-rt/lib \ 312 external/compiler-rt/lib/asan/tests \ 313 external/compiler-rt/lib/sanitizer_common/tests 314LOCAL_CFLAGS += $(asan_test_cflags) 315LOCAL_SRC_FILES := $(asan_test_files) 316LOCAL_CPP_EXTENSION := .cc 317LOCAL_STATIC_LIBRARIES := libasan_noinst_test 318LOCAL_SANITIZE := address 319LOCAL_CLANG := true 320LOCAL_CXX_STL := libc++ 321LOCAL_MULTILIB := both 322LOCAL_LDLIBS := -lrt 323LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 324LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 325include $(BUILD_HOST_NATIVE_TEST) 326endif # SKIP_LLVM_TESTS 327endif 328