Commit 6ec6c07795

Andrew Kelley <andrew@ziglang.org>
2023-12-12 05:22:16
linker: update output_mode references
1 parent 2be36c5
Changed files (6)
src/link/Coff/lld.zig
@@ -45,9 +45,9 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
     sub_prog_node.context.refresh();
     defer sub_prog_node.end();
 
-    const is_lib = self.base.options.output_mode == .Lib;
+    const is_lib = self.base.comp.config.output_mode == .Lib;
     const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;
-    const is_exe_or_dyn_lib = is_dyn_lib or self.base.options.output_mode == .Exe;
+    const is_exe_or_dyn_lib = is_dyn_lib or self.base.comp.config.output_mode == .Exe;
     const link_in_crt = self.base.options.link_libc and is_exe_or_dyn_lib;
     const target = self.base.options.target;
     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
         };
     }
 
-    if (self.base.options.output_mode == .Obj) {
+    if (self.base.comp.config.output_mode == .Obj) {
         // LLD's COFF driver does not support the equivalent of `-r` so we do a simple file copy
         // here. TODO: think carefully about how we can avoid this redundant operation when doing
         // 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
                 .ReleaseFast, .ReleaseSafe => try argv.append("-OPT:lldlto=3"),
             }
         }
-        if (self.base.options.output_mode == .Exe) {
+        if (self.base.comp.config.output_mode == .Exe) {
             try argv.append(try allocPrint(arena, "-STACK:{d}", .{self.base.stack_size}));
         }
         if (self.base.options.image_base_override) |image_base| {
src/link/Elf/Atom.zig
@@ -658,7 +658,7 @@ fn dynAbsRelocAction(symbol: *const Symbol, elf_file: *Elf) RelocAction {
 
 fn outputType(elf_file: *Elf) u2 {
     assert(!elf_file.isRelocatable());
-    return switch (elf_file.base.options.output_mode) {
+    return switch (elf_file.base.comp.config.output_mode) {
         .Obj => unreachable,
         .Lib => 0,
         .Exe => if (elf_file.base.options.pie) 1 else 2,
src/link/MachO/dead_strip.zig
@@ -33,7 +33,7 @@ fn addRoot(macho_file: *MachO, roots: *AtomTable, file: u32, sym_loc: SymbolWith
 fn collectRoots(macho_file: *MachO, roots: *AtomTable) !void {
     log.debug("collecting roots", .{});
 
-    switch (macho_file.base.options.output_mode) {
+    switch (macho_file.base.comp.config.output_mode) {
         .Exe => {
             // Add entrypoint as GC root
             if (macho_file.getEntryPoint()) |global| {
src/link/MachO/zld.zig
@@ -407,7 +407,7 @@ pub fn linkWithZld(
         try macho_file.createDyldPrivateAtom();
         try macho_file.createTentativeDefAtoms();
 
-        if (macho_file.base.options.output_mode == .Exe) {
+        if (macho_file.base.comp.config.output_mode == .Exe) {
             const global = macho_file.getEntryPoint().?;
             if (macho_file.getSymbol(global).undf()) {
                 // 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 {
     const gpa = macho_file.base.allocator;
     const page_size = MachO.getPageSize(macho_file.base.options.target.cpu.arch);
     const aligned_pagezero_vmsize = mem.alignBackward(u64, macho_file.pagezero_vmsize, page_size);
-    if (macho_file.base.options.output_mode != .Lib and aligned_pagezero_vmsize > 0) {
+    if (macho_file.base.comp.config.output_mode != .Lib and aligned_pagezero_vmsize > 0) {
         if (aligned_pagezero_vmsize != macho_file.pagezero_vmsize) {
             log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{macho_file.pagezero_vmsize});
             log.warn("  rounding down to 0x{x}", .{aligned_pagezero_vmsize});
src/link/Coff.zig
@@ -1658,7 +1658,7 @@ pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) lin
     if (use_lld) {
         return lld.linkWithLLD(self, comp, prog_node);
     }
-    switch (self.base.options.output_mode) {
+    switch (self.base.comp.config.output_mode) {
         .Exe, .Obj => return self.flushModule(comp, prog_node),
         .Lib => return error.TODOImplementWritingLibFiles,
     }
@@ -1779,7 +1779,7 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
     try self.writeDataDirectoriesHeaders();
     try self.writeSectionHeaders();
 
-    if (self.entry_addr == null and self.base.options.output_mode == .Exe) {
+    if (self.entry_addr == null and self.base.comp.config.output_mode == .Exe) {
         log.debug("flushing. no_entry_point_found = true\n", .{});
         self.error_flags.no_entry_point_found = true;
     } else {
@@ -2218,7 +2218,7 @@ fn writeHeader(self: *Coff) !void {
         .p32 => flags.@"32BIT_MACHINE" = 1,
         .p64 => flags.LARGE_ADDRESS_AWARE = 1,
     }
-    if (self.base.options.output_mode == .Lib and self.base.options.link_mode == .Dynamic) {
+    if (self.base.comp.config.output_mode == .Lib and self.base.options.link_mode == .Dynamic) {
         flags.DLL = 1;
     }
 
@@ -2451,7 +2451,7 @@ pub fn getEntryPoint(self: Coff) ?SymbolWithLoc {
 }
 
 pub fn getImageBase(self: Coff) u64 {
-    const image_base: u64 = self.base.options.image_base_override orelse switch (self.base.options.output_mode) {
+    const image_base: u64 = self.base.options.image_base_override orelse switch (self.base.comp.config.output_mode) {
         .Exe => switch (self.base.options.target.cpu.arch) {
             .aarch64 => @as(u64, 0x140000000),
             .x86_64, .x86 => 0x400000,
src/link/Wasm.zig
@@ -1305,7 +1305,7 @@ pub fn findGlobalSymbol(wasm: *Wasm, name: []const u8) ?SymbolLoc {
 }
 
 fn checkUndefinedSymbols(wasm: *const Wasm) !void {
-    if (wasm.base.options.output_mode == .Obj) return;
+    if (wasm.base.comp.config.output_mode == .Obj) return;
     if (wasm.base.options.import_symbols) return;
 
     var found_undefined_symbols = false;
@@ -2065,7 +2065,7 @@ fn mapFunctionTable(wasm: *Wasm) void {
         }
     }
 
-    if (wasm.import_table or wasm.base.options.output_mode == .Obj) {
+    if (wasm.import_table or wasm.base.comp.config.output_mode == .Obj) {
         const sym_loc = wasm.findGlobalSymbol("__indirect_function_table").?;
         const import = wasm.imports.getPtr(sym_loc).?;
         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 {
             // we set the entire region of it to zeroes.
             // We do not have to do this when exporting the memory (the default) because the runtime
             // will do it for us, and we do not emit the bss segment at all.
-            if ((wasm.base.options.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
+            if ((wasm.base.comp.config.output_mode == .Obj or wasm.base.options.import_memory) and kind.data == .uninitialized) {
                 @memset(atom.code.items, 0);
             }
 
-            const should_merge = wasm.base.options.output_mode != .Obj;
+            const should_merge = wasm.base.comp.config.output_mode != .Obj;
             const gop = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(should_merge));
             if (gop.found_existing) {
                 const index = gop.value_ptr.*;
@@ -2392,7 +2392,7 @@ fn allocateVirtualAddresses(wasm: *Wasm) void {
         };
 
         const atom = wasm.getAtom(atom_index);
-        const merge_segment = wasm.base.options.output_mode != .Obj;
+        const merge_segment = wasm.base.comp.config.output_mode != .Obj;
         const segment_info = if (atom.file) |object_index| blk: {
             break :blk wasm.objects.items[object_index].segment_info;
         } else wasm.segment_info.values();
@@ -2934,7 +2934,7 @@ fn mergeTypes(wasm: *Wasm) !void {
 
 fn setupExports(wasm: *Wasm) !void {
     const gpa = wasm.base.comp.gpa;
-    if (wasm.base.options.output_mode == .Obj) return;
+    if (wasm.base.comp.config.output_mode == .Obj) return;
     log.debug("Building exports from symbols", .{});
 
     const force_exp_names = wasm.base.options.export_symbol_names;
@@ -3009,7 +3009,7 @@ fn setupStart(wasm: *Wasm) !void {
     }
 
     // Ensure the symbol is exported so host environment can access it
-    if (wasm.base.options.output_mode != .Obj) {
+    if (wasm.base.comp.config.output_mode != .Obj) {
         symbol.setFlag(.WASM_SYM_EXPORTED);
     }
 }
@@ -3029,7 +3029,7 @@ fn setupMemory(wasm: *Wasm) !void {
         break :blk base;
     } else 0;
 
-    const is_obj = wasm.base.options.output_mode == .Obj;
+    const is_obj = wasm.base.comp.config.output_mode == .Obj;
 
     if (place_stack_first and !is_obj) {
         memory_ptr = stack_alignment.forward(memory_ptr);
@@ -3155,7 +3155,7 @@ pub fn getMatchingSegment(wasm: *Wasm, object_index: u16, symbol_index: u32) !u3
     switch (symbol.tag) {
         .data => {
             const segment_info = object.segment_info[symbol.index];
-            const merge_segment = wasm.base.options.output_mode != .Obj;
+            const merge_segment = wasm.base.comp.config.output_mode != .Obj;
             const result = try wasm.data_segments.getOrPut(gpa, segment_info.outputName(merge_segment));
             if (!result.found_existing) {
                 result.value_ptr.* = index;
@@ -3797,7 +3797,7 @@ fn writeToFile(
     var code_section_index: ?u32 = null;
     // Index of the data section. Used to tell relocation table where the section lives.
     var data_section_index: ?u32 = null;
-    const is_obj = wasm.base.options.output_mode == .Obj or (!use_llvm and use_lld);
+    const is_obj = wasm.base.comp.config.output_mode == .Obj or (!use_llvm and use_lld);
 
     var binary_bytes = std.ArrayList(u8).init(gpa);
     defer binary_bytes.deinit();
@@ -4550,7 +4550,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
     sub_prog_node.context.refresh();
     defer sub_prog_node.end();
 
-    const is_obj = wasm.base.options.output_mode == .Obj;
+    const is_obj = wasm.base.comp.config.output_mode == .Obj;
     const compiler_rt_path: ?[]const u8 = blk: {
         if (comp.compiler_rt_lib) |lib| break :blk lib.full_object_path;
         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) !
             try argv.append("--allow-undefined");
         }
 
-        if (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) {
+        if (wasm.base.comp.config.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic) {
             try argv.append("--shared");
         }
         if (wasm.base.options.pie) {
@@ -4769,8 +4769,8 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
         }
 
         if (target.os.tag == .wasi) {
-            const is_exe_or_dyn_lib = wasm.base.options.output_mode == .Exe or
-                (wasm.base.options.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);
+            const is_exe_or_dyn_lib = wasm.base.comp.config.output_mode == .Exe or
+                (wasm.base.comp.config.output_mode == .Lib and wasm.base.options.link_mode == .Dynamic);
             if (is_exe_or_dyn_lib) {
                 for (wasm.wasi_emulated_libs) |crt_file| {
                     try argv.append(try comp.get_libc_crt_file(
@@ -4818,7 +4818,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
             try argv.append(p);
         }
 
-        if (wasm.base.options.output_mode != .Obj and
+        if (wasm.base.comp.config.output_mode != .Obj and
             !wasm.base.options.skip_linker_dependencies and
             !wasm.base.options.link_libc)
         {
@@ -4904,7 +4904,7 @@ fn linkWithLLD(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
         // it, and then can react to that in the same way as trying to run an ELF file
         // from a foreign CPU architecture.
         if (fs.has_executable_bit and target.os.tag == .wasi and
-            wasm.base.options.output_mode == .Exe)
+            wasm.base.comp.config.output_mode == .Exe)
         {
             // TODO: what's our strategy for reporting linker errors from this function?
             // report a nice error here with the file path if it fails instead of