Bug 1551690 - be more specific about the LLVM target on OS X; r=nalexander
☠☠ backed out by 6cead9170981 ☠ ☠
authorNathan Froyd <froydnj@mozilla.com>
Tue, 21 May 2019 13:48:23 +0000
changeset 474750 ae7096d1add7bc70cd996485b423a18fe287a4e3
parent 474749 86e4c72840f20e7b524c001ef6b960f0bf9410ac
child 474751 c19e86931d1a72f32f5cd239998abdc00fdb3c1c
push id36046
push useraiakab@mozilla.com
push dateTue, 21 May 2019 21:45:52 +0000
treeherdermozilla-central@257f2c96cef5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1551690
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551690 - be more specific about the LLVM target on OS X; r=nalexander Our current OS X builds use `--target=x86_64-darwin11` (which corresponds to OS X 10.7). This target is problematic for two reasons: * We're actually targeting for OS X 10.9 (`MACOSX_DEPLOYMENT_TARGET`); * It's slightly different from the default Rust target. Let's address these problems in reverse order: differences from the Rust target are bad, because the `--target` we provide to `clang` and the Rust target find their way into LLVM bitcode files and the linker will refuse to link together bitcode files that have incompatible targets. Why are the two incompatible? The current `--target` doesn't have a "vendor" in triple-speak, whereas the Rust one has "apple" as the vendor (`x86_64-apple-darwin`) We therefore need to change the `--target` we pass to `clang` to have a vendor of "apple". This need is behind the {init,toolchain}.configure changes, but it has ramifications elsewhere, because `clang` looks for `--target`-prefixed build tools. So we have to change the `--target` for cctools to get the right tool prefixes and we have to change the `--target` for building clang ourselves so that *those* builds can find the newly renamed cctools. Once we've done, that's really enough; we don't *need to address the first problem: While the `--target` might be `x86_64-apple-darwin11`, both `clang` and `rustc` will dynamically choose the target triple that eventually lands in LLVM bitcode files based on `MACOSX_DEPLOYMENT_TARGET`, which we set in all builds. But the current target is slightly misleading, and the cctools don't need to be prefixed with a particular Darwin version, since they work for all Darwin targets. Let's just drop the "11" from the `--target` and eliminate a little bit of confusion. Differential Revision: https://phabricator.services.mozilla.com/D31128
build/build-clang/build-clang.py
build/build-clang/clang-8-macosx64.json
build/build-clang/clang-tidy-macosx64.json
build/build-clang/compiler-rt-cross-compile.patch
build/macosx/cross-mozconfig.common
build/moz.configure/init.configure
python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
taskcluster/scripts/misc/build-cctools-port.sh
--- a/build/build-clang/build-clang.py
+++ b/build/build-clang/build-clang.py
@@ -289,17 +289,17 @@ def build_one_stage(cc, cxx, asm, ld, ar
                 "-DCMAKE_FIND_ROOT_PATH=%s" % slashify_path(os.getenv("CROSS_CCTOOLS_PATH")), # noqa
                 "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER",
                 "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY",
                 "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY",
                 "-DCMAKE_MACOSX_RPATH=ON",
                 "-DCMAKE_OSX_ARCHITECTURES=x86_64",
                 "-DDARWIN_osx_ARCHS=x86_64",
                 "-DDARWIN_osx_SYSROOT=%s" % slashify_path(os.getenv("CROSS_SYSROOT")),
-                "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-darwin11"
+                "-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-apple-darwin"
             ]
         return cmake_args
 
     cmake_args = []
 
     runtime_targets = []
     if is_final_stage:
         if android_targets:
@@ -781,17 +781,17 @@ if __name__ == "__main__":
 
     if osx_cross_compile:
         # undo the damage done in the is_linux() block above, and also simulate
         # the is_darwin() block above.
         extra_cflags = []
         extra_cxxflags = ["-stdlib=libc++"]
         extra_cxxflags2 = ["-stdlib=libc++"]
 
