diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py index 6ad0abd..5aa6520 100755 --- a/tools/clang/scripts/update.py +++ b/tools/clang/scripts/update.py
@@ -27,7 +27,7 @@ # Do NOT CHANGE this if you don't know what you're doing -- see # https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang.md # Reverting problematic clang rolls is safe, though. -CLANG_REVISION = '337439' +CLANG_REVISION = '344066' use_head_revision = bool(os.environ.get('LLVM_FORCE_HEAD_REVISION', '0') in ('1', 'YES')) @@ -68,9 +68,11 @@ os.path.join(LLVM_DIR, '..', 'llvm-build-tools')) STAMP_FILE = os.path.normpath( os.path.join(LLVM_DIR, '..', 'llvm-build', 'cr_build_revision')) -VERSION = '7.0.0' +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', @@ -307,18 +309,6 @@ f.write('endif (CHROMIUM_TOOLS_SRC)\n') -def DownloadHostGcc(args): - """Downloads gcc 4.8.5 and makes sure args.gcc_toolchain is set.""" - if not sys.platform.startswith('linux') or args.gcc_toolchain: - return - gcc_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gcc485precise') - if not os.path.exists(gcc_dir): - print 'Downloading pre-built GCC 4.8.5...' - DownloadAndUnpack( - CDS_URL + '/tools/gcc485precise.tgz', LLVM_BUILD_TOOLS_DIR) - args.gcc_toolchain = gcc_dir - - def AddSvnToPathOnWin(): """Download svn.exe and add it to PATH.""" if sys.platform != 'win32': @@ -334,14 +324,18 @@ """Download CMake and add it to PATH.""" if args.use_system_cmake: return + if sys.platform == 'win32': - zip_name = 'cmake-3.4.3-win32-x86.zip' - cmake_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, - 'cmake-3.4.3-win32-x86', 'bin') + zip_name = 'cmake-3.12.1-win32-x86.zip' + dir_name = ['cmake-3.12.1-win32-x86', 'bin'] + elif sys.platform == 'darwin': + zip_name = 'cmake-3.12.1-Darwin-x86_64.tar.gz' + dir_name = ['cmake-3.12.1-Darwin-x86_64', 'CMake.app', 'Contents', 'bin'] else: - suffix = 'Darwin' if sys.platform == 'darwin' else 'Linux' - zip_name = 'cmake343_%s.tgz' % suffix - cmake_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'cmake343', 'bin') + zip_name = 'cmake-3.12.1-Linux-x86_64.tar.gz' + dir_name = ['cmake-3.12.1-Linux-x86_64', 'bin'] + + cmake_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, *dir_name) if not os.path.exists(cmake_dir): DownloadAndUnpack(CDS_URL + '/tools/' + zip_name, LLVM_BUILD_TOOLS_DIR) os.environ['PATH'] = cmake_dir + os.pathsep + os.environ.get('PATH', '') @@ -353,7 +347,7 @@ return gnuwin_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gnuwin') - GNUWIN_VERSION = '7' + GNUWIN_VERSION = '8' GNUWIN_STAMP = os.path.join(gnuwin_dir, 'stamp') if ReadStampFile(GNUWIN_STAMP) == GNUWIN_VERSION: print 'GNU Win tools already up to date.' @@ -491,17 +485,18 @@ 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 - if use_head_revision: - # TODO(hans): Trunk version was updated; remove after the next roll. - # Remove the old lib dir. - old_lib_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', '7.0.0') - if (os.path.isdir(old_lib_dir)): - print 'Removing old lib dir: %s' % old_lib_dir - RmTree(old_lib_dir) - - DownloadHostGcc(args) AddCMakeToPath(args) AddGnuWinToPath() @@ -514,21 +509,6 @@ cc, cxx = None, None libstdcpp = None - if args.gcc_toolchain: # This option is only used on Linux. - # Use the specified gcc installation for building. - cc = os.path.join(args.gcc_toolchain, 'bin', 'gcc') - cxx = os.path.join(args.gcc_toolchain, 'bin', 'g++') - - if not os.access(cc, os.X_OK): - print 'Invalid --gcc-toolchain: "%s"' % args.gcc_toolchain - print '"%s" does not appear to be valid.' % cc - return 1 - - # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap - # compiler, etc.) find the .so. - libstdcpp = subprocess.check_output( - [cxx, '-print-file-name=libstdc++.so.6']).rstrip() - os.environ['LD_LIBRARY_PATH'] = os.path.dirname(libstdcpp) cflags = [] cxxflags = [] @@ -578,11 +558,6 @@ cc = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang') cxx = os.path.join(LLVM_BOOTSTRAP_INSTALL_DIR, 'bin', 'clang++') - if args.gcc_toolchain: - # Tell the bootstrap compiler to use a specific gcc prefix to search - # for standard library headers and shared object files. - cflags = ['--gcc-toolchain=' + args.gcc_toolchain] - cxxflags = ['--gcc-toolchain=' + args.gcc_toolchain] print 'Building final compiler' # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is @@ -827,6 +802,7 @@ '-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), '-DSANITIZER_CXX_ABI=none', '-DSANITIZER_CXX_ABI_LIBRARY=' + abi_libs, '-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-u__cxa_demangle', @@ -836,8 +812,9 @@ RunCommand(['ninja', 'asan', 'ubsan', 'profile']) # And copy them into the main build tree. + asan_lib_path_format = 'lib/linux/libclang_rt.asan-{0}-android.so' libs_want = [ - 'lib/linux/libclang_rt.asan-{0}-android.so', + asan_lib_path_format, 'lib/linux/libclang_rt.ubsan_standalone-{0}-android.so', 'lib/linux/libclang_rt.profile-{0}-android.a', ] @@ -847,6 +824,62 @@ if os.path.exists(lib_path): shutil.copy(lib_path, rt_lib_dst_dir) + # We also use ASan i686 build for fuzzing. + lib_path = os.path.join(build_dir, asan_lib_path_format.format('i686')) + 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) @@ -862,6 +895,15 @@ return 0 +def gn_arg(v): + if v == 'True': + return True + if v == 'False': + return False + raise argparse.ArgumentTypeError('Expected one of %r or %r' % ( + 'True', 'False')) + + def main(): parser = argparse.ArgumentParser(description='Build Clang.') parser.add_argument('--bootstrap', action='store_true', @@ -896,10 +938,16 @@ 'and using prebuilt cmake binaries') parser.add_argument('--verify-version', help='verify that clang has the passed-in version') + parser.add_argument('--with-android', type=gn_arg, nargs='?', const=True, + help='build the Android ASan runtime (linux only)', + default=sys.platform.startswith('linux')) parser.add_argument('--without-android', action='store_false', help='don\'t build Android ASan runtime (linux only)', - dest='with_android', - default=sys.platform.startswith('linux')) + dest='with_android') + 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: @@ -949,9 +997,8 @@ PACKAGE_VERSION = CLANG_REVISION + '-0' args.force_local_build = True - 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)