authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 22:14:55+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-18 00:37:13+01:00
log7516dfff83368df4d67e3c10923c3d6da1b72879
tree832fad872bad5f873ce958ad79edeaa214fbc862
parent900658a85d57f4a6a554f8a8ed9d89fcd5483d5a

zld: use zld when linking aarch64 by default and cross-comp


6 files changed, 32 insertions(+), 32 deletions(-)

CMakeLists.txt+7
......@@ -564,7 +564,14 @@ set(ZIG_STAGE2_SOURCES
564564 "${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
565565 "${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
566566 "${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
567 "${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
568 "${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
569 "${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig"
570 "${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig"
567571 "${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
572 "${CMAKE_SOURCE_DIR}/src/link/MachO/Zld.zig"
573 "${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
574 "${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
568575 "${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
569576 "${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
570577 "${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
lib/std/debug.zig-18
......@@ -250,24 +250,6 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
250250 resetSegfaultHandler();
251251 }
252252
253 if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64)
254 nosuspend {
255 // As a workaround for not having threadlocal variable support in LLD for this target,
256 // we have a simpler panic implementation that does not use threadlocal variables.
257 // TODO https://github.com/ziglang/zig/issues/7527
258 const stderr = io.getStdErr().writer();
259 if (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst) == 0) {
260 stderr.print("panic: " ++ format ++ "\n", args) catch os.abort();
261 if (trace) |t| {
262 dumpStackTrace(t.*);
263 }
264 dumpCurrentStackTrace(first_trace_addr);
265 } else {
266 stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort();
267 }
268 os.abort();
269 };
270
271253 nosuspend switch (panic_stage) {
272254 0 => {
273255 panic_stage = 1;
src/Compilation.zig-2
......@@ -447,7 +447,6 @@ pub const InitOptions = struct {
447447 want_lto: ?bool = null,
448448 use_llvm: ?bool = null,
449449 use_lld: ?bool = null,
450 use_zld: ?bool = null,
451450 use_clang: ?bool = null,
452451 rdynamic: bool = false,
453452 strip: bool = false,
......@@ -1021,7 +1020,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
10211020 .link_mode = link_mode,
10221021 .object_format = ofmt,
10231022 .optimize_mode = options.optimize_mode,
1024 .use_zld = options.use_zld orelse false,
10251023 .use_lld = use_lld,
10261024 .use_llvm = use_llvm,
10271025 .system_linker_hack = darwin_options.system_linker_hack,
src/link.zig-2
......@@ -61,8 +61,6 @@ pub const Options = struct {
6161 /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will
6262 /// use system linker `ld` instead of the LLD.
6363 system_linker_hack: bool,
64 /// Experimental Zig linker.
65 use_zld: bool,
6664 link_libc: bool,
6765 link_libcpp: bool,
6866 function_sections: bool,
src/link/MachO.zig+23-5
......@@ -634,12 +634,26 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
634634 try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{});
635635 }
636636 } else {
637 // Create an LLD command line and invoke it.
638 var argv = std.ArrayList([]const u8).init(self.base.allocator);
639 defer argv.deinit();
637 const use_zld = blk: {
638 if (self.base.options.is_native_os and self.base.options.system_linker_hack) {
639 break :blk false;
640 }
640641
641 if (true) {
642 // if (self.base.options.use_zld) {
642 if (self.base.options.target.cpu.arch == .aarch64) {
643 break :blk true;
644 }
645
646 if (self.base.options.link_libcpp or
647 self.base.options.output_mode == .Lib or
648 self.base.options.linker_script != null)
649 {
650 break :blk false;
651 }
652
653 break :blk true;
654 };
655
656 if (use_zld) {
643657 var zld = Zld.init(self.base.allocator);
644658 defer zld.deinit();
645659 zld.arch = target.cpu.arch;
......@@ -663,6 +677,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
663677 return zld.link(input_files.items, full_out_path);
664678 }
665679
680 // Create an LLD command line and invoke it.
681 var argv = std.ArrayList([]const u8).init(self.base.allocator);
682 defer argv.deinit();
683
666684 // TODO https://github.com/ziglang/zig/issues/6971
667685 // Note that there is no need to check if running natively since we do that already
668686 // when setting `system_linker_hack` in Compilation struct.
src/main.zig+2-5
......@@ -547,7 +547,6 @@ fn buildOutputType(
547547 var image_base_override: ?u64 = null;
548548 var use_llvm: ?bool = null;
549549 var use_lld: ?bool = null;
550 var use_zld: ?bool = null;
551550 var use_clang: ?bool = null;
552551 var link_eh_frame_hdr = false;
553552 var link_emit_relocs = false;
......@@ -907,8 +906,6 @@ fn buildOutputType(
907906 use_lld = true;
908907 } else if (mem.eql(u8, arg, "-fno-LLD")) {
909908 use_lld = false;
910 } else if (mem.eql(u8, arg, "-fZLD")) {
911 use_zld = true;
912909 } else if (mem.eql(u8, arg, "-fClang")) {
913910 use_clang = true;
914911 } else if (mem.eql(u8, arg, "-fno-Clang")) {
......@@ -1867,7 +1864,6 @@ fn buildOutputType(
18671864 .want_compiler_rt = want_compiler_rt,
18681865 .use_llvm = use_llvm,
18691866 .use_lld = use_lld,
1870 .use_zld = use_zld,
18711867 .use_clang = use_clang,
18721868 .rdynamic = rdynamic,
18731869 .linker_script = linker_script,
......@@ -3245,7 +3241,8 @@ pub const ClangArgIterator = struct {
32453241 self.zig_equivalent = clang_arg.zig_equivalent;
32463242 break :find_clang_arg;
32473243 },
3248 } else {
3244 }
3245 else {
32493246 fatal("Unknown Clang option: '{s}'", .{arg});
32503247 }
32513248 }