-        extra_flags = ["-target", "x86_64-darwin11", "-mlinker-version=137",
+        extra_flags = ["-target", "x86_64-apple-darwin", "-mlinker-version=137",
                        "-B", "%s/bin" % os.getenv("CROSS_CCTOOLS_PATH"),
                        "-isysroot", os.getenv("CROSS_SYSROOT"),
                        # technically the sysroot flag there should be enough to deduce this,
                        # but clang needs some help to figure this out.
                        "-I%s/usr/include" % os.getenv("CROSS_SYSROOT"),
                        "-iframework", "%s/System/Library/Frameworks" % os.getenv("CROSS_SYSROOT")]
         extra_cflags += extra_flags
         extra_cxxflags += extra_flags
--- a/build/build-clang/clang-8-macosx64.json
+++ b/build/build-clang/clang-8-macosx64.json
@@ -11,19 +11,19 @@
     "compiler_repo": "https://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_800/final",
     "libcxx_repo": "https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_800/final",
     "libcxxabi_repo": "https://llvm.org/svn/llvm-project/libcxxabi/tags/RELEASE_800/final",
     "python_path": "/usr/bin/python2.7",
     "gcc_dir": "/builds/worker/workspace/build/src/gcc",
     "cc": "/builds/worker/workspace/build/src/clang/bin/clang",
     "cxx": "/builds/worker/workspace/build/src/clang/bin/clang++",
     "as": "/builds/worker/workspace/build/src/clang/bin/clang",
-    "ar": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-ar",
-    "ranlib": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-ranlib",
-    "libtool": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-libtool",
+    "ar": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-ar",
+    "ranlib": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-ranlib",
+    "libtool": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-libtool",
     "ld": "/builds/worker/workspace/build/src/clang/bin/clang",
     "patches": [
       "static-llvm-symbolizer.patch",
       "rename_gcov_flush.patch",
       "compiler-rt-cross-compile.patch",
       "compiler-rt-no-codesign.patch"
     ]
 }
--- a/build/build-clang/clang-tidy-macosx64.json
+++ b/build/build-clang/clang-tidy-macosx64.json
@@ -11,16 +11,16 @@
     "extra_repo": "https://llvm.org/svn/llvm-project/clang-tools-extra/tags/RELEASE_800/final",
     "libcxx_repo": "https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_800/final",
     "libcxxabi_repo": "https://llvm.org/svn/llvm-project/libcxxabi/tags/RELEASE_800/final",
     "python_path": "/usr/bin/python2.7",
     "gcc_dir": "/builds/worker/workspace/build/src/gcc",
     "cc": "/builds/worker/workspace/build/src/clang/bin/clang",
     "cxx": "/builds/worker/workspace/build/src/clang/bin/clang++",
     "as": "/builds/worker/workspace/build/src/clang/bin/clang",
-    "ar": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-ar",
-    "ranlib": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-ranlib",
-    "libtool": "/builds/worker/workspace/build/src/cctools/bin/x86_64-darwin11-libtool",
+    "ar": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-ar",
+    "ranlib": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-ranlib",
+    "libtool": "/builds/worker/workspace/build/src/cctools/bin/x86_64-apple-darwin-libtool",
     "ld": "/builds/worker/workspace/build/src/clang/bin/clang",
     "patches": [
       "clang-tidy-8.patch"
     ]
 }
--- a/build/build-clang/compiler-rt-cross-compile.patch
+++ b/build/build-clang/compiler-rt-cross-compile.patch
@@ -1,15 +1,15 @@
-Add `-target x86_64-darwin11' to the compiler-rt overridden CFLAGS
+Add `-target x86_64-apple-darwin' to the compiler-rt overridden CFLAGS
 
 diff --git a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
 index 28d398672..aac68bf36 100644
 --- a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
 +++ b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
 @@ -265,7 +265,7 @@ endfunction()
  macro(darwin_add_builtin_libraries)
    set(DARWIN_EXCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Darwin-excludes)
  
 -  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer")
