blob: dc9218bb641498c68a4bc4b19a3bead420cf0735 [file] [log] [blame]
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +04001#
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
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +040020ASAN_NEEDS_SEGV=0
21ASAN_HAS_EXCEPTIONS=1
22ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
23
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +040024asan_rtl_files := \
Stephen Hines6d186232014-11-26 17:56:19 -080025 asan_activation.cc \
Stephen Hines86277eb2015-03-23 12:06:32 -070026 asan_allocator.cc \
Stephen Hines6d186232014-11-26 17:56:19 -080027 asan_fake_stack.cc \
Stephen Hines86277eb2015-03-23 12:06:32 -070028 asan_flags.cc \
Stephen Hines6d186232014-11-26 17:56:19 -080029 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 \
Stephen Hines6d186232014-11-26 17:56:19 -080036 asan_poisoning.cc \
37 asan_posix.cc \
38 asan_report.cc \
39 asan_rtl.cc \
40 asan_stack.cc \
41 asan_stats.cc \
Stephen Hines86277eb2015-03-23 12:06:32 -070042 asan_suppressions.cc \
Stephen Hines6d186232014-11-26 17:56:19 -080043 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 \
Stephen Hines86277eb2015-03-23 12:06:32 -070056 ../sanitizer_common/sanitizer_flag_parser.cc \
Stephen Hines6d186232014-11-26 17:56:19 -080057 ../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 \
Pirama Arumuga Nainar7c915052015-04-08 08:58:29 -070082 ../sanitizer_common/sanitizer_symbolizer_process_libcdep.cc \
Stephen Hines6d186232014-11-26 17:56:19 -080083 ../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 \
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +040088
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +030089asan_rtl_cxx_files := \
90 asan_new_delete.cc \
91
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +040092asan_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 \
Stephen Hines3a02de32013-05-03 18:10:06 -0700100 -Wno-non-virtual-dtor \
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400101 -Wno-sign-compare \
102 -Wno-unused-parameter \
Dan Albert28b72ed2015-04-28 11:42:19 -0700103 -std=c++11 \
104 -fno-rtti \
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400105
106asan_test_files := \
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400107 tests/asan_globals_test.cc \
Stephen Hines7c98f2d2013-01-10 01:49:27 -0800108 tests/asan_test.cc
109
110#tests/asan_noinst_test.cc \
111#tests/asan_test_main.cc \
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400112
113asan_test_cflags := \
Stephen Hines6a211c52014-07-21 00:49:56 -0700114 -fsanitize-blacklist=external/compiler-rt/lib/asan/tests/asan_test.ignore \
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400115 -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 \
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400120 -Wno-covered-switch-default \
Stephen Hines3a02de32013-05-03 18:10:06 -0700121 -Wno-non-virtual-dtor \
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400122 -Wno-sign-compare \
123 -Wno-unused-parameter \
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700124 -std=c++11
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400125
126
Dan Albert93f64d92014-10-18 17:25:26 -0700127ifeq ($(TARGET_ARCH),arm)
128
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400129include $(CLEAR_VARS)
130
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400131LOCAL_MODULE := libasan
Dan Albertca8da892015-01-08 15:56:27 -0800132LOCAL_C_INCLUDES := \
133 external/compiler-rt/lib \
134 external/compiler-rt/include
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400135LOCAL_CFLAGS += $(asan_rtl_cflags)
Stephen Hinesff571e22013-03-05 23:44:58 -0800136LOCAL_SRC_FILES := asan_preinit.cc
137#LOCAL_SRC_FILES := asan_android_stub.cc asan_preinit.cc
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400138LOCAL_CPP_EXTENSION := .cc
139LOCAL_CLANG := true
Stephen Hines97ac43c2013-01-18 17:46:14 -0800140LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Albertd92fd092014-10-16 23:10:08 -0700141LOCAL_ADDRESS_SANITIZER := false
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400142include $(BUILD_STATIC_LIBRARY)
143
Evgenii Stepanov3f89dee2015-04-27 08:54:26 -0700144define build-asan-rt-shared-library
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400145
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400146include $(CLEAR_VARS)
Evgenii Stepanov3f89dee2015-04-27 08:54:26 -0700147LOCAL_MODULE := $(1)
148LOCAL_MULTILIB := $(2)
Evgenii Stepanov81f7b122015-05-05 10:27:14 -0700149# We need to unwind by frame pointers through a small portion of ASan runtime library code,
150# and that only works with ARM, not with Thumb.
151LOCAL_ARM_MODE := arm
Shih-wei Liaoed003382012-04-25 06:48:42 -0700152LOCAL_C_INCLUDES := \
Stephen Hines1f922a52012-09-10 20:14:46 -0700153 external/compiler-rt/lib \
154 external/compiler-rt/include
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400155LOCAL_CFLAGS += $(asan_rtl_cflags)
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300156LOCAL_SRC_FILES := $(asan_rtl_files) $(asan_rtl_cxx_files)
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400157LOCAL_CPP_EXTENSION := .cc
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700158LOCAL_SHARED_LIBRARIES := liblog libc libdl
Dan Alberta4424482014-10-17 10:32:45 -0700159LOCAL_STATIC_LIBRARIES := libcompiler_rt
Evgenii Stepanovbc45c9e2015-04-27 17:12:13 -0700160# MacOS toolchain is out-of-date and does not support -z global.
161# TODO: re-enable once the toolchain issue is fixed.
162ifneq ($(HOST_OS),darwin)
163 LOCAL_LDFLAGS += -Wl,-z,global
164endif
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400165LOCAL_CLANG := true
Dan Albertd92fd092014-10-16 23:10:08 -0700166LOCAL_ADDRESS_SANITIZER := false
Stephen Hines97ac43c2013-01-18 17:46:14 -0800167LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400168include $(BUILD_SHARED_LIBRARY)
169
Evgenii Stepanov3f89dee2015-04-27 08:54:26 -0700170endef
171
172ifdef 2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY
173 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),64))
174 $(eval $(call build-asan-rt-shared-library,$(2ND_ADDRESS_SANITIZER_RUNTIME_LIBRARY),32))
175else
176 $(eval $(call build-asan-rt-shared-library,$(ADDRESS_SANITIZER_RUNTIME_LIBRARY),32))
177endif
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400178
179include $(CLEAR_VARS)
180
181LOCAL_MODULE := asanwrapper
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400182LOCAL_SRC_FILES := asanwrapper.cc
183LOCAL_CPP_EXTENSION := .cc
Dan Albertf56c2bd2014-07-29 10:46:24 -0700184LOCAL_CPPFLAGS := -std=c++11
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700185LOCAL_SHARED_LIBRARIES += libc
Dan Albertd92fd092014-10-16 23:10:08 -0700186LOCAL_ADDRESS_SANITIZER := false
Stephen Hines97ac43c2013-01-18 17:46:14 -0800187LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Albert93f64d92014-10-18 17:25:26 -0700188LOCAL_CXX_STL := libc++
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400189
190include $(BUILD_EXECUTABLE)
191
192
193include $(CLEAR_VARS)
194
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400195LOCAL_MODULE := libasan_noinst_test
196LOCAL_MODULE_TAGS := tests
197LOCAL_C_INCLUDES := \
Dan Albert93f64d92014-10-18 17:25:26 -0700198 external/gtest/include \
199 external/compiler-rt/include \
200 external/compiler-rt/lib \
201 external/compiler-rt/lib/asan/tests \
202 external/compiler-rt/lib/sanitizer_common/tests
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400203LOCAL_CFLAGS += \
Stephen Hines86277eb2015-03-23 12:06:32 -0700204 -Wno-non-virtual-dtor \
Dan Albert93f64d92014-10-18 17:25:26 -0700205 -Wno-unused-parameter \
206 -Wno-sign-compare \
207 -DASAN_UAR=0 \
208 -DASAN_HAS_BLACKLIST=1 \
209 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \
Stephen Hines6d186232014-11-26 17:56:19 -0800210 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \
211 -std=c++11
Stephen Hines7c98f2d2013-01-10 01:49:27 -0800212LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400213LOCAL_CPP_EXTENSION := .cc
214LOCAL_CLANG := true
Dan Albertd92fd092014-10-16 23:10:08 -0700215LOCAL_ADDRESS_SANITIZER := false
Stephen Hines97ac43c2013-01-18 17:46:14 -0800216LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Albert93f64d92014-10-18 17:25:26 -0700217LOCAL_CXX_STL := libc++
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700218
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400219include $(BUILD_STATIC_LIBRARY)
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400220
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400221
222include $(CLEAR_VARS)
223
224LOCAL_MODULE := asan_test
225LOCAL_MODULE_TAGS := tests
226LOCAL_C_INCLUDES := \
Dan Albert93f64d92014-10-18 17:25:26 -0700227 external/gtest/include \
228 external/compiler-rt/lib \
229 external/compiler-rt/lib/asan/tests \
230 external/compiler-rt/lib/sanitizer_common/tests
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400231LOCAL_CFLAGS += $(asan_test_cflags)
232LOCAL_SRC_FILES := $(asan_test_files)
233LOCAL_CPP_EXTENSION := .cc
Dan Albert303c8fb2014-11-15 15:10:23 -0800234LOCAL_STATIC_LIBRARIES := libgtest libasan_noinst_test
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700235LOCAL_SHARED_LIBRARIES := libc
Evgeniy Stepanove48a1972012-03-29 18:09:56 +0400236LOCAL_ADDRESS_SANITIZER := true
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700237LOCAL_CLANG := true
Stephen Hines97ac43c2013-01-18 17:46:14 -0800238LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Albert93f64d92014-10-18 17:25:26 -0700239LOCAL_CXX_STL := libc++
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400240
241include $(BUILD_EXECUTABLE)
242
Evgeniy Stepanovdc3865b2012-03-13 15:38:23 +0400243endif # ifeq($(TARGET_ARCH),arm)
Dan Albert93f64d92014-10-18 17:25:26 -0700244
245################################################################################
246# Host modules
247
Dan Albert329755b2014-10-20 17:43:44 -0700248ifneq ($(HOST_OS),darwin)
Dan Albert93f64d92014-10-18 17:25:26 -0700249include $(CLEAR_VARS)
250LOCAL_MODULE := libasan
Dan Albert93f64d92014-10-18 17:25:26 -0700251LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include
252LOCAL_CFLAGS += $(asan_rtl_cflags)
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300253LOCAL_SRC_FILES := $(asan_rtl_files)
Dan Albert93f64d92014-10-18 17:25:26 -0700254LOCAL_CPP_EXTENSION := .cc
255LOCAL_CLANG := true
Dan Albertf50197a2014-10-20 15:15:58 -0700256LOCAL_MULTILIB := both
Dan Albert93f64d92014-10-18 17:25:26 -0700257LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Alberta7f893a2014-10-31 16:18:55 -0700258LOCAL_ADDRESS_SANITIZER := false
Dan Albert93f64d92014-10-18 17:25:26 -0700259include $(BUILD_HOST_STATIC_LIBRARY)
260
261include $(CLEAR_VARS)
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300262LOCAL_MODULE := libasan_cxx
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300263LOCAL_C_INCLUDES := external/compiler-rt/lib external/compiler-rt/include
264LOCAL_CFLAGS += $(asan_rtl_cflags)
265LOCAL_SRC_FILES := $(asan_rtl_cxx_files)
Dan Albert93f64d92014-10-18 17:25:26 -0700266LOCAL_CPP_EXTENSION := .cc
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300267LOCAL_CLANG := true
Dan Albertf50197a2014-10-20 15:15:58 -0700268LOCAL_MULTILIB := both
Dan Albert93f64d92014-10-18 17:25:26 -0700269LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Alberta7f893a2014-10-31 16:18:55 -0700270LOCAL_ADDRESS_SANITIZER := false
Evgeniy Stepanovd66dda02014-11-06 18:29:53 +0300271include $(BUILD_HOST_STATIC_LIBRARY)
Dan Albert93f64d92014-10-18 17:25:26 -0700272
273include $(CLEAR_VARS)
274LOCAL_MODULE := libasan_noinst_test
275LOCAL_MODULE_TAGS := tests
276LOCAL_C_INCLUDES := \
277 external/gtest/include \
278 external/compiler-rt/include \
279 external/compiler-rt/lib \
280 external/compiler-rt/lib/asan/tests \
281 external/compiler-rt/lib/sanitizer_common/tests
282LOCAL_CFLAGS += \
283 -Wno-unused-parameter \
284 -Wno-sign-compare \
285 -DASAN_UAR=0 \
286 -DASAN_HAS_BLACKLIST=1 \
287 -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \
Stephen Hines6d186232014-11-26 17:56:19 -0800288 -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \
289 -std=c++11
Dan Albert93f64d92014-10-18 17:25:26 -0700290LOCAL_SRC_FILES := tests/asan_noinst_test.cc tests/asan_test_main.cc
291LOCAL_CPP_EXTENSION := .cc
292LOCAL_CLANG := true
293LOCAL_CXX_STL := libc++
Dan Albertf50197a2014-10-20 15:15:58 -0700294LOCAL_MULTILIB := both
Dan Albert93f64d92014-10-18 17:25:26 -0700295LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Alberta7f893a2014-10-31 16:18:55 -0700296LOCAL_ADDRESS_SANITIZER := false
Dan Albert93f64d92014-10-18 17:25:26 -0700297include $(BUILD_HOST_STATIC_LIBRARY)
298
299include $(CLEAR_VARS)
300LOCAL_MODULE := asan_test
301LOCAL_MODULE_TAGS := tests
302LOCAL_C_INCLUDES := \
Dan Albert93f64d92014-10-18 17:25:26 -0700303 external/compiler-rt/lib \
304 external/compiler-rt/lib/asan/tests \
305 external/compiler-rt/lib/sanitizer_common/tests
306LOCAL_CFLAGS += $(asan_test_cflags)
307LOCAL_SRC_FILES := $(asan_test_files)
308LOCAL_CPP_EXTENSION := .cc
Dan Albert7e862da2014-11-09 00:50:03 -0800309LOCAL_STATIC_LIBRARIES := libasan_noinst_test
Dan Albert93f64d92014-10-18 17:25:26 -0700310LOCAL_ADDRESS_SANITIZER := true
311LOCAL_CLANG := true
312LOCAL_CXX_STL := libc++
Dan Albertf50197a2014-10-20 15:15:58 -0700313LOCAL_MULTILIB := both
Ying Wangeee80f92014-11-06 15:41:07 -0800314LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
315LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
Dan Albert93f64d92014-10-18 17:25:26 -0700316LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Dan Albert7e862da2014-11-09 00:50:03 -0800317include $(BUILD_HOST_NATIVE_TEST)
Dan Albert329755b2014-10-20 17:43:44 -0700318endif