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 | 46 +++++--------------------- 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, 75 insertions(+), 55 deletions(-) diff --git a/ci/travis_osx_install b/ci/travis_osx_install index 747c670a94339fddd6baa6dd8a0d44880ce48c81..bdd4de320ecae0b32f7dbb3983c5ee58abf129d8 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 - -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 +PREFIX_DIR=$HOME/local/llvm5 +export CC=/usr/local/opt/gcc/bin/gcc-7 +export CXX=/usr/local/opt/gcc/bin/g++-7 + +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 76c236f8c680bead79be67a9f9a3e6c4125483e3..cc21bf819ff2d3c21413cb5a24bd42c457488869 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 80ea5e6f6d3490a50315050418ae97ad3f1b8d44..7ca8abfc5df06d7d20512cdc9cf477e875adfbc3 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 b22b78c4f9c012b9bb38260e274a1cf9af024c0a..b51fa6e4ca6474fe0499cc201b2044989f26e31e 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 ebd629cac90bea5e95a5db0717ba996273ac782e..d7c33c6b9ff73de5bf788c41c716d12d18e2a466 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 1256e8ce7aed5fb7408b112b1c3cd1d33920bbfc..5aeeb4291d07a0d22b69c8ce1c5865c916cedb4d 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 bb5b651221d5874cc6809a356455957077ac0e19..a4e1a6053c1c71347563ee22c4365d0b3c0c7d26 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 17866f287348e0c530b30bdf519e546469842c26..d8f653c02355ec2aa5cbccbd50ed7d909bc13ff7 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 9e3355c4ff717d6d93e07edc79573f2da6fb6984..c1a4bf43c3fe5c355ef3eeedb2529dc96150eb45 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 88926e93f33e7646b067008a8a5d1317cf3e8747..7478aa307c59ea0fe80f84a75cf68ee426ef9524 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 d5ad7cee5db76de26f831372ed7eaefd99b417c1..07a26ac9466d23af3d610e1d6e3bbcfe7380b31e 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 1d41da27990398cb306e9d5381df6b8786dbdf36..54eba35b5871bb54dcd281eacf63b847f3defe8c 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 06a7c3ee3304dd56b8e1fc3f7d94768768f410c0..45315b1fdee802ffe77f85651aeb60de1fcfc1a1 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 b3aab00b047e79d699abe2e2022b6705385652c9..8937b22249dd4e638f7d57deabdabbe4d4d6f8e8 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 69b6ebece2ec3cc89c09f0fb6717fc8c99317fa0..7f11f7ddbfe32eacde52afc3e9aa1aad82c5108f 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 -- 2.54.0