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(
264264 // If using LLVM to generate the object file for the zig compilation unit,
265265 // we need a place to put the object file so that it can be subsequently
266266 // handled.
267 const zcu_object_sub_path = if (!use_lld and !use_llvm) null else p: {
268 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{
269 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),
270 });
271 break :p o_file_path;
272 };
267 const zcu_object_sub_path = if (!use_lld and !use_llvm)
268 null
269 else
270 try std.fmt.allocPrint(arena, "{s}.o", .{emit.sub_path});
273271
274272 const self = try arena.create(Elf);
275273 self.* = .{
......@@ -343,7 +341,7 @@ pub fn createEmpty(
343341 // can be passed to LLD.
344342 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
345343 self.base.file = try emit.directory.handle.createFile(sub_path, .{
346 .truncate = false,
344 .truncate = true,
347345 .read = true,
348346 .mode = link.File.determineMode(use_lld, output_mode, link_mode),
349347 });
......@@ -431,6 +429,8 @@ pub fn open(
431429 emit: Compilation.Emit,
432430 options: link.File.OpenOptions,
433431) !*Elf {
432 // TODO: restore saved linker state, don't truncate the file, and
433 // participate in incremental compilation.
434434 return createEmpty(arena, comp, emit, options);
435435}
436436