authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-14 11:42:49+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-14 12:12:22-05:00
log4e6f21e2cb2c557b5c019f4acf445665a26edcba
tree85e65057cac0af3fd557a8bda6a1b4f88e60da48
parent47e14b7ffbe02c800ac4c2b4f181ab6c7f022988

comp: reinstate -fcompiler-rt when used with build-obj as output

When the following is specified ``` $ zig build-obj -fcompiler-rt example.zig ``` the resulting relocatable object file will have the compiler-rt unconditionally embedded inside. ``` $ nm example.o ... 0000000012345678 W __truncsfhf2 ... ```

1 files changed, 23 insertions(+), 0 deletions(-)

src/Compilation.zig+23
......@@ -1635,10 +1635,25 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16351635 } else main_pkg;
16361636 errdefer if (options.is_test) root_pkg.destroy(gpa);
16371637
1638 const compiler_rt_pkg = if (include_compiler_rt and options.output_mode == .Obj) compiler_rt_pkg: {
1639 break :compiler_rt_pkg try Package.createWithDir(
1640 gpa,
1641 "compiler_rt",
1642 options.zig_lib_directory,
1643 null,
1644 "compiler_rt.zig",
1645 );
1646 } else null;
1647 errdefer if (compiler_rt_pkg) |p| p.destroy(gpa);
1648
16381649 try main_pkg.addAndAdopt(gpa, builtin_pkg);
16391650 try main_pkg.add(gpa, root_pkg);
16401651 try main_pkg.addAndAdopt(gpa, std_pkg);
16411652
1653 if (compiler_rt_pkg) |p| {
1654 try main_pkg.addAndAdopt(gpa, p);
1655 }
1656
16421657 const main_pkg_is_std = m: {
16431658 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{
16441659 std_pkg.root_src_directory.path orelse ".",
......@@ -2355,6 +2370,10 @@ pub fn update(comp: *Compilation) !void {
23552370 _ = try module.importPkg(module.main_pkg);
23562371 }
23572372
2373 if (module.main_pkg.table.get("compiler_rt")) |compiler_rt_pkg| {
2374 _ = try module.importPkg(compiler_rt_pkg);
2375 }
2376
23582377 // Put a work item in for every known source file to detect if
23592378 // it changed, and, if so, re-compute ZIR and then queue the job
23602379 // to update it.
......@@ -2379,6 +2398,10 @@ pub fn update(comp: *Compilation) !void {
23792398 if (comp.bin_file.options.is_test) {
23802399 try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg });
23812400 }
2401
2402 if (module.main_pkg.table.get("compiler_rt")) |compiler_rt_pkg| {
2403 try comp.work_queue.writeItem(.{ .analyze_pkg = compiler_rt_pkg });
2404 }
23822405 }
23832406
23842407 // If the terminal is dumb, we dont want to show the user all the output.