1# Copyright 2014 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/android/rules.gni") 6import("//build/config/c++/c++.gni") 7import("//build/config/compiler/compiler.gni") 8import("//build/config/sanitizers/sanitizers.gni") 9 10if (current_toolchain == default_toolchain) { 11 import("//build/toolchain/concurrent_links.gni") 12} 13 14assert(is_android) 15 16# This is included by reference in the //build/config/compiler config that 17# is applied to all targets. It is here to separate out the logic that is 18# Android-only. 19config("compiler") { 20 cflags = [ 21 "-ffunction-sections", 22 "-fno-short-enums", 23 ] 24 defines = [ 25 "ANDROID", 26 27 # https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#weak-symbols-for-api-definitions 28 "__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", 29 30 # The NDK has these things, but doesn't define the constants to say that it 31 # does. Define them here instead. 32 "HAVE_SYS_UIO_H", 33 34 # Forces full rebuilds on NDK rolls. To rebuild everything when NDK version 35 # stays the same, increment the suffix number. 36 "ANDROID_NDK_VERSION_ROLL=${android_ndk_version}_1", 37 ] 38 39 if (android_64bit_current_cpu) { 40 _max_page_size = 16384 41 } else { 42 _max_page_size = 4096 43 } 44 45 ldflags = [ 46 # Don't allow visible symbols from libraries that contain 47 # assembly code with symbols that aren't hidden properly. 48 # http://crbug.com/448386 49 "-Wl,--exclude-libs=libvpx_assembly_arm.a", 50 51 # Reduce the page size from 65536 in order to reduce binary size slightly 52 # by shrinking the alignment gap between segments. This also causes all 53 # segments to be mapped adjacently, which breakpad relies on. 54 "-Wl,-z,max-page-size=$_max_page_size", 55 ] 56 57 if (current_cpu == "arm64") { 58 if (arm_control_flow_integrity == "standard") { 59 cflags += [ "-mbranch-protection=standard" ] 60 rustflags = [ "-Zbranch-protection=bti" ] 61 } else if (arm_control_flow_integrity == "pac") { 62 cflags += [ "-mbranch-protection=pac-ret" ] 63 rustflags = [ "-Zbranch-protection=pac-ret" ] 64 } 65 } 66 67 # $compile_api_level corresponds to the API level used for the sysroot path 68 # calculation in //build/config/android/config.gni 69 if (android_64bit_target_cpu) { 70 compile_api_level = android64_ndk_api_level 71 } else { 72 compile_api_level = android32_ndk_api_level 73 } 74 75 cflags += [ "--target=$android_abi_target$compile_api_level" ] 76 ldflags += [ "--target=$android_abi_target$compile_api_level" ] 77 78 # Assign any flags set for the C compiler to asmflags so that they are sent 79 # to the assembler. 80 asmflags = cflags 81} 82 83# This is included by reference in the //build/config/compiler:runtime_library 84# config that is applied to all targets. It is here to separate out the logic 85# that is Android-only. Please see that target for advice on what should go in 86# :runtime_library vs. :compiler. 87config("runtime_library") { 88} 89 90config("hide_all_but_jni_onload") { 91 ldflags = [ "-Wl,--version-script=" + rebase_path( 92 "//build/android/android_only_explicit_jni_exports.lst", 93 root_build_dir) ] 94} 95 96config("hide_all_but_jni") { 97 ldflags = [ "-Wl,--version-script=" + 98 rebase_path("//build/android/android_only_jni_exports.lst", 99 root_build_dir) ] 100} 101 102config("lld_pack_relocations") { 103 ldflags = [ "-Wl,--pack-dyn-relocs=android" ] 104} 105 106config("lld_relr_relocations") { 107 # RELR supported API 30+, but supported 28+ with --use-android-relr-tags. 108 # https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#relative-relocations-relr 109 ldflags = [ "-Wl,--pack-dyn-relocs=relr,--use-android-relr-tags" ] 110} 111 112config("lld_branch_target_hardening") { 113 # Config opts a shared library into BTI linker hardening. This 114 # is an opt-in config (rather than default-enabled) to avoid 115 # interfering with the V8 CFI bots (crbug.com/1334614). 116 if (current_cpu == "arm64") { 117 if (arm_control_flow_integrity == "standard") { 118 # Linking objects without GNU_PROPERTY_AARCH64_FEATURE_1_BTI 119 # in their .gnu.note section implicitly results in the final 120 # binary losing Branch Target Identification (BTI) support. 121 # Issue a warning if this happens. 122 ldflags = [ "-Wl,-z,force-bti" ] 123 } 124 } 125} 126 127# Used for instrumented build to generate the orderfile. 128config("default_orderfile_instrumentation") { 129 if (use_order_profiling) { 130 cflags = [ "-finstrument-function-entry-bare" ] 131 if (use_thin_lto) { 132 # TODO(pcc): This should not be necessary. Remove once 133 # https://reviews.llvm.org/D50016 lands and gets rolled in. 134 ldflags = [ "-Wl,-u,__cyg_profile_func_enter_bare" ] 135 } 136 } 137} 138 139if (current_toolchain == default_toolchain) { 140 # nocompile tests share output directory to avoid them all needing to rebuild 141 # things. But this also means they can't run in parallel. 142 pool("nocompile_pool") { 143 depth = 1 144 } 145 146 # When defined, this pool should be used instead of link_pool for command 147 # that need 1-2GB of RAM. https://crbug.com/1078460 148 if (defined(java_cmd_pool_size)) { 149 pool("java_cmd_pool") { 150 depth = java_cmd_pool_size 151 } 152 } 153} 154