Skip to content

Commit 5722261

Browse files
authored
Merge pull request #17465
Compilation: default to self-hosted backends when not using libllvm
2 parents 42998e6 + da7e4fb commit 5722261

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

src/Compilation.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
845845
if (options.main_mod == null)
846846
break :blk false;
847847

848+
// If we cannot use LLVM libraries, then our own backends will be a
849+
// better default since the LLVM backend can only produce bitcode
850+
// and not an object file or executable.
851+
if (!use_lib_llvm)
852+
break :blk false;
853+
848854
// If LLVM does not support the target, then we can't use it.
849855
if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
850856
break :blk false;

src/link/Coff/lld.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
491491
}
492492
// MSVC compiler_rt is missing some stuff, so we build it unconditionally but
493493
// and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
494-
if (comp.compiler_rt_lib) |lib| {
495-
try argv.append(lib.full_object_path);
496-
}
494+
if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
495+
if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
497496
}
498497

499498
try argv.ensureUnusedCapacity(self.base.options.system_libs.count());

src/link/MachO/zld.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ pub fn linkWithZld(
186186
try positionals.append(.{ .path = p });
187187
}
188188

189-
if (comp.compiler_rt_lib) |lib| {
190-
try positionals.append(.{ .path = lib.full_object_path });
191-
}
189+
if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
190+
if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
192191

193192
// libc++ dep
194193
if (options.link_libcpp) {
@@ -301,9 +300,8 @@ pub fn linkWithZld(
301300
try argv.append(p);
302301
}
303302

304-
if (comp.compiler_rt_lib) |lib| {
305-
try argv.append(lib.full_object_path);
306-
}
303+
if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
304+
if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
307305

308306
if (options.link_libcpp) {
309307
try argv.append(comp.libcxxabi_static_lib.?.full_object_path);

src/link/Wasm.zig

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,11 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
32573257
sub_prog_node.activate();
32583258
defer sub_prog_node.end();
32593259

3260-
const is_obj = options.output_mode == .Obj;
3261-
const compiler_rt_path: ?[]const u8 = if (options.include_compiler_rt and !is_obj)
3262-
comp.compiler_rt_lib.?.full_object_path
3263-
else
3264-
null;
3260+
const compiler_rt_path: ?[]const u8 = blk: {
3261+
if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
3262+
if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
3263+
break :blk null;
3264+
};
3265+
32653266
const id_symlink_basename = "zld.id";
32663267

32673268
var man: Cache.Manifest = undefined;
@@ -3376,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
33763377
try positionals.append(c_object.status.success.object_path);
33773378
}
33783379

3379-
if (comp.compiler_rt_lib) |lib| {
3380-
try positionals.append(lib.full_object_path);
3381-
}
3380+
if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3381+
if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
33823382

33833383
try wasm.parseInputFiles(positionals.items);
33843384

@@ -3463,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
34633463
try positionals.append(c_object.status.success.object_path);
34643464
}
34653465

3466-
if (comp.compiler_rt_lib) |lib| {
3467-
try positionals.append(lib.full_object_path);
3468-
}
3466+
if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3467+
if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
34693468

34703469
try wasm.parseInputFiles(positionals.items);
34713470

@@ -4325,11 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
43254324
defer sub_prog_node.end();
43264325

43274326
const is_obj = wasm.base.options.output_mode == .Obj;
4328-
4329-
const compiler_rt_path: ?[]const u8 = if (wasm.base.options.include_compiler_rt and !is_obj)
4330-
comp.compiler_rt_lib.?.full_object_path
4331-
else
4332-
null;
4327+
const compiler_rt_path: ?[]const u8 = blk: {
4328+
if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
4329+
if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
4330+
break :blk null;
4331+
};
43334332

43344333
const target = wasm.base.options.target;
43354334

test/link/macho/bugs/16308/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
1717

1818
const check = lib.checkObject();
1919
check.checkInSymtab();
20-
check.checkNotPresent("external");
20+
check.checkNotPresent("external _abc");
2121

2222
test_step.dependOn(&check.step);
2323
}

0 commit comments

Comments
 (0)