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...@@ -1658,7 +1658,7 @@ pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) lin
1658 if (use_lld) {1658 if (use_lld) {
1659 return lld.linkWithLLD(self, comp, prog_node);1659 return lld.linkWithLLD(self, comp, prog_node);
1660 }1660 }
1661 switch (self.base.options.output_mode) {1661 switch (self.base.comp.config.output_mode) {
1662 .Exe, .Obj => return self.flushModule(comp, prog_node),1662 .Exe, .Obj => return self.flushModule(comp, prog_node),
1663 .Lib => return error.TODOImplementWritingLibFiles,1663 .Lib => return error.TODOImplementWritingLibFiles,
1664 }1664 }
...@@ -1779,7 +1779,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -1779,7 +1779,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
1779 try self.writeDataDirectoriesHeaders();1779 try self.writeDataDirectoriesHeaders();
1780 try self.writeSectionHeaders();1780 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) {
1783 log.debug("flushing. no_entry_point_found = true\n", .{});1783 log.debug("flushing. no_entry_point_found = true\n", .{});
1784 self.error_flags.no_entry_point_found = true;1784 self.error_flags.no_entry_point_found = true;
1785 } else {1785 } else {
...@@ -2218,7 +2218,7 @@ fn writeHeader(self: *Coff) !void {...@@ -2218,7 +2218,7 @@ fn writeHeader(self: *Coff) !void {
2218 .p32 => flags.@"32BIT_MACHINE" = 1,2218 .p32 => flags.@"32BIT_MACHINE" = 1,
2219 .p64 => flags.LARGE_ADDRESS_AWARE = 1,2219 .p64 => flags.LARGE_ADDRESS_AWARE = 1,
2220 }2220 }
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) {
2222 flags.DLL = 1;2222 flags.DLL = 1;
2223 }2223 }
22242224
...@@ -2451,7 +2451,7 @@ pub fn getEntryPoint(self: Coff) ?SymbolWithLoc {...@@ -2451,7 +2451,7 @@ pub fn getEntryPoint(self: Coff) ?SymbolWithLoc {
2451}2451}
24522452
2453pub fn getImageBase(self: Coff) u64 {2453pub 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) {
2455 .Exe => switch (self.base.options.target.cpu.arch) {2455 .Exe => switch (self.base.options.target.cpu.arch) {
2456 .aarch64 => @as(u64, 0x140000000),2456 .aarch64 => @as(u64, 0x140000000),
2457 .x86_64, .x86 => 0x400000,2457 .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...@@ -45,9 +45,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
45 sub_prog_node.context.refresh();45 sub_prog_node.context.refresh();
46 defer sub_prog_node.end();46 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;
49 const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;49 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;
51 const link_in_crt = self.base.options.link_libc and is_exe_or_dyn_lib;51 const link_in_crt = self.base.options.link_libc and is_exe_or_dyn_lib;
52 const target = self.base.options.target;52 const target = self.base.options.target;
53 const optimize_mode = self.base.comp.root_mod.optimize_mode;53 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...@@ -136,7 +136,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
136 };136 };
137 }137 }
138138
139 if (self.base.options.output_mode == .Obj) {139 if (self.base.comp.config.output_mode == .Obj) {
140 // LLD's COFF driver does not support the equivalent of `-r` so we do a simple file copy140 // LLD's COFF driver does not support the equivalent of `-r` so we do a simple file copy
141 // here. TODO: think carefully about how we can avoid this redundant operation when doing141 // here. TODO: think carefully about how we can avoid this redundant operation when doing
142 // build-obj. See also the corresponding TODO in linkAsArchive.142 // 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...@@ -192,7 +192,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
192 .ReleaseFast, .ReleaseSafe => try argv.append("-OPT:lldlto=3"),192 .ReleaseFast, .ReleaseSafe => try argv.append("-OPT:lldlto=3"),
193 }193 }
194 }194 }
195 if (self.base.options.output_mode == .Exe) {195 if (self.base.comp.config.output_mode == .Exe) {
196 try argv.append(try allocPrint(arena, "-STACK:{d}", .{self.base.stack_size}));196 try argv.append(try allocPrint(arena, "-STACK:{d}", .{self.base.stack_size}));
197 }197 }
198 if (self.base.options.image_base_override) |image_base| {198 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 {...@@ -658,7 +658,7 @@ fn dynAbsRelocAction(symbol: *const Symbol, elf_file: *Elf) RelocAction {
658658
659fn outputType(elf_file: *Elf) u2 {659fn outputType(elf_file: *Elf) u2 {
660 assert(!elf_file.isRelocatable());660 assert(!elf_file.isRelocatable());
661 return switch (elf_file.base.options.output_mode) {661 return switch (elf_file.base.comp.config.output_mode) {
662 .Obj => unreachable,662 .Obj => unreachable,
663 .Lib => 0,663 .Lib => 0,
664 .Exe => if (elf_file.base.options.pie) 1 else 2,664 .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...@@ -33,7 +33,7 @@ fn addRoot(macho_file: *MachO, roots: *AtomTable, file: u32, sym_loc: SymbolWith
33fn collectRoots(macho_file: *MachO, roots: *AtomTable) !void {33fn collectRoots(macho_file: *MachO, roots: *AtomTable) !void {
34 log.debug("collecting roots", .{});34 log.debug("collecting roots", .{});
3535
36 switch (macho_file.base.options.output_mode) {36 switch (macho_file.base.comp.config.output_mode) {
37 .Exe => {37 .Exe => {
38 // Add entrypoint as GC root38 // Add entrypoint as GC root
39 if (macho_file.getEntryPoint()) |global| {39 if (macho_file.getEntryPoint()) |global| {
src/link/MachO/zld.zig+2-2
...@@ -407,7 +407,7 @@ pub fn linkWithZld(...@@ -407,7 +407,7 @@ pub fn linkWithZld(
407 try macho_file.createDyldPrivateAtom();407 try macho_file.createDyldPrivateAtom();
408 try macho_file.createTentativeDefAtoms();408 try macho_file.createTentativeDefAtoms();
409409
410 if (macho_file.base.options.output_mode == .Exe) {410 if (macho_file.base.comp.config.output_mode == .Exe) {
411 const global = macho_file.getEntryPoint().?;411 const global = macho_file.getEntryPoint().?;
412 if (macho_file.getSymbol(global).undf()) {412 if (macho_file.getSymbol(global).undf()) {
413 // We do one additional check here in case the entry point was found in one of the dylibs.413 // 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 {...@@ -612,7 +612,7 @@ fn createSegments(macho_file: *MachO) !void {
612 const gpa = macho_file.base.allocator;612 const gpa = macho_file.base.allocator;
613 const page_size = MachO.getPageSize(macho_file.base.options.target.cpu.arch);613 const page_size = MachO.getPageSize(macho_file.base.options.target.cpu.arch);
614 const aligned_pagezero_vmsize = mem.alignBackward(u64, macho_file.pagezero_vmsize, page_size);614 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) {
616 if (aligned_pagezero_vmsize != macho_file.pagezero_vmsize) {616 if (aligned_pagezero_vmsize != macho_file.pagezero_vmsize) {
617 log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{macho_file.pagezero_vmsize});617 log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{macho_file.pagezero_vmsize});
618 log.warn(" rounding down to 0x{x}", .{aligned_pagezero_vmsize});618 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 {...@@ -1305,7 +1305,7 @@ pub fn findGlobalSymbol(wasm: *Wasm, name: []const u8) ?SymbolLoc {
1305}1305}
13061306
1307fn checkUndefinedSymbols(wasm: *const Wasm) !void {1307fn checkUndefinedSymbols(wasm: *const Wasm) !void {
1308 if (wasm.base.options.output_mode == .Obj) return;1308 if (wasm.base.comp.config.output_mode == .Obj) return;
1309 if (wasm.base.options.import_symbols) return;1309 if (wasm.base.options.import_symbols) return;
13101310
1311 var found_undefined_symbols = false;1311 var found_undefined_symbols = false;
...@@ -2065,7 +2065,7 @@ fn mapFunctionTable(wasm: *Wasm) void {...@@ -2065,7 +2065,7 @@ fn mapFunctionTable(wasm: *Wasm) void {
2065 }2065 }
2066 }2066 }
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) {
2069 const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?;2069 const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?;
2070 const import = wasm.imports.getPtr(sym_loc).?;2070 const import = wasm.imports.getPtr(sym_loc).?;
2071 import.kind.table.limits.min = index - 1; // we start at index 1.2071 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 {...@@ -2230,11 +2230,11 @@ fn parseAtom(wasm: *Wasm, atom_index: Atom.Index, kind: Kind) !void {
2230 // we set the entire region of it to zeroes.2230 // we set the entire region of it to zeroes.
2231 // We do not have to do this when exporting the memory (the default) because the runtime2231 // We do not have to do this when exporting the memory (the default) because the runtime
2232 // will do it for us, and we do not emit the bss segment at all.2232 // 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) {
2234 @memset(atom.code.items, 0);2234 @memset(atom.code.items, 0);
2235 }2235 }
22362236
2237 const should_merge = wasm.base.options.output_mode != .Obj;2237 const should_merge = wasm.base.comp.config.output_mode != .Obj;
2238 const gop = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(should_merge));2238 const gop = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(should_merge));
2239 if (gop.found_existing) {2239 if (gop.found_existing) {
2240 const index = gop.value_ptr.*;2240 const index = gop.value_ptr.*;
...@@ -2392,7 +2392,7 @@ fn allocateVirtualAddresses(wasm: *Wasm) void {...@@ -2392,7 +2392,7 @@ fn allocateVirtualAddresses(wasm: *Wasm) void {
2392 };2392 };
23932393
2394 const atom = wasm.getAtom(atom_index);2394 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;
2396 const segment_info = if (atom.file) |object_index| blk: {2396 const segment_info = if (atom.file) |object_index| blk: {
2397 break :blk wasm.objects.items[object_index].segment_info;2397 break :blk wasm.objects.items[object_index].segment_info;
2398 } else wasm.segment_info.values();2398 } else wasm.segment_info.values();
...@@ -2934,7 +2934,7 @@ fn mergeTypes(wasm: *Wasm) !void {...@@ -2934,7 +2934,7 @@ fn mergeTypes(wasm: *Wasm) !void {
29342934
2935fn setupExports(wasm: *Wasm) !void {2935fn setupExports(wasm: *Wasm) !void {
2936 const gpa = wasm.base.comp.gpa;2936 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;
2938 log.debug("Building exports from symbols", .{});2938 log.debug("Building exports from symbols", .{});
29392939
2940 const force_exp_names = wasm.base.options.export_symbol_names;2940 const force_exp_names = wasm.base.options.export_symbol_names;
...@@ -3009,7 +3009,7 @@ fn setupStart(wasm: *Wasm) !void {...@@ -3009,7 +3009,7 @@ fn setupStart(wasm: *Wasm) !void {
3009 }3009 }
30103010
3011 // Ensure the symbol is exported so host environment can access it3011 // 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) {
3013 symbol.setFlag(.WASM_SYM_EXPORTED);3013 symbol.setFlag(.WASM_SYM_EXPORTED);
3014 }3014 }
3015}3015}
...@@ -3029,7 +3029,7 @@ fn setupMemory(wasm: *Wasm) !void {...@@ -3029,7 +3029,7 @@ fn setupMemory(wasm: *Wasm) !void {
3029 break :blk base;3029 break :blk base;
3030 } else 0;3030 } 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
3034 if (place_stack_first and !is_obj) {3034 if (place_stack_first and !is_obj) {
3035 memory_ptr = stack_alignment.forward(memory_ptr);3035 memory_ptr = stack_alignment.forward(memory_ptr);
...@@ -3155,7 +3155,7 @@ pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, symbol_index: u32) !u3...@@ -3155,7 +3155,7 @@ pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, symbol_index: u32) !u3
3155 switch (symbol.tag) {3155 switch (symbol.tag) {
3156 .data => {3156 .data => {
3157 const segment_info = object.segment_info[symbol.index];3157 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;
3159 const result = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(merge_segment));3159 const result = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(merge_segment));
3160 if (!result.found_existing) {3160 if (!result.found_existing) {
3161 result.value_ptr.* = index;3161 result.value_ptr.* = index;
...@@ -3797,7 +3797,7 @@ fn writeToFile(...@@ -3797,7 +3797,7 @@ fn writeToFile(
3797 var code_section_index: ?u32 = null;3797 var code_section_index: ?u32 = null;
3798 // Index of the data section. Used to tell relocation table where the section lives.3798 // Index of the data section. Used to tell relocation table where the section lives.
3799 var data_section_index: ?u32 = null;3799 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
3802 var binary_bytes = std.ArrayList(u8).init(gpa);3802 var binary_bytes = std.ArrayList(u8).init(gpa);
3803 defer binary_bytes.deinit();3803 defer binary_bytes.deinit();
...@@ -4550,7 +4550,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4550,7 +4550,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4550 sub_prog_node.context.refresh();4550 sub_prog_node.context.refresh();
4551 defer sub_prog_node.end();4551 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;
4554 const compiler_rt_path: ?[]const u8 = blk: {4554 const compiler_rt_path: ?[]const u8 = blk: {
4555 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;4555 if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
4556 if (comp.compiler_rt_obj) |obj| break :blk obj.full_object_path;4556 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) !...@@ -4750,7 +4750,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4750 try argv.append("--allow-undefined");4750 try argv.append("--allow-undefined");
4751 }4751 }
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) {
4754 try argv.append("--shared");4754 try argv.append("--shared");
4755 }4755 }
4756 if (wasm.base.options.pie) {4756 if (wasm.base.options.pie) {
...@@ -4769,8 +4769,8 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4769,8 +4769,8 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4769 }4769 }
47704770
4771 if (target.os.tag == .wasi) {4771 if (target.os.tag == .wasi) {
4772 const is_exe_or_dyn_lib = wasm.base.options.output_mode == .Exe or4772 const is_exe_or_dyn_lib = wasm.base.comp.config.output_mode == .Exe or
4773 (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);4773 (wasm.base.comp.config.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);
4774 if (is_exe_or_dyn_lib) {4774 if (is_exe_or_dyn_lib) {
4775 for (wasm.wasi_emulated_libs) |crt_file| {4775 for (wasm.wasi_emulated_libs) |crt_file| {
4776 try argv.append(try comp.get_libc_crt_file(4776 try argv.append(try comp.get_libc_crt_file(
...@@ -4818,7 +4818,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4818,7 +4818,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4818 try argv.append(p);4818 try argv.append(p);
4819 }4819 }
48204820
4821 if (wasm.base.options.output_mode != .Obj and4821 if (wasm.base.comp.config.output_mode != .Obj and
4822 !wasm.base.options.skip_linker_dependencies and4822 !wasm.base.options.skip_linker_dependencies and
4823 !wasm.base.options.link_libc)4823 !wasm.base.options.link_libc)
4824 {4824 {
...@@ -4904,7 +4904,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -4904,7 +4904,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
4904 // it, and then can react to that in the same way as trying to run an ELF file4904 // it, and then can react to that in the same way as trying to run an ELF file
4905 // from a foreign CPU architecture.4905 // from a foreign CPU architecture.
4906 if (fs.has_executable_bit and target.os.tag == .wasi and4906 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)
4908 {4908 {
4909 // TODO: what's our strategy for reporting linker errors from this function?4909 // TODO: what's our strategy for reporting linker errors from this function?
4910 // report a nice error here with the file path if it fails instead of4910 // report a nice error here with the file path if it fails instead of