diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-09-08 14:03:11 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-09-30 13:44:51 +0100 |
| commit | 0c7b2a7bd5433b7e7bcde3bb49d48226dc2adef9 (patch) | |
| tree | 1cc257c75956449de2cd833b91ce17b73b29f724 /src | |
| parent | 202aeacc05a2fc53762c49d18daeefdf0fa5fbec (diff) | |
| download | zig-0c7b2a7bd5433b7e7bcde3bb49d48226dc2adef9.tar.gz zig-0c7b2a7bd5433b7e7bcde3bb49d48226dc2adef9.zip | |
fix compiler ftbfs from std.macho and std.dwarf changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Dwarf.zig | 2 | ||||
| -rw-r--r-- | src/link/Elf/eh_frame.zig | 6 | ||||
| -rw-r--r-- | src/link/MachO.zig | 4 | ||||
| -rw-r--r-- | src/link/MachO/InternalObject.zig | 30 | ||||
| -rw-r--r-- | src/link/MachO/Object.zig | 146 | ||||
| -rw-r--r-- | src/link/MachO/Symbol.zig | 42 | ||||
| -rw-r--r-- | src/link/MachO/Thunk.zig | 4 | ||||
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 32 | ||||
| -rw-r--r-- | src/link/MachO/eh_frame.zig | 20 | ||||
| -rw-r--r-- | src/link/MachO/file.zig | 16 |
10 files changed, 159 insertions, 143 deletions
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 8918386b35..228a8d6a25 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -4852,7 +4852,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro hw.writeSleb128(dwarf.debug_frame.header.data_alignment_factor) catch unreachable; hw.writeUleb128(dwarf.debug_frame.header.return_address_register) catch unreachable; hw.writeUleb128(1) catch unreachable; - hw.writeByte(DW.EH.PE.pcrel | DW.EH.PE.sdata4) catch unreachable; + hw.writeByte(@bitCast(@as(DW.EH.PE, .{ .type = .sdata4, .rel = .pcrel }))) catch unreachable; hw.writeByte(DW.CFA.def_cfa_sf) catch unreachable; hw.writeUleb128(Register.rsp.dwarfNum()) catch unreachable; hw.writeSleb128(-1) catch unreachable; diff --git a/src/link/Elf/eh_frame.zig b/src/link/Elf/eh_frame.zig index 76756d66d8..326764070a 100644 --- a/src/link/Elf/eh_frame.zig +++ b/src/link/Elf/eh_frame.zig @@ -456,10 +456,10 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, relocs: *std.array_list.Managed(elf.El pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { try writer.writeByte(1); // version - try writer.writeByte(DW_EH_PE.pcrel | DW_EH_PE.sdata4); // eh_frame_ptr_enc + try writer.writeByte(@bitCast(@as(DW_EH_PE, .{ .type = .sdata4, .rel = .pcrel }))); // eh_frame_ptr_enc // Building the lookup table would be expensive work on every `flush` -- omit it. - try writer.writeByte(DW_EH_PE.omit); // fde_count_enc - try writer.writeByte(DW_EH_PE.omit); // table_enc + try writer.writeByte(@bitCast(DW_EH_PE.omit)); // fde_count_enc + try writer.writeByte(@bitCast(DW_EH_PE.omit)); // table_enc const shdrs = elf_file.sections.items(.shdr); const eh_frame_shdr = shdrs[elf_file.section_indexes.eh_frame.?]; diff --git a/src/link/MachO.zig b/src/link/MachO.zig index fd1119851d..3e7e3a4e8a 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -4149,9 +4149,9 @@ pub const SymtabCtx = struct { pub const null_sym = macho.nlist_64{ .n_strx = 0, - .n_type = 0, + .n_type = @bitCast(@as(u8, 0)), .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; diff --git a/src/link/MachO/InternalObject.zig b/src/link/MachO/InternalObject.zig index 00721c470b..f0c6c1fee7 100644 --- a/src/link/MachO/InternalObject.zig +++ b/src/link/MachO/InternalObject.zig @@ -69,9 +69,9 @@ pub fn initSymbols(self: *InternalObject, macho_file: *MachO) !void { const nlist = obj.symtab.addOneAssumeCapacity(); nlist.* = .{ .n_strx = name.pos, - .n_type = args.type, + .n_type = @bitCast(args.type), .n_sect = 0, - .n_desc = args.desc, + .n_desc = @bitCast(args.desc), .n_value = 0, }; symbol.nlist_idx = nlist_idx; @@ -143,7 +143,7 @@ pub fn resolveSymbols(self: *InternalObject, macho_file: *MachO) !void { } global.* = gop.index; - if (nlist.undf()) continue; + if (nlist.n_type.bits.type == .undf) continue; if (gop.ref.getFile(macho_file) == null) { gop.ref.* = .{ .index = @intCast(i), .file = self.index }; continue; @@ -171,7 +171,7 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { const object = macho_file.getFile(index).?.object; for (object.symbols.items, 0..) |sym, i| { const nlist = object.symtab.items(.nlist)[i]; - if (!nlist.undf() or !nlist.ext()) continue; + if (nlist.n_type.bits.type != .undf or !nlist.n_type.bits.ext) continue; const ref = object.getSymbolRef(@intCast(i), macho_file); if (ref.getFile(macho_file) != null) continue; const name = sym.getName(macho_file); @@ -206,9 +206,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { const nlist = self.symtab.addOneAssumeCapacity(); nlist.* = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; sym.nlist_idx = nlist_idx; @@ -226,7 +226,7 @@ pub fn markLive(self: *InternalObject, macho_file: *MachO) void { for (0..self.symbols.items.len) |i| { const nlist = self.symtab.items[i]; - if (!nlist.ext()) continue; + if (!nlist.n_type.bits.ext) continue; const ref = self.getSymbolRef(@intCast(i), macho_file); const file = ref.getFile(macho_file) orelse continue; @@ -273,9 +273,9 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil const nlist = try self.symtab.addOne(gpa); nlist.* = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = @intCast(n_sect + 1), - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; sym.nlist_idx = nlist_idx; @@ -326,9 +326,9 @@ fn addObjcSelrefsSection(self: *InternalObject, methname_sym_index: Symbol.Index const nlist = try self.symtab.addOne(gpa); nlist.* = .{ .n_strx = 0, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = @intCast(n_sect + 1), - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; sym.nlist_idx = nlist_idx; @@ -352,8 +352,8 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi for (object.symbols.items, 0..) |sym, i| { const nlist = object.symtab.items(.nlist)[i]; - if (!nlist.ext()) continue; - if (!nlist.undf()) continue; + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type != .undf) continue; const ref = object.getSymbolRef(@intCast(i), macho_file); if (ref.getFile(macho_file) != null) continue; @@ -381,9 +381,9 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi const nlist = try self.symtab.addOne(gpa); nlist.* = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT | macho.N_EXT | macho.N_PEXT, + .n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = true, .is_stab = 0 } }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; sym.nlist_idx = nlist_idx; diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index e2d9564799..90d96b85d9 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -179,7 +179,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { idx: usize, fn rank(ctx: *const Object, nl: macho.nlist_64) u8 { - if (!nl.ext()) { + if (!nl.n_type.bits.ext) { const name = ctx.getNStrx(nl.n_strx); if (name.len == 0) return 5; if (name[0] == 'l' or name[0] == 'L') return 4; @@ -202,7 +202,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { var nlists = try std.array_list.Managed(NlistIdx).initCapacity(gpa, self.symtab.items(.nlist).len); defer nlists.deinit(); for (self.symtab.items(.nlist), 0..) |nlist, i| { - if (nlist.n_type.bits.is_stab != 0 or nlist.n_type.type != .sect) continue; + if (nlist.n_type.bits.is_stab != 0 or nlist.n_type.bits.type != .sect) continue; nlists.appendAssumeCapacity(.{ .nlist = nlist, .idx = i }); } mem.sort(NlistIdx, nlists.items, self, NlistIdx.lessThan); @@ -488,9 +488,9 @@ fn initCstringLiterals(self: *Object, allocator: Allocator, file: File.Handle, m self.symtab.set(nlist_index, .{ .nlist = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = @intCast(atom.n_sect + 1), - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = atom.getInputAddress(macho_file), }, .size = atom.size, @@ -555,9 +555,9 @@ fn initFixedSizeLiterals(self: *Object, allocator: Allocator, macho_file: *MachO self.symtab.set(nlist_index, .{ .nlist = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = @intCast(atom.n_sect + 1), - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = atom.getInputAddress(macho_file), }, .size = atom.size, @@ -613,9 +613,9 @@ fn initPointerLiterals(self: *Object, allocator: Allocator, macho_file: *MachO) self.symtab.set(nlist_index, .{ .nlist = .{ .n_strx = name_str.pos, - .n_type = macho.N_SECT, + .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, .n_sect = @intCast(atom.n_sect + 1), - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = atom.getInputAddress(macho_file), }, .size = atom.size, @@ -805,7 +805,7 @@ fn linkNlistToAtom(self: *Object, macho_file: *MachO) !void { const tracy = trace(@src()); defer tracy.end(); for (self.symtab.items(.nlist), self.symtab.items(.atom)) |nlist, *atom| { - if (!nlist.n_type.bits.is_stab != 0 and nlist.n_type.type == .sect) { + if (nlist.n_type.bits.is_stab == 0 and nlist.n_type.bits.type == .sect) { const sect = self.sections.items(.header)[nlist.n_sect - 1]; const subs = self.sections.items(.subsections)[nlist.n_sect - 1].items; if (nlist.n_value == sect.addr) { @@ -852,30 +852,30 @@ fn initSymbols(self: *Object, allocator: Allocator, macho_file: *MachO) !void { symbol.extra = self.addSymbolExtraAssumeCapacity(.{}); if (self.getAtom(atom_index)) |atom| { - assert(nlist.n_type.type != .abs); + assert(nlist.n_type.bits.type != .abs); symbol.value -= atom.getInputAddress(macho_file); symbol.atom_ref = .{ .index = atom_index, .file = self.index }; } symbol.flags.weak = nlist.n_desc.weak_def_or_ref_to_weak; - symbol.flags.abs = nlist.n_type.type == .abs; + symbol.flags.abs = nlist.n_type.bits.type == .abs; symbol.flags.tentative = nlist.tentative(); symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.n_desc.discarded_or_no_dead_strip; - symbol.flags.dyn_ref = nlist.n_desc & macho.REFERENCED_DYNAMICALLY != 0; + symbol.flags.dyn_ref = nlist.n_desc.referenced_dynamically; symbol.flags.interposable = false; // TODO - // symbol.flags.interposable = nlist.ext() and (nlist.n_type.type == .sect or nlist.n_type.type == .abs) and macho_file.base.isDynLib() and macho_file.options.namespace == .flat and !nlist.pext(); + // symbol.flags.interposable = nlist.ext() and (nlist.n_type.bits.type == .sect or nlist.n_type.bits.type == .abs) and macho_file.base.isDynLib() and macho_file.options.namespace == .flat and !nlist.pext(); - if (nlist.n_type.type == .sect and + if (nlist.n_type.bits.type == .sect and self.sections.items(.header)[nlist.n_sect - 1].type() == macho.S_THREAD_LOCAL_VARIABLES) { symbol.flags.tlv = true; } - if (nlist.ext()) { - if (nlist.n_type.type == .undf) { + if (nlist.n_type.bits.ext) { + if (nlist.n_type.bits.type == .undf) { symbol.flags.weak_ref = nlist.n_desc.weak_ref; - } else if (nlist.pext() or (nlist.n_desc.weak_def_or_ref_to_weak and nlist.n_desc.weak_ref) or self.hidden) { + } else if (nlist.n_type.bits.pext or (nlist.n_desc.weak_def_or_ref_to_weak and nlist.n_desc.weak_ref) or self.hidden) { symbol.visibility = .hidden; } else { symbol.visibility = .global; @@ -919,7 +919,7 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f var addr_lookup = std.StringHashMap(u64).init(allocator); defer addr_lookup.deinit(); for (syms) |sym| { - if (sym.n_type.type == .sect and (sym.ext() or sym.pext())) { + if (sym.n_type.bits.type == .sect and (sym.n_type.bits.ext or sym.n_type.bits.pext)) { try addr_lookup.putNoClobber(self.getNStrx(sym.n_strx), sym.n_value); } } @@ -927,41 +927,43 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f var i: u32 = start; while (i < end) : (i += 1) { const open = syms[i]; - if (open.n_type != macho.N_SO) { + if (open.n_type.stab != .so) { try macho_file.reportParseError2(self.index, "unexpected symbol stab type 0x{x} as the first entry", .{ - open.n_type, + @intFromEnum(open.n_type.stab), }); return error.MalformedObject; } - while (i < end and syms[i].n_type == macho.N_SO and syms[i].n_sect != 0) : (i += 1) {} + while (i < end and syms[i].n_type.stab == .so and syms[i].n_sect != 0) : (i += 1) {} var sf: StabFile = .{ .comp_dir = i }; // TODO validate i += 3; - while (i < end and syms[i].n_type != macho.N_SO) : (i += 1) { + while (i < end and syms[i].n_type.stab != .so) : (i += 1) { const nlist = syms[i]; var stab: StabFile.Stab = .{}; - switch (nlist.n_type) { - macho.N_BNSYM => { + switch (nlist.n_type.stab) { + .bnsym => { stab.is_func = true; stab.index = sym_lookup.find(nlist.n_value); // TODO validate i += 3; }, - macho.N_GSYM => { + .gsym => { stab.is_func = false; stab.index = sym_lookup.find(addr_lookup.get(self.getNStrx(nlist.n_strx)).?); }, - macho.N_STSYM => { + .stsym => { stab.is_func = false; stab.index = sym_lookup.find(nlist.n_value); }, + _ => { + try macho_file.reportParseError2(self.index, "unhandled symbol stab type 0x{x}", .{@intFromEnum(nlist.n_type.stab)}); + return error.MalformedObject; + }, else => { - try macho_file.reportParseError2(self.index, "unhandled symbol stab type 0x{x}", .{ - nlist.n_type, - }); + try macho_file.reportParseError2(self.index, "unhandled symbol stab type '{t}'", .{nlist.n_type.stab}); return error.MalformedObject; }, } @@ -1132,7 +1134,7 @@ fn initUnwindRecords(self: *Object, allocator: Allocator, sect_id: u8, file: Fil fn find(fs: @This(), addr: u64) ?Symbol.Index { for (0..fs.ctx.symbols.items.len) |i| { const nlist = fs.ctx.symtab.items(.nlist)[i]; - if (nlist.ext() and nlist.n_value == addr) return @intCast(i); + if (nlist.n_type.bits.ext and nlist.n_value == addr) return @intCast(i); } return null; } @@ -1242,7 +1244,7 @@ fn parseUnwindRecords(self: *Object, allocator: Allocator, cpu_arch: std.Target. const slice = self.symtab.slice(); for (slice.items(.nlist), slice.items(.atom), slice.items(.size)) |nlist, atom, size| { if (nlist.n_type.bits.is_stab != 0) continue; - if (nlist.n_type.type != .sect) continue; + if (nlist.n_type.bits.type != .sect) continue; const sect = self.sections.items(.header)[nlist.n_sect - 1]; if (sect.isCode() and sect.size > 0) { try superposition.ensureUnusedCapacity(1); @@ -1458,8 +1460,8 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { const gpa = macho_file.base.comp.gpa; for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { - if (!nlist.ext()) continue; - if (nlist.n_type.type == .sect) { + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type == .sect) { const atom = self.getAtom(atom_index).?; if (!atom.isAlive()) continue; } @@ -1473,7 +1475,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { } global.* = gop.index; - if (nlist.n_type.type == .undf and !nlist.tentative()) continue; + if (nlist.n_type.bits.type == .undf and !nlist.tentative()) continue; if (gop.ref.getFile(macho_file) == null) { gop.ref.* = .{ .index = @intCast(i), .file = self.index }; continue; @@ -1495,12 +1497,12 @@ pub fn markLive(self: *Object, macho_file: *MachO) void { for (0..self.symbols.items.len) |i| { const nlist = self.symtab.items(.nlist)[i]; - if (!nlist.ext()) continue; + if (!nlist.n_type.bits.ext) continue; const ref = self.getSymbolRef(@intCast(i), macho_file); const file = ref.getFile(macho_file) orelse continue; const sym = ref.getSymbol(macho_file).?; - const should_keep = nlist.n_type.type == .undf or (nlist.tentative() and !sym.flags.tentative); + const should_keep = nlist.n_type.bits.type == .undf or (nlist.tentative() and !sym.flags.tentative); if (should_keep and file == .object and !file.object.alive) { file.object.alive = true; file.object.markLive(macho_file); @@ -1565,7 +1567,7 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { const name = try std.fmt.allocPrintSentinel(gpa, "__DATA$__common${s}", .{sym.getName(macho_file)}, 0); defer gpa.free(name); - const alignment = (nlist.n_desc >> 8) & 0x0f; + const alignment = (@as(u16, @bitCast(nlist.n_desc)) >> 8) & 0x0f; const n_sect = try self.addSection(gpa, "__DATA", "__common"); const atom_index = try self.addAtom(gpa, .{ .name = try self.addString(gpa, name), @@ -1589,9 +1591,9 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { sym.visibility = .global; nlist.n_value = 0; - nlist.n_type = macho.N_EXT | macho.N_SECT; + nlist.n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = false, .is_stab = 0 } }; nlist.n_sect = 0; - nlist.n_desc = 0; + nlist.n_desc = @bitCast(@as(u16, 0)); nlist_atom.* = atom_index; } } @@ -1685,7 +1687,7 @@ pub fn parseAr(self: *Object, macho_file: *MachO) !void { pub fn updateArSymtab(self: Object, ar_symtab: *Archive.ArSymtab, macho_file: *MachO) error{OutOfMemory}!void { const gpa = macho_file.base.comp.gpa; for (self.symtab.items(.nlist)) |nlist| { - if (!nlist.ext() or (nlist.n_type.type == .undf and !nlist.tentative())) continue; + if (!nlist.n_type.bits.ext or (nlist.n_type.bits.type == .undf and !nlist.tentative())) continue; const off = try ar_symtab.strtab.insert(gpa, self.getNStrx(nlist.n_strx)); try ar_symtab.entries.append(gpa, .{ .off = off, .file = self.index }); } @@ -2028,30 +2030,30 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v ) void { context.symtab.items[index] = .{ .n_strx = 0, - .n_type = macho.N_BNSYM, + .n_type = .{ .stab = .bnsym }, .n_sect = n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = n_value, }; context.symtab.items[index + 1] = .{ .n_strx = n_strx, - .n_type = macho.N_FUN, + .n_type = .{ .stab = .fun }, .n_sect = n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = n_value, }; context.symtab.items[index + 2] = .{ .n_strx = 0, - .n_type = macho.N_FUN, + .n_type = .{ .stab = .fun }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = size, }; context.symtab.items[index + 3] = .{ .n_strx = 0, - .n_type = macho.N_ENSYM, + .n_type = .{ .stab = .ensym }, .n_sect = n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = size, }; } @@ -2068,9 +2070,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO comp_dir ctx.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; @@ -2081,9 +2083,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO tu_name macho_file.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; @@ -2094,9 +2096,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_OSO path ctx.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_OSO, + .n_type = .{ .stab = .oso }, .n_sect = 0, - .n_desc = 1, + .n_desc = @bitCast(@as(u16, 1)), .n_value = self.mtime, }; index += 1; @@ -2159,18 +2161,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v } else if (sym.visibility == .global) { ctx.symtab.items[index] = .{ .n_strx = sym_n_strx, - .n_type = macho.N_GSYM, + .n_type = .{ .stab = .gsym }, .n_sect = sym_n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; } else { ctx.symtab.items[index] = .{ .n_strx = sym_n_strx, - .n_type = macho.N_STSYM, + .n_type = .{ .stab = .stsym }, .n_sect = sym_n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = sym_n_value, }; index += 1; @@ -2181,9 +2183,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO ctx.symtab.items[index] = .{ .n_strx = 0, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; } else { @@ -2198,9 +2200,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO comp_dir ctx.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; @@ -2211,9 +2213,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO tu_name ctx.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; @@ -2224,9 +2226,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_OSO path ctx.symtab.items[index] = .{ .n_strx = n_strx, - .n_type = macho.N_OSO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 1, + .n_desc = @bitCast(@as(u16, 1)), .n_value = sf.getOsoModTime(self), }; index += 1; @@ -2254,18 +2256,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v } else if (sym.visibility == .global) { ctx.symtab.items[index] = .{ .n_strx = sym_n_strx, - .n_type = macho.N_GSYM, + .n_type = .{ .stab = .gsym }, .n_sect = sym_n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; } else { ctx.symtab.items[index] = .{ .n_strx = sym_n_strx, - .n_type = macho.N_STSYM, + .n_type = .{ .stab = .stsym }, .n_sect = sym_n_sect, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = sym_n_value, }; index += 1; @@ -2276,9 +2278,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v // N_SO ctx.symtab.items[index] = .{ .n_strx = 0, - .n_type = macho.N_SO, + .n_type = .{ .stab = .so }, .n_sect = 0, - .n_desc = 0, + .n_desc = @bitCast(@as(u16, 0)), .n_value = 0, }; index += 1; diff --git a/src/link/MachO/Symbol.zig b/src/link/MachO/Symbol.zig index 582768ad10..abf9dd81bd 100644 --- a/src/link/MachO/Symbol.zig +++ b/src/link/MachO/Symbol.zig @@ -36,7 +36,7 @@ pub fn isLocal(symbol: Symbol) bool { pub fn isSymbolStab(symbol: Symbol, macho_file: *MachO) bool { const file = symbol.getFile(macho_file) orelse return false; return switch (file) { - .object => symbol.getNlist(macho_file).stab(), + .object => symbol.getNlist(macho_file).n_type.bits.is_stab != 0, else => false, }; } @@ -233,35 +233,49 @@ pub inline fn setExtra(symbol: Symbol, extra: Extra, macho_file: *MachO) void { pub fn setOutputSym(symbol: Symbol, macho_file: *MachO, out: *macho.nlist_64) void { if (symbol.isLocal()) { - out.n_type = if (symbol.flags.abs) macho.N_ABS else macho.N_SECT; + out.n_type = .{ .bits = .{ + .ext = false, + .type = if (symbol.flags.abs) .abs else .sect, + .pext = false, + .is_stab = 0, + } }; out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); - out.n_desc = 0; + out.n_desc = @bitCast(@as(u16, 0)); out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); switch (symbol.visibility) { - .hidden => out.n_type |= macho.N_PEXT, + .hidden => out.n_type.bits.pext = true, else => {}, } } else if (symbol.flags.@"export") { assert(symbol.visibility == .global); - out.n_type = macho.N_EXT; - out.n_type |= if (symbol.flags.abs) macho.N_ABS else macho.N_SECT; + out.n_type = .{ .bits = .{ + .ext = true, + .type = if (symbol.flags.abs) .abs else .sect, + .pext = false, + .is_stab = 0, + } }; out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); - out.n_desc = 0; + out.n_desc = @bitCast(@as(u16, 0)); if (symbol.flags.weak) { - out.n_desc |= macho.N_WEAK_DEF; + out.n_desc.weak_def_or_ref_to_weak = true; } if (symbol.flags.dyn_ref) { - out.n_desc |= macho.REFERENCED_DYNAMICALLY; + out.n_desc.referenced_dynamically = true; } } else { assert(symbol.visibility == .global); - out.n_type = macho.N_EXT; + out.n_type = .{ .bits = .{ + .ext = true, + .type = .undf, + .pext = false, + .is_stab = 0, + } }; out.n_sect = 0; out.n_value = 0; - out.n_desc = 0; + out.n_desc = @bitCast(@as(u16, 0)); // TODO: // const ord: u16 = if (macho_file.options.namespace == .flat) @@ -274,14 +288,14 @@ pub fn setOutputSym(symbol: Symbol, macho_file: *MachO, out: *macho.nlist_64) vo ord else macho.BIND_SPECIAL_DYLIB_SELF; - out.n_desc = macho.N_SYMBOL_RESOLVER * ord; + out.n_desc = @bitCast(macho.N_SYMBOL_RESOLVER * ord); if (symbol.flags.weak) { - out.n_desc |= macho.N_WEAK_DEF; + out.n_desc.weak_def_or_ref_to_weak = true; } if (symbol.weakRef(macho_file)) { - out.n_desc |= macho.N_WEAK_REF; + out.n_desc.weak_ref = true; } } } diff --git a/src/link/MachO/Thunk.zig b/src/link/MachO/Thunk.zig index 4588a7f0e0..cdb9eb649a 100644 --- a/src/link/MachO/Thunk.zig +++ b/src/link/MachO/Thunk.zig @@ -56,10 +56,10 @@ pub fn writeSymtab(thunk: Thunk, macho_file: *MachO, ctx: anytype) void { n_strx += @intCast("__thunk".len); ctx.strtab.items[n_strx] = 0; n_strx += 1; - out_sym.n_type = macho.N_SECT; + out_sym.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; out_sym.n_sect = @intCast(thunk.out_n_sect + 1); out_sym.n_value = @intCast(thunk.getTargetAddress(ref, macho_file)); - out_sym.n_desc = 0; + out_sym.n_desc = @bitCast(@as(u16, 0)); } } diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 5a0a71f380..4a02802448 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -123,9 +123,9 @@ fn newSymbol(self: *ZigObject, allocator: Allocator, name: MachO.String, args: s self.symtab.set(nlist_idx, .{ .nlist = .{ .n_strx = name.pos, - .n_type = args.type, + .n_type = @bitCast(args.type), .n_sect = 0, - .n_desc = args.desc, + .n_desc = @bitCast(args.desc), .n_value = 0, }, .size = 0, @@ -206,8 +206,8 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { const gpa = macho_file.base.comp.gpa; for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { - if (!nlist.ext()) continue; - if (nlist.sect()) { + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type == .sect) { const atom = self.getAtom(atom_index).?; if (!atom.isAlive()) continue; } @@ -221,7 +221,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { } global.* = gop.index; - if (nlist.undf() and !nlist.tentative()) continue; + if (nlist.n_type.bits.type == .undf and !nlist.tentative()) continue; if (gop.ref.getFile(macho_file) == null) { gop.ref.* = .{ .index = @intCast(i), .file = self.index }; continue; @@ -229,7 +229,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { if (self.asFile().getSymbolRank(.{ .archive = false, - .weak = nlist.weakDef(), + .weak = nlist.n_desc.weak_def_or_ref_to_weak, .tentative = nlist.tentative(), }) < gop.ref.getSymbol(macho_file).?.getSymbolRank(macho_file)) { gop.ref.* = .{ .index = @intCast(i), .file = self.index }; @@ -243,12 +243,12 @@ pub fn markLive(self: *ZigObject, macho_file: *MachO) void { for (0..self.symbols.items.len) |i| { const nlist = self.symtab.items(.nlist)[i]; - if (!nlist.ext()) continue; + if (!nlist.n_type.bits.ext) continue; const ref = self.getSymbolRef(@intCast(i), macho_file); const file = ref.getFile(macho_file) orelse continue; const sym = ref.getSymbol(macho_file).?; - const should_keep = nlist.undf() or (nlist.tentative() and !sym.flags.tentative); + const should_keep = nlist.n_type.bits.type == .undf or (nlist.tentative() and !sym.flags.tentative); if (should_keep and file == .object and !file.object.alive) { file.object.alive = true; file.object.markLive(macho_file); @@ -331,8 +331,8 @@ pub fn claimUnresolved(self: *ZigObject, macho_file: *MachO) void { for (self.symbols.items, 0..) |*sym, i| { const nlist = self.symtab.items(.nlist)[i]; - if (!nlist.ext()) continue; - if (!nlist.undf()) continue; + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type != .undf) continue; if (self.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; @@ -974,7 +974,7 @@ fn updateNavCode( atom.setAlive(true); atom.name = sym.name; nlist.n_strx = sym.name.pos; - nlist.n_type = macho.N_SECT; + nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; nlist.n_sect = sect_index + 1; self.symtab.items(.size)[sym.nlist_idx] = code.len; @@ -1115,7 +1115,7 @@ fn createTlvDescriptor( atom.name = sym.name; nlist.n_strx = sym.name.pos; nlist.n_sect = sect_index + 1; - nlist.n_type = macho.N_SECT; + nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; nlist.n_value = 0; self.symtab.items(.size)[sym.nlist_idx] = size; @@ -1322,7 +1322,7 @@ pub fn updateExports( const global_sym = &self.symbols.items[global_nlist_index]; global_nlist.n_value = nlist.n_value; global_nlist.n_sect = nlist.n_sect; - global_nlist.n_type = macho.N_EXT | macho.N_SECT; + global_nlist.n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = false, .is_stab = 0 } }; self.symtab.items(.size)[global_nlist_index] = self.symtab.items(.size)[nlist_idx]; self.symtab.items(.atom)[global_nlist_index] = atom_index; global_sym.atom_ref = .{ .index = atom_index, .file = self.index }; @@ -1330,7 +1330,7 @@ pub fn updateExports( switch (exp.opts.linkage) { .internal => { // Symbol should be hidden, or in MachO lingo, private extern. - global_nlist.n_type |= macho.N_PEXT; + global_nlist.n_type.bits.pext = true; global_sym.visibility = .hidden; }, .strong => { @@ -1339,7 +1339,7 @@ pub fn updateExports( .weak => { // Weak linkage is specified as part of n_desc field. // Symbol's n_type is like for a symbol with strong linkage. - global_nlist.n_desc |= macho.N_WEAK_DEF; + global_nlist.n_desc.weak_def_or_ref_to_weak = true; global_sym.visibility = .global; global_sym.flags.weak = true; }, @@ -1394,7 +1394,7 @@ fn updateLazySymbol( const nlist = &self.symtab.items(.nlist)[sym.nlist_idx]; nlist.n_strx = name_str.pos; - nlist.n_type = macho.N_SECT; + nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; nlist.n_sect = output_section_index + 1; self.symtab.items(.size)[sym.nlist_idx] = code.len; diff --git a/src/link/MachO/eh_frame.zig b/src/link/MachO/eh_frame.zig index 86edf97396..1d3afaa3ac 100644 --- a/src/link/MachO/eh_frame.zig +++ b/src/link/MachO/eh_frame.zig @@ -26,24 +26,24 @@ pub const Cie = struct { for (aug[1..]) |ch| switch (ch) { 'R' => { - const enc = try reader.takeByte(); - if (enc != DW_EH_PE.pcrel | DW_EH_PE.absptr) { + const enc: DW.EH.PE = @bitCast(try reader.takeByte()); + if (enc != @as(DW.EH.PE, .{ .type = .absptr, .rel = .pcrel })) { @panic("unexpected pointer encoding"); // TODO error } }, 'P' => { - const enc = try reader.takeByte(); - if (enc != DW_EH_PE.pcrel | DW_EH_PE.indirect | DW_EH_PE.sdata4) { + const enc: DW.EH.PE = @bitCast(try reader.takeByte()); + if (enc != @as(DW.EH.PE, .{ .type = .sdata4, .rel = .pcrel, .indirect = true })) { @panic("unexpected personality pointer encoding"); // TODO error } _ = try reader.takeInt(u32, .little); // personality pointer }, 'L' => { - const enc = try reader.takeByte(); - switch (enc & DW_EH_PE.type_mask) { - DW_EH_PE.sdata4 => cie.lsda_size = .p32, - DW_EH_PE.absptr => cie.lsda_size = .p64, - else => unreachable, // TODO error + const enc: DW.EH.PE = @bitCast(try reader.takeByte()); + switch (enc.type) { + .sdata4 => cie.lsda_size = .p32, + .absptr => cie.lsda_size = .p64, + else => @panic("unexpected lsda encoding"), // TODO error } }, else => @panic("unexpected augmentation string"), // TODO error @@ -505,7 +505,7 @@ const Writer = std.Io.Writer; const Allocator = std.mem.Allocator; const Atom = @import("Atom.zig"); -const DW_EH_PE = std.dwarf.EH.PE; +const DW = std.dwarf; const File = @import("file.zig").File; const MachO = @import("../MachO.zig"); const Object = @import("Object.zig"); diff --git a/src/link/MachO/file.zig b/src/link/MachO/file.zig index 577e9374a6..ca3e1c0e82 100644 --- a/src/link/MachO/file.zig +++ b/src/link/MachO/file.zig @@ -192,21 +192,21 @@ pub const File = union(enum) { assert(file == .object or file == .zig_object); for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { - if (!nlist.ext()) continue; - if (!nlist.undf()) continue; + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type != .undf) continue; if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; const is_import = switch (macho_file.undefined_treatment) { .@"error" => false, - .warn, .suppress => nlist.weakRef(), + .warn, .suppress => nlist.n_desc.weak_ref, .dynamic_lookup => true, }; if (is_import) { sym.value = 0; sym.atom_ref = .{ .index = 0, .file = 0 }; sym.flags.weak = false; - sym.flags.weak_ref = nlist.weakRef(); + sym.flags.weak_ref = nlist.n_desc.weak_ref; sym.flags.import = is_import; sym.visibility = .global; @@ -223,13 +223,13 @@ pub const File = union(enum) { assert(file == .object or file == .zig_object); for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { - if (!nlist.ext()) continue; - if (!nlist.undf()) continue; + if (!nlist.n_type.bits.ext) continue; + if (nlist.n_type.bits.type != .undf) continue; if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; sym.value = 0; sym.atom_ref = .{ .index = 0, .file = 0 }; - sym.flags.weak_ref = nlist.weakRef(); + sym.flags.weak_ref = nlist.n_desc.weak_ref; sym.flags.import = true; sym.visibility = .global; @@ -247,7 +247,7 @@ pub const File = union(enum) { for (file.getSymbols(), file.getNlists(), 0..) |sym, nlist, i| { if (sym.visibility != .global) continue; if (sym.flags.weak) continue; - if (nlist.undf()) continue; + if (nlist.n_type.bits.type == .undf) continue; const ref = file.getSymbolRef(@intCast(i), macho_file); const ref_file = ref.getFile(macho_file) orelse continue; if (ref_file.getIndex() == file.getIndex()) continue; |
