1# Copyright 2014 The Chromium Authors. All rights reserved. 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/config.gni") 6import("//build/config/sanitizers/sanitizers.gni") 7import("//build/config/sysroot.gni") 8 9assert(is_android) 10 11use_gold = current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm" 12 13# This is included by reference in the //build/config/compiler config that 14# is applied to all targets. It is here to separate out the logic that is 15# Android-only. 16config("compiler") { 17 cflags = [ 18 "-ffunction-sections", 19 "-fno-short-enums", 20 ] 21 defines = [ 22 "ANDROID", 23 24 # The NDK has these things, but doesn't define the constants to say that it 25 # does. Define them here instead. 26 "HAVE_SYS_UIO_H", 27 ] 28 ldflags = [] 29 30 if (!is_clang) { 31 # Clang doesn't support these flags. 32 cflags += [ "-finline-limit=64" ] 33 } 34 if (is_clang) { 35 rebased_android_toolchain_root = 36 rebase_path(android_toolchain_root, root_build_dir) 37 assert(rebased_android_toolchain_root != "") # Mark as used. 38 if (current_cpu == "mipsel") { 39 cflags += [ 40 # TODO(gordanac) Enable integrated-as. 41 "-no-integrated-as", 42 "-B${rebased_android_toolchain_root}/bin", # Else /usr/bin/as gets picked up. 43 ] 44 } 45 } 46 47 # Use gold for Android for most CPU architectures. 48 if (use_gold) { 49 ldflags += [ "-fuse-ld=gold" ] 50 if (is_clang) { 51 # Let clang find the ld.gold in the NDK. 52 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ] 53 } 54 55 # Use -mstackrealign due to a bug on ia32 Jelly Bean. 56 # See crbug.com/521527 57 if (current_cpu == "x86") { 58 cflags += [ "-mstackrealign" ] 59 } 60 } 61 62 if (current_cpu == "mipsel" && is_clang) { 63 # Let clang find the ld.bfd in the NDK. 64 ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ] 65 } 66 67 ldflags += [ 68 "-Wl,--build-id=sha1", 69 "-Wl,--no-undefined", 70 71 # Don't allow visible symbols from libgcc or libc++ to be 72 # re-exported. 73 "-Wl,--exclude-libs=libgcc.a", 74 "-Wl,--exclude-libs=libc++_static.a", 75 76 # Don't allow visible symbols from libraries that contain 77 # assembly code with symbols that aren't hidden properly. 78 # http://crbug.com/448386 79 "-Wl,--exclude-libs=libvpx_assembly_arm.a", 80 ] 81 if (current_cpu == "arm" && !use_order_profiling) { 82 ldflags += [ 83 # Enable identical code folding to reduce size. 84 "-Wl,--icf=all", 85 ] 86 } 87 88 if (is_clang) { 89 if (current_cpu == "arm") { 90 abi_target = "arm-linux-androideabi" 91 } else if (current_cpu == "x86") { 92 abi_target = "i686-linux-androideabi" 93 } else if (current_cpu == "arm64") { 94 # Place holder for arm64 support, not tested. 95 # TODO: Enable clang support for Android Arm64. http://crbug.com/539781 96 abi_target = "aarch64-linux-android" 97 } else if (current_cpu == "x64") { 98 # Place holder for x64 support, not tested. 99 # TODO: Enable clang support for Android x64. http://crbug.com/539781 100 abi_target = "x86_64-linux-androideabi" 101 } else if (current_cpu == "mipsel") { 102 abi_target = "mipsel-linux-android" 103 } else if (current_cpu == "mips64el") { 104 # Place holder for mips64 support, not tested. 105 abi_target = "mips64el-linux-androideabi" 106 } else { 107 assert(false, "Architecture not supported") 108 } 109 cflags += [ "--target=$abi_target" ] 110 ldflags += [ "--target=$abi_target" ] 111 } 112 113 # Assign any flags set for the C compiler to asmflags so that they are sent 114 # to the assembler. 115 asmflags = cflags 116} 117 118# This is included by reference in the //build/config/compiler:runtime_library 119# config that is applied to all targets. It is here to separate out the logic 120# that is Android-only. Please see that target for advice on what should go in 121# :runtime_library vs. :compiler. 122config("runtime_library") { 123 # NOTE: The libc++ header include paths below are specified in cflags_cc 124 # rather than include_dirs because they need to come after include_dirs. 125 # Think of them like system headers, but don't use '-isystem' because the 126 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit 127 # strange errors. The include ordering here is important; change with 128 # caution. 129 cflags_cc = [ 130 "-isystem" + 131 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir), 132 "-isystem" + rebase_path( 133 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/include", 134 root_build_dir), 135 "-isystem" + 136 rebase_path("$android_ndk_root/sources/android/support/include", 137 root_build_dir), 138 ] 139 140 defines = [ "__GNU_SOURCE=1" ] # Necessary for clone(). 141 ldflags = [ "-nostdlib" ] 142 lib_dirs = [ android_libcpp_lib_dir ] 143 144 # The libc++ runtime library (must come first). 145 # ASan needs to dynamically link to libc++ even in static builds so 146 # that it can interpose operator new. 147 if (is_component_build || is_asan) { 148 libs = [ "c++_shared" ] 149 } else { 150 libs = [ "c++_static" ] 151 } 152 153 # Manually link the libgcc.a that the cross compiler uses. This is 154 # absolute because the linker will look inside the sysroot if it's not. 155 libs += [ 156 rebase_path(android_libgcc_file), 157 "c", 158 ] 159 160 # Clang with libc++ does not require an explicit atomic library reference. 161 if (!is_clang) { 162 libs += [ "atomic" ] 163 } 164 165 if (is_clang) { 166 # Work around incompatibilities between bionic and clang headers. 167 defines += [ 168 "__compiler_offsetof=__builtin_offsetof", 169 "nan=__builtin_nan", 170 ] 171 } 172 173 # TODO(jdduke) Re-enable on mips after resolving linking 174 # issues with libc++ (crbug.com/456380). 175 if (current_cpu != "mipsel" && current_cpu != "mips64el") { 176 ldflags += [ "-Wl,--warn-shared-textrel" ] 177 } 178} 179 180config("executable_config") { 181 cflags = [ "-fPIE" ] 182 asmflags = [ "-fPIE" ] 183 ldflags = [ "-pie" ] 184 185 if (!use_gold) { 186 # ld needs help finding libraries when linking. 187 _rebased_sysroot = rebase_path(sysroot, root_build_dir) 188 ldflags += [ "-Wl,-rpath-link=.:$_rebased_sysroot/usr/lib" ] 189 } 190} 191 192config("hide_native_jni_exports") { 193 ldflags = [ "-Wl,--version-script=" + 194 rebase_path("//build/android/android_no_jni_exports.lst") ] 195} 196 197# Instrumentation ------------------------------------------------------------- 198# 199# The BUILDCONFIG file sets the "default_cygprofile_instrumentation" config on 200# targets by default. You can override whether the cygprofile instrumentation is 201# used on a per-target basis: 202# 203# configs -= [ "//build/config/android:default_cygprofile_instrumentation" ] 204# configs += [ "//build/config/android:no_cygprofile_instrumentation" ] 205 206config("default_cygprofile_instrumentation") { 207 if (use_order_profiling) { 208 configs = [ ":cygprofile_instrumentation" ] 209 } else { 210 configs = [ ":no_cygprofile_instrumentation" ] 211 } 212} 213 214config("cygprofile_instrumentation") { 215 defines = [ "CYGPROFILE_INSTRUMENTATION=1" ] 216 cflags = [ "-finstrument-functions" ] 217 218 if (!is_clang) { 219 cflags += [ 220 # Allow mmx intrinsics to inline, so that the compiler can expand the intrinsics. 221 "-finstrument-functions-exclude-file-list=mmintrin.h", 222 223 # Avoid errors with current NDK: 224 # "third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/include/arm_neon.h:3426:3: error: argument must be a constant" 225 "-finstrument-functions-exclude-file-list=arm_neon.h", 226 ] 227 } 228} 229 230config("no_cygprofile_instrumentation") { 231} 232