| author | |
| committer | |
| log | 2d2a18831e9821e22d23b4a15ffd20e30e24b27b |
| tree | 4e1ba354fe14990efbab35c6ba3e8a85452fc3b8 |
| parent | 9b98d33d0b76a8c8b23958c89ab7e952893697be |
7 files changed, 41 insertions(+), 34 deletions(-)
src/link.zig+5-5| ... | ... | @@ -58,7 +58,7 @@ pub const File = struct { |
| 58 | 58 | file: ?fs.File, |
| 59 | 59 | /// When linking with LLD, this linker code will output an object file only at |
| 60 | 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 | 62 | disable_lld_caching: bool, |
| 63 | 63 | gc_sections: bool, |
| 64 | 64 | print_gc_sections: bool, |
| ... | ... | @@ -289,7 +289,7 @@ pub const File = struct { |
| 289 | 289 | switch (base.tag) { |
| 290 | 290 | .elf => if (base.file) |f| { |
| 291 | 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 | 293 | // The file we have open is not the final file that we want to |
| 294 | 294 | // make executable, so we don't have to close it. |
| 295 | 295 | return; |
| ... | ... | @@ -308,7 +308,7 @@ pub const File = struct { |
| 308 | 308 | }, |
| 309 | 309 | .coff, .macho, .plan9, .wasm => if (base.file) |f| { |
| 310 | 310 | if (build_options.only_c) unreachable; |
| 311 | if (base.intermediary_basename != null) { | |
| 311 | if (base.zcu_object_sub_path != null) { | |
| 312 | 312 | // The file we have open is not the final file that we want to |
| 313 | 313 | // make executable, so we don't have to close it. |
| 314 | 314 | return; |
| ... | ... | @@ -734,7 +734,7 @@ pub const File = struct { |
| 734 | 734 | try base.flushModule(comp, prog_node); |
| 735 | 735 | |
| 736 | 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 | 738 | } else null; |
| 739 | 739 | |
| 740 | 740 | log.debug("zcu_obj_path={s}", .{if (zcu_obj_path) |s| s else "(null)"}); |
| ... | ... | @@ -1022,7 +1022,7 @@ pub const File = struct { |
| 1022 | 1022 | .pre_bc_path = comp.verbose_llvm_bc, |
| 1023 | 1023 | .bin_path = try base.resolveEmitLoc(arena, .{ |
| 1024 | 1024 | .directory = null, |
| 1025 | .basename = base.intermediary_basename.?, | |
| 1025 | .basename = base.zcu_object_sub_path.?, | |
| 1026 | 1026 | }), |
| 1027 | 1027 | .asm_path = try base.resolveEmitLoc(arena, comp.emit_asm), |
| 1028 | 1028 | .post_ir_path = try base.resolveEmitLoc(arena, comp.emit_llvm_ir), |
src/link/Coff.zig+2-2| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | //! LLD for traditional linking (linking relocatable object files). |
| 4 | 4 | //! LLD is also the default linker for LLVM. |
| 5 | 5 | |
| 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. | |
| 7 | 7 | llvm_object: ?*LlvmObject = null, |
| 8 | 8 | |
| 9 | 9 | base: link.File, |
| ... | ... | @@ -261,7 +261,7 @@ pub fn open( |
| 261 | 261 | const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{ |
| 262 | 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 | 265 | break :p o_file_path; |
| 266 | 266 | }; |
| 267 | 267 |
src/link/Coff/lld.zig+2-2| ... | ... | @@ -35,9 +35,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 35 | 35 | try self.flushModule(comp, prog_node); |
| 36 | 36 | |
| 37 | 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 | 39 | } else { |
| 40 | break :blk self.base.intermediary_basename.?; | |
| 40 | break :blk self.base.zcu_object_sub_path.?; | |
| 41 | 41 | } |
| 42 | 42 | } else null; |
| 43 | 43 |
src/link/Elf.zig+22-15| ... | ... | @@ -28,7 +28,7 @@ print_map: bool, |
| 28 | 28 | |
| 29 | 29 | ptr_width: PtrWidth, |
| 30 | 30 | |
| 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. | |
| 32 | 32 | llvm_object: ?*LlvmObject = null, |
| 33 | 33 | |
| 34 | 34 | /// A list of all input files. |
| ... | ... | @@ -259,12 +259,25 @@ pub fn createEmpty( |
| 259 | 259 | else |
| 260 | 260 | elf.VER_NDX_LOCAL; |
| 261 | 261 | |
| 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 | 274 | const self = try arena.create(Elf); |
| 263 | 275 | self.* = .{ |
| 264 | 276 | .base = .{ |
| 265 | 277 | .tag = .elf, |
| 266 | 278 | .comp = comp, |
| 267 | 279 | .emit = emit, |
| 280 | .zcu_object_sub_path = zcu_object_sub_path, | |
| 268 | 281 | .gc_sections = options.gc_sections orelse (optimize_mode != .Debug and output_mode != .Obj), |
| 269 | 282 | .print_gc_sections = options.print_gc_sections, |
| 270 | 283 | .stack_size = options.stack_size orelse 16777216, |
| ... | ... | @@ -325,16 +338,10 @@ pub fn createEmpty( |
| 325 | 338 | const is_obj = output_mode == .Obj; |
| 326 | 339 | const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .Static); |
| 327 | 340 | |
| 328 | const sub_path = if (!use_lld) emit.sub_path else p: { | |
| 329 | // Open a temporary object file, not the final output file because we | |
| 330 | // want to link with LLD. | |
| 331 | const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{ | |
| 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 | ||
| 341 | // What path should this ELF linker code output to? | |
| 342 | // If using LLD to link, this code should produce an object file so that it | |
| 343 | // can be passed to LLD. | |
| 344 | const sub_path = if (use_lld) zcu_object_sub_path.? else emit.sub_path; | |
| 338 | 345 | self.base.file = try emit.directory.handle.createFile(sub_path, .{ |
| 339 | 346 | .truncate = false, |
| 340 | 347 | .read = true, |
| ... | ... | @@ -1045,7 +1052,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1045 | 1052 | const link_mode = comp.config.link_mode; |
| 1046 | 1053 | const directory = self.base.emit.directory; // Just an alias to make it shorter to type. |
| 1047 | 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 | 1056 | if (fs.path.dirname(full_out_path)) |dirname| { |
| 1050 | 1057 | break :blk try fs.path.join(arena, &.{ dirname, path }); |
| 1051 | 1058 | } else { |
| ... | ... | @@ -1613,7 +1620,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { |
| 1613 | 1620 | const link_mode = self.base.comp.config.link_mode; |
| 1614 | 1621 | const directory = self.base.emit.directory; // Just an alias to make it shorter to type. |
| 1615 | 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 | 1624 | if (fs.path.dirname(full_out_path)) |dirname| { |
| 1618 | 1625 | break :blk try fs.path.join(arena, &.{ dirname, path }); |
| 1619 | 1626 | } else { |
| ... | ... | @@ -2356,9 +2363,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 2356 | 2363 | try self.flushModule(comp, prog_node); |
| 2357 | 2364 | |
| 2358 | 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 | 2367 | } else { |
| 2361 | break :blk self.base.intermediary_basename.?; | |
| 2368 | break :blk self.base.zcu_object_sub_path.?; | |
| 2362 | 2369 | } |
| 2363 | 2370 | } else null; |
| 2364 | 2371 |
src/link/MachO.zig+3-3| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | base: File, |
| 2 | 2 | |
| 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. | |
| 4 | 4 | llvm_object: ?*LlvmObject = null, |
| 5 | 5 | |
| 6 | 6 | /// Debug symbols bundle (or dSym). |
| ... | ... | @@ -208,10 +208,10 @@ pub fn open( |
| 208 | 208 | errdefer self.base.destroy(); |
| 209 | 209 | |
| 210 | 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 | 212 | // we also want to put the intermediary object file in the cache while the |
| 213 | 213 | // main emit directory is the cwd. |
| 214 | self.base.intermediary_basename = sub_path; | |
| 214 | self.base.zcu_object_sub_path = sub_path; | |
| 215 | 215 | return self; |
| 216 | 216 | } |
| 217 | 217 |
src/link/MachO/zld.zig+2-2| ... | ... | @@ -24,9 +24,9 @@ pub fn linkWithZld( |
| 24 | 24 | try macho_file.flushModule(comp, prog_node); |
| 25 | 25 | |
| 26 | 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 | 28 | } else { |
| 29 | break :blk macho_file.base.intermediary_basename.?; | |
| 29 | break :blk macho_file.base.zcu_object_sub_path.?; | |
| 30 | 30 | } |
| 31 | 31 | } else null; |
| 32 | 32 |
src/link/Wasm.zig+5-5| ... | ... | @@ -401,7 +401,7 @@ pub fn open( |
| 401 | 401 | const o_file_path = try std.fmt.allocPrint(arena, "{s}{s}", .{ |
| 402 | 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 | 405 | break :p o_file_path; |
| 406 | 406 | }; |
| 407 | 407 | |
| ... | ... | @@ -3511,9 +3511,9 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l |
| 3511 | 3511 | try wasm.flushModule(comp, prog_node); |
| 3512 | 3512 | |
| 3513 | 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 | 3515 | } else { |
| 3516 | break :blk wasm.base.intermediary_basename.?; | |
| 3516 | break :blk wasm.base.zcu_object_sub_path.?; | |
| 3517 | 3517 | } |
| 3518 | 3518 | } else null; |
| 3519 | 3519 | |
| ... | ... | @@ -4604,9 +4604,9 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) ! |
| 4604 | 4604 | try wasm.flushModule(comp, prog_node); |
| 4605 | 4605 | |
| 4606 | 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 | 4608 | } else { |
| 4609 | break :blk wasm.base.intermediary_basename.?; | |
| 4609 | break :blk wasm.base.zcu_object_sub_path.?; | |
| 4610 | 4610 | } |
| 4611 | 4611 | } else null; |
| 4612 | 4612 |