authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-11 21:22:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
log6ec6c077957c8d1f96d83299b35f6c84a34b07e6
tree4ccd033a2b2602f85e394c9694e449acf42589da
parent2be36c5b8d7d22c2ffc20b88e497da7e6612de5c

linker: update output_mode references


6 files changed, 28 insertions(+), 28 deletions(-)

src/link/Coff.zig+4-4
......@@ -1658,7 +1658,7 @@ pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) lin
16581658 if (use_lld) {
16591659 return lld.linkWithLLD(self, comp, prog_node);
16601660 }
1661 switch (self.base.options.output_mode) {
1661 switch (self.base.comp.config.output_mode) {
16621662 .Exe, .Obj => return self.flushModule(comp, prog_node),
16631663 .Lib => return error.TODOImplementWritingLibFiles,
16641664 }
......@@ -1779,7 +1779,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
17791779 try self.writeDataDirectoriesHeaders();
17801780 try self.writeSectionHeaders();
17811781
1782 if (self.entry_addr == null and self.base.options.output_mode == .Exe) {
1782 if (self.entry_addr == null and self.base.comp.config.output_mode == .Exe) {
17831783 log.debug("flushing. no_entry_point_found = true\n", .{});
17841784 self.error_flags.no_entry_point_found = true;
17851785 } else {
......@@ -2218,7 +2218,7 @@ fn writeHeader(self: *Coff) !void {
22182218 .p32 => flags.@"32BIT_MACHINE" = 1,
22192219 .p64 => flags.LARGE_ADDRESS_AWARE = 1,
22202220 }
2221 if (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic) {
2221 if (self.base.comp.config.output_mode == .Lib and self.base.options.link_mode == .Dynamic) {
22222222 flags.DLL = 1;
22232223 }
22242224
......@@ -2451,7 +2451,7 @@ pub fn getEntryPoint(self: Coff) ?SymbolWithLoc {
24512451}
24522452
24532453pub fn getImageBase(self: Coff) u64 {
2454 const image_base: u64 = self.base.options.image_base_override orelse switch (self.base.options.output_mode) {
2454 const image_base: u64 = self.base.options.image_base_override orelse switch (self.base.comp.config.output_mode) {
24552455 .Exe => switch (self.base.options.target.cpu.arch) {
24562456 .aarch64 => @as(u64, 0x140000000),
24572457 .x86_64, .x86 => 0x400000,
src/link/Coff/lld.zig+4-4
......@@ -45,9 +45,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
4545 sub_prog_node.context.refresh();
4646 defer sub_prog_node.end();
4747
48 const is_lib = self.base.options.output_mode == .Lib;
48 const is_lib = self.base.comp.config.output_mode == .Lib;
4949 const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;
50 const is_exe_or_dyn_lib = is_dyn_lib or self.base.options.output_mode == .Exe;
50 const is_exe_or_dyn_lib = is_dyn_lib or self.base.comp.config.output_mode == .Exe;
5151 const link_in_crt = self.base.options.link_libc and is_exe_or_dyn_lib;
5252 const target = self.base.options.target;
5353 const optimize_mode = self.base.comp.root_mod.optimize_mode;
......@@ -136,7 +136,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
136136 };
137137 }
138138
139 if (self.base.options.output_mode == .Obj) {
139 if (self.base.comp.config.output_mode == .Obj) {
140140 // LLD's COFF driver does not support the equivalent of `-r` so we do a simple file copy
141141 // here. TODO: think carefully about how we can avoid this redundant operation when doing
142142 // build-obj. See also the corresponding TODO in linkAsArchive.
......@@ -192,7 +192,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
192192 .ReleaseFast, .ReleaseSafe => try argv.append("-OPT:lldlto=3"),
193193 }
194194 }
195 if (self.base.options.output_mode == .Exe) {
195 if (self.base.comp.config.output_mode == .Exe) {
196196 try argv.append(try allocPrint(arena, "-STACK:{d}", .{self.base.stack_size}));
197197 }
198198 if (self.base.options.image_base_override) |image_base| {
src/link/Elf/Atom.zig+1-1
......@@ -658,7 +658,7 @@ fn dynAbsRelocAction(symbol: *const Symbol, elf_file: *Elf) RelocAction {
658658
659659fn outputType(elf_file: *Elf) u2 {
660660 assert(!elf_file.isRelocatable());
661 return switch (elf_file.base.options.output_mode) {
661 return switch (elf_file.base.comp.config.output_mode) {
662662 .Obj => unreachable,
663663 .Lib => 0,
664664 .Exe => if (elf_file.base.options.pie) 1 else 2,
src/link/MachO/dead_strip.zig+1-1
......@@ -33,7 +33,7 @@ fn addRoot(macho_file: *MachO, roots: *AtomTable, file: u32, sym_loc: SymbolWith
3333fn collectRoots(macho_file: *MachO, roots: *AtomTable) !void {
3434 log.debug("collecting roots", .{});
3535
36 switch (macho_file.base.options.output_mode) {
36 switch (macho_file.base.comp.config.output_mode) {
3737 .Exe => {
3838 // Add entrypoint as GC root
3939 if (macho_file.getEntryPoint()) |global| {
src/link/MachO/zld.zig+2-2
......@@ -407,7 +407,7 @@ pub fn linkWithZld(
407407 try macho_file.createDyldPrivateAtom();
408408 try macho_file.createTentativeDefAtoms();
409409
410 if (macho_file.base.options.output_mode == .Exe) {
410 if (macho_file.base.comp.config.output_mode == .Exe) {
411411 const global = macho_file.getEntryPoint().?;
412412 if (macho_file.getSymbol(global).undf()) {
413413 // We do one additional check here in case the entry point was found in one of the dylibs.
......@@ -612,7 +612,7 @@ fn createSegments(macho_file: *MachO) !void {
612612 const gpa = macho_file.base.allocator;
613613 const page_size = MachO.getPageSize(macho_file.base.options.target.cpu.arch);
614614 const aligned_pagezero_vmsize = mem.alignBackward(u64, macho_file.pagezero_vmsize, page_size);
615 if (macho_file.base.options.output_mode != .Lib and aligned_pagezero_vmsize > 0) {
615 if (macho_file.base.comp.config.output_mode != .Lib and aligned_pagezero_vmsize > 0) {
616616 if (aligned_pagezero_vmsize != macho_file.pagezero_vmsize) {
617617 log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{macho_file.pagezero_vmsize});
618618 log.warn(" rounding down to 0x{x}", .{aligned_pagezero_vmsize});
src/link/Wasm.zig+16-16
......@@ -1305,7 +1305,7 @@ pub fn findGlobalSymbol(wasm: *Wasm, name: []const u8) ?SymbolLoc {
13051305}
13061306
13071307fn checkUndefinedSymbols(wasm: *const Wasm) !void {
1308 if (wasm.base.options.output_mode == .Obj) return;
1308 if (wasm.base.comp.config.output_mode == .Obj) return;
13091309 if (wasm.base.options.import_symbols) return;
13101310
13111311 var found_undefined_symbols = false;
......@@ -2065,7 +2065,7 @@ fn mapFunctionTable(wasm: *Wasm) void {
20652065 }
20662066 }
20672067
2068 if (wasm.import_table or wasm.base.options.output_mode == .Obj) {
2068 if (wasm.import_table or wasm.base.comp.config.output_mode == .Obj) {
20692069 const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?;
20702070 const import = wasm.imports.getPtr(sym_loc).?;
20712071 import.kind.table.limits.min = index - 1; // we start at index 1.
......@@ -2230,11 +2230,11 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
22302230 // we set the entire region of it to zeroes.
22312231 // We do not have to do this when exporting the memory (the default) because the runtime
22322232 // will do it for us, and we do not emit the bss segment at all.
2233 if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
2233 if ((wasm.base.comp.config.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
22342234 @memset(atom.code.items, 0);
22352235 }
22362236
2237 const should_merge = wasm.base.options.output_mode != .Obj;
2237 const should_merge = wasm.base.comp.config.output_mode != .Obj;
22382238 const gop = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(should_merge));
22392239 if (gop.found_existing) {
22402240 const index = gop.value_ptr.*;
......@@ -2392,7 +2392,7 @@ fn allocateVirtualAddresses(wasm: *Wasm) void {
23922392 };
23932393
23942394 const atom = wasm.getAtom(atom_index);
2395 const merge_segment = wasm.base.options.output_mode != .Obj;
2395 const merge_segment = wasm.base.comp.config.output_mode != .Obj;
23962396 const segment_info = if (atom.file) |object_index| blk: {
23972397 break :blk wasm.objects.items[object_index].segment_info;
23982398 } else wasm.segment_info.values();
......@@ -2934,7 +2934,7 @@ fn mergeTypes(wasm: *Wasm) !void {
29342934
29352935fn setupExports(wasm: *Wasm) !void {
29362936 const gpa = wasm.base.comp.gpa;
2937 if (wasm.base.options.output_mode == .Obj) return;
2937 if (wasm.base.comp.config.output_mode == .Obj) return;
29382938 log.debug("Building exports from symbols", .{});
29392939
29402940 const force_exp_names = wasm.base.options.export_symbol_names;
......@@ -3009,7 +3009,7 @@ fn setupStart(wasm: *Wasm) !void {
30093009 }
30103010
30113011 // Ensure the symbol is exported so host environment can access it
3012 if (wasm.base.options.output_mode != .Obj) {
3012 if (wasm.base.comp.config.output_mode != .Obj) {
30133013 symbol.setFlag(.WASM_SYM_EXPORTED);
30143014 }
30153015}
......@@ -3029,7 +3029,7 @@ fn setupMemory(wasm: *Wasm) !void {
30293029 break :blk base;
30303030 } else 0;
30313031
3032 const is_obj = wasm.base.options.output_mode == .Obj;
3032 const is_obj = wasm.base.comp.config.output_mode == .Obj;
30333033
30343034 if (place_stack_first and !is_obj) {
30353035 memory_ptr = stack_alignment.forward(memory_ptr);
......@@ -3155,7 +3155,7 @@ pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, symbol_index: u32) !u3
31553155 switch (symbol.tag) {
31563156 .data => {
31573157 const segment_info = object.segment_info[symbol.index];
3158 const merge_segment = wasm.base.options.output_mode != .Obj;
3158 const merge_segment = wasm.base.comp.config.output_mode != .Obj;
31593159 const result = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(merge_segment));
31603160 if (!result.found_existing) {
31613161 result.value_ptr.* = index;
......@@ -3797,7 +3797,7 @@ fn writeToFile(
37973797 var code_section_index: ?u32 = null;
37983798 // Index of the data section. Used to tell relocation table where the section lives.
37993799 var data_section_index: ?u32 = null;
3800 const is_obj = wasm.base.options.output_mode == .Obj or (!use_llvm and use_lld);
3800 const is_obj = wasm.base.comp.config.output_mode == .Obj or (!use_llvm and use_lld);
38013801
38023802 var binary_bytes = std.ArrayList(u8).init(gpa);
38033803 defer binary_bytes.deinit();
......@@ -4550,7 +4550,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
45504550 sub_prog_node.context.refresh();
45514551 defer sub_prog_node.end();
45524552
4553 const is_obj = wasm.base.options.output_mode == .Obj;
4553 const is_obj = wasm.base.comp.config.output_mode == .Obj;
45544554 const compiler_rt_path: ?[]const u8 = blk: {
45554555 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
45564556 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;
......@@ -4750,7 +4750,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
47504750 try argv.append("--allow-undefined");
47514751 }
47524752
4753 if (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) {
4753 if (wasm.base.comp.config.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) {
47544754 try argv.append("--shared");
47554755 }
47564756 if (wasm.base.options.pie) {
......@@ -4769,8 +4769,8 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
47694769 }
47704770
47714771 if (target.os.tag == .wasi) {
4772 const is_exe_or_dyn_lib = wasm.base.options.output_mode == .Exe or
4773 (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);
4772 const is_exe_or_dyn_lib = wasm.base.comp.config.output_mode == .Exe or
4773 (wasm.base.comp.config.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);
47744774 if (is_exe_or_dyn_lib) {
47754775 for (wasm.wasi_emulated_libs) |crt_file| {
47764776 try argv.append(try comp.get_libc_crt_file(
......@@ -4818,7 +4818,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
48184818 try argv.append(p);
48194819 }
48204820
4821 if (wasm.base.options.output_mode != .Obj and
4821 if (wasm.base.comp.config.output_mode != .Obj and
48224822 !wasm.base.options.skip_linker_dependencies and
48234823 !wasm.base.options.link_libc)
48244824 {
......@@ -4904,7 +4904,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
49044904 // it, and then can react to that in the same way as trying to run an ELF file
49054905 // from a foreign CPU architecture.
49064906 if (fs.has_executable_bit and target.os.tag == .wasi and
4907 wasm.base.options.output_mode == .Exe)
4907 wasm.base.comp.config.output_mode == .Exe)
49084908 {
49094909 // TODO: what's our strategy for reporting linker errors from this function?
49104910 // report a nice error here with the file path if it fails instead of