aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-03-17 22:14:55 +0100
committerJakub Konka <kubkon@jakubkonka.com>2021-03-18 00:37:13 +0100
commit7516dfff83368df4d67e3c10923c3d6da1b72879 (patch)
tree832fad872bad5f873ce958ad79edeaa214fbc862 /src
parent900658a85d57f4a6a554f8a8ed9d89fcd5483d5a (diff)
downloadzig-7516dfff83368df4d67e3c10923c3d6da1b72879.tar.gz
zig-7516dfff83368df4d67e3c10923c3d6da1b72879.zip
zld: use zld when linking aarch64 by default and cross-comp
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig2
-rw-r--r--src/link.zig2
-rw-r--r--src/link/MachO.zig28
-rw-r--r--src/main.zig7
4 files changed, 25 insertions, 14 deletions
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});
}
}