-+  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer -target x86_64-darwin11 -isysroot ${CMAKE_OSX_SYSROOT} -I${CMAKE_OSX_SYSROOT}/usr/include")
++  set(CFLAGS "-fPIC -O3 -fvisibility=hidden -DVISIBILITY_HIDDEN -Wall -fomit-frame-pointer -target x86_64-apple-darwin -isysroot ${CMAKE_OSX_SYSROOT} -I${CMAKE_OSX_SYSROOT}/usr/include")
    set(CMAKE_C_FLAGS "")
    set(CMAKE_CXX_FLAGS "")
    set(CMAKE_ASM_FLAGS "")
--- a/build/macosx/cross-mozconfig.common
+++ b/build/macosx/cross-mozconfig.common
@@ -32,17 +32,17 @@ mk_add_options "export REAL_DSYMUTIL=$to
 export MKFSHFS=$topsrcdir/hfsplus-tools/newfs_hfs
 export DMG_TOOL=$topsrcdir/dmg/dmg
 export HFS_TOOL=$topsrcdir/dmg/hfsplus
 
 export HOST_CFLAGS="-g"
 export HOST_CXXFLAGS="-g"
 export HOST_LDFLAGS="-g"
 
-ac_add_options --target=x86_64-apple-darwin11
+ac_add_options --target=x86_64-apple-darwin
 export MACOS_SDK_DIR=$CROSS_SYSROOT
 export MACOS_PRIVATE_FRAMEWORKS_DIR=$CROSS_PRIVATE_FRAMEWORKS
 
 if [ "x$MOZ_PKG_SPECIAL" != "xasan" -a -z "$MOZ_AUTOMATION_ARTIFACT_BUILDS" ]; then
   # Enable static analysis checks by default on OSX cross builds.
   # Exception is ASan, where this breaks.
   # The option is not valid on artifact builds, so don't add it there either.
   ac_add_options --enable-clang-plugin
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -745,28 +745,35 @@ def split_triplet(triplet, allow_unknown
         except (KeyError, ValueError):
             if allow_unknown:
                 return value
             raise
 
     def bitness(cpu):
         return CPU_bitness[cpu]
 
+    # Toolchains, most notably for cross compilation may use cpu-os
+    # prefixes. We need to be more specific about the LLVM target on Mac
+    # so cross-language LTO will work correctly.
+
+    if os.startswith('darwin'):
+        toolchain = '%s-apple-%s' % (cpu, os)
+    else:
+        toolchain = '%s-%s' % (cpu, os)
+
     return namespace(
         alias=triplet,
         cpu=sanitize(CPU, canonical_cpu),
         bitness=sanitize(bitness, canonical_cpu),
         kernel=sanitize(Kernel, canonical_kernel),
         os=sanitize(OS, canonical_os),
         endianness=sanitize(Endianness, endianness),
         raw_cpu=cpu,
         raw_os=os,
-        # Toolchains, most notably for cross compilation may use cpu-os
-        # prefixes.
-        toolchain='%s-%s' % (cpu, os),
+        toolchain=toolchain,
     )
 
 
 # This defines a fake target/host namespace for when running with --help
 # If either --host or --target is passed on the command line, then fall
 # back to the real deal.
 @depends('--help', '--host', '--target')
 def help_host_target(help, host, target):
--- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -201,19 +201,19 @@ CLANGXX_3_6 = CLANGXX('3.6.2') + {
 }
 DEFAULT_CLANG = CLANG_3_6
 DEFAULT_CLANGXX = CLANGXX_3_6
 
 
 def CLANG_PLATFORM(gcc_platform):
     base = {
         '--target=x86_64-linux-gnu': GCC_PLATFORM_X86_64_LINUX[None],
-        '--target=x86_64-darwin11.2.0': GCC_PLATFORM_X86_64_OSX[None],
+        '--target=x86_64-apple-darwin11.2.0': GCC_PLATFORM_X86_64_OSX[None],
         '--target=i686-linux-gnu': GCC_PLATFORM_X86_LINUX[None],
-        '--target=i686-darwin11.2.0': GCC_PLATFORM_X86_OSX[None],
+        '--target=i686-apple-darwin11.2.0': GCC_PLATFORM_X86_OSX[None],
         '--target=arm-linux-gnu': GCC_PLATFORM_ARM_LINUX[None],
     }
     undo_gcc_platform = {
         k: {symbol: False for symbol in gcc_platform[None]}
         for k in base
     }
     return FakeCompiler(gcc_platform, undo_gcc_platform, base)
 
@@ -1327,20 +1327,20 @@ class OSXCrossToolchainTest(BaseToolchai
     TARGET = 'i686-apple-darwin11.2.0'
     PATHS = LinuxToolchainTest.PATHS
     DEFAULT_CLANG_RESULT = LinuxToolchainTest.DEFAULT_CLANG_RESULT
     DEFAULT_CLANGXX_RESULT = LinuxToolchainTest.DEFAULT_CLANGXX_RESULT
 
     def test_osx_cross(self):
         self.do_toolchain_test(self.PATHS, {
             'c_compiler': self.DEFAULT_CLANG_RESULT + {
-                'flags': ['--target=i686-darwin11.2.0'],
+                'flags': ['--target=i686-apple-darwin11.2.0'],
             },
             'cxx_compiler': self.DEFAULT_CLANGXX_RESULT + {
-                'flags': ['--target=i686-darwin11.2.0'],
+                'flags': ['--target=i686-apple-darwin11.2.0'],
             },
             'host_c_compiler': self.DEFAULT_CLANG_RESULT,
             'host_cxx_compiler': self.DEFAULT_CLANGXX_RESULT,
         }, environ={
             'CC': 'clang',
         })
 
     def test_cannot_osx_cross(self):
--- a/taskcluster/scripts/misc/build-cctools-port.sh
+++ b/taskcluster/scripts/misc/build-cctools-port.sh
@@ -37,21 +37,21 @@ cd $WORKSPACE/build/src
 . taskcluster/scripts/misc/tooltool-download.sh
 
 # Configure crosstools-port
 cd $CROSSTOOLS_CCTOOLS_DIR
 export CC=$CLANG_DIR/bin/clang
 export CXX=$CLANG_DIR/bin/clang++
 export LDFLAGS="-lpthread -Wl,-rpath-link,$CLANG_DIR/lib"
 ./autogen.sh
-./configure --prefix=$CROSSTOOLS_BUILD_DIR --target=x86_64-darwin11 --with-llvm-config=$CLANG_DIR/bin/llvm-config
+./configure --prefix=$CROSSTOOLS_BUILD_DIR --target=x86_64-apple-darwin --with-llvm-config=$CLANG_DIR/bin/llvm-config
 
 # Build cctools
 make -j `nproc --all` install
 strip $CROSSTOOLS_BUILD_DIR/bin/*
 # cctools-port doesn't include dsymutil but clang will need to find it.
-cp $CLANG_DIR/bin/dsymutil $CROSSTOOLS_BUILD_DIR/bin/x86_64-darwin11-dsymutil
+cp $CLANG_DIR/bin/dsymutil $CROSSTOOLS_BUILD_DIR/bin/x86_64-apple-darwin-dsymutil
 # various build scripts based on cmake want to find `lipo` without a prefix
-cp $CROSSTOOLS_BUILD_DIR/bin/x86_64-darwin11-lipo $CROSSTOOLS_BUILD_DIR/bin/lipo
+cp $CROSSTOOLS_BUILD_DIR/bin/x86_64-apple-darwin-lipo $CROSSTOOLS_BUILD_DIR/bin/lipo
 
 # Put a tarball in the artifacts dir
 mkdir -p $UPLOAD_DIR
 tar cJf $UPLOAD_DIR/cctools.tar.xz -C $CROSSTOOLS_BUILD_DIR/.. `basename $CROSSTOOLS_BUILD_DIR`