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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nathan Froyd 2019-05-21 17:53:44 +00:00
Родитель fa7002c45d
Коммит 37d0db29a9
13 изменённых файлов: 33 добавлений и 34 удалений

Просмотреть файл

@ -294,7 +294,7 @@ def build_one_stage(cc, cxx, asm, ld, ar, ranlib, libtool,
"-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
@ -786,7 +786,7 @@ if __name__ == "__main__":
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,

Просмотреть файл

@ -16,9 +16,9 @@
"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",

Просмотреть файл

@ -16,9 +16,9 @@
"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"

Просмотреть файл

@ -1,4 +1,4 @@
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
@ -9,7 +9,7 @@ index 28d398672..aac68bf36 100644
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 "")

Просмотреть файл

@ -37,7 +37,7 @@ 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

Просмотреть файл

@ -750,6 +750,15 @@ def split_triplet(triplet, allow_unknown=False):
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),
@ -759,9 +768,7 @@ def split_triplet(triplet, allow_unknown=False):
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,
)

Просмотреть файл

@ -206,9 +206,9 @@ 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 = {
@ -1332,10 +1332,10 @@ class OSXCrossToolchainTest(BaseToolchainTest):
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,

Просмотреть файл

@ -38,7 +38,7 @@ if [ "$TARGET" == "x86_64-apple-darwin" ]; then
export PATH="$PWD/cctools/bin:$PATH"
cat >cross-linker <<EOF
exec $PWD/clang/bin/clang -v \
-fuse-ld=$PWD/cctools/bin/x86_64-darwin11-ld \
-fuse-ld=$PWD/cctools/bin/x86_64-apple-darwin-ld \
-mmacosx-version-min=10.11 \
-target $TARGET \
-B $PWD/cctools/bin \

Просмотреть файл

@ -23,7 +23,7 @@ CLANG_DIR=$WORKSPACE/build/src/clang
CCTOOLS_DIR=$WORKSPACE/build/src/cctools
MACOSX_SDK_DIR=$WORKSPACE/build/src/MacOSX10.11.sdk
TARGET_TRIPLE=x86_64-darwin11
TARGET_TRIPLE=x86_64-apple-darwin
# Create our directories
mkdir -p $CROSSTOOLS_BUILD_DIR

Просмотреть файл

@ -42,15 +42,15 @@ 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

Просмотреть файл

@ -14,7 +14,7 @@ export LD_LIBRARY_PATH=$WORKSPACE/build/src/clang/lib
export CC=$WORKSPACE/build/src/clang/bin/clang
export CXX=$WORKSPACE/build/src/clang/bin/clang++
export AR=$WORKSPACE/build/src/clang/bin/llvm-ar
export CFLAGS="-target x86_64-darwin11 -mlinker-version=137 -B ${CROSS_CCTOOLS_PATH}/bin -isysroot ${CROSS_SYSROOT} -I${CROSS_SYSROOT}/usr/include -iframework ${CROSS_SYSROOT}/System/Library/Frameworks"
export CFLAGS="-target x86_64-apple-darwin -mlinker-version=137 -B ${CROSS_CCTOOLS_PATH}/bin -isysroot ${CROSS_SYSROOT} -I${CROSS_SYSROOT}/usr/include -iframework ${CROSS_SYSROOT}/System/Library/Frameworks"
export CXXFLAGS="-stdlib=libc++ ${CFLAGS}"
export LDFLAGS="${CXXFLAGS} -Wl,-syslibroot,${CROSS_SYSROOT} -Wl,-dead_strip"
@ -34,7 +34,7 @@ cd $WORKSPACE/build/src
# The ninja templates used to bootstrap gn have hard-coded references to
# 'libtool', make sure we find the right one.
ln -s $CROSS_CCTOOLS_PATH/bin/x86_64-darwin11-libtool $CROSS_CCTOOLS_PATH/bin/libtool
ln -s $CROSS_CCTOOLS_PATH/bin/x86_64-apple-darwin-libtool $CROSS_CCTOOLS_PATH/bin/libtool
export PATH=$CROSS_CCTOOLS_PATH/bin:$PATH
. taskcluster/scripts/misc/build-gn-common.sh

Просмотреть файл

@ -20,7 +20,7 @@ MINIDUMP_STACKWALK=minidump_stackwalk
case "$1" in
macosx64)
TOOLCHAINS="cctools rustc clang"
echo ac_add_options --target=x86_64-apple-darwin11 >> .mozconfig
echo ac_add_options --target=x86_64-apple-darwin >> .mozconfig
echo ac_add_options --with-macos-sdk=$WORKSPACE/build/src/MacOSX10.11.sdk >> .mozconfig
;;
mingw32)

8
taskcluster/scripts/misc/wr-macos-cross-build-setup.sh Normal file → Executable file
Просмотреть файл

@ -25,14 +25,6 @@ mv ${TOOLS_DIR}/wrench-deps/{vendor,.cargo} "${GECKO_PATH}/gfx/wr/"
# to make this cross-compile properly.
pushd "${TOOLS_DIR}/cctools/bin"
# Link all the tools from x86_64-darwin11-* to x86_64-apple-darwin-* because
# x86_64-apple-darwin is the Official Rust Triple (TM) and so that's the prefix
# we run configure with, and the toolchain configure/make will look for.
# We can't just rename the files because e.g. the ar tool invokes the ranlib
# tool with the old prefix hard-coded. So we symlink instead.
for TOOL in x86_64-darwin11-*; do
ln -s "${TOOL}" "${TOOL/x86_64-darwin11/${TARGET_TRIPLE}}"
done
# Add a pkg-config cross-compile wrapper. Without this, the configure script
# will use pkg-config from the host, which will find host libraries that are