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_scudo_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// http://go/android-license-faq 35license { 36 name: "external_scudo_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_library_headers { 50 name: "scudo_headers", 51 ramdisk_available: true, 52 recovery_available: true, 53 vendor_ramdisk_available: true, 54 55 export_include_dirs: [ 56 "standalone/include", 57 ], 58 59 apex_available: [ 60 "com.android.runtime", 61 "//apex_available:platform", 62 ], 63 64 visibility: [ 65 "//system/core/debuggerd", 66 ], 67} 68 69cc_defaults { 70 name: "scudo_config_defaults", 71 cflags: [ 72 // Use a custom Android configuration. 73 "-DSCUDO_USE_CUSTOM_CONFIG", 74 ], 75 76 include_dirs: [ 77 "external/scudo/config", 78 ], 79 80 product_variables: { 81 malloc_low_memory: { 82 cflags: ["-DSCUDO_LOW_MEMORY"], 83 }, 84 }, 85} 86 87cc_defaults { 88 name: "scudo_warning_defaults", 89 cflags: [ 90 "-Wall", 91 "-Wextra", 92 "-Wunused", 93 "-Wno-unused-result", 94 "-Wconversion", 95 96 "-Werror=pointer-to-int-cast", 97 "-Werror=int-to-pointer-cast", 98 "-Werror=thread-safety", 99 "-Werror=type-limits", 100 "-Werror", 101 ], 102} 103 104cc_defaults { 105 name: "libscudo_defaults", 106 defaults: [ 107 "scudo_config_defaults", 108 "scudo_warning_defaults", 109 ], 110 native_coverage: false, 111 ramdisk_available: true, 112 vendor_ramdisk_available: true, 113 recovery_available: true, 114 host_supported: true, 115 native_bridge_supported: true, 116 117 rtti: false, 118 stl: "none", 119 120 cflags: [ 121 "-O3", 122 "-fno-rtti", 123 // This option speeds up alloc/free code paths by about 5% to 7%. 124 "-fno-stack-protector", 125 ], 126 cppflags: [ 127 "-nostdinc++", 128 "-fno-exceptions", 129 ], 130 131 include_dirs: [ 132 "external/scudo/standalone/include", 133 ], 134 135 srcs: [ 136 "standalone/checksum.cpp", 137 "standalone/common.cpp", 138 "standalone/condition_variable_linux.cpp", 139 "standalone/flags.cpp", 140 "standalone/flags_parser.cpp", 141 "standalone/linux.cpp", 142 "standalone/mem_map.cpp", 143 "standalone/mem_map_linux.cpp", 144 "standalone/release.cpp", 145 "standalone/report.cpp", 146 "standalone/report_linux.cpp", 147 "standalone/string_utils.cpp", 148 "standalone/timing.cpp", 149 ], 150 arch: { 151 arm: { 152 cflags: ["-mcrc"], 153 srcs: ["standalone/crc32_hw.cpp"], 154 }, 155 arm64: { 156 cflags: ["-mcrc"], 157 srcs: ["standalone/crc32_hw.cpp"], 158 }, 159 riscv64: { 160 // This is a temporary fix, and should be reverted after 161 // yieldProcessor supports riscv. 162 cflags: ["-Wno-unused-parameter"], 163 }, 164 x86_64: { 165 cflags: ["-msse4.2"], 166 srcs: ["standalone/crc32_hw.cpp"], 167 }, 168 x86: { 169 cflags: ["-msse4.2"], 170 srcs: ["standalone/crc32_hw.cpp"], 171 }, 172 }, 173 174 target: { 175 bionic: { 176 system_shared_libs: [], 177 header_libs: [ 178 "libc_headers", 179 "bionic_libc_platform_headers", 180 ], 181 srcs: ["standalone/wrappers_c_bionic.cpp"], 182 cflags: [ 183 "-D_BIONIC=1", 184 185 // Indicate that bionic has reserved a TLS for Scudo. 186 "-DSCUDO_HAS_PLATFORM_TLS_SLOT", 187 188 // Always force alignment to 16 bytes even on 32 bit. 189 // Android assumes that allocations of multiples of 16 bytes 190 // will be aligned to at least 16 bytes. 191 "-DSCUDO_MIN_ALIGNMENT_LOG=4", 192 193 // Allow scudo to use android_unsafe_frame_pointer_chase(), 194 // which is normally a private function. 195 "-DHAVE_ANDROID_UNSAFE_FRAME_POINTER_CHASE", 196 ], 197 }, 198 native_bridge: { 199 cflags: ["-DSCUDO_DISABLE_TBI"], 200 }, 201 host: { 202 srcs: ["standalone/wrappers_c.cpp"], 203 }, 204 }, 205} 206 207cc_library { 208 name: "libscudo", 209 defaults: ["libscudo_defaults"], 210 visibility: [ 211 "//bionic:__subpackages__", 212 "//build/kati:__subpackages__", 213 "//frameworks/libs/native_bridge_support/android_api/libc:__subpackages__", 214 "//external/ninja:__subpackages__", 215 "//external/stg:__subpackages__", 216 "//system/core/debuggerd:__subpackages__", 217 ], 218 shared: { 219 enabled: false, 220 }, 221 target: { 222 host: { 223 shared: { 224 enabled: true, 225 }, 226 }, 227 }, 228 apex_available: [ 229 "com.android.runtime", 230 ], 231} 232 233cc_library_static { 234 name: "libscudo_for_testing", 235 defaults: ["libscudo_defaults"], 236 cflags: [ 237 "-DSCUDO_DEBUG=1", 238 ], 239} 240 241cc_defaults { 242 name: "scudo_unit_tests_default", 243 defaults: [ 244 "scudo_config_defaults", 245 "scudo_warning_defaults", 246 ], 247 isolated: true, 248 static_libs: ["libscudo_for_testing"], 249 include_dirs: [ 250 "external/scudo/standalone", 251 "external/scudo/standalone/include", 252 ], 253 cflags: [ 254 // In memtag_test.cpp, some tests are disabled by GTEST_SKIP() so that 255 // they won't be run. However, for those disabled tests, it may contain 256 // unreachable code paths which will mislead some compiler checks. Given 257 // this flag won't be impacted too much, disable it only in the test. 258 "-Wno-unreachable-code-loop-increment", 259 "-DSCUDO_DEBUG=1", 260 "-DSCUDO_NO_TEST_MAIN", 261 ], 262 target: { 263 bionic: { 264 header_libs: ["bionic_libc_platform_headers"], 265 }, 266 }, 267 test_suites: ["general-tests"], 268 bootstrap: true, 269 srcs: [ 270 "standalone/tests/scudo_unit_test_main.cpp", 271 ], 272} 273 274cc_test { 275 name: "scudo_unit_tests", 276 defaults: ["scudo_unit_tests_default"], 277 host_supported: true, 278 srcs: [ 279 "standalone/tests/allocator_config_test.cpp", 280 "standalone/tests/atomic_test.cpp", 281 "standalone/tests/bytemap_test.cpp", 282 "standalone/tests/checksum_test.cpp", 283 "standalone/tests/chunk_test.cpp", 284 "standalone/tests/combined_test.cpp", 285 "standalone/tests/condition_variable_test.cpp", 286 "standalone/tests/flags_test.cpp", 287 "standalone/tests/list_test.cpp", 288 "standalone/tests/map_test.cpp", 289 "standalone/tests/memtag_test.cpp", 290 "standalone/tests/mutex_test.cpp", 291 "standalone/tests/primary_test.cpp", 292 "standalone/tests/quarantine_test.cpp", 293 "standalone/tests/release_test.cpp", 294 "standalone/tests/report_test.cpp", 295 "standalone/tests/secondary_test.cpp", 296 "standalone/tests/size_class_map_test.cpp", 297 "standalone/tests/stats_test.cpp", 298 "standalone/tests/strings_test.cpp", 299 "standalone/tests/timing_test.cpp", 300 "standalone/tests/tsd_test.cpp", 301 "standalone/tests/vector_test.cpp", 302 ], 303} 304 305cc_test { 306 name: "scudo_wrappers_unit_tests", 307 defaults: ["scudo_unit_tests_default"], 308 // These are wrapper tests, disable the host tests since they would run 309 // against glibc. 310 host_supported: false, 311 cflags: [ 312 "-Wno-mismatched-new-delete", 313 ], 314 srcs: [ 315 "standalone/tests/wrappers_c_test.cpp", 316 "standalone/tests/wrappers_cpp_test.cpp", 317 ], 318} 319 320cc_fuzz { 321 name: "scudo_get_error_info_fuzzer", 322 host_supported: true, 323 compile_multilib: "64", 324 static_libs: ["libscudo"], 325 include_dirs: [ 326 "external/scudo/standalone", 327 "external/scudo/standalone/include", 328 ], 329 cflags: [ 330 "-Wno-unneeded-internal-declaration", 331 ], 332 srcs: ["standalone/fuzz/get_error_info_fuzzer.cpp"], 333 fuzz_config: { 334 componentid: 87896, 335 }, 336} 337 338cc_test { 339 name: "size_map_verify_unit_tests", 340 host_supported: true, 341 static_libs: ["libscudo"], 342 343 include_dirs: [ 344 "external/scudo/android/tools", 345 "external/scudo/standalone", 346 "external/scudo/standalone/include", 347 "external/scudo/standalone/tools", 348 ], 349 srcs: [ 350 "android/tests/size_map_verify_unit_tests.cpp", 351 ], 352} 353 354cc_binary { 355 name: "size_map_gen", 356 defaults: ["scudo_config_defaults"], 357 host_supported: true, 358 static_libs: ["libscudo"], 359 include_dirs: [ 360 "external/scudo/android/tools", 361 "external/scudo/standalone", 362 "external/scudo/standalone/include", 363 ], 364 srcs: ["android/tools/size_map_gen.cpp"], 365} 366 367// The targets below verify that all configuration is set up properly for 368// the library or tests. 369cc_defaults { 370 name: "scudo_verify_defaults", 371 host_supported: true, 372 srcs: ["config/config_build_check.cpp"], 373 374 include_dirs: [ 375 "external/scudo/standalone", 376 ], 377 378 product_variables: { 379 malloc_low_memory: { 380 cflags: ["-DSCUDO_LOW_MEMORY_CHECK"], 381 }, 382 }, 383} 384 385cc_test { 386 name: "scudo_verify_config", 387 defaults: [ 388 "scudo_verify_defaults", 389 "scudo_unit_tests_default", 390 ], 391} 392 393dirgroup { 394 name: "trusty_dirgroup_external_scudo", 395 dirs: ["."], 396 visibility: ["//trusty/vendor/google/aosp/scripts"], 397} 398