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