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 // GWP-ASan headers are currently referenced by the following additional APEXes 99 "com.android.art", 100 "com.android.art.debug", 101 "com.android.media", 102 "com.android.media.swcodec", 103 "com.android.virt", 104 ], 105} 106 107// Only static linkage is provided for performance reasons. 108cc_library_static { 109 name: "gwp_asan", 110 defaults: ["gwp_asan_no_libs_defaults"], 111 header_libs: [ 112 "gwp_asan_headers", 113 ], 114 srcs: [ 115 "gwp_asan/common.cpp", 116 "gwp_asan/guarded_pool_allocator.cpp", 117 "gwp_asan/platform_specific/common_posix.cpp", 118 "gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp", 119 "gwp_asan/platform_specific/mutex_posix.cpp", 120 "gwp_asan/platform_specific/utilities_posix.cpp", 121 "gwp_asan/stack_trace_compressor.cpp", 122 ], 123 // GWP-ASan requires platform (non-emulated) TLS. We use thread local 124 // variables in the core, inlined interface to GWP-ASan. 125 cflags: [ 126 "-fno-emulated-tls", 127 ], 128 apex_available: [ 129 // Required to not occlude the default platform variation from being 130 // skipped by the apex mutator. If this happens - the license file for 131 // the static GWP-ASan library won't be generated, and you'll get errors 132 // at build time. 133 "//apex_available:platform", 134 135 "com.android.runtime", // GWP-ASan is used in libc. 136 "com.android.media.swcodec", // libc_scudo (from media) uses GWP-ASan. 137 ], 138} 139 140// GWP-ASan crash handler API. Provides all the tools you need to symbolize a 141// GWP-ASan crash. 142cc_library { 143 name: "gwp_asan_crash_handler", 144 defaults: ["gwp_asan_defaults"], 145 header_libs: [ 146 "gwp_asan_headers", 147 ], 148 srcs: [ 149 "gwp_asan/common.cpp", 150 "gwp_asan/crash_handler.cpp", 151 "gwp_asan/platform_specific/common_posix.cpp", 152 "gwp_asan/platform_specific/utilities_posix.cpp", 153 "gwp_asan/stack_trace_compressor.cpp", 154 ], 155 apex_available: [ 156 "//apex_available:platform", 157 "com.android.runtime", 158 ], 159} 160 161cc_fuzz { 162 name: "stack_trace_compressor_fuzzer", 163 host_supported: true, 164 srcs: ["tools/stack_trace_compressor_fuzzer.cpp"], 165 static_libs: ["gwp_asan"], 166} 167 168cc_fuzz { 169 name: "options_parser_fuzzer", 170 host_supported: true, 171 srcs: [ 172 "tools/options_parser_fuzzer.cpp", 173 "gwp_asan/optional/options_parser.cpp", 174 ], 175 static_libs: ["gwp_asan"], 176} 177 178// These unit tests are also continuously run upstream in LLVM's buildbots. 179cc_test { 180 name: "gwp_asan_unittest", 181 defaults: ["linux_bionic_supported"], 182 static_libs: [ 183 "gwp_asan", 184 "gwp_asan_crash_handler", 185 "libasync_safe", 186 "liblog", 187 "libunwindstack_no_dex", 188 "liblzma", // Dependency from libunwindstack. 189 ], 190 shared_libs: [ 191 "libbase", 192 ], 193 194 ldflags: [ 195 // Ensure that ICF doesn't clobber DeallocateMemory2 into 196 // DeallocateMemory in tests/backtrace.cpp. This is done in the linker, 197 // so `optnone` in the function declaration doesn't help. 198 "-Wl,--icf=none", 199 ], 200 srcs: [ 201 "android/test_backtrace.cpp", 202 "android/test_printf.cpp", 203 "gwp_asan/optional/options_parser.cpp", 204 "gwp_asan/optional/segv_handler_posix.cpp", 205 "gwp_asan/tests/alignment.cpp", 206 "gwp_asan/tests/backtrace.cpp", 207 "gwp_asan/tests/basic.cpp", 208 "gwp_asan/tests/compression.cpp", 209 "gwp_asan/tests/crash_handler_api.cpp", 210 "gwp_asan/tests/enable_disable.cpp", 211 "gwp_asan/tests/harness.cpp", 212 "gwp_asan/tests/iterate.cpp", 213 "gwp_asan/tests/late_init.cpp", 214 "gwp_asan/tests/mutex_test.cpp", 215 "gwp_asan/tests/options.cpp", 216 "gwp_asan/tests/slot_reuse.cpp", 217 "gwp_asan/tests/thread_contention.cpp", 218 ], 219 include_dirs: ["bionic/libc/async_safe/include"], 220 test_suites: ["general-tests"], 221 cflags: [ 222 // GWP-ASan requires anything that uses GuardedPoolAllocator headers to 223 // use platform (ELF) TLS. 224 "-fno-emulated-tls", 225 226 // Ensure that the helper functions in test/backtrace.cpp don't get 227 // tail-call optimised, as this breaks the unwind chain. 228 "-fno-optimize-sibling-calls", 229 ], 230} 231