authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-16 15:49:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:20-07:00
log2d2a18831e9821e22d23b4a15ffd20e30e24b27b
tree4e1ba354fe14990efbab35c6ba3e8a85452fc3b8
parent9b98d33d0b76a8c8b23958c89ab7e952893697be

linker: rename intermediary_basname to zcu_object_sub_path


7 files changed, 41 insertions(+), 34 deletions(-)

src/link.zig+5-5
...@@ -58,7 +58,7 @@ pub const File = struct {...@@ -58,7 +58,7 @@ pub const File = struct {
58 file: ?fs.File,58 file: ?fs.File,
59 /// When linking with LLD, this linker code will output an object file only at59 /// When linking with LLD, this linker code will output an object file only at
60 /// this location, and then this path can be placed on the LLD linker line.60 /// this location, and then this path can be placed on the LLD linker line.
61 intermediary_basename: ?[]const u8 = null,61 zcu_object_sub_path: ?[]const u8 = null,
62 disable_lld_caching: bool,62 disable_lld_caching: bool,
63 gc_sections: bool,63 gc_sections: bool,
64 print_gc_sections: bool,64 print_gc_sections: bool,
...@@ -289,7 +289,7 @@ pub const File = struct {...@@ -289,7 +289,7 @@ pub const File = struct {
289 switch (base.tag) {289 switch (base.tag) {
290 .elf => if (base.file) |f| {290 .elf => if (base.file) |f| {
291 if (build_options.only_c) unreachable;291 if (build_options.only_c) unreachable;
292 if (base.intermediary_basename != null and use_lld) {292 if (base.zcu_object_sub_path != null and use_lld) {
293 // The file we have open is not the final file that we want to293 // The file we have open is not the final file that we want to
294 // make executable, so we don't have to close it.294 // make executable, so we don't have to close it.
295 return;295 return;
...@@ -308,7 +308,7 @@ pub const File = struct {...@@ -308,7 +308,7 @@ pub const File = struct {
308 },308 },
309 .coff, .macho, .plan9, .wasm => if (base.file) |f| {309 .coff, .macho, .plan9, .wasm => if (base.file) |f| {
310 if (build_options.only_c) unreachable;310 if (build_options.only_c) unreachable;
311 if (base.intermediary_basename != null) {311 if (base.zcu_object_sub_path != null) {
312 // The file we have open is not the final file that we want to312 // The file we have open is not the final file that we want to
313 // make executable, so we don't have to close it.313 // make executable, so we don't have to close it.
314 return;314 return;
...@@ -734,7 +734,7 @@ pub const File = struct {...@@ -734,7 +734,7 @@ pub const File = struct {
734 try base.flushModule(comp, prog_node);734 try base.flushModule(comp, prog_node);
735735
736 const dirname = fs.path.dirname(full_out_path_z) orelse ".";736 const dirname = fs.path.dirname(full_out_path_z) orelse ".";
737 break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });737 break :blk try fs.path.join(arena, &.{ dirname, base.zcu_object_sub_path.? });
738 } else null;738 } else null;
739739
740 log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"});740 log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"});
...@@ -1022,7 +1022,7 @@ pub const File = struct {...@@ -1022,7 +1022,7 @@ pub const File = struct {
1022 .pre_bc_path = comp.verbose_llvm_bc,1022 .pre_bc_path = comp.verbose_llvm_bc,
1023 .bin_path = try base.resolveEmitLoc(arena, .{1023 .bin_path = try base.resolveEmitLoc(arena, .{
1024 .directory = null,1024 .directory = null,
1025 .basename = base.intermediary_basename.?,1025 .basename = base.zcu_object_sub_path.?,
1026 }),1026 }),
1027 .asm_path = try base.resolveEmitLoc(arena, comp.emit_asm),1027 .asm_path = try base.resolveEmitLoc(arena, comp.emit_asm),
1028 .post_ir_path = try base.resolveEmitLoc(arena, comp.emit_llvm_ir),1028 .post_ir_path = try base.resolveEmitLoc(arena, comp.emit_llvm_ir),
src/link/Coff.zig+2-2
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3//! LLD for traditional linking (linking relocatable object files).3//! LLD for traditional linking (linking relocatable object files).
4//! LLD is also the default linker for LLVM.4//! LLD is also the default linker for LLVM.
55
6/// If this is not null, an object file is created by LLVM and emitted to intermediary_basename.6/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
7llvm_object: ?*LlvmObject = null,7llvm_object: ?*LlvmObject = null,
88
9base: link.File,9base: link.File,
...@@ -261,7 +261,7 @@ pub fn open(...@@ -261,7 +261,7 @@ pub fn open(
261 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{261 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{
262 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),262 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),
263 });263 });
264 self.base.intermediary_basename = o_file_path;264 self.base.zcu_object_sub_path = o_file_path;
265 break :p o_file_path;265 break :p o_file_path;
266 };266 };
267267
src/link/Coff/lld.zig+2-2
...@@ -35,9 +35,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -35,9 +35,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
35 try self.flushModule(comp, prog_node);35 try self.flushModule(comp, prog_node);
3636
37 if (fs.path.dirname(full_out_path)) |dirname| {37 if (fs.path.dirname(full_out_path)) |dirname| {
38 break :blk try fs.path.join(arena, &.{ dirname, self.base.intermediary_basename.? });38 break :blk try fs.path.join(arena, &.{ dirname, self.base.zcu_object_sub_path.? });
39 } else {39 } else {
40 break :blk self.base.intermediary_basename.?;40 break :blk self.base.zcu_object_sub_path.?;
41 }41 }
42 } else null;42 } else null;
4343
src/link/Elf.zig+22-15
...@@ -28,7 +28,7 @@ print_map: bool,...@@ -28,7 +28,7 @@ print_map: bool,
2828
29ptr_width: PtrWidth,29ptr_width: PtrWidth,
3030
31/// If this is not null, an object file is created by LLVM and emitted to intermediary_basename.31/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
32llvm_object: ?*LlvmObject = null,32llvm_object: ?*LlvmObject = null,
3333
34/// A list of all input files.34/// A list of all input files.
...@@ -259,12 +259,25 @@ pub fn createEmpty(...@@ -259,12 +259,25 @@ pub fn createEmpty(
259 else259 else
260 elf.VER_NDX_LOCAL;260 elf.VER_NDX_LOCAL;
261261
262 // If using LLD to link, this code should produce an object file so that it
263 // can be passed to LLD.
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 subsequently
266 // 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 };
273
262 const self = try arena.create(Elf);274 const self = try arena.create(Elf);
263 self.* = .{275 self.* = .{
264 .base = .{276 .base = .{
265 .tag = .elf,277 .tag = .elf,
266 .comp = comp,278 .comp = comp,
267 .emit = emit,279 .emit = emit,
280 .zcu_object_sub_path = zcu_object_sub_path,
268 .gc_sections = options.gc_sections orelse (optimize_mode != .Debug and output_mode != .Obj),281 .gc_sections = options.gc_sections orelse (optimize_mode != .Debug and output_mode != .Obj),
269 .print_gc_sections = options.print_gc_sections,282 .print_gc_sections = options.print_gc_sections,
270 .stack_size = options.stack_size orelse 16777216,283 .stack_size = options.stack_size orelse 16777216,
...@@ -325,16 +338,10 @@ pub fn createEmpty(...@@ -325,16 +338,10 @@ pub fn createEmpty(
325 const is_obj = output_mode == .Obj;338 const is_obj = output_mode == .Obj;
326 const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .Static);339 const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .Static);
327340
328 const sub_path = if (!use_lld) emit.sub_path else p: {341 // What path should this ELF linker code output to?
329 // Open a temporary object file, not the final output file because we342 // If using LLD to link, this code should produce an object file so that it
330 // want to link with LLD.343 // can be passed to LLD.
331 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{344 const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path;
332 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),
333 });
334 self.base.intermediary_basename = o_file_path;
335 break :p o_file_path;
336 };
337
338 self.base.file = try emit.directory.handle.createFile(sub_path, .{345 self.base.file = try emit.directory.handle.createFile(sub_path, .{
339 .truncate = false,346 .truncate = false,
340 .read = true,347 .read = true,
...@@ -1045,7 +1052,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1045,7 +1052,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1045 const link_mode = comp.config.link_mode;1052 const link_mode = comp.config.link_mode;
1046 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.1053 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
1047 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});1054 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
1048 const module_obj_path: ?[]const u8 = if (self.base.intermediary_basename) |path| blk: {1055 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
1049 if (fs.path.dirname(full_out_path)) |dirname| {1056 if (fs.path.dirname(full_out_path)) |dirname| {
1050 break :blk try fs.path.join(arena, &.{ dirname, path });1057 break :blk try fs.path.join(arena, &.{ dirname, path });
1051 } else {1058 } else {
...@@ -1613,7 +1620,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {...@@ -1613,7 +1620,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
1613 const link_mode = self.base.comp.config.link_mode;1620 const link_mode = self.base.comp.config.link_mode;
1614 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.1621 const directory = self.base.emit.directory; // Just an alias to make it shorter to type.
1615 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});1622 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path});
1616 const module_obj_path: ?[]const u8 = if (self.base.intermediary_basename) |path| blk: {1623 const module_obj_path: ?[]const u8 = if (self.base.zcu_object_sub_path) |path| blk: {
1617 if (fs.path.dirname(full_out_path)) |dirname| {1624 if (fs.path.dirname(full_out_path)) |dirname| {
1618 break :blk try fs.path.join(arena, &.{ dirname, path });1625 break :blk try fs.path.join(arena, &.{ dirname, path });
1619 } else {1626 } else {
...@@ -2356,9 +2363,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -2356,9 +2363,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
2356 try self.flushModule(comp, prog_node);2363 try self.flushModule(comp, prog_node);
23572364
2358 if (fs.path.dirname(full_out_path)) |dirname| {2365 if (fs.path.dirname(full_out_path)) |dirname| {
2359 break :blk try fs.path.join(arena, &.{ dirname, self.base.intermediary_basename.? });2366 break :blk try fs.path.join(arena, &.{ dirname, self.base.zcu_object_sub_path.? });
2360 } else {2367 } else {
2361 break :blk self.base.intermediary_basename.?;2368 break :blk self.base.zcu_object_sub_path.?;
2362 }2369 }
2363 } else null;2370 } else null;
23642371
src/link/MachO.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1base: File,1base: File,
22
3/// If this is not null, an object file is created by LLVM and emitted to intermediary_basename.3/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
4llvm_object: ?*LlvmObject = null,4llvm_object: ?*LlvmObject = null,
55
6/// Debug symbols bundle (or dSym).6/// Debug symbols bundle (or dSym).
...@@ -208,10 +208,10 @@ pub fn open(...@@ -208,10 +208,10 @@ pub fn open(
208 errdefer self.base.destroy();208 errdefer self.base.destroy();
209209
210 if (mode == .zld) {210 if (mode == .zld) {
211 // TODO this intermediary_basename isn't enough; in the case of `zig build-exe`,211 // TODO this zcu_object_sub_path isn't enough; in the case of `zig build-exe`,
212 // we also want to put the intermediary object file in the cache while the212 // we also want to put the intermediary object file in the cache while the
213 // main emit directory is the cwd.213 // main emit directory is the cwd.
214 self.base.intermediary_basename = sub_path;214 self.base.zcu_object_sub_path = sub_path;
215 return self;215 return self;
216 }216 }
217217
src/link/MachO/zld.zig+2-2
...@@ -24,9 +24,9 @@ pub fn linkWithZld(...@@ -24,9 +24,9 @@ pub fn linkWithZld(
24 try macho_file.flushModule(comp, prog_node);24 try macho_file.flushModule(comp, prog_node);
2525
26 if (fs.path.dirname(full_out_path)) |dirname| {26 if (fs.path.dirname(full_out_path)) |dirname| {
27 break :blk try fs.path.join(arena, &.{ dirname, macho_file.base.intermediary_basename.? });27 break :blk try fs.path.join(arena, &.{ dirname, macho_file.base.zcu_object_sub_path.? });
28 } else {28 } else {
29 break :blk macho_file.base.intermediary_basename.?;29 break :blk macho_file.base.zcu_object_sub_path.?;
30 }30 }
31 } else null;31 } else null;
3232
src/link/Wasm.zig+5-5
...@@ -401,7 +401,7 @@ pub fn open(...@@ -401,7 +401,7 @@ pub fn open(
401 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{401 const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{
402 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),402 emit.sub_path, target.ofmt.fileExt(target.cpu.arch),
403 });403 });
404 wasm.base.intermediary_basename = o_file_path;404 wasm.base.zcu_object_sub_path = o_file_path;
405 break :p o_file_path;405 break :p o_file_path;
406 };406 };
407407
...@@ -3511,9 +3511,9 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l...@@ -3511,9 +3511,9 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l
3511 try wasm.flushModule(comp, prog_node);3511 try wasm.flushModule(comp, prog_node);
35123512
3513 if (fs.path.dirname(full_out_path)) |dirname| {3513 if (fs.path.dirname(full_out_path)) |dirname| {
3514 break :blk try fs.path.join(arena, &.{ dirname, wasm.base.intermediary_basename.? });3514 break :blk try fs.path.join(arena, &.{ dirname, wasm.base.zcu_object_sub_path.? });
3515 } else {3515 } else {
3516 break :blk wasm.base.intermediary_basename.?;3516 break :blk wasm.base.zcu_object_sub_path.?;
3517 }3517 }
3518 } else null;3518 } else null;
35193519
...@@ -4604,9 +4604,9 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4604,9 +4604,9 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4604 try wasm.flushModule(comp, prog_node);4604 try wasm.flushModule(comp, prog_node);
46054605
4606 if (fs.path.dirname(full_out_path)) |dirname| {4606 if (fs.path.dirname(full_out_path)) |dirname| {
4607 break :blk try fs.path.join(arena, &.{ dirname, wasm.base.intermediary_basename.? });4607 break :blk try fs.path.join(arena, &.{ dirname, wasm.base.zcu_object_sub_path.? });
4608 } else {4608 } else {
4609 break :blk wasm.base.intermediary_basename.?;4609 break :blk wasm.base.zcu_object_sub_path.?;
4610 }4610 }
4611 } else null;4611 } else null;
46124612