Skip to content

Commit

Permalink
Merge pull request #17465
Browse files Browse the repository at this point in the history
Compilation: default to self-hosted backends when not using libllvm
  • Loading branch information
andrewrk authored Oct 11, 2023
2 parents 42998e6 + da7e4fb commit 5722261
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/link/Coff/lld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 4 additions & 6 deletions src/link/MachO/zld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 15 additions & 16 deletions src/link/Wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/link/macho/bugs/16308/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {

const check = lib.checkObject();
check.checkInSymtab();
check.checkNotPresent("external");
check.checkNotPresent("external _abc");

test_step.dependOn(&check.step);
}

0 comments on commit 5722261

Please sign in to comment.