Update build.py

This commit is contained in:
Alexander David Frick 2022-08-03 06:04:18 -05:00 committed by GitHub
parent 48ec8f8e8b
commit 114cf8fe55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,22 +25,24 @@ import subprocess
import sys import sys
import tempfile import tempfile
os.environ['NINJA_STATUS'] = "[%r processes, %f/%t @ %o/s | %e sec. ] "
from update import (CDS_URL, CHROMIUM_DIR, CLANG_REVISION, LLVM_BUILD_DIR, from update import (CDS_URL, CHROMIUM_DIR, CLANG_REVISION, LLVM_BUILD_DIR,
FORCE_HEAD_REVISION_FILE, PACKAGE_VERSION, RELEASE_VERSION, FORCE_HEAD_REVISION_FILE, PACKAGE_VERSION, RELEASE_VERSION,
STAMP_FILE, DownloadUrl, DownloadAndUnpack, EnsureDirExists, STAMP_FILE, THIS_DIR, DownloadUrl, DownloadAndUnpack,
ReadStampFile, RmTree, WriteStampFile) EnsureDirExists, ReadStampFile, RmTree, WriteStampFile)
# Path constants. (All of these should be absolute paths.) # Path constants. (All of these should be absolute paths.)
THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party') THIRD_PARTY_DIR = os.path.join(CHROMIUM_DIR, 'third_party')
LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm') LLVM_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm')
COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt') COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'compiler-rt')
LLVM_BUILD_TOOLS_DIR = os.path.abspath( LLVM_BOOTSTRAP_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-bootstrap')
os.path.join(THIRD_PARTY_DIR, 'llvm-build-tools')) LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(THIRD_PARTY_DIR,
LLVM_BOOTSTRAP_DIR = os.path.join(LLVM_BUILD_TOOLS_DIR, 'llvm-bootstrap')
LLVM_BOOTSTRAP_INSTALL_DIR = os.path.join(LLVM_BUILD_TOOLS_DIR,
'llvm-bootstrap-install') 'llvm-bootstrap-install')
LLVM_INSTRUMENTED_DIR = os.path.join(LLVM_BUILD_TOOLS_DIR, 'llvm-instrumented') LLVM_INSTRUMENTED_DIR = os.path.join(THIRD_PARTY_DIR, 'llvm-instrumented')
LLVM_PROFDATA_FILE = os.path.join(LLVM_INSTRUMENTED_DIR, 'profdata.prof') LLVM_PROFDATA_FILE = os.path.join(LLVM_INSTRUMENTED_DIR, 'profdata.prof')
LLVM_BUILD_TOOLS_DIR = os.path.abspath(
os.path.join(LLVM_DIR, '..', 'llvm-build-tools'))
ANDROID_NDK_DIR = os.path.join( ANDROID_NDK_DIR = os.path.join(
CHROMIUM_DIR, 'third_party', 'android_ndk') CHROMIUM_DIR, 'third_party', 'android_ndk')
FUCHSIA_SDK_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'fuchsia-sdk', FUCHSIA_SDK_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'fuchsia-sdk',
@ -183,14 +185,6 @@ def GetCommitDescription(commit):
universal_newlines=True).rstrip() universal_newlines=True).rstrip()
def DeleteChromeToolsShim():
# TODO: These dirs are no longer used. Remove this code after a while.
OLD_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'zzz-chrometools')
shutil.rmtree(OLD_SHIM_DIR, ignore_errors=True)
CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'llvm', 'tools', 'chrometools')
shutil.rmtree(CHROME_TOOLS_SHIM_DIR, ignore_errors=True)
def AddCMakeToPath(args): def AddCMakeToPath(args):
"""Download CMake and add it to PATH.""" """Download CMake and add it to PATH."""
if args.use_system_cmake: if args.use_system_cmake:
@ -302,6 +296,7 @@ def BuildLibXml2():
[ [
'cmake', 'cmake',
'-GNinja', '-GNinja',
'-DCMAKE_VERBOSE_MAKEFILE=ON',
'-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_INSTALL_PREFIX=install',
# The mac_arm bot builds a clang arm binary, but currently on an intel # The mac_arm bot builds a clang arm binary, but currently on an intel
@ -392,16 +387,19 @@ def DownloadPinnedClang():
# The update.py in this current revision may have a patched revision while # The update.py in this current revision may have a patched revision while
# building new clang packages. Get update.py off HEAD~ to pull the current # building new clang packages. Get update.py off HEAD~ to pull the current
# pinned clang. # pinned clang.
with tempfile.NamedTemporaryFile() as f: if not os.path.exists(PINNED_CLANG_DIR):
os.mkdir(os.path.join(PINNED_CLANG_DIR))
script_path = os.path.join(PINNED_CLANG_DIR, 'update.py')
with open(script_path, 'w') as f:
subprocess.check_call( subprocess.check_call(
['git', 'show', 'HEAD~:tools/clang/scripts/update.py'], ['git', 'show', 'HEAD~:tools/clang/scripts/update.py'],
stdout=f, stdout=f,
cwd=CHROMIUM_DIR) cwd=CHROMIUM_DIR)
print("Running update.py") print("Running pinned update.py")
# Without the flush, the subprocess call below doesn't work. subprocess.check_call(
f.flush() [sys.executable, script_path, '--output-dir=' + PINNED_CLANG_DIR])
subprocess.check_call(
[sys.executable, f.name, '--output-dir=' + PINNED_CLANG_DIR])
# TODO(crbug.com/929645): Remove once we don't need gcc's libstdc++. # TODO(crbug.com/929645): Remove once we don't need gcc's libstdc++.
@ -410,9 +408,11 @@ def MaybeDownloadHostGcc(args):
assert sys.platform.startswith('linux') assert sys.platform.startswith('linux')
if args.gcc_toolchain: if args.gcc_toolchain:
return return
gcc_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gcc-10.2.0-trusty') gcc_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gcc-10.2.0-bionic')
if os.path.isdir(gcc_dir):
RmTree(gcc_dir) # TODO(thakis): Remove this branch after a few weeks.
if not os.path.exists(gcc_dir): if not os.path.exists(gcc_dir):
DownloadAndUnpack(CDS_URL + '/tools/gcc-10.2.0-trusty.tgz', gcc_dir) DownloadAndUnpack(CDS_URL + '/tools/gcc-10.2.0-bionic.tgz', gcc_dir)
args.gcc_toolchain = gcc_dir args.gcc_toolchain = gcc_dir
@ -471,6 +471,28 @@ def CopyLibstdcpp(args, build_dir):
CopyFile(libstdcpp, os.path.join(build_dir, 'lib')) CopyFile(libstdcpp, os.path.join(build_dir, 'lib'))
def compiler_rt_cmake_flags(*, sanitizers, profile):
# Don't set -DCOMPILER_RT_BUILD_BUILTINS=ON/OFF as it interferes with the
# runtimes logic of building builtins.
args = [
# Build crtbegin/crtend. It's just two tiny TUs, so just enable this
# everywhere, even though we only need it on Linux.
'COMPILER_RT_BUILD_CRT=ON',
'COMPILER_RT_BUILD_LIBFUZZER=OFF',
'COMPILER_RT_BUILD_MEMPROF=OFF',
'COMPILER_RT_BUILD_ORC=OFF',
'COMPILER_RT_BUILD_PROFILE=' + ('ON' if profile else 'OFF'),
'COMPILER_RT_BUILD_SANITIZERS=' + ('ON' if sanitizers else 'OFF'),
'COMPILER_RT_BUILD_XRAY=OFF',
# See crbug.com/1205046: don't build scudo (and others we don't need).
'COMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi',
# We explicitly list all targets we want to build, do not autodetect
# targets.
'COMPILER_RT_DEFAULT_TARGET_ONLY=ON',
]
return args
def gn_arg(v): def gn_arg(v):
if v == 'True': if v == 'True':
return True return True
@ -488,6 +510,12 @@ def main():
help='Build arm binaries. Only valid on macOS.') help='Build arm binaries. Only valid on macOS.')
parser.add_argument('--disable-asserts', action='store_true', parser.add_argument('--disable-asserts', action='store_true',
help='build with asserts disabled') help='build with asserts disabled')
parser.add_argument('--host-cc',
help='build with host C compiler, requires --host-cxx as '
'well')
parser.add_argument('--host-cxx',
help='build with host C++ compiler, requires --host-cc '
'as well')
parser.add_argument('--gcc-toolchain', help='what gcc toolchain to use for ' parser.add_argument('--gcc-toolchain', help='what gcc toolchain to use for '
'building; --gcc-toolchain=/opt/foo picks ' 'building; --gcc-toolchain=/opt/foo picks '
'/opt/foo/bin/gcc') '/opt/foo/bin/gcc')
@ -579,9 +607,6 @@ def main():
# move this down to where we fetch other build tools. # move this down to where we fetch other build tools.
AddGnuWinToPath() AddGnuWinToPath()
if sys.platform == 'darwin':
isysroot = subprocess.check_output(['xcrun', '--show-sdk-path'],
universal_newlines=True).rstrip()
if args.build_dir: if args.build_dir:
LLVM_BUILD_DIR = args.build_dir LLVM_BUILD_DIR = args.build_dir
@ -603,7 +628,6 @@ def main():
WriteStampFile('', FORCE_HEAD_REVISION_FILE) WriteStampFile('', FORCE_HEAD_REVISION_FILE)
AddCMakeToPath(args) AddCMakeToPath(args)
DeleteChromeToolsShim()
if args.skip_build: if args.skip_build:
@ -616,24 +640,22 @@ def main():
# LLVM_ENABLE_LLD). # LLVM_ENABLE_LLD).
cc, cxx, lld = None, None, None cc, cxx, lld = None, None, None
cflags = [] cflags = [ "-O3", ]
cxxflags = [] cxxflags = [ "-O3", ]
ldflags = [] ldflags = [ "-Wl,-O3", ]
targets = 'AArch64;ARM;Mips;PowerPC;RISCV;SystemZ;WebAssembly;X86' targets = 'AArch64;ARM;Mips;PowerPC;RISCV;SystemZ;WebAssembly;X86'
projects = 'clang;compiler-rt;lld;clang-tools-extra;polly' projects = 'clang;lld;clang-tools-extra;polly'
runtimes = 'compiler-rt'
if sys.platform == 'darwin':
# clang needs libc++, else -stdlib=libc++ won't find includes
# (this is needed for bootstrap builds and for building the fuchsia runtime)
projects += ';libcxx'
base_cmake_args = [ base_cmake_args = [
'-GNinja', '-GNinja',
'-DCMAKE_VERBOSE_MAKEFILE=ON',
'-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_BUILD_TYPE=Release',
'-DLLVM_ENABLE_ASSERTIONS=%s' % ('OFF' if args.disable_asserts else 'ON'), '-DLLVM_ENABLE_ASSERTIONS=%s' % ('OFF' if args.disable_asserts else 'ON'),
'-DLLVM_ENABLE_PROJECTS=' + projects, '-DLLVM_ENABLE_PROJECTS=' + projects,
'-DLLVM_ENABLE_RUNTIMES=' + runtimes,
'-DLLVM_TARGETS_TO_BUILD=' + targets, '-DLLVM_TARGETS_TO_BUILD=' + targets,
# PIC needed for Rust build (links LLVM into shared object) # PIC needed for Rust build (links LLVM into shared object)
'-DLLVM_ENABLE_PIC=ON', '-DLLVM_ENABLE_PIC=ON',
@ -646,12 +668,8 @@ def main():
'-DBUG_REPORT_URL=' + BUG_REPORT_URL, '-DBUG_REPORT_URL=' + BUG_REPORT_URL,
# Don't run Go bindings tests; PGO makes them confused. # Don't run Go bindings tests; PGO makes them confused.
'-DLLVM_INCLUDE_GO_TESTS=OFF', '-DLLVM_INCLUDE_GO_TESTS=OFF',
# TODO(crbug.com/1113475): Update binutils.
'-DENABLE_X86_RELAX_RELOCATIONS=NO',
# See crbug.com/1126219: Use native symbolizer instead of DIA # See crbug.com/1126219: Use native symbolizer instead of DIA
'-DLLVM_ENABLE_DIA_SDK=OFF', '-DLLVM_ENABLE_DIA_SDK=OFF',
# See crbug.com/1205046: don't build scudo (and others we don't need).
'-DCOMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi',
# The default value differs per platform, force it off everywhere. # The default value differs per platform, force it off everywhere.
'-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF', '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF',
# Don't use curl. # Don't use curl.
@ -660,37 +678,105 @@ def main():
'-DLIBCLANG_BUILD_STATIC=ON', '-DLIBCLANG_BUILD_STATIC=ON',
] ]
if sys.platform.startswith('linux'):
MaybeDownloadHostGcc(args)
DownloadPinnedClang()
cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang')
cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++')
# Use the libraries in the specified gcc installation for building.
cflags.append('--gcc-toolchain=' + args.gcc_toolchain)
cxxflags.append('--gcc-toolchain=' + args.gcc_toolchain)
base_cmake_args += [
# The host clang has lld.
'-DLLVM_ENABLE_LLD=ON',
'-DLLVM_STATIC_LINK_CXX_STDLIB=ON',
# Force compiler-rt tests to use our gcc toolchain
# because the one on the host may be too old.
# Even with -static-libstdc++ the compiler-rt tests add -lstdc++
# which adds a DT_NEEDED to libstdc++.so so we need to add RPATHs
# to the gcc toolchain.
'-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=' +
args.gcc_toolchain + ' -Wl,-rpath,' +
os.path.join(args.gcc_toolchain, 'lib64') + ' -Wl,-rpath,' +
os.path.join(args.gcc_toolchain, 'lib32')
]
if sys.platform == 'darwin': if sys.platform == 'darwin':
# For libc++, we only want the headers. isysroot = subprocess.check_output(['xcrun', '--show-sdk-path'],
base_cmake_args.extend([ universal_newlines=True).rstrip()
'-DLIBCXX_ENABLE_SHARED=OFF',
'-DLIBCXX_ENABLE_STATIC=OFF', # clang only automatically links to libc++ when targeting OS X 10.9+, so
'-DLIBCXX_INCLUDE_TESTS=OFF', # add stdlib=libc++ explicitly so clang can run on OS X versions as old as
'-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF', # 10.7.
]) cxxflags += ['-stdlib=libc++']
ldflags += ['-stdlib=libc++']
# See https://crbug.com/1302636#c49 - #c56 -- intercepting crypt_r() does not
# work with the sysroot for not fully understood reasons. Disable it.
sanitizers_override = [
'-DSANITIZER_OVERRIDE_INTERCEPTORS',
'-I' + os.path.join(THIS_DIR, 'sanitizers'),
]
cflags += sanitizers_override
cxxflags += sanitizers_override
if args.host_cc or args.host_cxx:
assert args.host_cc and args.host_cxx, \
"--host-cc and --host-cxx need to be used together"
cc = args.host_cc
cxx = args.host_cxx
else:
DownloadPinnedClang()
if sys.platform == 'win32':
cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang-cl.exe')
cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang-cl.exe')
lld = os.path.join(PINNED_CLANG_DIR, 'bin', 'lld-link.exe')
# CMake has a hard time with backslashes in compiler paths:
# https://stackoverflow.com/questions/13050827
cc = cc.replace('\\', '/')
cxx = cxx.replace('\\', '/')
lld = lld.replace('\\', '/')
else:
cc = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang')
cxx = os.path.join(PINNED_CLANG_DIR, 'bin', 'clang++')
if sys.platform.startswith('linux'):
MaybeDownloadHostGcc(args)
base_cmake_args += [ '-DLLVM_STATIC_LINK_CXX_STDLIB=ON' ]
if sys.platform != 'darwin':
# The host clang has lld, but self-hosting with lld is still slightly
# broken on mac.
# TODO: check if this works now.
base_cmake_args.append('-DLLVM_ENABLE_LLD=ON')
if sys.platform.startswith('linux'):
# Download sysroots. This uses basically Chromium's sysroots, but with
# minor changes:
# - glibc version bumped to 2.18 to make __cxa_thread_atexit_impl
# work (clang can require 2.18; chromium currently doesn't)
# - libcrypt.so.1 reversioned so that crypt() is picked up from glibc
# The sysroot was built at
# https://chromium-review.googlesource.com/c/chromium/src/+/3684954/1
# and the hashes here are from sysroots.json in that CL.
toolchain_bucket = 'https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/'
# amd64
# hash from https://chromium-review.googlesource.com/c/chromium/src/+/3684954/1/build/linux/sysroot_scripts/sysroots.json#3
toolchain_hash = '2028cdaf24259d23adcff95393b8cc4f0eef714b'
toolchain_name = 'debian_bullseye_amd64_sysroot'
U = toolchain_bucket + toolchain_hash + '/' + toolchain_name + '.tar.xz'
sysroot_amd64 = os.path.join(LLVM_BUILD_TOOLS_DIR, toolchain_name)
DownloadAndUnpack(U, sysroot_amd64)
# i386
# hash from https://chromium-review.googlesource.com/c/chromium/src/+/3684954/1/build/linux/sysroot_scripts/sysroots.json#23
toolchain_hash = 'a033618b5e092c86e96d62d3c43f7363df6cebe7'
toolchain_name = 'debian_bullseye_i386_sysroot'
U = toolchain_bucket + toolchain_hash + '/' + toolchain_name + '.tar.xz'
sysroot_i386 = os.path.join(LLVM_BUILD_TOOLS_DIR, toolchain_name)
DownloadAndUnpack(U, sysroot_i386)
# arm
# hash from https://chromium-review.googlesource.com/c/chromium/src/+/3684954/1/build/linux/sysroot_scripts/sysroots.json#8
toolchain_hash = '0b9a3c54d2d5f6b1a428369aaa8d7ba7b227f701'
toolchain_name = 'debian_bullseye_arm_sysroot'
U = toolchain_bucket + toolchain_hash + '/' + toolchain_name + '.tar.xz'
sysroot_arm = os.path.join(LLVM_BUILD_TOOLS_DIR, toolchain_name)
DownloadAndUnpack(U, sysroot_arm)
# arm64
# hash from https://chromium-review.googlesource.com/c/chromium/src/+/3684954/1/build/linux/sysroot_scripts/sysroots.json#12
toolchain_hash = '0e28d9832614729bb5b731161ff96cb4d516f345'
toolchain_name = 'debian_bullseye_arm64_sysroot'
U = toolchain_bucket + toolchain_hash + '/' + toolchain_name + '.tar.xz'
sysroot_arm64 = os.path.join(LLVM_BUILD_TOOLS_DIR, toolchain_name)
DownloadAndUnpack(U, sysroot_arm64)
# Add the sysroot to base_cmake_args.
if platform.machine() == 'aarch64':
base_cmake_args.append('-DCMAKE_SYSROOT=' + sysroot_arm64)
else:
# amd64 is the default toolchain.
base_cmake_args.append('-DCMAKE_SYSROOT=' + sysroot_amd64)
if sys.platform == 'win32': if sys.platform == 'win32':
base_cmake_args.append('-DLLVM_USE_CRT_RELEASE=MT') base_cmake_args.append('-DLLVM_USE_CRT_RELEASE=MT')
@ -721,14 +807,16 @@ def main():
os.chdir(LLVM_BOOTSTRAP_DIR) os.chdir(LLVM_BOOTSTRAP_DIR)
projects = 'clang' projects = 'clang'
if args.pgo: runtimes = ''
# Need libclang_rt.profile if args.pgo or sys.platform == 'darwin':
projects += ';compiler-rt' # Need libclang_rt.profile for PGO.
# On macOS, the bootstrap toolchain needs to have compiler-rt because
# dsymutil's link needs libclang_rt.osx.a. Only the x86_64 osx
# libraries are needed though, and only libclang_rt (i.e.
# COMPILER_RT_BUILD_BUILTINS).
runtimes += ';compiler-rt'
if sys.platform != 'darwin': if sys.platform != 'darwin':
projects += ';lld' projects += ';lld'
if sys.platform == 'darwin':
# Need libc++ and compiler-rt for the bootstrap compiler on mac.
projects += ';libcxx;compiler-rt'
bootstrap_targets = 'X86' bootstrap_targets = 'X86'
if sys.platform == 'darwin': if sys.platform == 'darwin':
@ -737,6 +825,7 @@ def main():
bootstrap_args = base_cmake_args + [ bootstrap_args = base_cmake_args + [
'-DLLVM_TARGETS_TO_BUILD=' + bootstrap_targets, '-DLLVM_TARGETS_TO_BUILD=' + bootstrap_targets,
'-DLLVM_ENABLE_PROJECTS=' + projects, '-DLLVM_ENABLE_PROJECTS=' + projects,
'-DLLVM_ENABLE_RUNTIMES=' + runtimes,
'-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR, '-DCMAKE_INSTALL_PREFIX=' + LLVM_BOOTSTRAP_INSTALL_DIR,
'-DCMAKE_C_FLAGS=' + ' '.join(cflags), '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
@ -746,19 +835,13 @@ def main():
# Ignore args.disable_asserts for the bootstrap compiler. # Ignore args.disable_asserts for the bootstrap compiler.
'-DLLVM_ENABLE_ASSERTIONS=ON', '-DLLVM_ENABLE_ASSERTIONS=ON',
] ]
# PGO needs libclang_rt.profile but none of the other compiler-rt stuff.
bootstrap_args.extend([
'-D' + f
for f in compiler_rt_cmake_flags(sanitizers=False, profile=args.pgo)
])
if sys.platform == 'darwin': if sys.platform == 'darwin':
# On macOS, the bootstrap toolchain needs to have compiler-rt because
# dsymutil's link needs libclang_rt.osx.a. Only the x86_64 osx
# libraries are needed though, and only libclang_rt (i.e.
# COMPILER_RT_BUILD_BUILTINS).
bootstrap_args.extend([ bootstrap_args.extend([
'-DCOMPILER_RT_BUILD_BUILTINS=ON',
'-DCOMPILER_RT_BUILD_CRT=OFF',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
'-DCOMPILER_RT_ENABLE_IOS=OFF', '-DCOMPILER_RT_ENABLE_IOS=OFF',
'-DCOMPILER_RT_ENABLE_WATCHOS=OFF', '-DCOMPILER_RT_ENABLE_WATCHOS=OFF',
'-DCOMPILER_RT_ENABLE_TVOS=OFF', '-DCOMPILER_RT_ENABLE_TVOS=OFF',
@ -767,18 +850,6 @@ def main():
bootstrap_args.extend(['-DDARWIN_osx_ARCHS=arm64']) bootstrap_args.extend(['-DDARWIN_osx_ARCHS=arm64'])
else: else:
bootstrap_args.extend(['-DDARWIN_osx_ARCHS=x86_64']) bootstrap_args.extend(['-DDARWIN_osx_ARCHS=x86_64'])
elif args.pgo:
# PGO needs libclang_rt.profile but none of the other compiler-rt stuff.
bootstrap_args.extend([
'-DCOMPILER_RT_BUILD_BUILTINS=OFF',
'-DCOMPILER_RT_BUILD_CRT=OFF',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=ON',
'-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
])
if cc is not None: bootstrap_args.append('-DCMAKE_C_COMPILER=' + cc) if cc is not None: bootstrap_args.append('-DCMAKE_C_COMPILER=' + cc)
if cxx is not None: bootstrap_args.append('-DCMAKE_CXX_COMPILER=' + cxx) if cxx is not None: bootstrap_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
@ -813,8 +884,6 @@ def main():
os.chdir(LLVM_INSTRUMENTED_DIR) os.chdir(LLVM_INSTRUMENTED_DIR)
projects = 'clang' projects = 'clang'
if sys.platform == 'darwin':
projects += ';libcxx;compiler-rt'
instrument_args = base_cmake_args + [ instrument_args = base_cmake_args + [
'-DLLVM_ENABLE_PROJECTS=' + projects, '-DLLVM_ENABLE_PROJECTS=' + projects,
@ -862,7 +931,7 @@ def main():
with open(training_source, 'wb') as f: with open(training_source, 'wb') as f:
DownloadUrl(CDS_URL + '/' + training_source, f) DownloadUrl(CDS_URL + '/' + training_source, f)
train_cmd = [os.path.join(LLVM_INSTRUMENTED_DIR, 'bin', 'clang++'), train_cmd = [os.path.join(LLVM_INSTRUMENTED_DIR, 'bin', 'clang++'),
'-target', 'x86_64-unknown-unknown', '-O2', '-g', '-std=c++14', '-target', 'x86_64-unknown-unknown', '-O3', '-g', '-std=c++14',
'-fno-exceptions', '-fno-rtti', '-w', '-c', training_source] '-fno-exceptions', '-fno-rtti', '-w', '-c', training_source]
if sys.platform == 'darwin': if sys.platform == 'darwin':
train_cmd.extend(['-stdlib=libc++', '-isysroot', isysroot]) train_cmd.extend(['-stdlib=libc++', '-isysroot', isysroot])
@ -875,49 +944,7 @@ def main():
'*.profraw')), msvc_arch='x64') '*.profraw')), msvc_arch='x64')
print('Profile generated.') print('Profile generated.')
compiler_rt_args = [ deployment_target = '10.7'
# Build crtbegin/crtend. It's just two tiny TUs, so just enable this
# everywhere, even though we only need it on Linux.
'-DCOMPILER_RT_BUILD_CRT=ON',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=ON',
'-DCOMPILER_RT_BUILD_SANITIZERS=ON',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
]
if sys.platform == 'darwin':
compiler_rt_args.extend([
'-DCOMPILER_RT_ENABLE_IOS=ON',
'-DCOMPILER_RT_ENABLE_WATCHOS=OFF',
'-DCOMPILER_RT_ENABLE_TVOS=OFF',
# armv7 is A5 and earlier, armv7s is A6+ (2012 and later, before 64-bit
# iPhones). armv7k is Apple Watch, which we don't need.
'-DDARWIN_ios_ARCHS=armv7;armv7s;arm64',
'-DDARWIN_iossim_ARCHS=i386;x86_64;arm64',
# We don't need 32-bit intel support for macOS, we only ship 64-bit.
'-DDARWIN_osx_ARCHS=arm64;x86_64',
])
if sys.platform == 'win32':
# https://crbug.com/1293778
compiler_rt_args.append('-DCOMPILER_RT_BUILD_BUILTINS=OFF')
else:
compiler_rt_args.append('-DCOMPILER_RT_BUILD_BUILTINS=ON')
# LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
# needed, on OS X it requires libc++. clang only automatically links to libc++
# when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run
# on OS X versions as old as 10.7.
deployment_target = ''
if sys.platform == 'darwin' and args.bootstrap:
# When building on 10.9, /usr/include usually doesn't exist, and while
# Xcode's clang automatically sets a sysroot, self-built clangs don't.
cflags = ['-isysroot', isysroot]
cxxflags = ['-stdlib=libc++'] + cflags
ldflags += ['-stdlib=libc++']
deployment_target = '10.7'
# If building at head, define a macro that plugins can use for #ifdefing # If building at head, define a macro that plugins can use for #ifdefing
# out code that builds at head, but not at CLANG_REVISION or vice versa. # out code that builds at head, but not at CLANG_REVISION or vice versa.
@ -945,7 +972,7 @@ def main():
if cc is not None: base_cmake_args.append('-DCMAKE_C_COMPILER=' + cc) if cc is not None: base_cmake_args.append('-DCMAKE_C_COMPILER=' + cc)
if cxx is not None: base_cmake_args.append('-DCMAKE_CXX_COMPILER=' + cxx) if cxx is not None: base_cmake_args.append('-DCMAKE_CXX_COMPILER=' + cxx)
if lld is not None: base_cmake_args.append('-DCMAKE_LINKER=' + lld) if lld is not None: base_cmake_args.append('-DCMAKE_LINKER=' + lld)
cmake_args = base_cmake_args + compiler_rt_args + [ cmake_args = base_cmake_args + [
'-DCMAKE_C_FLAGS=' + ' '.join(cflags), '-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags), '-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
'-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags), '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
@ -963,13 +990,11 @@ def main():
if sys.platform == 'win32': if sys.platform == 'win32':
cmake_args.append('-DLLVM_ENABLE_ZLIB=FORCE_ON') cmake_args.append('-DLLVM_ENABLE_ZLIB=FORCE_ON')
if sys.platform == 'darwin': if args.build_mac_arm:
cmake_args += ['-DCOMPILER_RT_ENABLE_IOS=ON', assert platform.machine() != 'arm64', 'build_mac_arm for cross build only'
'-DSANITIZER_MIN_OSX_VERSION=10.7'] cmake_args += [
if args.build_mac_arm: '-DCMAKE_OSX_ARCHITECTURES=arm64', '-DCMAKE_SYSTEM_NAME=Darwin'
assert platform.machine() != 'arm64', 'build_mac_arm for cross build only' ]
cmake_args += ['-DCMAKE_OSX_ARCHITECTURES=arm64',
'-DLLVM_USE_HOST_TOOLS=ON']
# The default LLVM_DEFAULT_TARGET_TRIPLE depends on the host machine. # The default LLVM_DEFAULT_TARGET_TRIPLE depends on the host machine.
# Set it explicitly to make the build of clang more hermetic, and also to # Set it explicitly to make the build of clang more hermetic, and also to
@ -992,12 +1017,164 @@ def main():
elif sys.platform == 'win32': elif sys.platform == 'win32':
cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-windows-msvc') cmake_args.append('-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-pc-windows-msvc')
# List of (triple, list of CMake vars without '-D').
runtimes_triples_args = []
if sys.platform.startswith('linux'):
runtimes_triples_args.append(
('i386-unknown-linux-gnu',
compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'CMAKE_SYSROOT=%s' % sysroot_i386,
]))
runtimes_triples_args.append(
('x86_64-unknown-linux-gnu',
compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'CMAKE_SYSROOT=%s' % sysroot_amd64,
]))
runtimes_triples_args.append(
# Using "armv7a-unknown-linux-gnueabhihf" confuses the compiler-rt
# builtins build, since compiler-rt/cmake/builtin-config-ix.cmake
# doesn't include "armv7a" in its `ARM32` list.
# TODO(thakis): It seems to work for everything else though, see try
# results on
# https://chromium-review.googlesource.com/c/chromium/src/+/3702739/4
# Maybe it should work for builtins too?
('armv7-unknown-linux-gnueabihf',
compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'CMAKE_SYSROOT=%s' % sysroot_arm,
]))
runtimes_triples_args.append(
('aarch64-unknown-linux-gnu',
compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'CMAKE_SYSROOT=%s' % sysroot_arm64,
]))
elif sys.platform == 'win32':
runtimes_triples_args.append(
('i386-pc-windows-msvc',
compiler_rt_cmake_flags(sanitizers=False, profile=True) + [
'LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF',
]))
runtimes_triples_args.append(
('x86_64-pc-windows-msvc',
compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF',
]))
elif sys.platform == 'darwin':
compiler_rt_args = [
'SANITIZER_MIN_OSX_VERSION=10.7',
'COMPILER_RT_ENABLE_MACCATALYST=ON',
'COMPILER_RT_ENABLE_IOS=ON',
'COMPILER_RT_ENABLE_WATCHOS=OFF',
'COMPILER_RT_ENABLE_TVOS=OFF',
'DARWIN_ios_ARCHS=arm64',
'DARWIN_iossim_ARCHS=arm64;x86_64',
'DARWIN_osx_ARCHS=arm64;x86_64',
] + compiler_rt_cmake_flags(sanitizers=True, profile=True)
# compiler-rt is built for all platforms/arches with a single
# configuration, we should only specify one target triple. 'default' is
# specially handled.
runtimes_triples_args.append(('default', compiler_rt_args))
if args.with_android:
toolchain_dir = ANDROID_NDK_DIR + '/toolchains/llvm/prebuilt/linux-x86_64'
for target_arch in ['aarch64', 'arm', 'i686', 'x86_64']:
target_triple = target_arch
if target_arch == 'arm':
target_triple = 'armv7'
api_level = '19'
if target_arch == 'aarch64' or target_arch == 'x86_64':
api_level = '21'
target_triple += '-linux-android' + api_level
cflags = [
'--sysroot=%s/sysroot' % toolchain_dir,
# We don't have an unwinder ready, and don't need it either.
'--unwindlib=none',
]
if target_arch == 'aarch64':
# Use PAC/BTI instructions for AArch64
cflags += [ '-mbranch-protection=standard' ]
android_args = compiler_rt_cmake_flags(sanitizers=True, profile=True) + [
'LLVM_ENABLE_RUNTIMES=compiler-rt',
# On Android, we want DWARF info for the builtins for unwinding. See
# crbug.com/1311807.
'CMAKE_BUILD_TYPE=RelWithDebInfo',
'CMAKE_C_FLAGS=' + ' '.join(cflags),
'CMAKE_CXX_FLAGS=' + ' '.join(cflags),
'CMAKE_ASM_FLAGS=' + ' '.join(cflags),
'COMPILER_RT_USE_BUILTINS_LIBRARY=ON',
'SANITIZER_CXX_ABI=libcxxabi',
'CMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle',
'ANDROID=1',
'LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF',
'LLVM_INCLUDE_TESTS=OFF',
# This prevents static_asserts from firing in 32-bit builds.
# TODO: remove once we only support API >=24.
'ANDROID_NATIVE_API_LEVEL=' + api_level,
]
runtimes_triples_args.append((target_triple, android_args))
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')
target_triple = target_arch + '-unknown-fuchsia'
# Build the Fuchsia profile and asan runtimes. This is done after the rt
# builtins have been created because the CMake build runs link checks that
# require that the builtins already exist to succeed.
# TODO(thakis): Figure out why this doesn't build with the stage0
# compiler in arm cross builds.
build_profile = target_arch == 'x86_64' and not args.build_mac_arm
# Build the asan runtime only on non-Mac platforms. Macs are excluded
# because the asan install changes library RPATHs which CMake only
# supports on ELF platforms and MacOS uses Mach-O instead of ELF.
build_sanitizers = build_profile and sys.platform != 'darwin'
# TODO(thakis): Might have to pass -B here once sysroot contains
# binaries (e.g. gas for arm64?)
fuchsia_args = compiler_rt_cmake_flags(
sanitizers=build_sanitizers, profile=build_profile
) + [
'LLVM_ENABLE_RUNTIMES=compiler-rt',
'CMAKE_SYSTEM_NAME=Fuchsia',
'CMAKE_SYSROOT=%s' % toolchain_dir,
# TODO(thakis|scottmg): Use PER_TARGET_RUNTIME_DIR for all platforms.
# https://crbug.com/882485.
'LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON',
]
if build_sanitizers:
fuchsia_args.append('SANITIZER_NO_UNDEFINED_SYMBOLS=OFF')
runtimes_triples_args.append((target_triple, fuchsia_args))
# Convert FOO=BAR CMake flags per triple into
# -DBUILTINS_$triple_FOO=BAR/-DRUNTIMES_$triple_FOO=BAR and build up
# -DLLVM_BUILTIN_TARGETS/-DLLVM_RUNTIME_TARGETS.
all_triples = ''
for (triple, a) in runtimes_triples_args:
all_triples += ';' + triple
for arg in a:
assert not arg.startswith('-')
# 'default' is specially handled to pass through relevant CMake flags.
if triple == 'default':
cmake_args.append('-D' + arg)
else:
cmake_args.append('-DBUILTINS_' + triple + '_' + arg)
cmake_args.append('-DRUNTIMES_' + triple + '_' + arg)
cmake_args.append('-DLLVM_BUILTIN_TARGETS=' + all_triples)
cmake_args.append('-DLLVM_RUNTIME_TARGETS=' + all_triples)
if os.path.exists(LLVM_BUILD_DIR): if os.path.exists(LLVM_BUILD_DIR):
RmTree(LLVM_BUILD_DIR) RmTree(LLVM_BUILD_DIR)
EnsureDirExists(LLVM_BUILD_DIR) EnsureDirExists(LLVM_BUILD_DIR)
os.chdir(LLVM_BUILD_DIR) os.chdir(LLVM_BUILD_DIR)
RunCommand(['cmake'] + cmake_args + [os.path.join(LLVM_DIR, 'llvm')], RunCommand(['cmake'] + cmake_args + [os.path.join(LLVM_DIR, 'llvm')],
msvc_arch='x64', env=deployment_env) msvc_arch='x64',
env=deployment_env)
CopyLibstdcpp(args, LLVM_BUILD_DIR) CopyLibstdcpp(args, LLVM_BUILD_DIR)
RunCommand(['ninja'], msvc_arch='x64') RunCommand(['ninja'], msvc_arch='x64')
@ -1009,290 +1186,22 @@ def main():
VerifyVersionOfBuiltClangMatchesVERSION() VerifyVersionOfBuiltClangMatchesVERSION()
VerifyZlibSupport() VerifyZlibSupport()
if sys.platform == 'win32':
rt_platform = 'windows'
elif sys.platform == 'darwin':
rt_platform = 'darwin'
else:
assert sys.platform.startswith('linux')
rt_platform = 'linux'
rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', RELEASE_VERSION,
'lib', rt_platform)
# Make sure the directory exists; this will not be implicilty created if
# built with per-target runtime directories.
if not os.path.exists(rt_lib_dst_dir):
os.makedirs(rt_lib_dst_dir)
# Do an out-of-tree build of compiler-rt for 32-bit Win clang_rt.profile.lib.
if sys.platform == 'win32':
compiler_rt_build_dir = os.path.join(LLVM_BUILD_DIR, 'compiler-rt')
if os.path.isdir(compiler_rt_build_dir):
RmTree(compiler_rt_build_dir)
os.makedirs(compiler_rt_build_dir)
os.chdir(compiler_rt_build_dir)
if args.bootstrap:
# The bootstrap compiler produces 64-bit binaries by default.
cflags += ['-m32']
cxxflags += ['-m32']
compiler_rt_args = base_cmake_args + [
'-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cxxflags),
'-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(ldflags),
'-DCOMPILER_RT_BUILD_BUILTINS=OFF',
'-DCOMPILER_RT_BUILD_CRT=OFF',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=ON',
'-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
# The libxml2 we built above is 64-bit. Since it's only needed by
# lld-link and not compiler-rt, just turn it off down here.
'-DLLVM_ENABLE_LIBXML2=OFF',
]
RunCommand(['cmake'] + compiler_rt_args +
[os.path.join(LLVM_DIR, 'llvm')],
msvc_arch='x86', env=deployment_env)
RunCommand(['ninja', 'compiler-rt'], msvc_arch='x86')
# Copy select output to the main tree.
rt_lib_src_dir = os.path.join(compiler_rt_build_dir, 'lib', 'clang',
RELEASE_VERSION, 'lib', rt_platform)
# Static and dynamic libraries:
CopyDirectoryContents(rt_lib_src_dir, rt_lib_dst_dir)
if args.with_android:
# TODO(thakis): Now that the NDK uses clang, try to build all archs in
# one LLVM build instead of building 3 times.
toolchain_dir = ANDROID_NDK_DIR + '/toolchains/llvm/prebuilt/linux-x86_64'
for target_arch in ['aarch64', 'arm', 'i686', 'x86_64']:
# Build compiler-rt runtimes needed for Android in a separate build tree.
build_dir = os.path.join(LLVM_BUILD_DIR, 'android-' + target_arch)
if not os.path.exists(build_dir):
os.mkdir(os.path.join(build_dir))
os.chdir(build_dir)
target_triple = target_arch
if target_arch == 'arm':
target_triple = 'armv7'
api_level = '19'
if target_arch == 'aarch64' or target_arch == 'x86_64':
api_level = '21'
target_triple += '-linux-android' + api_level
cflags = [
'--target=' + target_triple,
'--sysroot=%s/sysroot' % toolchain_dir,
# pylint: disable=line-too-long
# android_ndk/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/ld
# depends on a newer version of libxml2.so than what's available on
# the bots. To make things work, use our just-built lld as linker.
# pylint: enable=line-too-long
'-fuse-ld=lld',
# We don't have an unwinder ready, and don't need it either.
'--unwindlib=none',
]
if target_arch == 'aarch64':
# Use PAC/BTI instructions for AArch64
cflags += [ '-mbranch-protection=standard' ]
android_args = base_cmake_args + [
'-DCMAKE_C_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang'),
'-DCMAKE_CXX_COMPILER=' + os.path.join(LLVM_BUILD_DIR, 'bin/clang++'),
'-DLLVM_CONFIG_PATH=' + os.path.join(LLVM_BUILD_DIR, 'bin/llvm-config'),
'-DCMAKE_C_FLAGS=' + ' '.join(cflags),
'-DCMAKE_CXX_FLAGS=' + ' '.join(cflags),
'-DCMAKE_ASM_FLAGS=' + ' '.join(cflags),
'-DCOMPILER_RT_BUILD_BUILTINS=ON',
'-DCOMPILER_RT_BUILD_CRT=OFF',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=OFF',
'-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
'-DSANITIZER_CXX_ABI=libcxxabi',
'-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle',
'-DANDROID=1'
# 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_CXX_COMPILER_WORKS=ON',
'-DCMAKE_C_COMPILER_WORKS=ON',
'-DCMAKE_ASM_COMPILER_WORKS=ON',
]
# First build the builtins and copy to the main build tree.
RunCommand(
['cmake'] + android_args +
# On Android, we want DWARF info for the builtins for
# unwinding. See crbug.com/1311807.
['-DCMAKE_BUILD_TYPE=RelWithDebInfo'] +
[os.path.join(COMPILER_RT_DIR, 'lib', 'builtins')])
builtins_a = 'lib/linux/libclang_rt.builtins-%s-android.a' % target_arch
RunCommand(['ninja', builtins_a])
shutil.copy(builtins_a, rt_lib_dst_dir)
# With the builtins in place, we can build the other runtimes.
build_dir_2 = build_dir + '-phase2'
if not os.path.exists(build_dir_2):
os.mkdir(os.path.join(build_dir_2))
os.chdir(build_dir_2)
android_args.extend([
'-DCOMPILER_RT_BUILD_BUILTINS=OFF',
'-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON',
'-DCOMPILER_RT_BUILD_PROFILE=ON',
'-DCOMPILER_RT_BUILD_SANITIZERS=ON',
])
RunCommand(['cmake'] + android_args + [COMPILER_RT_DIR])
libs_want = [
'lib/linux/libclang_rt.asan-{0}-android.so',
'lib/linux/libclang_rt.asan_static-{0}-android.a',
'lib/linux/libclang_rt.ubsan_standalone-{0}-android.so',
'lib/linux/libclang_rt.profile-{0}-android.a',
]
# Only build HWASan for AArch64.
if target_arch == 'aarch64':
libs_want += ['lib/linux/libclang_rt.hwasan-{0}-android.so']
libs_want = [lib.format(target_arch) for lib in libs_want]
RunCommand(['ninja'] + libs_want)
# And copy them into the main build tree.
for p in libs_want:
shutil.copy(p, 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 + '-unknown-fuchsia'
if args.build_mac_arm:
# Just-built clang can't run (it's an arm binary on an intel host), so
# use the bootstrap compiler instead.
host_path = LLVM_BOOTSTRAP_INSTALL_DIR
else:
host_path = LLVM_BUILD_DIR
# TODO(thakis): Might have to pass -B here once sysroot contains
# binaries (e.g. gas for arm64?)
fuchsia_args = base_cmake_args + [
'-DCMAKE_C_COMPILER=' + os.path.join(host_path, 'bin/clang'),
'-DCMAKE_CXX_COMPILER=' + os.path.join(host_path, 'bin/clang++'),
'-DCMAKE_LINKER=' + os.path.join(host_path, 'bin/clang'),
'-DCMAKE_AR=' + os.path.join(host_path, 'bin/llvm-ar'),
'-DLLVM_CONFIG_PATH=' + os.path.join(host_path, 'bin/llvm-config'),
'-DCMAKE_SYSTEM_NAME=Fuchsia',
'-DCMAKE_CXX_COMPILER_TARGET=' + target_spec,
'-DCMAKE_C_COMPILER_TARGET=' + target_spec,
'-DCMAKE_ASM_COMPILER_TARGET=' + target_spec,
'-DCOMPILER_RT_BUILD_BUILTINS=ON',
'-DCOMPILER_RT_BUILD_CRT=OFF',
'-DCOMPILER_RT_BUILD_LIBFUZZER=OFF',
'-DCOMPILER_RT_BUILD_MEMPROF=OFF',
'-DCOMPILER_RT_BUILD_ORC=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=OFF',
'-DCOMPILER_RT_BUILD_SANITIZERS=OFF',
'-DCOMPILER_RT_BUILD_XRAY=OFF',
'-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_CXX_COMPILER_WORKS=ON',
'-DCMAKE_C_COMPILER_WORKS=ON',
'-DCMAKE_ASM_COMPILER_WORKS=ON',
]
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',
RELEASE_VERSION, 'lib', target_spec)
if not os.path.exists(fuchsia_lib_dst_dir):
os.makedirs(fuchsia_lib_dst_dir)
CopyFile(os.path.join(build_dir, 'lib', target_spec, builtins_a),
fuchsia_lib_dst_dir)
# Build the Fuchsia profile and asan runtimes. This is done after the rt
# builtins have been created because the CMake build runs link checks that
# require that the builtins already exist to succeed.
# TODO(thakis): Figure out why this doesn't build with the stage0
# compiler in arm cross builds.
if target_arch == 'x86_64' and not args.build_mac_arm:
fuchsia_args.extend([
'-DCOMPILER_RT_BUILD_BUILTINS=OFF',
'-DCOMPILER_RT_BUILD_PROFILE=ON',
])
# Build the asan runtime only on non-Mac platforms. Macs are excluded
# because the asan install changes library RPATHs which CMake only
# supports on ELF platforms and MacOS uses Mach-O instead of ELF.
if sys.platform != 'darwin':
fuchsia_args.extend([
'-DCOMPILER_RT_BUILD_SANITIZERS=ON',
'-DSANITIZER_NO_UNDEFINED_SYMBOLS=OFF',
])
build_phase2_dir = os.path.join(LLVM_BUILD_DIR,
'fuchsia-phase2-' + target_arch)
if not os.path.exists(build_phase2_dir):
os.mkdir(os.path.join(build_phase2_dir))
os.chdir(build_phase2_dir)
RunCommand(['cmake'] +
fuchsia_args +
[COMPILER_RT_DIR])
profile_a = 'libclang_rt.profile.a'
asan_preinit_a = 'libclang_rt.asan-preinit.a'
asan_static_a = 'libclang_rt.asan_static.a'
asan_so = 'libclang_rt.asan.so'
ninja_command = ['ninja', profile_a]
if sys.platform != 'darwin':
ninja_command.append(asan_so)
ninja_command.append(asan_preinit_a)
ninja_command.append(asan_static_a)
RunCommand(ninja_command)
CopyFile(os.path.join(build_phase2_dir, 'lib', target_spec, profile_a),
fuchsia_lib_dst_dir)
if sys.platform != 'darwin':
CopyFile(os.path.join(build_phase2_dir, 'lib', target_spec, asan_so),
fuchsia_lib_dst_dir)
CopyFile(
os.path.join(build_phase2_dir, 'lib', target_spec,
asan_preinit_a), fuchsia_lib_dst_dir)
CopyFile(
os.path.join(build_phase2_dir, 'lib', target_spec, asan_static_a),
fuchsia_lib_dst_dir)
# Run tests. # Run tests.
if (not args.build_mac_arm and if (not args.build_mac_arm and
(args.run_tests or args.llvm_force_head_revision)): (args.run_tests or args.llvm_force_head_revision)):
RunCommand(['ninja', '-C', LLVM_BUILD_DIR, 'cr-check-all'], msvc_arch='x64') RunCommand(['ninja', '-C', LLVM_BUILD_DIR, 'cr-check-all'], msvc_arch='x64')
if not args.build_mac_arm and args.run_tests: if not args.build_mac_arm and args.run_tests:
test_targets = [ 'check-all' ] env = None
if sys.platform == 'darwin': if sys.platform.startswith('linux'):
# TODO(thakis): Run check-all on Darwin too, https://crbug.com/959361 env = os.environ.copy()
test_targets = [ 'check-llvm', 'check-clang', 'check-lld' ] # See SANITIZER_OVERRIDE_INTERCEPTORS above: We disable crypt_r()
RunCommand(['ninja', '-C', LLVM_BUILD_DIR] + test_targets, msvc_arch='x64') # interception, so its tests can't pass.
env['LIT_FILTER_OUT'] = ('^SanitizerCommon-(a|l|m|ub|t)san-x86_64-Linux' +
' :: Linux/crypt_r.cpp$')
RunCommand(['ninja', '-C', LLVM_BUILD_DIR, 'check-all'],
env=env,
msvc_arch='x64')
WriteStampFile(PACKAGE_VERSION, STAMP_FILE) WriteStampFile(PACKAGE_VERSION, STAMP_FILE)
WriteStampFile(PACKAGE_VERSION, FORCE_HEAD_REVISION_FILE) WriteStampFile(PACKAGE_VERSION, FORCE_HEAD_REVISION_FILE)