diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-02-14 11:42:49 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-02-14 12:12:22 -0500 |
| commit | 4e6f21e2cb2c557b5c019f4acf445665a26edcba (patch) | |
| tree | 85e65057cac0af3fd557a8bda6a1b4f88e60da48 /src/Compilation.zig | |
| parent | 47e14b7ffbe02c800ac4c2b4f181ab6c7f022988 (diff) | |
| download | zig-4e6f21e2cb2c557b5c019f4acf445665a26edcba.tar.gz zig-4e6f21e2cb2c557b5c019f4acf445665a26edcba.zip | |
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
...
```
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 5e408554d5..c6737ed3eb 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1635,10 +1635,25 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { } else main_pkg; errdefer if (options.is_test) root_pkg.destroy(gpa); + const compiler_rt_pkg = if (include_compiler_rt and options.output_mode == .Obj) compiler_rt_pkg: { + break :compiler_rt_pkg try Package.createWithDir( + gpa, + "compiler_rt", + options.zig_lib_directory, + null, + "compiler_rt.zig", + ); + } else null; + errdefer if (compiler_rt_pkg) |p| p.destroy(gpa); + try main_pkg.addAndAdopt(gpa, builtin_pkg); try main_pkg.add(gpa, root_pkg); try main_pkg.addAndAdopt(gpa, std_pkg); + if (compiler_rt_pkg) |p| { + try main_pkg.addAndAdopt(gpa, p); + } + const main_pkg_is_std = m: { const std_path = try std.fs.path.resolve(arena, &[_][]const u8{ std_pkg.root_src_directory.path orelse ".", @@ -2355,6 +2370,10 @@ pub fn update(comp: *Compilation) !void { _ = try module.importPkg(module.main_pkg); } + if (module.main_pkg.table.get("compiler_rt")) |compiler_rt_pkg| { + _ = try module.importPkg(compiler_rt_pkg); + } + // Put a work item in for every known source file to detect if // it changed, and, if so, re-compute ZIR and then queue the job // to update it. @@ -2379,6 +2398,10 @@ pub fn update(comp: *Compilation) !void { if (comp.bin_file.options.is_test) { try comp.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg }); } + + if (module.main_pkg.table.get("compiler_rt")) |compiler_rt_pkg| { + try comp.work_queue.writeItem(.{ .analyze_pkg = compiler_rt_pkg }); + } } // If the terminal is dumb, we dont want to show the user all the output. |
