authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-11 00:53:07-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-11 00:53:07-07:00
log5722261e6474e8bac5b8cb341b6344100b8514f2
tree8fc8006e8f3cedeac4a45c88305bc0eb0b0e3fb0
parent42998e637b29df66992d10be270fb97e47758fba
parentda7e4fb31a05f2063eb829c4c383a44b38ed21e1
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17465

Compilation: default to self-hosted backends when not using libllvm

5 files changed, 28 insertions(+), 26 deletions(-)

src/Compilation.zig+6
...@@ -845,6 +845,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -845,6 +845,12 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
845 if (options.main_mod == null)845 if (options.main_mod == null)
846 break :blk false;846 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
848 // If LLVM does not support the target, then we can't use it.854 // If LLVM does not support the target, then we can't use it.
849 if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))855 if (!target_util.hasLlvmSupport(options.target, options.target.ofmt))
850 break :blk false;856 break :blk false;
src/link/Coff/lld.zig+2-3
...@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -491,9 +491,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
491 }491 }
492 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but492 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but
493 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.493 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
494 if (comp.compiler_rt_lib) |lib| {494 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
495 try argv.append(lib.full_object_path);495 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
496 }
497 }496 }
498497
499 try argv.ensureUnusedCapacity(self.base.options.system_libs.count());498 try argv.ensureUnusedCapacity(self.base.options.system_libs.count());
src/link/MachO/zld.zig+4-6
...@@ -186,9 +186,8 @@ pub fn linkWithZld(...@@ -186,9 +186,8 @@ pub fn linkWithZld(
186 try positionals.append(.{ .path = p });186 try positionals.append(.{ .path = p });
187 }187 }
188188
189 if (comp.compiler_rt_lib) |lib| {189 if (comp.compiler_rt_lib) |lib| try positionals.append(.{ .path = lib.full_object_path });
190 try positionals.append(.{ .path = lib.full_object_path });190 if (comp.compiler_rt_obj) |obj| try positionals.append(.{ .path = obj.full_object_path });
191 }
192191
193 // libc++ dep192 // libc++ dep
194 if (options.link_libcpp) {193 if (options.link_libcpp) {
...@@ -301,9 +300,8 @@ pub fn linkWithZld(...@@ -301,9 +300,8 @@ pub fn linkWithZld(
301 try argv.append(p);300 try argv.append(p);
302 }301 }
303302
304 if (comp.compiler_rt_lib) |lib| {303 if (comp.compiler_rt_lib) |lib| try argv.append(lib.full_object_path);
305 try argv.append(lib.full_object_path);304 if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path);
306 }
307305
308 if (options.link_libcpp) {306 if (options.link_libcpp) {
309 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);307 try argv.append(comp.libcxxabi_static_lib.?.full_object_path);
src/link/Wasm.zig+15-16
...@@ -3257,11 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3257,11 +3257,12 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3257 sub_prog_node.activate();3257 sub_prog_node.activate();
3258 defer sub_prog_node.end();3258 defer sub_prog_node.end();
32593259
3260 const is_obj = options.output_mode == .Obj;3260 const compiler_rt_path: ?[]const u8 = blk: {
3261 const compiler_rt_path: ?[]const u8 = if (options.include_compiler_rt and !is_obj)3261 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
3262 comp.compiler_rt_lib.?.full_object_path3262 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
3263 else3263 break :blk null;
3264 null;3264 };
3265
3265 const id_symlink_basename = "zld.id";3266 const id_symlink_basename = "zld.id";
32663267
3267 var man: Cache.Manifest = undefined;3268 var man: Cache.Manifest = undefined;
...@@ -3376,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3376,9 +3377,8 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3376 try positionals.append(c_object.status.success.object_path);3377 try positionals.append(c_object.status.success.object_path);
3377 }3378 }
33783379
3379 if (comp.compiler_rt_lib) |lib| {3380 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3380 try positionals.append(lib.full_object_path);3381 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
3381 }
33823382
3383 try wasm.parseInputFiles(positionals.items);3383 try wasm.parseInputFiles(positionals.items);
33843384
...@@ -3463,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -3463,9 +3463,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3463 try positionals.append(c_object.status.success.object_path);3463 try positionals.append(c_object.status.success.object_path);
3464 }3464 }
34653465
3466 if (comp.compiler_rt_lib) |lib| {3466 if (comp.compiler_rt_lib) |lib| try positionals.append(lib.full_object_path);
3467 try positionals.append(lib.full_object_path);3467 if (comp.compiler_rt_obj) |obj| try positionals.append(obj.full_object_path);
3468 }
34693468
3470 try wasm.parseInputFiles(positionals.items);3469 try wasm.parseInputFiles(positionals.items);
34713470
...@@ -4325,11 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4325,11 +4324,11 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4325 defer sub_prog_node.end();4324 defer sub_prog_node.end();
43264325
4327 const is_obj = wasm.base.options.output_mode == .Obj;4326 const is_obj = wasm.base.options.output_mode == .Obj;
43284327 const compiler_rt_path: ?[]const u8 = blk: {
4329 const compiler_rt_path: ?[]const u8 = if (wasm.base.options.include_compiler_rt and !is_obj)4328 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
4330 comp.compiler_rt_lib.?.full_object_path4329 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
4331 else4330 break :blk null;
4332 null;4331 };
43334332
4334 const target = wasm.base.options.target;4333 const target = wasm.base.options.target;
43354334
test/link/macho/bugs/16308/build.zig+1-1
...@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {...@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
1717
18 const check = lib.checkObject();18 const check = lib.checkObject();
19 check.checkInSymtab();19 check.checkInSymtab();
20 check.checkNotPresent("external");20 check.checkNotPresent("external _abc");
2121
22 test_step.dependOn(&check.step);22 test_step.dependOn(&check.step);
23}23}