diff --git a/CMakeLists.txt b/CMakeLists.txt index 55198f3581..5c68791872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -564,7 +564,14 @@ set(ZIG_STAGE2_SOURCES "${CMAKE_SOURCE_DIR}/src/link/Coff.zig" "${CMAKE_SOURCE_DIR}/src/link/Elf.zig" "${CMAKE_SOURCE_DIR}/src/link/MachO.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig" "${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/Zld.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig" + "${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig" "${CMAKE_SOURCE_DIR}/src/link/Wasm.zig" "${CMAKE_SOURCE_DIR}/src/link/C/zig.h" "${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin" diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 74fb95ffa8..a7badf7ed1 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -250,24 +250,6 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c resetSegfaultHandler(); } - if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64) - nosuspend { - // As a workaround for not having threadlocal variable support in LLD for this target, - // we have a simpler panic implementation that does not use threadlocal variables. - // TODO https://github.com/ziglang/zig/issues/7527 - const stderr = io.getStdErr().writer(); - if (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst) == 0) { - stderr.print("panic: " ++ format ++ "\n", args) catch os.abort(); - if (trace) |t| { - dumpStackTrace(t.*); - } - dumpCurrentStackTrace(first_trace_addr); - } else { - stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort(); - } - os.abort(); - }; - nosuspend switch (panic_stage) { 0 => { panic_stage = 1; diff --git a/src/Compilation.zig b/src/Compilation.zig index e2ecc44fdb..786280f9ef 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -447,7 +447,6 @@ pub const InitOptions = struct { want_lto: ?bool = null, use_llvm: ?bool = null, use_lld: ?bool = null, - use_zld: ?bool = null, use_clang: ?bool = null, rdynamic: bool = false, strip: bool = false, @@ -1021,7 +1020,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .link_mode = link_mode, .object_format = ofmt, .optimize_mode = options.optimize_mode, - .use_zld = options.use_zld orelse false, .use_lld = use_lld, .use_llvm = use_llvm, .system_linker_hack = darwin_options.system_linker_hack, diff --git a/src/link.zig b/src/link.zig index 6767b8d1b3..db3e973f84 100644 --- a/src/link.zig +++ b/src/link.zig @@ -61,8 +61,6 @@ pub const Options = struct { /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will /// use system linker `ld` instead of the LLD. system_linker_hack: bool, - /// Experimental Zig linker. - use_zld: bool, link_libc: bool, link_libcpp: bool, function_sections: bool, diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 8f599a64a3..78e38ed8a3 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -634,12 +634,26 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{}); } } else { - // Create an LLD command line and invoke it. - var argv = std.ArrayList([]const u8).init(self.base.allocator); - defer argv.deinit(); + const use_zld = blk: { + if (self.base.options.is_native_os and self.base.options.system_linker_hack) { + break :blk false; + } - if (true) { - // if (self.base.options.use_zld) { + if (self.base.options.target.cpu.arch == .aarch64) { + break :blk true; + } + + if (self.base.options.link_libcpp or + self.base.options.output_mode == .Lib or + self.base.options.linker_script != null) + { + break :blk false; + } + + break :blk true; + }; + + if (use_zld) { var zld = Zld.init(self.base.allocator); defer zld.deinit(); zld.arch = target.cpu.arch; @@ -663,6 +677,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { return zld.link(input_files.items, full_out_path); } + // Create an LLD command line and invoke it. + var argv = std.ArrayList([]const u8).init(self.base.allocator); + defer argv.deinit(); + // TODO https://github.com/ziglang/zig/issues/6971 // Note that there is no need to check if running natively since we do that already // when setting `system_linker_hack` in Compilation struct. diff --git a/src/main.zig b/src/main.zig index 4549f6f954..19248d1a44 100644 --- a/src/main.zig +++ b/src/main.zig @@ -547,7 +547,6 @@ fn buildOutputType( var image_base_override: ?u64 = null; var use_llvm: ?bool = null; var use_lld: ?bool = null; - var use_zld: ?bool = null; var use_clang: ?bool = null; var link_eh_frame_hdr = false; var link_emit_relocs = false; @@ -907,8 +906,6 @@ fn buildOutputType( use_lld = true; } else if (mem.eql(u8, arg, "-fno-LLD")) { use_lld = false; - } else if (mem.eql(u8, arg, "-fZLD")) { - use_zld = true; } else if (mem.eql(u8, arg, "-fClang")) { use_clang = true; } else if (mem.eql(u8, arg, "-fno-Clang")) { @@ -1867,7 +1864,6 @@ fn buildOutputType( .want_compiler_rt = want_compiler_rt, .use_llvm = use_llvm, .use_lld = use_lld, - .use_zld = use_zld, .use_clang = use_clang, .rdynamic = rdynamic, .linker_script = linker_script, @@ -3245,7 +3241,8 @@ pub const ClangArgIterator = struct { self.zig_equivalent = clang_arg.zig_equivalent; break :find_clang_arg; }, - } else { + } + else { fatal("Unknown Clang option: '{s}'", .{arg}); } }