From 91536813ec5d159ed4bea857621ed10a1216411a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 27 Aug 2017 02:51:25 -0400 Subject: [PATCH] macos updates * try some macos travis stuff * put c in the link libs for macos since we always link with libSystem * for non-native targets on macos, allow runtime symbol resolution - it's causing an infinite loop in LLD. * for macos, always build compiler_rt and turn on LinkOnce because compiler_rt on darwin is missing some stuff. --- ci/travis_osx_install | 44 ++++---------------------- ci/travis_osx_script | 6 ++-- src/codegen.cpp | 1 + src/link.cpp | 36 +++++++++++++-------- std/special/compiler_rt/comparetf2.zig | 26 ++++++++++++++- std/special/compiler_rt/fixunsdfdi.zig | 1 + std/special/compiler_rt/fixunsdfsi.zig | 1 + std/special/compiler_rt/fixunsdfti.zig | 1 + std/special/compiler_rt/fixunssfdi.zig | 1 + std/special/compiler_rt/fixunssfsi.zig | 1 + std/special/compiler_rt/fixunssfti.zig | 1 + std/special/compiler_rt/fixunstfdi.zig | 1 + std/special/compiler_rt/fixunstfsi.zig | 1 + std/special/compiler_rt/fixunstfti.zig | 1 + std/special/compiler_rt/index.zig | 6 ++++ 15 files changed, 74 insertions(+), 54 deletions(-) diff --git a/ci/travis_osx_install b/ci/travis_osx_install index 747c670a94..bdd4de320e 100755 --- a/ci/travis_osx_install +++ b/ci/travis_osx_install @@ -6,44 +6,14 @@ brew install gcc@7 brew outdated gcc@7 || brew upgrade gcc@7 brew link --overwrite gcc@7 -which gcc -which g++ -which gcc-7 -which g++-7 - SRC_DIR=$(pwd) -PREFIX_DIR=$SRC_DIR/local -export CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 -export CXX=/usr/local/Cellar/gcc/7.2.0/bin/g++-7 +PREFIX_DIR=$HOME/local/llvm5 +export CC=/usr/local/opt/gcc/bin/gcc-7 +export CXX=/usr/local/opt/gcc/bin/g++-7 -wget http://prereleases.llvm.org/5.0.0/rc2/llvm-5.0.0rc2.src.tar.xz -wget http://prereleases.llvm.org/5.0.0/rc2/cfe-5.0.0rc2.src.tar.xz -wget http://prereleases.llvm.org/5.0.0/rc2/lld-5.0.0rc2.src.tar.xz - -ls -ahl /usr/local/opt - -cd $SRC_DIR -tar xf llvm-5.0.0rc2.src.tar.xz -cd llvm-5.0.0rc2.src -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX_DIR -DCMAKE_PREFIX_PATH=$PREFIX_DIR -make install - -cd $SRC_DIR -tar xf lld-5.0.0rc2.src.tar.xz -cd lld-5.0.0rc2.src -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX_DIR -DCMAKE_PREFIX_PATH=$PREFIX_DIR -make install - -cd $SRC_DIR -tar xf cfe-5.0.0rc2.src.tar.xz -cd cfe-5.0.0rc2.src -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PREFIX_DIR -DCMAKE_PREFIX_PATH=$PREFIX_DIR -make install +mkdir -p $HOME/local +cd $HOME/local +wget http://s3.amazonaws.com/superjoe/temp/llvm5.tar.xz +tar xfp llvm5.tar.xz cd $SRC_DIR diff --git a/ci/travis_osx_script b/ci/travis_osx_script index 76c236f8c6..cc21bf819f 100755 --- a/ci/travis_osx_script +++ b/ci/travis_osx_script @@ -2,9 +2,9 @@ set -x -PREFIX_DIR=$(pwd)/local -export CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 -export CXX=/usr/local/Cellar/gcc/7.2.0/bin/g++-7 +PREFIX_DIR=$HOME/local/llvm5 +export CC=/usr/local/opt/gcc/bin/gcc-7 +export CXX=/usr/local/opt/gcc/bin/g++-7 echo $PATH mkdir build diff --git a/src/codegen.cpp b/src/codegen.cpp index 80ea5e6f6d..7ca8abfc5d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -139,6 +139,7 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out g->zig_target.os == ZigLLVM_IOS) { g->libc_link_lib = create_link_lib(buf_create_from_str("c")); + g->link_libs_list.append(g->libc_link_lib); } return g; diff --git a/src/link.cpp b/src/link.cpp index b22b78c4f9..b51fa6e4ca 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -570,7 +570,7 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) { } else if (g->mios_version_min) { platform->kind = IPhoneOS; } else { - zig_panic("unable to infer -macosx-version-min or -mios-version-min"); + zig_panic("unable to infer -mmacosx-version-min or -mios-version-min"); } bool had_extra; @@ -703,20 +703,30 @@ static void construct_linker_job_macho(LinkJob *lj) { lj->args.append((const char *)buf_ptr(g->link_objects.at(i))); } - for (size_t i = 0; i < g->link_libs_list.length; i += 1) { - LinkLib *link_lib = g->link_libs_list.at(i); - if (buf_eql_str(link_lib->name, "c")) { - continue; - } - Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name)); - lj->args.append(buf_ptr(arg)); + // compiler_rt on darwin is missing some stuff, so we still build it and rely on LinkOnce + if (g->out_type == OutTypeExe || g->out_type == OutTypeLib) { + Buf *compiler_rt_o_path = build_compiler_rt(g); + lj->args.append(buf_ptr(compiler_rt_o_path)); } - // on Darwin, libSystem has libc in it, but also you have to use it - // to make syscalls because the syscall numbers are not documented - // and change between versions. - // so we always link against libSystem - lj->args.append("-lSystem"); + if (g->is_native_target) { + for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { + LinkLib *link_lib = g->link_libs_list.at(lib_i); + if (buf_eql_str(link_lib->name, "c")) { + // on Darwin, libSystem has libc in it, but also you have to use it + // to make syscalls because the syscall numbers are not documented + // and change between versions. + // so we always link against libSystem + lj->args.append("-lSystem"); + } else { + Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name)); + lj->args.append(buf_ptr(arg)); + } + } + } else { + lj->args.append("-undefined"); + lj->args.append("dynamic_lookup"); + } if (platform.kind == MacOS) { if (darwin_version_lt(&platform, 10, 5)) { diff --git a/std/special/compiler_rt/comparetf2.zig b/std/special/compiler_rt/comparetf2.zig index ebd629cac9..d7c33c6b9f 100644 --- a/std/special/compiler_rt/comparetf2.zig +++ b/std/special/compiler_rt/comparetf2.zig @@ -18,7 +18,13 @@ const significandMask = implicitBit - 1; const exponentMask = absMask ^ significandMask; const infRep = exponentMask; +const builtin = @import("builtin"); +const is_test = builtin.is_test; + export fn __letf2(a: f128, b: f128) -> c_int { + @setDebugSafety(this, is_test); + @setGlobalLinkage(__letf2, builtin.GlobalLinkage.LinkOnce); + const aInt = @bitCast(rep_t, a); const bInt = @bitCast(rep_t, b); @@ -58,7 +64,11 @@ export fn __letf2(a: f128, b: f128) -> c_int { // Alias for libgcc compatibility // TODO https://github.com/zig-lang/zig/issues/420 -export fn __cmptf2(a: f128, b: f128) -> c_int { __letf2(a, b) } +export fn __cmptf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__cmptf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); + return __letf2(a, b); +} // TODO https://github.com/zig-lang/zig/issues/305 // and then make the return types of some of these functions the enum instead of c_int @@ -68,6 +78,9 @@ const GE_GREATER = c_int(1); const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED export fn __getf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__getf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); + const aInt = @bitCast(srep_t, a); const bInt = @bitCast(srep_t, b); const aAbs = @bitCast(rep_t, aInt) & absMask; @@ -95,6 +108,9 @@ export fn __getf2(a: f128, b: f128) -> c_int { } export fn __unordtf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__unordtf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); + const aAbs = @bitCast(rep_t, a) & absMask; const bAbs = @bitCast(rep_t, b) & absMask; return c_int(aAbs > infRep or bAbs > infRep); @@ -103,17 +119,25 @@ export fn __unordtf2(a: f128, b: f128) -> c_int { // The following are alternative names for the preceding routines. export fn __eqtf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__eqtf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); return __letf2(a, b); } export fn __lttf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__lttf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); return __letf2(a, b); } export fn __netf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__netf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); return __letf2(a, b); } export fn __gttf2(a: f128, b: f128) -> c_int { + @setGlobalLinkage(__gttf2, builtin.GlobalLinkage.LinkOnce); + @setDebugSafety(this, is_test); return __getf2(a, b); } diff --git a/std/special/compiler_rt/fixunsdfdi.zig b/std/special/compiler_rt/fixunsdfdi.zig index 1256e8ce7a..5aeeb4291d 100644 --- a/std/special/compiler_rt/fixunsdfdi.zig +++ b/std/special/compiler_rt/fixunsdfdi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunsdfdi(a: f64) -> u64 { + @setGlobalLinkage(__fixunsdfdi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f64, u64, a); } diff --git a/std/special/compiler_rt/fixunsdfsi.zig b/std/special/compiler_rt/fixunsdfsi.zig index bb5b651221..a4e1a6053c 100644 --- a/std/special/compiler_rt/fixunsdfsi.zig +++ b/std/special/compiler_rt/fixunsdfsi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunsdfsi(a: f64) -> u32 { + @setGlobalLinkage(__fixunsdfsi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f64, u32, a); } diff --git a/std/special/compiler_rt/fixunsdfti.zig b/std/special/compiler_rt/fixunsdfti.zig index 17866f2873..d8f653c023 100644 --- a/std/special/compiler_rt/fixunsdfti.zig +++ b/std/special/compiler_rt/fixunsdfti.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunsdfti(a: f64) -> u128 { + @setGlobalLinkage(__fixunsdfti, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f64, u128, a); } diff --git a/std/special/compiler_rt/fixunssfdi.zig b/std/special/compiler_rt/fixunssfdi.zig index 9e3355c4ff..c1a4bf43c3 100644 --- a/std/special/compiler_rt/fixunssfdi.zig +++ b/std/special/compiler_rt/fixunssfdi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunssfdi(a: f32) -> u64 { + @setGlobalLinkage(__fixunssfdi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f32, u64, a); } diff --git a/std/special/compiler_rt/fixunssfsi.zig b/std/special/compiler_rt/fixunssfsi.zig index 88926e93f3..7478aa307c 100644 --- a/std/special/compiler_rt/fixunssfsi.zig +++ b/std/special/compiler_rt/fixunssfsi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunssfsi(a: f32) -> u32 { + @setGlobalLinkage(__fixunssfsi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f32, u32, a); } diff --git a/std/special/compiler_rt/fixunssfti.zig b/std/special/compiler_rt/fixunssfti.zig index d5ad7cee5d..07a26ac946 100644 --- a/std/special/compiler_rt/fixunssfti.zig +++ b/std/special/compiler_rt/fixunssfti.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunssfti(a: f32) -> u128 { + @setGlobalLinkage(__fixunssfti, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f32, u128, a); } diff --git a/std/special/compiler_rt/fixunstfdi.zig b/std/special/compiler_rt/fixunstfdi.zig index 1d41da2799..54eba35b58 100644 --- a/std/special/compiler_rt/fixunstfdi.zig +++ b/std/special/compiler_rt/fixunstfdi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunstfdi(a: f128) -> u64 { + @setGlobalLinkage(__fixunstfdi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f128, u64, a); } diff --git a/std/special/compiler_rt/fixunstfsi.zig b/std/special/compiler_rt/fixunstfsi.zig index 06a7c3ee33..45315b1fde 100644 --- a/std/special/compiler_rt/fixunstfsi.zig +++ b/std/special/compiler_rt/fixunstfsi.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunstfsi(a: f128) -> u32 { + @setGlobalLinkage(__fixunstfsi, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f128, u32, a); } diff --git a/std/special/compiler_rt/fixunstfti.zig b/std/special/compiler_rt/fixunstfti.zig index b3aab00b04..8937b22249 100644 --- a/std/special/compiler_rt/fixunstfti.zig +++ b/std/special/compiler_rt/fixunstfti.zig @@ -1,6 +1,7 @@ const fixuint = @import("fixuint.zig").fixuint; export fn __fixunstfti(a: f128) -> u128 { + @setGlobalLinkage(__fixunstfti, @import("builtin").GlobalLinkage.LinkOnce); return fixuint(f128, u128, a); } diff --git a/std/special/compiler_rt/index.zig b/std/special/compiler_rt/index.zig index 69b6ebece2..7f11f7ddbf 100644 --- a/std/special/compiler_rt/index.zig +++ b/std/special/compiler_rt/index.zig @@ -23,11 +23,13 @@ const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4; export fn __udivdi3(a: u64, b: u64) -> u64 { @setDebugSafety(this, is_test); + @setGlobalLinkage(__udivdi3, builtin.GlobalLinkage.LinkOnce); return __udivmoddi4(a, b, null); } export fn __umoddi3(a: u64, b: u64) -> u64 { @setDebugSafety(this, is_test); + @setGlobalLinkage(__umoddi3, builtin.GlobalLinkage.LinkOnce); var r: u64 = undefined; _ = __udivmoddi4(a, b, &r); @@ -63,6 +65,7 @@ export nakedcc fn __aeabi_uidivmod() { @setDebugSafety(this, false); if (comptime isArmArch()) { + @setGlobalLinkage(__aeabi_uidivmod, builtin.GlobalLinkage.LinkOnce); asm volatile ( \\ push { lr } \\ sub sp, sp, #4 @@ -80,6 +83,7 @@ export nakedcc fn __aeabi_uidivmod() { export fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 { @setDebugSafety(this, is_test); + @setGlobalLinkage(__udivmodsi4, builtin.GlobalLinkage.LinkOnce); const d = __udivsi3(a, b); *rem = u32(i32(a) -% (i32(d) * i32(b))); @@ -92,12 +96,14 @@ export fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 { export fn __aeabi_uidiv(n: u32, d: u32) -> u32 { @setDebugSafety(this, is_test); + @setGlobalLinkage(__aeabi_uidiv, builtin.GlobalLinkage.LinkOnce); return __udivsi3(n, d); } export fn __udivsi3(n: u32, d: u32) -> u32 { @setDebugSafety(this, is_test); + @setGlobalLinkage(__udivsi3, builtin.GlobalLinkage.LinkOnce); const n_uword_bits: c_uint = u32.bit_count; // special cases