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