aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJacob Young <15544577+jacobly0@users.noreply.github.com>2025-06-20 00:20:56 -0400
committerGitHub <noreply@github.com>2025-06-20 00:20:56 -0400
commitcf1a7bbd44b9542552c7b5dc6532aafb5142bf7a (patch)
tree23d82265b3a4500514063f0fa13533b255f88f64 /src/link
parentf5a327cd366348a739a282f380acd627815183b5 (diff)
parent1f98c98fffb09bf15a9fc04ecd5f1fa38a4bd4b8 (diff)
downloadzig-cf1a7bbd44b9542552c7b5dc6532aafb5142bf7a.tar.gz
zig-cf1a7bbd44b9542552c7b5dc6532aafb5142bf7a.zip
Merge pull request #24193 from jacobly0/x86_64-spring-cleaning
x86_64: increase passing test coverage on windows
Diffstat (limited to 'src/link')
-rw-r--r--src/link/C.zig4
-rw-r--r--src/link/Coff.zig81
-rw-r--r--src/link/Dwarf.zig8
-rw-r--r--src/link/Elf.zig14
-rw-r--r--src/link/Elf/Object.zig10
-rw-r--r--src/link/Elf/SharedObject.zig2
-rw-r--r--src/link/Elf/ZigObject.zig28
-rw-r--r--src/link/Goff.zig4
-rw-r--r--src/link/Lld.zig16
-rw-r--r--src/link/MachO.zig10
-rw-r--r--src/link/MachO/ZigObject.zig30
-rw-r--r--src/link/Plan9.zig16
-rw-r--r--src/link/SpirV.zig2
-rw-r--r--src/link/Wasm.zig2
-rw-r--r--src/link/Xcoff.zig4
15 files changed, 116 insertions, 115 deletions
diff --git a/src/link/C.zig b/src/link/C.zig
index f3465055b8..1ea130f6b1 100644
--- a/src/link/C.zig
+++ b/src/link/C.zig
@@ -116,7 +116,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*C {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .c);
const optimize_mode = comp.root_mod.optimize_mode;
const use_lld = build_options.have_llvm and comp.config.use_lld;
@@ -331,7 +331,7 @@ pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedIn
_ = ti_id;
}
-fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {
+fn abiDefines(self: *C, target: *const std.Target) !std.ArrayList(u8) {
const gpa = self.base.comp.gpa;
var defines = std.ArrayList(u8).init(gpa);
errdefer defines.deinit();
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
index 0e00229b78..ea5d6a901c 100644
--- a/src/link/Coff.zig
+++ b/src/link/Coff.zig
@@ -208,7 +208,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Coff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .coff);
const optimize_mode = comp.root_mod.optimize_mode;
const output_mode = comp.config.output_mode;
@@ -752,7 +752,7 @@ fn shrinkAtom(coff: *Coff, atom_index: Atom.Index, new_block_size: u32) void {
// capacity, insert a free list node for it.
}
-fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8) !void {
+fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8, resolve_relocs: bool) !void {
const atom = coff.getAtom(atom_index);
const sym = atom.getSymbol(coff);
const section = coff.sections.get(@intFromEnum(sym.section_number) - 1);
@@ -774,11 +774,13 @@ fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8) !void {
var relocs = std.ArrayList(*Relocation).init(gpa);
defer relocs.deinit();
- if (coff.relocs.getPtr(atom_index)) |rels| {
- try relocs.ensureTotalCapacityPrecise(rels.items.len);
- for (rels.items) |*reloc| {
- if (reloc.isResolvable(coff) and reloc.dirty) {
- relocs.appendAssumeCapacity(reloc);
+ if (resolve_relocs) {
+ if (coff.relocs.getPtr(atom_index)) |rels| {
+ try relocs.ensureTotalCapacityPrecise(rels.items.len);
+ for (rels.items) |*reloc| {
+ if (reloc.isResolvable(coff) and reloc.dirty) {
+ relocs.appendAssumeCapacity(reloc);
+ }
}
}
}
@@ -812,12 +814,15 @@ fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8) !void {
}
}
- coff.resolveRelocs(atom_index, relocs.items, code, coff.image_base);
+ if (resolve_relocs) {
+ coff.resolveRelocs(atom_index, relocs.items, code, coff.image_base);
+ }
try coff.pwriteAll(code, file_offset);
-
- // Now we can mark the relocs as resolved.
- while (relocs.pop()) |reloc| {
- reloc.dirty = false;
+ if (resolve_relocs) {
+ // Now we can mark the relocs as resolved.
+ while (relocs.pop()) |reloc| {
+ reloc.dirty = false;
+ }
}
}
@@ -914,6 +919,7 @@ fn writeOffsetTableEntry(coff: *Coff, index: usize) !void {
}
fn markRelocsDirtyByTarget(coff: *Coff, target: SymbolWithLoc) void {
+ if (!coff.base.comp.incremental) return;
// TODO: reverse-lookup might come in handy here
for (coff.relocs.values()) |*relocs| {
for (relocs.items) |*reloc| {
@@ -924,6 +930,7 @@ fn markRelocsDirtyByTarget(coff: *Coff, target: SymbolWithLoc) void {
}
fn markRelocsDirtyByAddress(coff: *Coff, addr: u32) void {
+ if (!coff.base.comp.incremental) return;
const got_moved = blk: {
const sect_id = coff.got_section_index orelse break :blk false;
break :blk coff.sections.items(.header)[sect_id].virtual_address >= addr;
@@ -1129,7 +1136,7 @@ fn lowerConst(
log.debug("allocated atom for {s} at 0x{x}", .{ name, atom.getSymbol(coff).value });
log.debug(" (required alignment 0x{x})", .{required_alignment});
- try coff.writeAtom(atom_index, code);
+ try coff.writeAtom(atom_index, code, coff.base.comp.incremental);
return .{ .ok = atom_index };
}
@@ -1212,8 +1219,7 @@ fn updateLazySymbolAtom(
});
defer gpa.free(name);
- const atom = coff.getAtomPtr(atom_index);
- const local_sym_index = atom.getSymbolIndex().?;
+ const local_sym_index = coff.getAtomPtr(atom_index).getSymbolIndex().?;
const src = Type.fromInterned(sym.ty).srcLocOrNull(zcu) orelse Zcu.LazySrcLoc.unneeded;
try codegen.generateLazySymbol(
@@ -1228,12 +1234,13 @@ fn updateLazySymbolAtom(
);
const code = code_buffer.items;
- const code_len: u32 = @intCast(code.len);
+ const atom = coff.getAtomPtr(atom_index);
const symbol = atom.getSymbolPtr(coff);
try coff.setSymbolName(symbol, name);
symbol.section_number = @enumFromInt(section_index + 1);
symbol.type = .{ .complex_type = .NULL, .base_type = .NULL };
+ const code_len: u32 = @intCast(code.len);
const vaddr = try coff.allocateAtom(atom_index, code_len, @intCast(required_alignment.toByteUnits() orelse 0));
errdefer coff.freeAtom(atom_index);
@@ -1244,7 +1251,7 @@ fn updateLazySymbolAtom(
symbol.value = vaddr;
try coff.addGotEntry(.{ .sym_index = local_sym_index });
- try coff.writeAtom(atom_index, code);
+ try coff.writeAtom(atom_index, code, coff.base.comp.incremental);
}
pub fn getOrCreateAtomForLazySymbol(
@@ -1328,7 +1335,7 @@ fn updateNavCode(
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
- const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
+ const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
const required_alignment = switch (pt.navAlignment(nav_index)) {
.none => target_util.defaultFunctionAlignment(target),
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
@@ -1392,7 +1399,7 @@ fn updateNavCode(
};
}
- coff.writeAtom(atom_index, code) catch |err| switch (err) {
+ coff.writeAtom(atom_index, code, coff.base.comp.incremental) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => |e| return coff.base.cgFail(nav_index, "failed to write atom: {s}", .{@errorName(e)}),
};
@@ -1430,7 +1437,7 @@ pub fn updateExports(
const first_exp = export_indices[0].ptr(zcu);
const res = try coff.lowerUav(pt, uav, .none, first_exp.src);
switch (res) {
- .mcv => {},
+ .sym_index => {},
.fail => |em| {
// TODO maybe it's enough to return an error here and let Module.processExportsInner
// handle the error?
@@ -1677,7 +1684,7 @@ fn flushInner(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id) !void {
const amt = try coff.base.file.?.preadAll(code.items, file_offset);
if (amt != code.items.len) return error.InputOutput;
- try coff.writeAtom(atom_index, code.items);
+ try coff.writeAtom(atom_index, code.items, true);
}
// Update GOT if it got moved in memory.
@@ -1715,6 +1722,21 @@ fn flushInner(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id) !void {
}
assert(!coff.imports_count_dirty);
+
+ // hack for stage2_x86_64 + coff
+ if (comp.compiler_rt_dyn_lib) |crt_file| {
+ const compiler_rt_sub_path = try std.fs.path.join(gpa, &.{
+ std.fs.path.dirname(coff.base.emit.sub_path) orelse "",
+ std.fs.path.basename(crt_file.full_object_path.sub_path),
+ });
+ defer gpa.free(compiler_rt_sub_path);
+ try crt_file.full_object_path.root_dir.handle.copyFile(
+ crt_file.full_object_path.sub_path,
+ coff.base.emit.root_dir.handle,
+ compiler_rt_sub_path,
+ .{},
+ );
+ }
}
pub fn getNavVAddr(
@@ -1755,7 +1777,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: InternPool.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
const zcu = pt.zcu;
const gpa = zcu.gpa;
const val = Value.fromInterned(uav);
@@ -1767,7 +1789,7 @@ pub fn lowerUav(
const atom = coff.getAtom(metadata.atom);
const existing_addr = atom.getSymbol(coff).value;
if (uav_alignment.check(existing_addr))
- return .{ .mcv = .{ .load_symbol = atom.getSymbolIndex().? } };
+ return .{ .sym_index = atom.getSymbolIndex().? };
}
var name_buf: [32]u8 = undefined;
@@ -1798,9 +1820,7 @@ pub fn lowerUav(
.atom = atom_index,
.section = coff.rdata_section_index.?,
});
- return .{ .mcv = .{
- .load_symbol = coff.getAtom(atom_index).getSymbolIndex().?,
- } };
+ return .{ .sym_index = coff.getAtom(atom_index).getSymbolIndex().? };
}
pub fn getUavVAddr(
@@ -2153,7 +2173,7 @@ fn writeDataDirectoriesHeaders(coff: *Coff) !void {
}
fn writeHeader(coff: *Coff) !void {
- const target = coff.base.comp.root_mod.resolved_target.result;
+ const target = &coff.base.comp.root_mod.resolved_target.result;
const gpa = coff.base.comp.gpa;
var buffer = std.ArrayList(u8).init(gpa);
defer buffer.deinit();
@@ -2464,11 +2484,6 @@ const GetOrPutGlobalPtrResult = struct {
value_ptr: *SymbolWithLoc,
};
-/// Used only for disambiguating local from global at relocation level.
-/// TODO this must go away.
-pub const global_symbol_bit: u32 = 0x80000000;
-pub const global_symbol_mask: u32 = 0x7fffffff;
-
/// Return pointer to the global entry for `name` if one exists.
/// Puts a new global entry for `name` if one doesn't exist, and
/// returns a pointer to it.
@@ -2800,7 +2815,7 @@ pub const Relocation = struct {
.ptr_width = coff.ptr_width,
};
- const target = coff.base.comp.root_mod.resolved_target.result;
+ const target = &coff.base.comp.root_mod.resolved_target.result;
switch (target.cpu.arch) {
.aarch64 => reloc.resolveAarch64(ctx),
.x86, .x86_64 => reloc.resolveX86(ctx),
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig
index 0afe10ef03..605d1d23a4 100644
--- a/src/link/Dwarf.zig
+++ b/src/link/Dwarf.zig
@@ -92,7 +92,7 @@ const DebugFrame = struct {
};
fn headerBytes(dwarf: *Dwarf) u32 {
- const target = dwarf.bin_file.comp.root_mod.resolved_target.result;
+ const target = &dwarf.bin_file.comp.root_mod.resolved_target.result;
return @intCast(switch (dwarf.debug_frame.header.format) {
.none => return 0,
.debug_frame => dwarf.unitLengthBytes() + dwarf.sectionOffsetBytes() + 1 + "\x00".len + 1 + 1,
@@ -2140,7 +2140,7 @@ fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) {
pub fn init(lf: *link.File, format: DW.Format) Dwarf {
const comp = lf.comp;
const gpa = comp.gpa;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
return .{
.gpa = gpa,
.bin_file = lf,
@@ -2573,7 +2573,7 @@ fn initWipNavInner(
try wip_nav.infoAddrSym(sym_index, 0);
wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
try diw.writeInt(u32, 0, dwarf.endian);
- const target = mod.resolved_target.result;
+ const target = &mod.resolved_target.result;
try uleb128(diw, switch (nav.status.fully_resolved.alignment) {
.none => target_info.defaultFunctionAlignment(target),
else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),
@@ -4529,7 +4529,7 @@ pub fn flush(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
dwarf.debug_aranges.section.dirty = false;
}
if (dwarf.debug_frame.section.dirty) {
- const target = dwarf.bin_file.comp.root_mod.resolved_target.result;
+ const target = &dwarf.bin_file.comp.root_mod.resolved_target.result;
switch (dwarf.debug_frame.header.format) {
.none => {},
.debug_frame => unreachable,
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 0beea0d9e7..dc27e0bdd7 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -196,7 +196,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Elf {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .elf);
const use_llvm = comp.config.use_llvm;
@@ -473,7 +473,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: InternPool.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
return self.zigObjectPtr().?.lowerUav(self, pt, uav, explicit_alignment, src_loc);
}
@@ -1073,7 +1073,7 @@ fn parseObject(self: *Elf, obj: link.Input.Object) !void {
const gpa = self.base.comp.gpa;
const diags = &self.base.comp.link_diags;
- const target = self.base.comp.root_mod.resolved_target.result;
+ const target = &self.base.comp.root_mod.resolved_target.result;
const debug_fmt_strip = self.base.comp.config.debug_format == .strip;
const default_sym_version = self.default_sym_version;
const file_handles = &self.file_handles;
@@ -1104,7 +1104,7 @@ fn parseArchive(
diags: *Diags,
file_handles: *std.ArrayListUnmanaged(File.Handle),
files: *std.MultiArrayList(File.Entry),
- target: std.Target,
+ target: *const std.Target,
debug_fmt_strip: bool,
default_sym_version: elf.Versym,
objects: *std.ArrayListUnmanaged(File.Index),
@@ -1139,7 +1139,7 @@ fn parseDso(
dso: link.Input.Dso,
shared_objects: *std.StringArrayHashMapUnmanaged(File.Index),
files: *std.MultiArrayList(File.Entry),
- target: std.Target,
+ target: *const std.Target,
) !void {
const tracy = trace(@src());
defer tracy.end();
@@ -4121,8 +4121,8 @@ pub fn lsearch(comptime T: type, haystack: []const T, predicate: anytype) usize
return i;
}
-pub fn getTarget(self: Elf) std.Target {
- return self.base.comp.root_mod.resolved_target.result;
+pub fn getTarget(self: *const Elf) *const std.Target {
+ return &self.base.comp.root_mod.resolved_target.result;
}
fn requiresThunks(self: Elf) bool {
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig
index dcea9fe402..4d5b5378c4 100644
--- a/src/link/Elf/Object.zig
+++ b/src/link/Elf/Object.zig
@@ -69,7 +69,7 @@ pub fn parse(
/// For error reporting purposes only.
path: Path,
handle: fs.File,
- target: std.Target,
+ target: *const std.Target,
debug_fmt_strip: bool,
default_sym_version: elf.Versym,
) !void {
@@ -98,7 +98,7 @@ pub fn parseCommon(
diags: *Diags,
path: Path,
handle: fs.File,
- target: std.Target,
+ target: *const std.Target,
) !void {
const offset = if (self.archive) |ar| ar.offset else 0;
const file_size = (try handle.stat()).size;
@@ -182,7 +182,7 @@ pub fn parseCommon(
pub fn validateEFlags(
diags: *Diags,
path: Path,
- target: std.Target,
+ target: *const std.Target,
e_flags: elf.Word,
) !void {
switch (target.cpu.arch) {
@@ -263,7 +263,7 @@ fn initAtoms(
path: Path,
handle: fs.File,
debug_fmt_strip: bool,
- target: std.Target,
+ target: *const std.Target,
) !void {
const shdrs = self.shdrs.items;
try self.atoms.ensureTotalCapacityPrecise(gpa, shdrs.len);
@@ -420,7 +420,7 @@ fn parseEhFrame(
gpa: Allocator,
handle: fs.File,
shndx: u32,
- target: std.Target,
+ target: *const std.Target,
) !void {
const relocs_shndx = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {
elf.SHT_RELA => if (shdr.sh_info == shndx) break @as(u32, @intCast(i)),
diff --git a/src/link/Elf/SharedObject.zig b/src/link/Elf/SharedObject.zig
index ac3b3857a1..30def4429b 100644
--- a/src/link/Elf/SharedObject.zig
+++ b/src/link/Elf/SharedObject.zig
@@ -96,7 +96,7 @@ pub fn parseHeader(
file_path: Path,
fs_file: std.fs.File,
stat: Stat,
- target: std.Target,
+ target: *const std.Target,
) !Header {
var ehdr: elf.Elf64_Ehdr = undefined;
{
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig
index 71b42819e2..f4b340a549 100644
--- a/src/link/Elf/ZigObject.zig
+++ b/src/link/Elf/ZigObject.zig
@@ -997,7 +997,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: InternPool.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
const zcu = pt.zcu;
const gpa = zcu.gpa;
const val = Value.fromInterned(uav);
@@ -1010,7 +1010,7 @@ pub fn lowerUav(
const sym = self.symbol(metadata.symbol_index);
const existing_alignment = sym.atom(elf_file).?.alignment;
if (uav_alignment.order(existing_alignment).compare(.lte))
- return .{ .mcv = .{ .load_symbol = metadata.symbol_index } };
+ return .{ .sym_index = metadata.symbol_index };
}
const osec = if (self.data_relro_index) |sym_index|
@@ -1047,12 +1047,11 @@ pub fn lowerUav(
.{@errorName(e)},
) },
};
- const sym_index = switch (res) {
- .ok => |sym_index| sym_index,
- .fail => |em| return .{ .fail = em },
- };
- try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index, .allocated = true });
- return .{ .mcv = .{ .load_symbol = sym_index } };
+ switch (res) {
+ .sym_index => |sym_index| try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index, .allocated = true }),
+ .fail => {},
+ }
+ return res;
}
pub fn getOrCreateMetadataForLazySymbol(
@@ -1271,7 +1270,7 @@ fn updateNavCode(
log.debug("updateNavCode {}({d})", .{ nav.fqn.fmt(ip), nav_index });
- const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
+ const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
const required_alignment = switch (pt.navAlignment(nav_index)) {
.none => target_util.defaultFunctionAlignment(target),
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
@@ -1692,11 +1691,6 @@ fn updateLazySymbol(
try elf_file.pwriteAll(code, atom_ptr.offset(elf_file));
}
-const LowerConstResult = union(enum) {
- ok: Symbol.Index,
- fail: *Zcu.ErrorMsg,
-};
-
fn lowerConst(
self: *ZigObject,
elf_file: *Elf,
@@ -1706,7 +1700,7 @@ fn lowerConst(
required_alignment: InternPool.Alignment,
output_section_index: u32,
src_loc: Zcu.LazySrcLoc,
-) !LowerConstResult {
+) !codegen.SymbolResult {
const gpa = pt.zcu.gpa;
var code_buffer: std.ArrayListUnmanaged(u8) = .empty;
@@ -1740,7 +1734,7 @@ fn lowerConst(
try elf_file.pwriteAll(code, atom_ptr.offset(elf_file));
- return .{ .ok = sym_index };
+ return .{ .sym_index = sym_index };
}
pub fn updateExports(
@@ -1764,7 +1758,7 @@ pub fn updateExports(
const first_exp = export_indices[0].ptr(zcu);
const res = try self.lowerUav(elf_file, pt, uav, .none, first_exp.src);
switch (res) {
- .mcv => {},
+ .sym_index => {},
.fail => |em| {
// TODO maybe it's enough to return an error here and let Zcu.processExportsInner
// handle the error?
diff --git a/src/link/Goff.zig b/src/link/Goff.zig
index 1f4a7a4d30..9a39e4b9f8 100644
--- a/src/link/Goff.zig
+++ b/src/link/Goff.zig
@@ -26,7 +26,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Goff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const use_lld = build_options.have_llvm and comp.config.use_lld;
const use_llvm = comp.config.use_llvm;
@@ -59,7 +59,7 @@ pub fn open(
emit: Path,
options: link.File.OpenOptions,
) !*Goff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .goff);
return createEmpty(arena, comp, emit, options);
}
diff --git a/src/link/Lld.zig b/src/link/Lld.zig
index 4ea809428e..45ef112dc4 100644
--- a/src/link/Lld.zig
+++ b/src/link/Lld.zig
@@ -30,7 +30,7 @@ const Coff = struct {
dllmain_crt_startup: bool,
},
fn init(comp: *Compilation, options: link.File.OpenOptions) !Coff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const output_mode = comp.config.output_mode;
return .{
.image_base = options.image_base orelse switch (output_mode) {
@@ -103,7 +103,7 @@ pub const Elf = struct {
fn init(comp: *Compilation, options: link.File.OpenOptions) !Elf {
const PtrWidth = enum { p32, p64 };
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const output_mode = comp.config.output_mode;
const is_dyn_lib = output_mode == .Lib and comp.config.link_mode == .dynamic;
const ptr_width: PtrWidth = switch (target.ptrBitWidth()) {
@@ -202,7 +202,7 @@ pub fn createEmpty(
emit: Cache.Path,
options: link.File.OpenOptions,
) !*Lld {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const output_mode = comp.config.output_mode;
const optimize_mode = comp.root_mod.optimize_mode;
const is_native_os = comp.root_mod.resolved_target.is_native_os;
@@ -342,7 +342,7 @@ fn linkAsArchive(lld: *Lld, arena: Allocator) !void {
const llvm_bindings = @import("../codegen/llvm/bindings.zig");
const llvm = @import("../codegen/llvm.zig");
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
llvm.initializeLLVMTarget(target.cpu.arch);
const bad = llvm_bindings.WriteArchive(
full_out_path_z,
@@ -374,7 +374,7 @@ fn coffLink(lld: *Lld, arena: Allocator) !void {
const is_dyn_lib = comp.config.link_mode == .dynamic and is_lib;
const is_exe_or_dyn_lib = is_dyn_lib or comp.config.output_mode == .Exe;
const link_in_crt = comp.config.link_libc and is_exe_or_dyn_lib;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const optimize_mode = comp.root_mod.optimize_mode;
const entry_name: ?[]const u8 = switch (coff.entry) {
// This logic isn't quite right for disabled or enabled. No point in fixing it
@@ -811,7 +811,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
const is_dyn_lib = link_mode == .dynamic and is_lib;
const is_exe_or_dyn_lib = is_dyn_lib or output_mode == .Exe;
const have_dynamic_linker = link_mode == .dynamic and is_exe_or_dyn_lib;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const compiler_rt_path: ?Cache.Path = blk: {
if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
@@ -1281,7 +1281,7 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
try spawnLld(comp, arena, argv.items);
}
}
-fn getLDMOption(target: std.Target) ?[]const u8 {
+fn getLDMOption(target: *const std.Target) ?[]const u8 {
// This should only return emulations understood by LLD's parseEmulation().
return switch (target.cpu.arch) {
.aarch64 => switch (target.os.tag) {
@@ -1364,7 +1364,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
const shared_memory = comp.config.shared_memory;
const export_memory = comp.config.export_memory;
const import_memory = comp.config.import_memory;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const base = &lld.base;
const wasm = &lld.ofmt.wasm;
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index 3f3a94bee7..7443435264 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -163,7 +163,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*MachO {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .macho);
const gpa = comp.gpa;
@@ -3092,7 +3092,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: InternPool.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
return self.getZigObject().?.lowerUav(self, pt, uav, explicit_alignment, src_loc);
}
@@ -3545,8 +3545,8 @@ pub fn markDirty(self: *MachO, sect_index: u8) void {
}
}
-pub fn getTarget(self: MachO) std.Target {
- return self.base.comp.root_mod.resolved_target.result;
+pub fn getTarget(self: *const MachO) *const std.Target {
+ return &self.base.comp.root_mod.resolved_target.result;
}
/// XNU starting with Big Sur running on arm64 is caching inodes of running binaries.
@@ -4233,7 +4233,7 @@ pub const Platform = struct {
}
}
- pub fn fromTarget(target: std.Target) Platform {
+ pub fn fromTarget(target: *const std.Target) Platform {
return .{
.os_tag = target.os.tag,
.abi = target.abi,
diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig
index f9ecdc6fb5..97c1a0ad54 100644
--- a/src/link/MachO/ZigObject.zig
+++ b/src/link/MachO/ZigObject.zig
@@ -704,7 +704,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: Atom.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
const zcu = pt.zcu;
const gpa = zcu.gpa;
const val = Value.fromInterned(uav);
@@ -716,7 +716,7 @@ pub fn lowerUav(
const sym = self.symbols.items[metadata.symbol_index];
const existing_alignment = sym.getAtom(macho_file).?.alignment;
if (uav_alignment.order(existing_alignment).compare(.lte))
- return .{ .mcv = .{ .load_symbol = sym.nlist_idx } };
+ return .{ .sym_index = metadata.symbol_index };
}
var name_buf: [32]u8 = undefined;
@@ -740,14 +740,11 @@ pub fn lowerUav(
.{@errorName(e)},
) },
};
- const sym_index = switch (res) {
- .ok => |sym_index| sym_index,
- .fail => |em| return .{ .fail = em },
- };
- try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index });
- return .{ .mcv = .{
- .load_symbol = self.symbols.items[sym_index].nlist_idx,
- } };
+ switch (res) {
+ .sym_index => |sym_index| try self.uavs.put(gpa, uav, .{ .symbol_index = sym_index }),
+ .fail => {},
+ }
+ return res;
}
fn freeNavMetadata(self: *ZigObject, macho_file: *MachO, sym_index: Symbol.Index) void {
@@ -948,7 +945,7 @@ fn updateNavCode(
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
- const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
+ const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
const required_alignment = switch (pt.navAlignment(nav_index)) {
.none => target_util.defaultFunctionAlignment(target),
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
@@ -1187,11 +1184,6 @@ fn getNavOutputSection(
return macho_file.zig_data_sect_index.?;
}
-const LowerConstResult = union(enum) {
- ok: Symbol.Index,
- fail: *Zcu.ErrorMsg,
-};
-
fn lowerConst(
self: *ZigObject,
macho_file: *MachO,
@@ -1201,7 +1193,7 @@ fn lowerConst(
required_alignment: Atom.Alignment,
output_section_index: u8,
src_loc: Zcu.LazySrcLoc,
-) !LowerConstResult {
+) !codegen.SymbolResult {
const gpa = macho_file.base.comp.gpa;
var code_buffer: std.ArrayListUnmanaged(u8) = .empty;
@@ -1241,7 +1233,7 @@ fn lowerConst(
const file_offset = sect.offset + atom.value;
try macho_file.pwriteAll(code, file_offset);
- return .{ .ok = sym_index };
+ return .{ .sym_index = sym_index };
}
pub fn updateExports(
@@ -1265,7 +1257,7 @@ pub fn updateExports(
const first_exp = export_indices[0].ptr(zcu);
const res = try self.lowerUav(macho_file, pt, uav, .none, first_exp.src);
switch (res) {
- .mcv => {},
+ .sym_index => {},
.fail => |em| {
// TODO maybe it's enough to return an error here and let Zcu.processExportsInner
// handle the error?
diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig
index c99ebb81bb..9658495bce 100644
--- a/src/link/Plan9.zig
+++ b/src/link/Plan9.zig
@@ -184,7 +184,7 @@ pub const Atom = struct {
// asserts that self.got_index != null
pub fn getOffsetTableAddress(self: Atom, plan9: *Plan9) u64 {
- const target = plan9.base.comp.root_mod.resolved_target.result;
+ const target = &plan9.base.comp.root_mod.resolved_target.result;
const ptr_bytes = @divExact(target.ptrBitWidth(), 8);
const got_addr = plan9.bases.data;
const got_index = self.got_index.?;
@@ -278,7 +278,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Plan9 {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const gpa = comp.gpa;
const optimize_mode = comp.root_mod.optimize_mode;
const output_mode = comp.config.output_mode;
@@ -394,7 +394,7 @@ pub fn updateFunc(
const zcu = pt.zcu;
const gpa = zcu.gpa;
- const target = self.base.comp.root_mod.resolved_target.result;
+ const target = &self.base.comp.root_mod.resolved_target.result;
const func = zcu.funcInfo(func_index);
const atom_idx = try self.seeNav(pt, func.owner_nav);
@@ -583,7 +583,7 @@ pub fn flush(
const comp = self.base.comp;
const diags = &comp.link_diags;
const gpa = comp.gpa;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
switch (comp.config.output_mode) {
.Exe => {},
@@ -1153,7 +1153,7 @@ pub fn open(
emit: Path,
options: link.File.OpenOptions,
) !*Plan9 {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const use_lld = build_options.have_llvm and comp.config.use_lld;
const use_llvm = comp.config.use_llvm;
@@ -1358,7 +1358,7 @@ pub fn lowerUav(
uav: InternPool.Index,
explicit_alignment: InternPool.Alignment,
src_loc: Zcu.LazySrcLoc,
-) !codegen.GenResult {
+) !codegen.SymbolResult {
_ = explicit_alignment;
// example:
// const ty = mod.intern_pool.typeOf(decl_val).toType();
@@ -1370,7 +1370,7 @@ pub fn lowerUav(
// ...
const gpa = self.base.comp.gpa;
const gop = try self.uavs.getOrPut(gpa, uav);
- if (gop.found_existing) return .{ .mcv = .{ .load_direct = gop.value_ptr.* } };
+ if (gop.found_existing) return .{ .sym_index = gop.value_ptr.* };
const val = Value.fromInterned(uav);
const name = try std.fmt.allocPrint(gpa, "__anon_{d}", .{@intFromEnum(uav)});
@@ -1395,7 +1395,7 @@ pub fn lowerUav(
.value = undefined,
.name = name,
};
- return .{ .mcv = .{ .load_direct = index } };
+ return .{ .sym_index = index };
}
pub fn getUavVAddr(self: *Plan9, uav: InternPool.Index, reloc_info: link.File.RelocInfo) !u64 {
diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig
index bafefccfc0..1e01a50a6c 100644
--- a/src/link/SpirV.zig
+++ b/src/link/SpirV.zig
@@ -58,7 +58,7 @@ pub fn createEmpty(
options: link.File.OpenOptions,
) !*SpirV {
const gpa = comp.gpa;
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve
assert(!comp.config.use_llvm); // Caught by Compilation.Config.resolve
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index eda7552986..5f98771dcf 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -2943,7 +2943,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Wasm {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .wasm);
const use_llvm = comp.config.use_llvm;
diff --git a/src/link/Xcoff.zig b/src/link/Xcoff.zig
index fd143713ff..127ff18917 100644
--- a/src/link/Xcoff.zig
+++ b/src/link/Xcoff.zig
@@ -26,7 +26,7 @@ pub fn createEmpty(
emit: Path,
options: link.File.OpenOptions,
) !*Xcoff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
const use_lld = build_options.have_llvm and comp.config.use_lld;
const use_llvm = comp.config.use_llvm;
@@ -59,7 +59,7 @@ pub fn open(
emit: Path,
options: link.File.OpenOptions,
) !*Xcoff {
- const target = comp.root_mod.resolved_target.result;
+ const target = &comp.root_mod.resolved_target.result;
assert(target.ofmt == .xcoff);
return createEmpty(arena, comp, emit, options);
}