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...@@ -564,7 +564,14 @@ set(ZIG_STAGE2_SOURCES
564 "${CMAKE_SOURCE_DIR}/src/link/Coff.zig"564 "${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
565 "${CMAKE_SOURCE_DIR}/src/link/Elf.zig"565 "${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
566 "${CMAKE_SOURCE_DIR}/src/link/MachO.zig"566 "${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"
567 "${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"571 "${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"
568 "${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"575 "${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
569 "${CMAKE_SOURCE_DIR}/src/link/C/zig.h"576 "${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
570 "${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"577 "${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...@@ -250,24 +250,6 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
250 resetSegfaultHandler();250 resetSegfaultHandler();
251 }251 }
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
271 nosuspend switch (panic_stage) {253 nosuspend switch (panic_stage) {
272 0 => {254 0 => {
273 panic_stage = 1;255 panic_stage = 1;
src/Compilation.zig-2
...@@ -447,7 +447,6 @@ pub const InitOptions = struct {...@@ -447,7 +447,6 @@ pub const InitOptions = struct {
447 want_lto: ?bool = null,447 want_lto: ?bool = null,
448 use_llvm: ?bool = null,448 use_llvm: ?bool = null,
449 use_lld: ?bool = null,449 use_lld: ?bool = null,
450 use_zld: ?bool = null,
451 use_clang: ?bool = null,450 use_clang: ?bool = null,
452 rdynamic: bool = false,451 rdynamic: bool = false,
453 strip: bool = false,452 strip: bool = false,
...@@ -1021,7 +1020,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -1021,7 +1020,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
1021 .link_mode = link_mode,1020 .link_mode = link_mode,
1022 .object_format = ofmt,1021 .object_format = ofmt,
1023 .optimize_mode = options.optimize_mode,1022 .optimize_mode = options.optimize_mode,
1024 .use_zld = options.use_zld orelse false,
1025 .use_lld = use_lld,1023 .use_lld = use_lld,
1026 .use_llvm = use_llvm,1024 .use_llvm = use_llvm,
1027 .system_linker_hack = darwin_options.system_linker_hack,1025 .system_linker_hack = darwin_options.system_linker_hack,
src/link.zig-2
...@@ -61,8 +61,6 @@ pub const Options = struct {...@@ -61,8 +61,6 @@ pub const Options = struct {
61 /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will61 /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will
62 /// use system linker `ld` instead of the LLD.62 /// use system linker `ld` instead of the LLD.
63 system_linker_hack: bool,63 system_linker_hack: bool,
64 /// Experimental Zig linker.
65 use_zld: bool,
66 link_libc: bool,64 link_libc: bool,
67 link_libcpp: bool,65 link_libcpp: bool,
68 function_sections: bool,66 function_sections: bool,
src/link/MachO.zig+23-5
...@@ -634,12 +634,26 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -634,12 +634,26 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
634 try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{});634 try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{});
635 }635 }
636 } else {636 } else {
637 // Create an LLD command line and invoke it.637 const use_zld = blk: {
638 var argv = std.ArrayList([]const u8).init(self.base.allocator);638 if (self.base.options.is_native_os and self.base.options.system_linker_hack) {
639 defer argv.deinit();639 break :blk false;
640 }
640641
641 if (true) {642 if (self.base.options.target.cpu.arch == .aarch64) {
642 // if (self.base.options.use_zld) {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) {
643 var zld = Zld.init(self.base.allocator);657 var zld = Zld.init(self.base.allocator);
644 defer zld.deinit();658 defer zld.deinit();
645 zld.arch = target.cpu.arch;659 zld.arch = target.cpu.arch;
...@@ -663,6 +677,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {...@@ -663,6 +677,10 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
663 return zld.link(input_files.items, full_out_path);677 return zld.link(input_files.items, full_out_path);
664 }678 }
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
666 // TODO https://github.com/ziglang/zig/issues/6971684 // TODO https://github.com/ziglang/zig/issues/6971
667 // Note that there is no need to check if running natively since we do that already685 // Note that there is no need to check if running natively since we do that already
668 // when setting `system_linker_hack` in Compilation struct.686 // when setting `system_linker_hack` in Compilation struct.
src/main.zig+2-5
...@@ -547,7 +547,6 @@ fn buildOutputType(...@@ -547,7 +547,6 @@ fn buildOutputType(
547 var image_base_override: ?u64 = null;547 var image_base_override: ?u64 = null;
548 var use_llvm: ?bool = null;548 var use_llvm: ?bool = null;
549 var use_lld: ?bool = null;549 var use_lld: ?bool = null;
550 var use_zld: ?bool = null;
551 var use_clang: ?bool = null;550 var use_clang: ?bool = null;
552 var link_eh_frame_hdr = false;551 var link_eh_frame_hdr = false;
553 var link_emit_relocs = false;552 var link_emit_relocs = false;
...@@ -907,8 +906,6 @@ fn buildOutputType(...@@ -907,8 +906,6 @@ fn buildOutputType(
907 use_lld = true;906 use_lld = true;
908 } else if (mem.eql(u8, arg, "-fno-LLD")) {907 } else if (mem.eql(u8, arg, "-fno-LLD")) {
909 use_lld = false;908 use_lld = false;
910 } else if (mem.eql(u8, arg, "-fZLD")) {
911 use_zld = true;
912 } else if (mem.eql(u8, arg, "-fClang")) {909 } else if (mem.eql(u8, arg, "-fClang")) {
913 use_clang = true;910 use_clang = true;
914 } else if (mem.eql(u8, arg, "-fno-Clang")) {911 } else if (mem.eql(u8, arg, "-fno-Clang")) {
...@@ -1867,7 +1864,6 @@ fn buildOutputType(...@@ -1867,7 +1864,6 @@ fn buildOutputType(
1867 .want_compiler_rt = want_compiler_rt,1864 .want_compiler_rt = want_compiler_rt,
1868 .use_llvm = use_llvm,1865 .use_llvm = use_llvm,
1869 .use_lld = use_lld,1866 .use_lld = use_lld,
1870 .use_zld = use_zld,
1871 .use_clang = use_clang,1867 .use_clang = use_clang,
1872 .rdynamic = rdynamic,1868 .rdynamic = rdynamic,
1873 .linker_script = linker_script,1869 .linker_script = linker_script,
...@@ -3245,7 +3241,8 @@ pub const ClangArgIterator = struct {...@@ -3245,7 +3241,8 @@ pub const ClangArgIterator = struct {
3245 self.zig_equivalent = clang_arg.zig_equivalent;3241 self.zig_equivalent = clang_arg.zig_equivalent;
3246 break :find_clang_arg;3242 break :find_clang_arg;
3247 },3243 },
3248 } else {3244 }
3245 else {
3249 fatal("Unknown Clang option: '{s}'", .{arg});3246 fatal("Unknown Clang option: '{s}'", .{arg});
3250 }3247 }
3251 }3248 }