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