diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-16 23:57:30 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-16 23:57:33 +0200 |
| commit | 43fb74f81a8cdefa447c949ff761bfce3aa8aa91 (patch) | |
| tree | 8709d8e6945a6bb8b75b0b920ca14d89ec7cd41a /src | |
| parent | 77443ac2b54aa4f6ccf8046fe787d7409af526d2 (diff) | |
| download | zig-43fb74f81a8cdefa447c949ff761bfce3aa8aa91.tar.gz zig-43fb74f81a8cdefa447c949ff761bfce3aa8aa91.zip | |
elf: do not open file if emitting object file for LLVM and elf linker
This is at least until we implement `-r` option in the linker.
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf.zig | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index ebc289a959..31867421b6 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -241,6 +241,9 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option const self = try createEmpty(allocator, options); errdefer self.base.destroy(); + const is_obj = options.output_mode == .Obj; + const is_obj_or_ar = is_obj or (options.output_mode == .Lib and options.link_mode == .Static); + if (options.use_llvm) { const use_lld = build_options.have_llvm and self.base.options.use_lld; if (use_lld) return self; @@ -250,6 +253,10 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option sub_path, options.target.ofmt.fileExt(options.target.cpu.arch), }); } + if (is_obj) { + // TODO until we implement -r option, we don't want to open a file at this stage. + return self; + } } errdefer if (self.base.intermediary_basename) |path| allocator.free(path); @@ -273,11 +280,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option // There must always be a null shdr in index 0 _ = try self.addSection(.{ .name = "" }); - const is_obj_or_ar = switch (options.output_mode) { - .Obj => true, - .Lib => options.link_mode == .Static, - else => false, - }; if (!is_obj_or_ar) { try self.dynstrtab.buffer.append(allocator, 0); @@ -1006,6 +1008,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node if (self.base.options.output_mode == .Obj and self.zig_module_index == null) { // TODO this will become -r route I guess. For now, just copy the object file. + assert(self.base.file == null); // TODO uncomment once we implement -r const the_object_path = blk: { if (self.base.options.objects.len != 0) { break :blk self.base.options.objects[0].path; |
