aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-11 00:53:07 -0700
committerGitHub <noreply@github.com>2023-10-11 00:53:07 -0700
commit5722261e6474e8bac5b8cb341b6344100b8514f2 (patch)
tree8fc8006e8f3cedeac4a45c88305bc0eb0b0e3fb0 /src
parent42998e637b29df66992d10be270fb97e47758fba (diff)
parentda7e4fb31a05f2063eb829c4c383a44b38ed21e1 (diff)
downloadzig-5722261e6474e8bac5b8cb341b6344100b8514f2.tar.gz
zig-5722261e6474e8bac5b8cb341b6344100b8514f2.zip
Merge pull request #17465
Compilation: default to self-hosted backends when not using libllvm
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig6
-rw-r--r--src/link/Coff/lld.zig5
-rw-r--r--src/link/MachO/zld.zig10
-rw-r--r--src/link/Wasm.zig31
4 files changed, 27 insertions, 25 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index cd4c6ea11b..25d0d63b1e 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -845,6 +845,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
if (options.main_mod == null)
break :blk false;
+ // If we cannot use LLVM libraries, then our own backends will be a
+ // better default since the LLVM backend can only produce bitcode
+ // and not an object file or executable.
+ if (!use_lib_llvm)
+ break :blk false;
+
// If LLVM does not support the target, then we can't use it.
if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
break :blk false;
diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig
index 7675aa49f5..cbefcbd91e 100644
--- a/src/link/Coff/lld.zig
+++ b/src/link/Coff/lld.zig
@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
}
// MSVC compiler_rt is missing some stuff, so we build it unconditionally but
// and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
- if (comp.compiler_rt_lib) |lib| {
- try argv.append(lib.full_object_path);
- }
+ if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
+ if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
}
try argv.ensureUnusedCapacity(self.base.options.system_libs.count());
diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig
index 19339eb19a..595c64436d 100644
--- a/src/link/MachO/zld.zig
+++ b/src/link/MachO/zld.zig
@@ -186,9 +186,8 @@ pub fn linkWithZld(
try positionals.append(.{ .path = p });
}
- if (comp.compiler_rt_lib) |lib| {
- try positionals.append(.{ .path = lib.full_object_path });
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
+ if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
// libc++ dep
if (options.link_libcpp) {
@@ -301,9 +300,8 @@ pub fn linkWithZld(
try argv.append(p);
}
- if (comp.compiler_rt_lib) |lib| {
- try argv.append(lib.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
if (options.link_libcpp) {
try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index 2116cd7708..92e7bbe5ea 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -3257,11 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
sub_prog_node.activate();
defer sub_prog_node.end();
- const is_obj = options.output_mode == .Obj;
- const compiler_rt_path: ?[]const u8 = if (options.include_compiler_rt and !is_obj)
- comp.compiler_rt_lib.?.full_object_path
- else
- null;
+ const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
+ if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
+ break :blk null;
+ };
+
const id_symlink_basename = "zld.id";
var man: Cache.Manifest = undefined;
@@ -3376,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
try positionals.append(c_object.status.success.object_path);
}
- if (comp.compiler_rt_lib) |lib| {
- try positionals.append(lib.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
try wasm.parseInputFiles(positionals.items);
@@ -3463,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
try positionals.append(c_object.status.success.object_path);
}
- if (comp.compiler_rt_lib) |lib| {
- try positionals.append(lib.full_object_path);
- }
+ if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
+ if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
try wasm.parseInputFiles(positionals.items);
@@ -4325,11 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
defer sub_prog_node.end();
const is_obj = wasm.base.options.output_mode == .Obj;
-
- const compiler_rt_path: ?[]const u8 = if (wasm.base.options.include_compiler_rt and !is_obj)
- comp.compiler_rt_lib.?.full_object_path
- else
- null;
+ const compiler_rt_path: ?[]const u8 = blk: {
+ if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
+ if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
+ break :blk null;
+ };
const target = wasm.base.options.target;