1// 2// Copyright (C) 2019 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 17package { 18 default_applicable_licenses: ["external_gwp_asan_license"], 19} 20 21// Added automatically by a large-scale-change that took the approach of 22// 'apply every license found to every target'. While this makes sure we respect 23// every license restriction, it may not be entirely correct. 24// 25// e.g. GPL in an MIT project might only apply to the contrib/ directory. 26// 27// Please consider splitting the single license below into multiple licenses, 28// taking care not to lose any license_kind information, and overriding the 29// default license using the 'licenses: [...]' property on targets as needed. 30// 31// For unused files, consider creating a 'fileGroup' with "//visibility:private" 32// to attach the license to, and including a comment whether the files may be 33// used in the current project. 34// See: http://go/android-license-faq 35license { 36 name: "external_gwp_asan_license", 37 visibility: [":__subpackages__"], 38 license_kinds: [ 39 "SPDX-license-identifier-Apache-2.0", 40 "SPDX-license-identifier-BSD", 41 "SPDX-license-identifier-MIT", 42 "SPDX-license-identifier-NCSA", 43 ], 44 license_text: [ 45 "LICENSE.TXT", 46 ], 47} 48 49cc_defaults { 50 name: "gwp_asan_defaults", 51 host_supported: true, 52 vendor_available: true, 53 product_available: true, 54 recovery_available: true, 55 native_bridge_supported: true, 56 ramdisk_available: true, 57 vendor_ramdisk_available: true, 58 59 // GWP-ASan currently has no support for darwin. 60 target: { 61 darwin: { 62 enabled: false, 63 }, 64 }, 65 min_sdk_version: "S", 66} 67 68cc_defaults { 69 name: "gwp_asan_no_libs_defaults", 70 defaults: ["gwp_asan_defaults"], 71 72 // GWP-ASan is used by bionic libc, and should have no libc/libc++ 73 // dependencies. 74 target: { 75 bionic: { 76 system_shared_libs: [], 77 header_libs: ["libc_headers"], 78 }, 79 }, 80 stl: "none", 81} 82 83cc_library_headers { 84 name: "gwp_asan_headers", 85 defaults: [ 86 "gwp_asan_defaults", 87 "gwp_asan_no_libs_defaults", 88 ], 89 export_include_dirs: [ 90 ".", 91 ], 92 apex_available: [ 93 // This header lib is compiled also as part of the platform due to libasync_safe 94 // and others that are compiled with this header and are statically included 95 // in the platform side. 96 "//apex_available:platform", 97 "com.android.runtime", 98 ], 99} 100 101// Only static linkage is provided for performance reasons. 102cc_library_static { 103 name: "gwp_asan", 104 defaults: ["gwp_asan_no_libs_defaults"], 105 header_libs: [ 106 "gwp_asan_headers", 107 ], 108 srcs: [ 109 "gwp_asan/common.cpp", 110 "gwp_asan/guarded_pool_allocator.cpp", 111 "gwp_asan/platform_specific/common_posix.cpp", 112 "gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp", 113 "gwp_asan/platform_specific/mutex_posix.cpp", 114 "gwp_asan/platform_specific/utilities_posix.cpp", 115 "gwp_asan/stack_trace_compressor.cpp", 116 ], 117 apex_available: [ 118 // Required to not occlude the default platform variation from being 119 // skipped by the apex mutator. If this happens - the license file for 120 // the static GWP-ASan library won't be generated, and you'll get errors 121 // at build time. 122 "//apex_available:platform", 123 124 "com.android.runtime", // GWP-ASan is used in libc. 125 "com.android.media.swcodec", // libc_scudo (from media) uses GWP-ASan. 126 ], 127} 128 129// GWP-ASan crash handler API. Provides all the tools you need to symbolize a 130// GWP-ASan crash. 131cc_library_static { 132 name: "gwp_asan_crash_handler", 133 defaults: ["gwp_asan_no_libs_defaults"], 134 header_libs: [ 135 "gwp_asan_headers", 136 ], 137 srcs: [ 138 "gwp_asan/common.cpp", 139 "gwp_asan/crash_handler.cpp", 140 "gwp_asan/platform_specific/common_posix.cpp", 141 "gwp_asan/platform_specific/utilities_posix.cpp", 142 "gwp_asan/stack_trace_compressor.cpp", 143 ], 144 apex_available: [ 145 "//apex_available:platform", 146 "com.android.runtime", 147 ], 148} 149 150cc_fuzz { 151 name: "stack_trace_compressor_fuzzer", 152 host_supported: true, 153 srcs: ["tools/stack_trace_compressor_fuzzer.cpp"], 154 static_libs: ["gwp_asan"], 155} 156 157cc_fuzz { 158 name: "options_parser_fuzzer", 159 host_supported: true, 160 srcs: [ 161 "tools/options_parser_fuzzer.cpp", 162 "gwp_asan/optional/options_parser.cpp", 163 ], 164 static_libs: ["gwp_asan"], 165} 166 167// These unit tests are also continuously run upstream in LLVM's buildbots. 168cc_test { 169 name: "gwp_asan_unittest", 170 defaults: ["linux_bionic_supported"], 171 static_libs: [ 172 "gwp_asan", 173 "gwp_asan_crash_handler", 174 "libasync_safe", 175 "liblog", 176 "libunwindstack_no_dex", 177 "liblzma", // Dependency from libunwindstack. 178 "libz", // Dependency from libunwindstack. 179 ], 180 shared_libs: [ 181 "libbase", 182 ], 183 184 ldflags: [ 185 // Ensure that ICF doesn't clobber DeallocateMemory2 into 186 // DeallocateMemory in tests/backtrace.cpp. This is done in the linker, 187 // so `optnone` in the function declaration doesn't help. 188 "-Wl,--icf=none", 189 ], 190 srcs: [ 191 "android/test_backtrace.cpp", 192 "android/test_printf.cpp", 193 "gwp_asan/optional/options_parser.cpp", 194 "gwp_asan/optional/segv_handler_posix.cpp", 195 "gwp_asan/tests/alignment.cpp", 196 "gwp_asan/tests/backtrace.cpp", 197 "gwp_asan/tests/basic.cpp", 198 "gwp_asan/tests/compression.cpp", 199 "gwp_asan/tests/crash_handler_api.cpp", 200 "gwp_asan/tests/enable_disable.cpp", 201 "gwp_asan/tests/harness.cpp", 202 "gwp_asan/tests/iterate.cpp", 203 "gwp_asan/tests/late_init.cpp", 204 "gwp_asan/tests/mutex_test.cpp", 205 "gwp_asan/tests/never_allocated.cpp", 206 "gwp_asan/tests/recoverable.cpp", 207 "gwp_asan/tests/options.cpp", 208 "gwp_asan/tests/slot_reuse.cpp", 209 "gwp_asan/tests/thread_contention.cpp", 210 ], 211 include_dirs: ["bionic/libc/async_safe/include"], 212 test_suites: ["general-tests"], 213 cflags: [ 214 // GWP-ASan requires anything that uses GuardedPoolAllocator headers to 215 // use platform (ELF) TLS. 216 "-fno-emulated-tls", 217 218 // Ensure that the helper functions in test/backtrace.cpp don't get 219 // tail-call optimised, as this breaks the unwind chain. 220 "-fno-optimize-sibling-calls", 221 ], 222} 223