authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-24 19:47:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:21-07:00
log981166e33f967c62971de1aee79779fcfb3e37b7
treea02c4b9fd1b3e66544638828c7c16ad0265760ad
parent4d28db7329c32d7a2b7915d7a5da7f93c4088ccd

link.Elf: truncate=true in createEmpty


1 files changed, 7 insertions(+), 7 deletions(-)

src/link/Elf.zig+7-7
...@@ -264,12 +264,10 @@ pub fn createEmpty(...@@ -264,12 +264,10 @@ pub fn createEmpty(
264 // If using LLVM to generate the object file for the zig compilation unit,264 // If using LLVM to generate the object file for the zig compilation unit,
265 // we need a place to put the object file so that it can be subsequently265 // we need a place to put the object file so that it can be subsequently
266 // handled.266 // handled.
267 const zcu_object_sub_path = if (!use_lld and !use_llvm) null else p: {267 const zcu_object_sub_path = if (!use_lld and !use_llvm)
268 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{268 null
269 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),269 else
270 });270 try std.fmt.allocPrint(arena, "{s}.o", .{emit.sub_path});
271 break :p o_file_path;
272 };
273271
274 const self = try arena.create(Elf);272 const self = try arena.create(Elf);
275 self.* = .{273 self.* = .{
...@@ -343,7 +341,7 @@ pub fn createEmpty(...@@ -343,7 +341,7 @@ pub fn createEmpty(
343 // can be passed to LLD.341 // can be passed to LLD.
344 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;342 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
345 self.base.file = try emit.directory.handle.createFile(sub_path, .{343 self.base.file = try emit.directory.handle.createFile(sub_path, .{
346 .truncate = false,344 .truncate = true,
347 .read = true,345 .read = true,
348 .mode = link.File.determineMode(use_lld, output_mode, link_mode),346 .mode = link.File.determineMode(use_lld, output_mode, link_mode),
349 });347 });
...@@ -431,6 +429,8 @@ pub fn open(...@@ -431,6 +429,8 @@ pub fn open(
431 emit: Compilation.Emit,429 emit: Compilation.Emit,
432 options: link.File.OpenOptions,430 options: link.File.OpenOptions,
433) !*Elf {431) !*Elf {
432 // TODO: restore saved linker state, don't truncate the file, and
433 // participate in incremental compilation.
434 return createEmpty(arena, comp, emit, options);434 return createEmpty(arena, comp, emit, options);
435}435}
436436