Commit e06dc056 authored by bmeurer's avatar bmeurer Committed by Commit bot

[linux] Improve link time with Chromium-bundled binutils.

Also enabled concurrent linking with gold on Linux.

Mostly copy and paste from Chromium with customization for
V8 where necessary.

BUG=v8:3880
LOG=n

Review URL: https://codereview.chromium.org/896703003

Cr-Commit-Position: refs/heads/master@{#26536}
parent 0b692450
......@@ -80,6 +80,17 @@ hooks = [
"-s", "v8/buildtools/linux64/clang-format.sha1",
],
},
# Pull binutils for linux, enabled debug fission for faster linking /
# debugging when used with clang on Ubuntu Precise.
# https://code.google.com/p/chromium/issues/detail?id=352046
{
'name': 'binutils',
'pattern': 'v8/third_party/binutils',
'action': [
'python',
'v8/third_party/binutils/download.py',
],
},
{
# Pull clang if needed or requested via GYP_DEFINES.
# Note: On Win, this should run after win_toolchain, as it may use it.
......
......@@ -86,6 +86,46 @@
# Allow to suppress the array bounds warning (default is no suppression).
'wno_array_bounds%': '',
# Override where to find binutils
'binutils_dir%': '',
'conditions': [
['OS=="linux" and host_arch=="x64"', {
'binutils_dir%': 'third_party/binutils/Linux_x64/Release/bin',
}],
['OS=="linux" and host_arch=="ia32"', {
'binutils_dir%': 'third_party/binutils/Linux_ia32/Release/bin',
}],
# linux_use_bundled_gold: whether to use the gold linker binary checked
# into third_party/binutils. Force this off via GYP_DEFINES when you
# are using a custom toolchain and need to control -B in ldflags.
# Do not use 32-bit gold on 32-bit hosts as it runs out address space
# for component=static_library builds.
['OS=="linux" and (target_arch=="x64" or target_arch=="arm")', {
'linux_use_bundled_gold%': 1,
}, {
'linux_use_bundled_gold%': 0,
}],
# linux_use_bundled_binutils: whether to use the binary binutils
# checked into third_party/binutils. These are not multi-arch so cannot
# be used except on x86 and x86-64 (the only two architectures which
# are currently checke in). Force this off via GYP_DEFINES when you
# are using a custom toolchain and need to control -B in cflags.
['OS=="linux" and (target_arch=="ia32" or target_arch=="x64")', {
'linux_use_bundled_binutils%': 1,
}, {
'linux_use_bundled_binutils%': 0,
}],
# linux_use_gold_flags: whether to use build flags that rely on gold.
# On by default for x64 Linux.
['OS=="linux" and target_arch=="x64"', {
'linux_use_gold_flags%': 1,
}, {
'linux_use_gold_flags%': 0,
}],
],
# Link-Time Optimizations
'use_lto%': 0,
......@@ -797,6 +837,26 @@
'-mx32',
],
}], # v8_target_arch=="x32"
['linux_use_gold_flags==1', {
# 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
'ldflags': [ '-fuse-ld=gold', ],
}],
['linux_use_bundled_binutils==1', {
'cflags': [
'-B<!(cd <(DEPTH) && pwd -P)/<(binutils_dir)',
],
}],
['linux_use_bundled_gold==1', {
# Put our binutils, which contains gold in the search path. We pass
# the path to gold to the compiler. gyp leaves unspecified what the
# cwd is when running the compiler, so the normal gyp path-munging
# fails us. This hack gets the right path.
'ldflags': [
'-B<!(cd <(DEPTH) && pwd -P)/<(binutils_dir)',
],
}],
['OS=="win"', {
'defines': [
'WIN32',
......@@ -1083,6 +1143,21 @@
}],
],
}],
['linux_use_gold_flags==1', {
'target_conditions': [
['_toolset=="target"', {
'ldflags': [
# 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.
'-Wl,--threads',
'-Wl,--thread-count=4',
],
}],
],
}],
],
}, # DebugBaseCommon
'Debug': {
......
fd80d8d02666517d0781d3039499b4131e5d3e4e
\ No newline at end of file
905e9e6eb9b0e11f0587177cfbaf9f7822736f34
\ No newline at end of file
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# vim: set ts=2 sw=2 et sts=2 ai:
"""Minimal tool to download binutils from Google storage.
TODO(mithro): Replace with generic download_and_extract tool.
"""
import os
import platform
import re
import shutil
import subprocess
import sys
BINUTILS_DIR = os.path.abspath(os.path.dirname(__file__))
BINUTILS_FILE = 'binutils.tar.bz2'
BINUTILS_TOOLS = ['bin/ld.gold', 'bin/objcopy', 'bin/objdump']
BINUTILS_OUT = 'Release'
DETECT_HOST_ARCH = os.path.abspath(os.path.join(
BINUTILS_DIR, '../../build/detect_v8_host_arch.py'))
def ReadFile(filename):
with file(filename, 'r') as f:
return f.read().strip()
def WriteFile(filename, content):
assert not os.path.exists(filename)
with file(filename, 'w') as f:
f.write(content)
f.write('\n')
def GetArch():
gyp_host_arch = re.search(
'host_arch=(\S*)', os.environ.get('GYP_DEFINES', ''))
if gyp_host_arch:
arch = gyp_host_arch.group(1)
# This matches detect_host_arch.py.
if arch == 'x86_64':
return 'x64'
return arch
return subprocess.check_output(['python', DETECT_HOST_ARCH]).strip()
def FetchAndExtract(arch):
archdir = os.path.join(BINUTILS_DIR, 'Linux_' + arch)
tarball = os.path.join(archdir, BINUTILS_FILE)
outdir = os.path.join(archdir, BINUTILS_OUT)
sha1file = tarball + '.sha1'
if not os.path.exists(sha1file):
print "WARNING: No binutils found for your architecture (%s)!" % arch
return 0
checksum = ReadFile(sha1file)
stampfile = tarball + '.stamp'
if os.path.exists(stampfile):
if (os.path.exists(tarball) and
os.path.exists(outdir) and
checksum == ReadFile(stampfile)):
return 0
else:
os.unlink(stampfile)
print "Downloading", tarball
subprocess.check_call([
'download_from_google_storage',
'--no_resume',
'--no_auth',
'--bucket', 'chromium-binutils',
'-s', sha1file])
assert os.path.exists(tarball)
if os.path.exists(outdir):
shutil.rmtree(outdir)
assert not os.path.exists(outdir)
os.makedirs(outdir)
assert os.path.exists(outdir)
print "Extracting", tarball
subprocess.check_call(['tar', 'axf', tarball], cwd=outdir)
for tool in BINUTILS_TOOLS:
assert os.path.exists(os.path.join(outdir, tool))
WriteFile(stampfile, checksum)
return 0
def main(args):
if not sys.platform.startswith('linux'):
return 0
arch = GetArch()
if arch == 'x64':
return FetchAndExtract(arch)
if arch == 'ia32':
ret = FetchAndExtract(arch)
if ret != 0:
return ret
# Fetch the x64 toolchain as well for official bots with 64-bit kernels.
return FetchAndExtract('x64')
print "Host architecture %s is not supported." % arch
return 1
if __name__ == '__main__':
sys.exit(main(sys.argv))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment