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