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 20ifeq ($(TARGET_ARCH),arm) 21 22ASAN_NEEDS_SEGV=0 23ASAN_HAS_EXCEPTIONS=1 24ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 25 26asan_rtl_files := \ 27 asan_rtl.cc \ 28 asan_allocator.cc \ 29 asan_globals.cc \ 30 asan_interceptors.cc \ 31 asan_linux.cc \ 32 asan_malloc_linux.cc \ 33 asan_malloc_mac.cc \ 34 asan_new_delete.cc \ 35 asan_poisoning.cc \ 36 asan_posix.cc \ 37 asan_printf.cc \ 38 asan_stack.cc \ 39 asan_stats.cc \ 40 asan_thread.cc \ 41 asan_thread_registry.cc \ 42 interception/interception_linux.cc 43 44asan_rtl_cflags := \ 45 -fvisibility=hidden \ 46 -fno-exceptions \ 47 -DASAN_LOW_MEMORY=1 \ 48 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 49 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 50 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=$(ASAN_FLEXIBLE_MAPPING_AND_OFFSET) \ 51 -Wno-covered-switch-default \ 52 -Wno-sign-compare \ 53 -Wno-unused-parameter \ 54 -D__WORDSIZE=32 55 56asan_test_files := \ 57 tests/asan_test.cc \ 58 tests/asan_globals_test.cc \ 59 tests/asan_break_optimization.cc \ 60 tests/asan_interface_test.cc 61 62asan_test_cflags := \ 63 -mllvm -asan-blacklist=external/compiler-rt/lib/asan/tests/asan_test.ignore \ 64 -DASAN_LOW_MEMORY=1 \ 65 -DASAN_UAR=0 \ 66 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ 67 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ 68 -DASAN_HAS_BLACKLIST=1 \ 69 -Wno-covered-switch-default \ 70 -Wno-sign-compare \ 71 -Wno-unused-parameter \ 72 -D__WORDSIZE=32 73 74 75include $(CLEAR_VARS) 76 77LOCAL_MODULE := libasan 78LOCAL_MODULE_TAGS := optional 79LOCAL_C_INCLUDES := bionic 80LOCAL_CFLAGS += $(asan_rtl_cflags) 81LOCAL_SRC_FILES := asan_android_stub.cc 82LOCAL_CPP_EXTENSION := .cc 83LOCAL_CLANG := true 84include $(BUILD_STATIC_LIBRARY) 85 86 87include $(CLEAR_VARS) 88 89LOCAL_MODULE := libasan_preload 90LOCAL_MODULE_TAGS := eng 91LOCAL_C_INCLUDES := \ 92 bionic \ 93 external/stlport/stlport 94LOCAL_CFLAGS += $(asan_rtl_cflags) 95LOCAL_SRC_FILES := $(asan_rtl_files) 96LOCAL_CPP_EXTENSION := .cc 97LOCAL_SHARED_LIBRARIES := libc libstlport libdl 98LOCAL_CLANG := true 99include $(BUILD_SHARED_LIBRARY) 100 101 102include $(CLEAR_VARS) 103 104LOCAL_MODULE := asanwrapper 105LOCAL_MODULE_TAGS := eng 106LOCAL_C_INCLUDES := \ 107 bionic \ 108 external/stlport/stlport 109LOCAL_SRC_FILES := asanwrapper.cc 110LOCAL_CPP_EXTENSION := .cc 111LOCAL_SHARED_LIBRARIES := libstlport libc 112 113include $(BUILD_EXECUTABLE) 114 115 116include $(CLEAR_VARS) 117 118LOCAL_MODULE := libasan_noinst_test 119LOCAL_MODULE_TAGS := tests 120LOCAL_C_INCLUDES := \ 121 bionic \ 122 external/stlport/stlport \ 123 external/gtest/include 124LOCAL_CFLAGS += \ 125 -Wno-unused-parameter \ 126 -Wno-sign-compare \ 127 -D__WORDSIZE=32 128LOCAL_SRC_FILES := tests/asan_noinst_test.cc 129LOCAL_CPP_EXTENSION := .cc 130LOCAL_CLANG := true 131include $(BUILD_STATIC_LIBRARY) 132 133 134include $(CLEAR_VARS) 135 136LOCAL_MODULE := asan_test 137LOCAL_MODULE_TAGS := tests 138LOCAL_C_INCLUDES := \ 139 bionic \ 140 external/stlport/stlport \ 141 external/gtest/include 142LOCAL_CFLAGS += $(asan_test_cflags) 143LOCAL_SRC_FILES := $(asan_test_files) 144LOCAL_CPP_EXTENSION := .cc 145LOCAL_STATIC_LIBRARIES := libgtest libasan_noinst_test 146LOCAL_SHARED_LIBRARIES := libc libstlport 147LOCAL_ADDRESS_SANITIZER := true 148 149include $(BUILD_EXECUTABLE) 150 151# Build output tests for AddressSanitizer. 152 153define asan-output-test 154 include $(CLEAR_VARS) 155 LOCAL_MODULE := $(1) 156 LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)/asan 157 LOCAL_MODULE_TAGS := tests 158 LOCAL_SRC_FILES := output_tests/$(1).cc 159 LOCAL_CPP_EXTENSION := .cc 160 LOCAL_ADDRESS_SANITIZER := true 161 LOCAL_C_INCLUDES := bionic external/stlport/stlport 162 LOCAL_CFLAGS := -Wno-unused-parameter 163 LOCAL_SHARED_LIBRARIES := libstlport 164 include $(BUILD_EXECUTABLE) 165endef 166 167define asan-output-test-so 168 include $(CLEAR_VARS) 169 LOCAL_MODULE := $(1) 170 LOCAL_MODULE_TAGS := tests 171 LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)/asan 172 LOCAL_SRC_FILES := output_tests/$(1).cc 173 LOCAL_CPP_EXTENSION := .cc 174 LOCAL_ADDRESS_SANITIZER := true 175 LOCAL_C_INCLUDES := bionic external/stlport/stlport 176 LOCAL_CFLAGS := -Wno-unused-parameter 177 LOCAL_SHARED_LIBRARIES := libstlport 178 include $(BUILD_SHARED_LIBRARY) 179endef 180 181OUTPUT_TESTS := \ 182 clone_test \ 183 deep_tail_call \ 184 dlclose-test \ 185 dlclose-test-so \ 186 global-overflow \ 187 heap-overflow \ 188 large_func_test \ 189 null_deref \ 190 shared-lib-test \ 191 shared-lib-test-so \ 192 stack-overflow \ 193 strncpy-overflow \ 194 use-after-free 195 196$(foreach test,$(filter %-so,$(OUTPUT_TESTS)),$(eval $(call asan-output-test-so,$(test)))) 197$(foreach test,$(filter-out %-so,$(OUTPUT_TESTS)),$(eval $(call asan-output-test,$(test)))) 198 199endif # ifeq($(TARGET_ARCH),arm) 200