Commit 9fc3a5c2 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

Include libclang_rt.builtins.a for Fuchsia

Based on https://codereview.chromium.org/2897463003/.

Test: Run update.py --force-local-build, remove https://cs.chromium.org/chromium/src/build/config/fuchsia/BUILD.gn?l=41 and referenced files, and rebuild some Fuchsia binaries
Test: Run package.py and verify the .a's are included.
Bug: 724204
Change-Id: If1492138829846a0f970d034f28a84d517554401
Reviewed-on: https://chromium-review.googlesource.com/1211879Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590521}
parent 150f0b78
......@@ -30,16 +30,6 @@ config("compiler") {
asmflags = cflags
ldflags += [
# TODO(thakis): Once Fuchsia's libclang_rt.builtin no longer has upstream
# patches, we might want to make tools/clang/scripts/update.py build it
# and bundle it with the clang package instead of using the library from
# the SDK, https://crbug.com/724204
# Note: Intentionally 8.0.0 instead of $clang_version because the clang
# version of the toolchain_libs directory in the Fuchsia SDK can be
# different from the version of Chromium's clang.
"-resource-dir",
rebase_path(fuchsia_sdk, root_build_dir) + "/toolchain_libs/clang/8.0.0",
# The stack defaults to 256k on Fuchsia (see
# https://fuchsia.googlesource.com/zircon/+/master/system/private/zircon/stack.h#9),
# but on other platforms it's much higher, so a variety of code assumes more
......
......@@ -282,6 +282,12 @@ def main():
'lib/clang/*/lib/windows/clang_rt.ubsan*.lib',
])
if sys.platform in ('linux2', 'darwin'):
# Include libclang_rt.builtins.a for Fuchsia targets.
want.extend(['lib/clang/*/aarch64-fuchsia/lib/libclang_rt.builtins.a',
'lib/clang/*/x86_64-fuchsia/lib/libclang_rt.builtins.a',
])
for root, dirs, files in os.walk(LLVM_RELEASE_DIR):
# root: third_party/llvm-build/Release+Asserts/lib/..., rel_root: lib/...
rel_root = root[len(LLVM_RELEASE_DIR)+1:]
......
......@@ -35,7 +35,7 @@ if use_head_revision:
CLANG_REVISION = 'HEAD'
# This is incremented when pushing a new build of Clang at the same revision.
CLANG_SUB_REVISION=1
CLANG_SUB_REVISION=2
PACKAGE_VERSION = "%s-%s" % (CLANG_REVISION, CLANG_SUB_REVISION)
......@@ -71,6 +71,8 @@ STAMP_FILE = os.path.normpath(
VERSION = '8.0.0'
ANDROID_NDK_DIR = os.path.join(
CHROMIUM_DIR, 'third_party', 'android_ndk')
FUCHSIA_SDK_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'fuchsia-sdk',
'sdk')
# URL for pre-built binaries.
CDS_URL = os.environ.get('CDS_CLANG_BUCKET_OVERRIDE',
......@@ -483,6 +485,16 @@ def UpdateClang(args):
print 'for how to install the NDK, or pass --without-android.'
return 1
if args.with_fuchsia and not os.path.exists(FUCHSIA_SDK_DIR):
print 'Fuchsia SDK not found at ' + FUCHSIA_SDK_DIR
print 'The Fuchsia SDK is needed to build libclang_rt for Fuchsia.'
print 'Install the Fuchsia SDK by adding fuchsia to the '
print 'target_os section in your .gclient and running hooks, '
print 'or pass --without-fuchsia.'
print 'https://chromium.googlesource.com/chromium/src/+/master/docs/fuchsia_build_instructions.md'
print 'for general Fuchsia build instructions.'
return 1
print 'Locally building Clang %s...' % PACKAGE_VERSION
AddCMakeToPath(args)
......@@ -816,6 +828,57 @@ def UpdateClang(args):
if os.path.exists(lib_path):
shutil.copy(lib_path, rt_lib_dst_dir)
if args.with_fuchsia:
# Fuchsia links against libclang_rt.builtins-<arch>.a instead of libgcc.a.
for target_arch in ['aarch64', 'x86_64']:
fuchsia_arch_name = {'aarch64': 'arm64', 'x86_64': 'x64'}[target_arch]
toolchain_dir = os.path.join(
FUCHSIA_SDK_DIR, 'arch', fuchsia_arch_name, 'sysroot')
# Build clang_rt runtime for Fuchsia in a separate build tree.
build_dir = os.path.join(LLVM_BUILD_DIR, 'fuchsia-' + target_arch)
if not os.path.exists(build_dir):
os.mkdir(os.path.join(build_dir))
os.chdir(build_dir)
target_spec = target_arch + '-fuchsia'
# TODO(thakis): Might have to pass -B here once sysroot contains
# binaries (e.g. gas for arm64?)
fuchsia_args = base_cmake_args + [
'-DLLVM_ENABLE_THREADS=OFF',
'-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'),
'-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'),
'-DCMAKE_LINKER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'),
'-DCMAKE_AR=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-ar'),
'-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'),
'-DCMAKE_SYSTEM_NAME=Fuchsia',
'-DCMAKE_C_COMPILER_TARGET=%s-fuchsia' % target_arch,
'-DCMAKE_ASM_COMPILER_TARGET=%s-fuchsia' % target_arch,
'-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON',
'-DCMAKE_SYSROOT=%s' % toolchain_dir,
# TODO(thakis|scottmg): Use PER_TARGET_RUNTIME_DIR for all platforms.
# https://crbug.com/882485.
'-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON',
# These are necessary because otherwise CMake tries to build an
# executable to test to see if the compiler is working, but in doing so,
# it links against the builtins.a that we're about to build.
'-DCMAKE_C_COMPILER_WORKS=ON',
'-DCMAKE_ASM_COMPILER_WORKS=ON',
]
RmCmakeCache('.')
RunCommand(['cmake'] +
fuchsia_args +
[os.path.join(COMPILER_RT_DIR, 'lib', 'builtins')])
builtins_a = 'libclang_rt.builtins.a'
RunCommand(['ninja', builtins_a])
# And copy it into the main build tree.
fuchsia_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang',
VERSION, target_spec, 'lib')
if not os.path.exists(fuchsia_lib_dst_dir):
os.makedirs(fuchsia_lib_dst_dir)
CopyFile(os.path.join(build_dir, target_spec, 'lib', builtins_a),
fuchsia_lib_dst_dir)
# Run tests.
if args.run_tests or use_head_revision:
os.chdir(LLVM_BUILD_DIR)
......@@ -869,6 +932,10 @@ def main():
help='don\'t build Android ASan runtime (linux only)',
dest='with_android',
default=sys.platform.startswith('linux'))
parser.add_argument('--without-fuchsia', action='store_false',
help='don\'t build Fuchsia clang_rt runtime (linux/mac)',
dest='with_fuchsia',
default=sys.platform in ('linux2', 'darwin'))
args = parser.parse_args()
if args.lto_lld and not args.bootstrap:
......@@ -921,6 +988,8 @@ def main():
if 'OS=android' not in os.environ.get('GYP_DEFINES', ''):
# Only build the Android ASan rt on ToT bots when targetting Android.
args.with_android = False
# Don't build fuchsia runtime on ToT bots at all.
args.with_fuchsia = False
return UpdateClang(args)
......
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