Commit 9d5c5712 authored by machenbach's avatar machenbach Committed by Commit bot

Port cfi configuration from chromium.

BUG=chromium:515782
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#30058}
parent 5defb720
#!/usr/bin/env python
# Copyright 2015 the V8 project authors. All rights reserved.
# Copyright 2015 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.
"""Script to download LLVM gold plugin from google storage."""
import json
import os
import shutil
import subprocess
import sys
import zipfile
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
CHROME_SRC = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
sys.path.insert(0, os.path.join(CHROME_SRC, 'tools'))
import find_depot_tools
DEPOT_PATH = find_depot_tools.add_depot_tools_to_path()
GSUTIL_PATH = os.path.join(DEPOT_PATH, 'gsutil.py')
LLVM_BUILD_PATH = os.path.join(CHROME_SRC, 'third_party', 'llvm-build',
'Release+Asserts')
CLANG_UPDATE_PY = os.path.join(CHROME_SRC, 'tools', 'clang', 'scripts',
'update.py')
CLANG_REVISION = os.popen(CLANG_UPDATE_PY + ' --print-revision').read().rstrip()
CLANG_BUCKET = 'gs://chromium-browser-clang/Linux_x64'
def main():
targz_name = 'llvmgold-%s.tgz' % CLANG_REVISION
remote_path = '%s/%s' % (CLANG_BUCKET, targz_name)
os.chdir(LLVM_BUILD_PATH)
# TODO(pcc): Fix gsutil.py cp url file < /dev/null 2>&0
# (currently aborts with exit code 1,
# https://github.com/GoogleCloudPlatform/gsutil/issues/289) or change the
# stdin->stderr redirect in update.py to do something else (crbug.com/494442).
subprocess.check_call(['python', GSUTIL_PATH,
'cp', remote_path, targz_name],
stderr=open('/dev/null', 'w'))
subprocess.check_call(['tar', 'xzf', targz_name])
os.remove(targz_name)
return 0
if __name__ == '__main__':
sys.exit(main())
......@@ -88,6 +88,13 @@
'clang_dir%': '<(base_dir)/third_party/llvm-build/Release+Asserts',
'use_lto%': 0,
# Control Flow Integrity for virtual calls and casts.
# See http://clang.llvm.org/docs/ControlFlowIntegrity.html
'cfi_vptr%': 0,
'cfi_diag%': 0,
# goma settings.
# 1 to use goma.
# If no gomadir is set, it uses the default gomadir.
......@@ -105,6 +112,16 @@
}, {
'host_clang%': '0',
}],
# 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" or OS=="android") and (target_arch=="x64" or target_arch=="arm" or (target_arch=="ia32" and host_arch=="x64"))', {
'linux_use_bundled_gold%': 1,
}, {
'linux_use_bundled_gold%': 0,
}],
],
},
'base_dir%': '<(base_dir)',
......@@ -122,6 +139,10 @@
'tsan%': '<(tsan)',
'sanitizer_coverage%': '<(sanitizer_coverage)',
'use_custom_libcxx%': '<(use_custom_libcxx)',
'linux_use_bundled_gold%': '<(linux_use_bundled_gold)',
'use_lto%': '<(use_lto)',
'cfi_vptr%': '<(cfi_vptr)',
'cfi_diag%': '<(cfi_diag)',
# Add a simple extra solely for the purpose of the cctests
'v8_extra_library_files': ['../test/cctest/test-extra.js'],
......@@ -207,6 +228,9 @@
# the C++ standard library is used.
'use_custom_libcxx%': 1,
}],
['cfi_vptr==1', {
'use_lto%': 1,
}],
['OS=="linux"', {
# Gradually roll out v8_use_external_startup_data.
# Should eventually be default enabled on all platforms.
......@@ -535,6 +559,21 @@
}],
],
}],
['linux_use_bundled_gold==1 and not (clang==0 and use_lto==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.
#
# Disabled when using GCC LTO because GCC also uses the -B search
# path at link time to find "as", and our bundled "as" can only
# target x86.
'ldflags': [
# Note, Chromium allows ia32 host arch as well, we limit this to
# x64 in v8.
'-B<(base_dir)/third_party/binutils/Linux_x64/Release/bin',
],
}],
],
},
}],
......@@ -1144,5 +1183,100 @@
['CXX.host_wrapper', '<(gomadir)/gomacc'],
],
}],
['use_lto==1', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'cflags': [
'-flto',
],
}],
],
},
}],
['use_lto==1 and clang==0', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'cflags': [
'-ffat-lto-objects',
],
}],
],
},
}],
['use_lto==1 and clang==1', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'arflags': [
'--plugin', '<(clang_dir)/lib/LLVMgold.so',
],
# Apply a lower optimization level with lto. Chromium does this
# for non-official builds only - a differentiation that doesn't
# exist in v8.
'ldflags': [
'-Wl,--plugin-opt,O1',
],
}],
],
},
}],
['use_lto==1 and clang==0', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'ldflags': [
'-flto=32',
],
}],
],
},
}],
['use_lto==1 and clang==1', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'ldflags': [
'-flto',
],
}],
],
},
}],
['cfi_diag==1', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'cflags': [
'-fno-sanitize-trap=cfi',
'-fsanitize-recover=cfi',
],
'ldflags': [
'-fno-sanitize-trap=cfi',
'-fsanitize-recover=cfi',
],
}],
],
},
}],
['cfi_vptr==1', {
'target_defaults': {
'target_conditions': [
['_toolset=="target"', {
'cflags': [
'-fsanitize=cfi-vcall',
'-fsanitize=cfi-derived-cast',
'-fsanitize=cfi-unrelated-cast',
],
'ldflags': [
'-fsanitize=cfi-vcall',
'-fsanitize=cfi-derived-cast',
'-fsanitize=cfi-unrelated-cast',
],
}],
],
},
}],
],
}
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