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 {...@@ -1635,10 +1635,25 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1635 } else main_pkg;1635 } else main_pkg;
1636 errdefer if (options.is_test) root_pkg.destroy(gpa);1636 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
1638 try main_pkg.addAndAdopt(gpa, builtin_pkg);1649 try main_pkg.addAndAdopt(gpa, builtin_pkg);
1639 try main_pkg.add(gpa, root_pkg);1650 try main_pkg.add(gpa, root_pkg);
1640 try main_pkg.addAndAdopt(gpa, std_pkg);1651 try main_pkg.addAndAdopt(gpa, std_pkg);
16411652
1653 if (compiler_rt_pkg) |p| {
1654 try main_pkg.addAndAdopt(gpa, p);
1655 }
1656
1642 const main_pkg_is_std = m: {1657 const main_pkg_is_std = m: {
1643 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{1658 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{
1644 std_pkg.root_src_directory.path orelse ".",1659 std_pkg.root_src_directory.path orelse ".",
...@@ -2355,6 +2370,10 @@ pub fn update(comp: *Compilation) !void {...@@ -2355,6 +2370,10 @@ pub fn update(comp: *Compilation) !void {
2355 _ = try module.importPkg(module.main_pkg);2370 _ = try module.importPkg(module.main_pkg);
2356 }2371 }
23572372
2373 if (module.main_pkg.table.get("compiler_rt")) |compiler_rt_pkg| {
2374 _ = try module.importPkg(compiler_rt_pkg);
2375 }
2376
2358 // Put a work item in for every known source file to detect if2377 // Put a work item in for every known source file to detect if
2359 // it changed, and, if so, re-compute ZIR and then queue the job2378 // it changed, and, if so, re-compute ZIR and then queue the job
2360 // to update it.2379 // to update it.
...@@ -2379,6 +2398,10 @@ pub fn update(comp: *Compilation) !void {...@@ -2379,6 +2398,10 @@ pub fn update(comp: *Compilation) !void {
2379 if (comp.bin_file.options.is_test) {2398 if (comp.bin_file.options.is_test) {
2380 try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg });2399 try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg });
2381 }2400 }
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 }
2382 }2405 }
23832406
2384 // If the terminal is dumb, we dont want to show the user all the output.2407 // If the terminal is dumb, we dont want to show the user all the output.