From f5657b5552ea1219706c79f67bd0620767ecc4ec Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 20 May 2019 17:04:00 +0200 Subject: [PATCH 1/4] Build archives using the K_DARWIN format when targeting osx --- src/zig_llvm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 7d45871b2a..c825ed3896 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -877,6 +877,7 @@ bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size case ZigLLVM_Linux: kind = object::Archive::K_GNU; break; + case ZigLLVM_MacOSX: case ZigLLVM_Darwin: case ZigLLVM_IOS: kind = object::Archive::K_DARWIN; From 266b2de1505ed64f05260c7057b9b563a2161e48 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 20 May 2019 23:09:25 +0200 Subject: [PATCH 2/4] Remove macos-specific linking hacks --- CMakeLists.txt | 2 -- build.zig | 12 ++---------- src/link.cpp | 8 -------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03fae22296..e55402b4f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6707,8 +6707,6 @@ target_link_libraries(zig0 compiler) if(WIN32) set(LIBUSERLAND "${CMAKE_BINARY_DIR}/userland.lib") -elseif(APPLE) - set(LIBUSERLAND "${CMAKE_BINARY_DIR}/userland.o") else() set(LIBUSERLAND "${CMAKE_BINARY_DIR}/libuserland.a") endif() diff --git a/build.zig b/build.zig index 2bc0229475..6e73e0445a 100644 --- a/build.zig +++ b/build.zig @@ -385,17 +385,9 @@ const Context = struct { }; fn addLibUserlandStep(b: *Builder) void { - // Sadly macOS requires hacks to work around the buggy MACH-O linker code. - const artifact = if (builtin.os == .macosx) - b.addObject("userland", "src-self-hosted/stage1.zig") - else - b.addStaticLibrary("userland", "src-self-hosted/stage1.zig"); + const artifact = b.addStaticLibrary("userland", "src-self-hosted/stage1.zig"); artifact.disable_gen_h = true; - if (builtin.os == .macosx) { - artifact.disable_stack_probing = true; - } else { - artifact.bundle_compiler_rt = true; - } + artifact.bundle_compiler_rt = true; artifact.setTarget(builtin.arch, builtin.os, builtin.abi); artifact.linkSystemLibrary("c"); const libuserland_step = b.step("libuserland", "Build the userland compiler library for use in stage1"); diff --git a/src/link.cpp b/src/link.cpp index 3585f675a5..b47da87c68 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -776,14 +776,6 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { } static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path, OutType child_out_type) { - // The Mach-O LLD code is not well maintained, and trips an assertion - // when we link compiler_rt and libc.zig as libraries rather than objects. - // Here we workaround this by having compiler_rt and libc.zig be objects. - // TODO write our own linker. https://github.com/ziglang/zig/issues/1535 - if (parent_gen->zig_target->os == OsMacOSX) { - child_out_type = OutTypeObj; - } - CodeGen *child_gen = create_child_codegen(parent_gen, full_path, child_out_type, parent_gen->libc); codegen_set_out_name(child_gen, buf_create_from_str(aname)); From 798720224341820da8ec756a20a93a33cc41835e Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 20 May 2019 23:14:49 +0200 Subject: [PATCH 3/4] Fix signedness mismatch in comparison --- src/os.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os.cpp b/src/os.cpp index 8ab5007d80..e3d223325f 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1350,7 +1350,7 @@ static void init_rand() { zig_panic("unable to open /dev/urandom"); } char bytes[sizeof(unsigned)]; - size_t amt_read; + ssize_t amt_read; while ((amt_read = read(fd, bytes, sizeof(unsigned))) == -1) { if (errno == EINTR) continue; zig_panic("unable to read /dev/urandom"); From d110818cfe96b8038e02d49122d42070d6059197 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 28 May 2019 00:12:09 +0200 Subject: [PATCH 4/4] Trigger rebuild on sr.ht