Reland of Merge android's use_gold settings with the main use_gold GN arg logic

This also fixes Android setting -Wl,--icf=all in a different spot.

Reason for reland:
Removed --icf=safe for x86

BUG=606749,576197,611668

Review-Url: https://codereview.chromium.org/1996433002
Cr-Original-Commit-Position: refs/heads/master@{#394655}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 10371eae8d24d0ea7efa880571d51d62ce8f197c
This commit is contained in:
agrieve 2016-05-18 20:34:51 -07:00 коммит произвёл Commit bot
Родитель b2d1568643
Коммит 86ffb80c8b
4 изменённых файлов: 65 добавлений и 73 удалений

Просмотреть файл

@ -4,12 +4,9 @@
import("//build/config/android/config.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/sysroot.gni")
assert(is_android)
use_gold = current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm"
# This is included by reference in the //build/config/compiler config that
# is applied to all targets. It is here to separate out the logic that is
# Android-only.
@ -25,12 +22,7 @@ config("compiler") {
# does. Define them here instead.
"HAVE_SYS_UIO_H",
]
ldflags = []
if (!is_clang) {
# Clang doesn't support these flags.
cflags += [ "-finline-limit=64" ]
}
if (is_clang) {
rebased_android_toolchain_root =
rebase_path(android_toolchain_root, root_build_dir)
@ -42,29 +34,12 @@ config("compiler") {
"-B${rebased_android_toolchain_root}/bin", # Else /usr/bin/as gets picked up.
]
}
} else {
# Clang doesn't support these flags.
cflags += [ "-finline-limit=64" ]
}
# Use gold for Android for most CPU architectures.
if (use_gold) {
ldflags += [ "-fuse-ld=gold" ]
if (is_clang) {
# Let clang find the ld.gold in the NDK.
ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
}
# Use -mstackrealign due to a bug on ia32 Jelly Bean.
# See crbug.com/521527
if (current_cpu == "x86") {
cflags += [ "-mstackrealign" ]
}
}
if (current_cpu == "mipsel" && is_clang) {
# Let clang find the ld.bfd in the NDK.
ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
}
ldflags += [
ldflags = [
"-Wl,--build-id=sha1",
"-Wl,--no-undefined",
@ -78,12 +53,6 @@ config("compiler") {
# http://crbug.com/448386
"-Wl,--exclude-libs=libvpx_assembly_arm.a",
]
if (current_cpu == "arm" && !use_order_profiling) {
ldflags += [
# Enable identical code folding to reduce size.
"-Wl,--icf=all",
]
}
if (is_clang) {
if (current_cpu == "arm") {
@ -181,12 +150,6 @@ config("executable_config") {
cflags = [ "-fPIE" ]
asmflags = [ "-fPIE" ]
ldflags = [ "-pie" ]
if (!use_gold) {
# ld needs help finding libraries when linking.
_rebased_sysroot = rebase_path(sysroot, root_build_dir)
ldflags += [ "-Wl,-rpath-link=.:$_rebased_sysroot/usr/lib" ]
}
}
config("hide_native_jni_exports") {

Просмотреть файл

@ -46,11 +46,6 @@ declare_args() {
# Requires profiling to be set to true.
enable_full_stack_frames_for_profiling = false
# Whether to use the gold linker from binutils instead of lld or bfd.
use_gold =
!use_lld && is_linux &&
(current_cpu == "x64" || current_cpu == "x86" || current_cpu == "arm")
# When we are going to use gold we need to find it.
# This is initialized below, after use_gold might have been overridden.
gold_path = false
@ -303,24 +298,35 @@ config("compiler") {
if (is_posix && use_lld && !is_nacl) {
ldflags += [ "-fuse-ld=lld" ]
} else if (use_gold) {
ldflags += [
"-B$gold_path",
ldflags += [ "-fuse-ld=gold" ]
if (is_android) {
if (is_clang) {
_rebased_android_toolchain_root =
rebase_path(android_toolchain_root, root_build_dir)
# Newer gccs and clangs support -fuse-ld, use the flag to force gold
# selection.
# gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
"-fuse-ld=gold",
# Let clang find the ld.gold in the NDK.
ldflags += [ "--gcc-toolchain=$_rebased_android_toolchain_root" ]
}
# Experimentation found that using four linking threads
# saved ~20% of link time.
# https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
# Only apply this to the target linker, since the host
# linker might not be gold, but isn't used much anyway.
# TODO(raymes): Disable threading because gold is frequently
# crashing on the bots: crbug.com/161942.
#"-Wl,--threads",
#"-Wl,--thread-count=4",
]
# Use -mstackrealign due to a bug on ia32 Jelly Bean.
# See crbug.com/521527
if (current_cpu == "x86") {
cflags += [ "-mstackrealign" ]
}
} else {
ldflags += [
"-B$gold_path",
# Experimentation found that using four linking threads
# saved ~20% of link time.
# https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
# Only apply this to the target linker, since the host
# linker might not be gold, but isn't used much anyway.
# TODO(raymes): Disable threading because gold is frequently
# crashing on the bots: crbug.com/161942.
#"-Wl,--threads",
#"-Wl,--thread-count=4",
]
}
if (gdb_index) {
ldflags += [ "-Wl,--gdb-index" ]
@ -336,15 +342,21 @@ config("compiler") {
# Gold is the default linker for the bundled binutils so we explicitly
# enable the bfd linker when use_gold is not set.
ldflags += [ "-fuse-ld=bfd" ]
} else if (is_android && current_cpu == "mipsel" && is_clang) {
# Let clang find the ld.bfd in the NDK.
_rebased_android_toolchain_root =
rebase_path(android_toolchain_root, root_build_dir)
ldflags += [ "--gcc-toolchain=$rebased_android_toolchain_root" ]
}
if (is_posix && (use_gold || (use_lld && !is_nacl)) && !using_sanitizer &&
!(is_android && use_order_profiling)) {
# TODO(crbug.com/576197) - gcc on x86 platforms + gold + icf=all
# doesn't currently work. Once it does, use icf=all everywhere.
# Additionally, on Android x86 --icf=safe seems to cause issues as well.
if (is_clang || (target_cpu != "x86" && target_cpu != "x64")) {
ldflags += [ "-Wl,--icf=all" ]
} else {
} else if (!is_android) {
ldflags += [ "-Wl,--icf=safe" ]
}
}

Просмотреть файл

@ -6,6 +6,7 @@ import("//build/config/android/config.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/toolchain.gni")
declare_args() {
# How many symbols to include in the build. This affects the performance of
@ -33,6 +34,15 @@ declare_args() {
full_wpo_on_official = false
}
declare_args() {
# Whether to use the gold linker from binutils instead of lld or bfd.
use_gold = !use_lld &&
((is_linux && (current_cpu == "x64" || current_cpu == "x86" ||
current_cpu == "arm")) ||
(is_android && (current_cpu == "x86" || current_cpu == "x64" ||
current_cpu == "arm")))
}
# If it wasn't manually set, set to an appropriate default.
assert(symbol_level >= -1 && symbol_level <= 2, "Invalid symbol_level")
if (symbol_level == -1) {

Просмотреть файл

@ -2,7 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/sysroot.gni")
import("//build/toolchain/toolchain.gni")
# This config causes functions not to be automatically exported from shared
@ -69,8 +71,9 @@ config("rpath_for_built_shared_libraries") {
# Settings for executables.
config("executable_ldconfig") {
ldflags = []
if (is_android) {
ldflags = [
ldflags += [
"-Bdynamic",
"-Wl,-z,nocopyreloc",
]
@ -80,19 +83,26 @@ config("executable_ldconfig") {
if (is_component_build || using_sanitizer) {
configs = [ ":rpath_for_built_shared_libraries" ]
}
if (current_cpu == "mipsel") {
ldflags += [ "-pie" ]
}
}
if (!is_android || !use_gold) {
# Find the path containing shared libraries for this toolchain
# relative to the build directory. ${root_out_dir} will be a
# subdirectory of ${root_build_dir} when cross compiling.
rebased_out_dir = rebase_path(root_out_dir, root_build_dir)
_rpath_link = rebase_path(root_out_dir, root_build_dir)
if (shlib_subdir != ".") {
rpath_link = "${rebased_out_dir}/${shlib_subdir}"
} else {
rpath_link = rebased_out_dir
_rpath_link += "/$shlib_subdir"
}
if (is_android) {
_rebased_sysroot = rebase_path(sysroot, root_build_dir)
_rpath_link += ":$_rebased_sysroot/usr/lib"
}
ldflags = [
"-Wl,-rpath-link=${rpath_link}",
ldflags += [
"-Wl,-rpath-link=$_rpath_link",
# TODO(GYP): Do we need a check on the binutils version here?
#
@ -100,9 +110,6 @@ config("executable_ldconfig") {
# and the new DT_RUNPATH doesn't work without --no-as-needed flag.
"-Wl,--disable-new-dtags",
]
if (current_cpu == "mipsel") {
ldflags += [ "-pie" ]
}
}
}