authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 23:57:30+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 23:57:33+02:00
log43fb74f81a8cdefa447c949ff761bfce3aa8aa91
tree8709d8e6945a6bb8b75b0b920ca14d89ec7cd41a
parent77443ac2b54aa4f6ccf8046fe787d7409af526d2

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.

1 files changed, 8 insertions(+), 5 deletions(-)

src/link/Elf.zig+8-5
...@@ -241,6 +241,9 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -241,6 +241,9 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
241 const self = try createEmpty(allocator, options);241 const self = try createEmpty(allocator, options);
242 errdefer self.base.destroy();242 errdefer self.base.destroy();
243243
244 const is_obj = options.output_mode == .Obj;
245 const is_obj_or_ar = is_obj or (options.output_mode == .Lib and options.link_mode == .Static);
246
244 if (options.use_llvm) {247 if (options.use_llvm) {
245 const use_lld = build_options.have_llvm and self.base.options.use_lld;248 const use_lld = build_options.have_llvm and self.base.options.use_lld;
246 if (use_lld) return self;249 if (use_lld) return self;
...@@ -250,6 +253,10 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -250,6 +253,10 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
250 sub_path, options.target.ofmt.fileExt(options.target.cpu.arch),253 sub_path, options.target.ofmt.fileExt(options.target.cpu.arch),
251 });254 });
252 }255 }
256 if (is_obj) {
257 // TODO until we implement -r option, we don't want to open a file at this stage.
258 return self;
259 }
253 }260 }
254 errdefer if (self.base.intermediary_basename) |path| allocator.free(path);261 errdefer if (self.base.intermediary_basename) |path| allocator.free(path);
255262
...@@ -273,11 +280,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -273,11 +280,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
273 // There must always be a null shdr in index 0280 // There must always be a null shdr in index 0
274 _ = try self.addSection(.{ .name = "" });281 _ = try self.addSection(.{ .name = "" });
275282
276 const is_obj_or_ar = switch (options.output_mode) {
277 .Obj => true,
278 .Lib => options.link_mode == .Static,
279 else => false,
280 };
281 if (!is_obj_or_ar) {283 if (!is_obj_or_ar) {
282 try self.dynstrtab.buffer.append(allocator, 0);284 try self.dynstrtab.buffer.append(allocator, 0);
283285
...@@ -1006,6 +1008,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1006,6 +1008,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10061008
1007 if (self.base.options.output_mode == .Obj and self.zig_module_index == null) {1009 if (self.base.options.output_mode == .Obj and self.zig_module_index == null) {
1008 // TODO this will become -r route I guess. For now, just copy the object file.1010 // TODO this will become -r route I guess. For now, just copy the object file.
1011 assert(self.base.file == null); // TODO uncomment once we implement -r
1009 const the_object_path = blk: {1012 const the_object_path = blk: {
1010 if (self.base.options.objects.len != 0) {1013 if (self.base.options.objects.len != 0) {
1011 break :blk self.base.options.objects[0].path;1014 break :blk self.base.options.objects[0].path;