| author | |
| committer | |
| log | 0c7b2a7bd5433b7e7bcde3bb49d48226dc2adef9 |
| tree | 1cc257c75956449de2cd833b91ce17b73b29f724 |
| parent | 202aeacc05a2fc53762c49d18daeefdf0fa5fbec |
| signature |
12 files changed, 165 insertions(+), 147 deletions(-)
lib/std/debug/Dwarf/Unwind.zig+1-1| ... | @@ -603,13 +603,13 @@ fn readEhPointerAbs(r: *Reader, enc_ty: EH.PE.Type, addr_size_bytes: u8, endian: | ... | @@ -603,13 +603,13 @@ fn readEhPointerAbs(r: *Reader, enc_ty: EH.PE.Type, addr_size_bytes: u8, endian: |
| 603 | /// Returns `error.InvalidDebugInfo` if the encoding is `EH.PE.omit`. | 603 | /// Returns `error.InvalidDebugInfo` if the encoding is `EH.PE.omit`. |
| 604 | fn readEhPointer(r: *Reader, enc: EH.PE, addr_size_bytes: u8, ctx: EhPointerContext, endian: Endian) !u64 { | 604 | fn readEhPointer(r: *Reader, enc: EH.PE, addr_size_bytes: u8, ctx: EhPointerContext, endian: Endian) !u64 { |
| 605 | const offset = try readEhPointerAbs(r, enc.type, addr_size_bytes, endian); | 605 | const offset = try readEhPointerAbs(r, enc.type, addr_size_bytes, endian); |
| 606 | if (enc.indirect) return bad(); // GCC extension; not supported | ||
| 606 | const base = switch (enc.rel) { | 607 | const base = switch (enc.rel) { |
| 607 | .abs, .aligned => 0, | 608 | .abs, .aligned => 0, |
| 608 | .pcrel => ctx.pc_rel_base, | 609 | .pcrel => ctx.pc_rel_base, |
| 609 | .textrel => ctx.text_rel_base orelse return bad(), | 610 | .textrel => ctx.text_rel_base orelse return bad(), |
| 610 | .datarel => ctx.data_rel_base orelse return bad(), | 611 | .datarel => ctx.data_rel_base orelse return bad(), |
| 611 | .funcrel => ctx.function_rel_base orelse return bad(), | 612 | .funcrel => ctx.function_rel_base orelse return bad(), |
| 612 | .indirect => return bad(), // GCC extension; not supported | ||
| 613 | _ => return bad(), | 613 | _ => return bad(), |
| 614 | }; | 614 | }; |
| 615 | return switch (offset) { | 615 | return switch (offset) { |
lib/std/dwarf/EH.zig+5-3| ... | @@ -1,6 +1,8 @@ | ... | @@ -1,6 +1,8 @@ |
| 1 | pub const PE = packed struct(u8) { | 1 | pub const PE = packed struct(u8) { |
| 2 | type: Type, | 2 | type: Type, |
| 3 | rel: Rel, | 3 | rel: Rel, |
| 4 | /// Undocumented GCC extension | ||
| 5 | indirect: bool = false, | ||
| 4 | 6 | ||
| 5 | /// This is a special encoding which does not correspond to named `type`/`rel` values. | 7 | /// This is a special encoding which does not correspond to named `type`/`rel` values. |
| 6 | pub const omit: PE = @bitCast(@as(u8, 0xFF)); | 8 | pub const omit: PE = @bitCast(@as(u8, 0xFF)); |
| ... | @@ -18,15 +20,15 @@ pub const PE = packed struct(u8) { | ... | @@ -18,15 +20,15 @@ pub const PE = packed struct(u8) { |
| 18 | _, | 20 | _, |
| 19 | }; | 21 | }; |
| 20 | 22 | ||
| 21 | pub const Rel = enum(u4) { | 23 | /// The specification considers this a `u4`, but the GCC `indirect` field extension conflicts |
| 24 | /// with that, so we consider it a `u3` instead. | ||
| 25 | pub const Rel = enum(u3) { | ||
| 22 | abs = 0x0, | 26 | abs = 0x0, |
| 23 | pcrel = 0x1, | 27 | pcrel = 0x1, |
| 24 | textrel = 0x2, | 28 | textrel = 0x2, |
| 25 | datarel = 0x3, | 29 | datarel = 0x3, |
| 26 | funcrel = 0x4, | 30 | funcrel = 0x4, |
| 27 | aligned = 0x5, | 31 | aligned = 0x5, |
| 28 | /// Undocumented GCC extension | ||
| 29 | indirect = 0x8, | ||
| 30 | _, | 32 | _, |
| 31 | }; | 33 | }; |
| 32 | }; | 34 | }; |
src/link/Dwarf.zig+1-1| ... | @@ -4852,7 +4852,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro | ... | @@ -4852,7 +4852,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (FlushError || Writer.Erro |
| 4852 | hw.writeSleb128(dwarf.debug_frame.header.data_alignment_factor) catch unreachable; | 4852 | hw.writeSleb128(dwarf.debug_frame.header.data_alignment_factor) catch unreachable; |
| 4853 | hw.writeUleb128(dwarf.debug_frame.header.return_address_register) catch unreachable; | 4853 | hw.writeUleb128(dwarf.debug_frame.header.return_address_register) catch unreachable; |
| 4854 | hw.writeUleb128(1) catch unreachable; | 4854 | hw.writeUleb128(1) catch unreachable; |
| 4855 | hw.writeByte(DW.EH.PE.pcrel | DW.EH.PE.sdata4) catch unreachable; | 4855 | hw.writeByte(@bitCast(@as(DW.EH.PE, .{ .type = .sdata4, .rel = .pcrel }))) catch unreachable; |
| 4856 | hw.writeByte(DW.CFA.def_cfa_sf) catch unreachable; | 4856 | hw.writeByte(DW.CFA.def_cfa_sf) catch unreachable; |
| 4857 | hw.writeUleb128(Register.rsp.dwarfNum()) catch unreachable; | 4857 | hw.writeUleb128(Register.rsp.dwarfNum()) catch unreachable; |
| 4858 | hw.writeSleb128(-1) catch unreachable; | 4858 | hw.writeSleb128(-1) catch unreachable; |
src/link/Elf/eh_frame.zig+3-3| ... | @@ -456,10 +456,10 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, relocs: *std.array_list.Managed(elf.El | ... | @@ -456,10 +456,10 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, relocs: *std.array_list.Managed(elf.El |
| 456 | 456 | ||
| 457 | pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { | 457 | pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| 458 | try writer.writeByte(1); // version | 458 | try writer.writeByte(1); // version |
| 459 | try writer.writeByte(DW_EH_PE.pcrel | DW_EH_PE.sdata4); // eh_frame_ptr_enc | 459 | try writer.writeByte(@bitCast(@as(DW_EH_PE, .{ .type = .sdata4, .rel = .pcrel }))); // eh_frame_ptr_enc |
| 460 | // Building the lookup table would be expensive work on every `flush` -- omit it. | 460 | // Building the lookup table would be expensive work on every `flush` -- omit it. |
| 461 | try writer.writeByte(DW_EH_PE.omit); // fde_count_enc | 461 | try writer.writeByte(@bitCast(DW_EH_PE.omit)); // fde_count_enc |
| 462 | try writer.writeByte(DW_EH_PE.omit); // table_enc | 462 | try writer.writeByte(@bitCast(DW_EH_PE.omit)); // table_enc |
| 463 | 463 | ||
| 464 | const shdrs = elf_file.sections.items(.shdr); | 464 | const shdrs = elf_file.sections.items(.shdr); |
| 465 | const eh_frame_shdr = shdrs[elf_file.section_indexes.eh_frame.?]; | 465 | const eh_frame_shdr = shdrs[elf_file.section_indexes.eh_frame.?]; |
src/link/MachO.zig+2-2| ... | @@ -4149,9 +4149,9 @@ pub const SymtabCtx = struct { | ... | @@ -4149,9 +4149,9 @@ pub const SymtabCtx = struct { |
| 4149 | 4149 | ||
| 4150 | pub const null_sym = macho.nlist_64{ | 4150 | pub const null_sym = macho.nlist_64{ |
| 4151 | .n_strx = 0, | 4151 | .n_strx = 0, |
| 4152 | .n_type = 0, | 4152 | .n_type = @bitCast(@as(u8, 0)), |
| 4153 | .n_sect = 0, | 4153 | .n_sect = 0, |
| 4154 | .n_desc = 0, | 4154 | .n_desc = @bitCast(@as(u16, 0)), |
| 4155 | .n_value = 0, | 4155 | .n_value = 0, |
| 4156 | }; | 4156 | }; |
| 4157 | 4157 |
src/link/MachO/InternalObject.zig+15-15| ... | @@ -69,9 +69,9 @@ pub fn initSymbols(self: *InternalObject, macho_file: *MachO) !void { | ... | @@ -69,9 +69,9 @@ pub fn initSymbols(self: *InternalObject, macho_file: *MachO) !void { |
| 69 | const nlist = obj.symtab.addOneAssumeCapacity(); | 69 | const nlist = obj.symtab.addOneAssumeCapacity(); |
| 70 | nlist.* = .{ | 70 | nlist.* = .{ |
| 71 | .n_strx = name.pos, | 71 | .n_strx = name.pos, |
| 72 | .n_type = args.type, | 72 | .n_type = @bitCast(args.type), |
| 73 | .n_sect = 0, | 73 | .n_sect = 0, |
| 74 | .n_desc = args.desc, | 74 | .n_desc = @bitCast(args.desc), |
| 75 | .n_value = 0, | 75 | .n_value = 0, |
| 76 | }; | 76 | }; |
| 77 | symbol.nlist_idx = nlist_idx; | 77 | symbol.nlist_idx = nlist_idx; |
| ... | @@ -143,7 +143,7 @@ pub fn resolveSymbols(self: *InternalObject, macho_file: *MachO) !void { | ... | @@ -143,7 +143,7 @@ pub fn resolveSymbols(self: *InternalObject, macho_file: *MachO) !void { |
| 143 | } | 143 | } |
| 144 | global.* = gop.index; | 144 | global.* = gop.index; |
| 145 | 145 | ||
| 146 | if (nlist.undf()) continue; | 146 | if (nlist.n_type.bits.type == .undf) continue; |
| 147 | if (gop.ref.getFile(macho_file) == null) { | 147 | if (gop.ref.getFile(macho_file) == null) { |
| 148 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; | 148 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| 149 | continue; | 149 | continue; |
| ... | @@ -171,7 +171,7 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { | ... | @@ -171,7 +171,7 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { |
| 171 | const object = macho_file.getFile(index).?.object; | 171 | const object = macho_file.getFile(index).?.object; |
| 172 | for (object.symbols.items, 0..) |sym, i| { | 172 | for (object.symbols.items, 0..) |sym, i| { |
| 173 | const nlist = object.symtab.items(.nlist)[i]; | 173 | const nlist = object.symtab.items(.nlist)[i]; |
| 174 | if (!nlist.undf() or !nlist.ext()) continue; | 174 | if (nlist.n_type.bits.type != .undf or !nlist.n_type.bits.ext) continue; |
| 175 | const ref = object.getSymbolRef(@intCast(i), macho_file); | 175 | const ref = object.getSymbolRef(@intCast(i), macho_file); |
| 176 | if (ref.getFile(macho_file) != null) continue; | 176 | if (ref.getFile(macho_file) != null) continue; |
| 177 | const name = sym.getName(macho_file); | 177 | const name = sym.getName(macho_file); |
| ... | @@ -206,9 +206,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { | ... | @@ -206,9 +206,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { |
| 206 | const nlist = self.symtab.addOneAssumeCapacity(); | 206 | const nlist = self.symtab.addOneAssumeCapacity(); |
| 207 | nlist.* = .{ | 207 | nlist.* = .{ |
| 208 | .n_strx = name_str.pos, | 208 | .n_strx = name_str.pos, |
| 209 | .n_type = macho.N_SECT, | 209 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 210 | .n_sect = 0, | 210 | .n_sect = 0, |
| 211 | .n_desc = 0, | 211 | .n_desc = @bitCast(@as(u16, 0)), |
| 212 | .n_value = 0, | 212 | .n_value = 0, |
| 213 | }; | 213 | }; |
| 214 | sym.nlist_idx = nlist_idx; | 214 | sym.nlist_idx = nlist_idx; |
| ... | @@ -226,7 +226,7 @@ pub fn markLive(self: *InternalObject, macho_file: *MachO) void { | ... | @@ -226,7 +226,7 @@ pub fn markLive(self: *InternalObject, macho_file: *MachO) void { |
| 226 | 226 | ||
| 227 | for (0..self.symbols.items.len) |i| { | 227 | for (0..self.symbols.items.len) |i| { |
| 228 | const nlist = self.symtab.items[i]; | 228 | const nlist = self.symtab.items[i]; |
| 229 | if (!nlist.ext()) continue; | 229 | if (!nlist.n_type.bits.ext) continue; |
| 230 | 230 | ||
| 231 | const ref = self.getSymbolRef(@intCast(i), macho_file); | 231 | const ref = self.getSymbolRef(@intCast(i), macho_file); |
| 232 | const file = ref.getFile(macho_file) orelse continue; | 232 | const file = ref.getFile(macho_file) orelse continue; |
| ... | @@ -273,9 +273,9 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil | ... | @@ -273,9 +273,9 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil |
| 273 | const nlist = try self.symtab.addOne(gpa); | 273 | const nlist = try self.symtab.addOne(gpa); |
| 274 | nlist.* = .{ | 274 | nlist.* = .{ |
| 275 | .n_strx = name_str.pos, | 275 | .n_strx = name_str.pos, |
| 276 | .n_type = macho.N_SECT, | 276 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 277 | .n_sect = @intCast(n_sect + 1), | 277 | .n_sect = @intCast(n_sect + 1), |
| 278 | .n_desc = 0, | 278 | .n_desc = @bitCast(@as(u16, 0)), |
| 279 | .n_value = 0, | 279 | .n_value = 0, |
| 280 | }; | 280 | }; |
| 281 | sym.nlist_idx = nlist_idx; | 281 | sym.nlist_idx = nlist_idx; |
| ... | @@ -326,9 +326,9 @@ fn addObjcSelrefsSection(self: *InternalObject, methname_sym_index: Symbol.Index | ... | @@ -326,9 +326,9 @@ fn addObjcSelrefsSection(self: *InternalObject, methname_sym_index: Symbol.Index |
| 326 | const nlist = try self.symtab.addOne(gpa); | 326 | const nlist = try self.symtab.addOne(gpa); |
| 327 | nlist.* = .{ | 327 | nlist.* = .{ |
| 328 | .n_strx = 0, | 328 | .n_strx = 0, |
| 329 | .n_type = macho.N_SECT, | 329 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 330 | .n_sect = @intCast(n_sect + 1), | 330 | .n_sect = @intCast(n_sect + 1), |
| 331 | .n_desc = 0, | 331 | .n_desc = @bitCast(@as(u16, 0)), |
| 332 | .n_value = 0, | 332 | .n_value = 0, |
| 333 | }; | 333 | }; |
| 334 | sym.nlist_idx = nlist_idx; | 334 | sym.nlist_idx = nlist_idx; |
| ... | @@ -352,8 +352,8 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi | ... | @@ -352,8 +352,8 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi |
| 352 | 352 | ||
| 353 | for (object.symbols.items, 0..) |sym, i| { | 353 | for (object.symbols.items, 0..) |sym, i| { |
| 354 | const nlist = object.symtab.items(.nlist)[i]; | 354 | const nlist = object.symtab.items(.nlist)[i]; |
| 355 | if (!nlist.ext()) continue; | 355 | if (!nlist.n_type.bits.ext) continue; |
| 356 | if (!nlist.undf()) continue; | 356 | if (nlist.n_type.bits.type != .undf) continue; |
| 357 | 357 | ||
| 358 | const ref = object.getSymbolRef(@intCast(i), macho_file); | 358 | const ref = object.getSymbolRef(@intCast(i), macho_file); |
| 359 | if (ref.getFile(macho_file) != null) continue; | 359 | if (ref.getFile(macho_file) != null) continue; |
| ... | @@ -381,9 +381,9 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi | ... | @@ -381,9 +381,9 @@ pub fn resolveObjcMsgSendSymbols(self: *InternalObject, macho_file: *MachO) !voi |
| 381 | const nlist = try self.symtab.addOne(gpa); | 381 | const nlist = try self.symtab.addOne(gpa); |
| 382 | nlist.* = .{ | 382 | nlist.* = .{ |
| 383 | .n_strx = name_str.pos, | 383 | .n_strx = name_str.pos, |
| 384 | .n_type = macho.N_SECT | macho.N_EXT | macho.N_PEXT, | 384 | .n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = true, .is_stab = 0 } }, |
| 385 | .n_sect = 0, | 385 | .n_sect = 0, |
| 386 | .n_desc = 0, | 386 | .n_desc = @bitCast(@as(u16, 0)), |
| 387 | .n_value = 0, | 387 | .n_value = 0, |
| 388 | }; | 388 | }; |
| 389 | sym.nlist_idx = nlist_idx; | 389 | sym.nlist_idx = nlist_idx; |
src/link/MachO/Object.zig+74-72| ... | @@ -179,7 +179,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { | ... | @@ -179,7 +179,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { |
| 179 | idx: usize, | 179 | idx: usize, |
| 180 | 180 | ||
| 181 | fn rank(ctx: *const Object, nl: macho.nlist_64) u8 { | 181 | fn rank(ctx: *const Object, nl: macho.nlist_64) u8 { |
| 182 | if (!nl.ext()) { | 182 | if (!nl.n_type.bits.ext) { |
| 183 | const name = ctx.getNStrx(nl.n_strx); | 183 | const name = ctx.getNStrx(nl.n_strx); |
| 184 | if (name.len == 0) return 5; | 184 | if (name.len == 0) return 5; |
| 185 | if (name[0] == 'l' or name[0] == 'L') return 4; | 185 | if (name[0] == 'l' or name[0] == 'L') return 4; |
| ... | @@ -202,7 +202,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { | ... | @@ -202,7 +202,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { |
| 202 | var nlists = try std.array_list.Managed(NlistIdx).initCapacity(gpa, self.symtab.items(.nlist).len); | 202 | var nlists = try std.array_list.Managed(NlistIdx).initCapacity(gpa, self.symtab.items(.nlist).len); |
| 203 | defer nlists.deinit(); | 203 | defer nlists.deinit(); |
| 204 | for (self.symtab.items(.nlist), 0..) |nlist, i| { | 204 | for (self.symtab.items(.nlist), 0..) |nlist, i| { |
| 205 | if (nlist.n_type.bits.is_stab != 0 or nlist.n_type.type != .sect) continue; | 205 | if (nlist.n_type.bits.is_stab != 0 or nlist.n_type.bits.type != .sect) continue; |
| 206 | nlists.appendAssumeCapacity(.{ .nlist = nlist, .idx = i }); | 206 | nlists.appendAssumeCapacity(.{ .nlist = nlist, .idx = i }); |
| 207 | } | 207 | } |
| 208 | mem.sort(NlistIdx, nlists.items, self, NlistIdx.lessThan); | 208 | mem.sort(NlistIdx, nlists.items, self, NlistIdx.lessThan); |
| ... | @@ -488,9 +488,9 @@ fn initCstringLiterals(self: *Object, allocator: Allocator, file: File.Handle, m | ... | @@ -488,9 +488,9 @@ fn initCstringLiterals(self: *Object, allocator: Allocator, file: File.Handle, m |
| 488 | self.symtab.set(nlist_index, .{ | 488 | self.symtab.set(nlist_index, .{ |
| 489 | .nlist = .{ | 489 | .nlist = .{ |
| 490 | .n_strx = name_str.pos, | 490 | .n_strx = name_str.pos, |
| 491 | .n_type = macho.N_SECT, | 491 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 492 | .n_sect = @intCast(atom.n_sect + 1), | 492 | .n_sect = @intCast(atom.n_sect + 1), |
| 493 | .n_desc = 0, | 493 | .n_desc = @bitCast(@as(u16, 0)), |
| 494 | .n_value = atom.getInputAddress(macho_file), | 494 | .n_value = atom.getInputAddress(macho_file), |
| 495 | }, | 495 | }, |
| 496 | .size = atom.size, | 496 | .size = atom.size, |
| ... | @@ -555,9 +555,9 @@ fn initFixedSizeLiterals(self: *Object, allocator: Allocator, macho_file: *MachO | ... | @@ -555,9 +555,9 @@ fn initFixedSizeLiterals(self: *Object, allocator: Allocator, macho_file: *MachO |
| 555 | self.symtab.set(nlist_index, .{ | 555 | self.symtab.set(nlist_index, .{ |
| 556 | .nlist = .{ | 556 | .nlist = .{ |
| 557 | .n_strx = name_str.pos, | 557 | .n_strx = name_str.pos, |
| 558 | .n_type = macho.N_SECT, | 558 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 559 | .n_sect = @intCast(atom.n_sect + 1), | 559 | .n_sect = @intCast(atom.n_sect + 1), |
| 560 | .n_desc = 0, | 560 | .n_desc = @bitCast(@as(u16, 0)), |
| 561 | .n_value = atom.getInputAddress(macho_file), | 561 | .n_value = atom.getInputAddress(macho_file), |
| 562 | }, | 562 | }, |
| 563 | .size = atom.size, | 563 | .size = atom.size, |
| ... | @@ -613,9 +613,9 @@ fn initPointerLiterals(self: *Object, allocator: Allocator, macho_file: *MachO) | ... | @@ -613,9 +613,9 @@ fn initPointerLiterals(self: *Object, allocator: Allocator, macho_file: *MachO) |
| 613 | self.symtab.set(nlist_index, .{ | 613 | self.symtab.set(nlist_index, .{ |
| 614 | .nlist = .{ | 614 | .nlist = .{ |
| 615 | .n_strx = name_str.pos, | 615 | .n_strx = name_str.pos, |
| 616 | .n_type = macho.N_SECT, | 616 | .n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }, |
| 617 | .n_sect = @intCast(atom.n_sect + 1), | 617 | .n_sect = @intCast(atom.n_sect + 1), |
| 618 | .n_desc = 0, | 618 | .n_desc = @bitCast(@as(u16, 0)), |
| 619 | .n_value = atom.getInputAddress(macho_file), | 619 | .n_value = atom.getInputAddress(macho_file), |
| 620 | }, | 620 | }, |
| 621 | .size = atom.size, | 621 | .size = atom.size, |
| ... | @@ -805,7 +805,7 @@ fn linkNlistToAtom(self: *Object, macho_file: *MachO) !void { | ... | @@ -805,7 +805,7 @@ fn linkNlistToAtom(self: *Object, macho_file: *MachO) !void { |
| 805 | const tracy = trace(@src()); | 805 | const tracy = trace(@src()); |
| 806 | defer tracy.end(); | 806 | defer tracy.end(); |
| 807 | for (self.symtab.items(.nlist), self.symtab.items(.atom)) |nlist, *atom| { | 807 | for (self.symtab.items(.nlist), self.symtab.items(.atom)) |nlist, *atom| { |
| 808 | if (!nlist.n_type.bits.is_stab != 0 and nlist.n_type.type == .sect) { | 808 | if (nlist.n_type.bits.is_stab == 0 and nlist.n_type.bits.type == .sect) { |
| 809 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; | 809 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; |
| 810 | const subs = self.sections.items(.subsections)[nlist.n_sect - 1].items; | 810 | const subs = self.sections.items(.subsections)[nlist.n_sect - 1].items; |
| 811 | if (nlist.n_value == sect.addr) { | 811 | if (nlist.n_value == sect.addr) { |
| ... | @@ -852,30 +852,30 @@ fn initSymbols(self: *Object, allocator: Allocator, macho_file: *MachO) !void { | ... | @@ -852,30 +852,30 @@ fn initSymbols(self: *Object, allocator: Allocator, macho_file: *MachO) !void { |
| 852 | symbol.extra = self.addSymbolExtraAssumeCapacity(.{}); | 852 | symbol.extra = self.addSymbolExtraAssumeCapacity(.{}); |
| 853 | 853 | ||
| 854 | if (self.getAtom(atom_index)) |atom| { | 854 | if (self.getAtom(atom_index)) |atom| { |
| 855 | assert(nlist.n_type.type != .abs); | 855 | assert(nlist.n_type.bits.type != .abs); |
| 856 | symbol.value -= atom.getInputAddress(macho_file); | 856 | symbol.value -= atom.getInputAddress(macho_file); |
| 857 | symbol.atom_ref = .{ .index = atom_index, .file = self.index }; | 857 | symbol.atom_ref = .{ .index = atom_index, .file = self.index }; |
| 858 | } | 858 | } |
| 859 | 859 | ||
| 860 | symbol.flags.weak = nlist.n_desc.weak_def_or_ref_to_weak; | 860 | symbol.flags.weak = nlist.n_desc.weak_def_or_ref_to_weak; |
| 861 | symbol.flags.abs = nlist.n_type.type == .abs; | 861 | symbol.flags.abs = nlist.n_type.bits.type == .abs; |
| 862 | symbol.flags.tentative = nlist.tentative(); | 862 | symbol.flags.tentative = nlist.tentative(); |
| 863 | symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.n_desc.discarded_or_no_dead_strip; | 863 | symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.n_desc.discarded_or_no_dead_strip; |
| 864 | symbol.flags.dyn_ref = nlist.n_desc & macho.REFERENCED_DYNAMICALLY != 0; | 864 | symbol.flags.dyn_ref = nlist.n_desc.referenced_dynamically; |
| 865 | symbol.flags.interposable = false; | 865 | symbol.flags.interposable = false; |
| 866 | // TODO | 866 | // TODO |
| 867 | // 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(); | 867 | // 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(); |
| 868 | 868 | ||
| 869 | if (nlist.n_type.type == .sect and | 869 | if (nlist.n_type.bits.type == .sect and |
| 870 | self.sections.items(.header)[nlist.n_sect - 1].type() == macho.S_THREAD_LOCAL_VARIABLES) | 870 | self.sections.items(.header)[nlist.n_sect - 1].type() == macho.S_THREAD_LOCAL_VARIABLES) |
| 871 | { | 871 | { |
| 872 | symbol.flags.tlv = true; | 872 | symbol.flags.tlv = true; |
| 873 | } | 873 | } |
| 874 | 874 | ||
| 875 | if (nlist.ext()) { | 875 | if (nlist.n_type.bits.ext) { |
| 876 | if (nlist.n_type.type == .undf) { | 876 | if (nlist.n_type.bits.type == .undf) { |
| 877 | symbol.flags.weak_ref = nlist.n_desc.weak_ref; | 877 | symbol.flags.weak_ref = nlist.n_desc.weak_ref; |
| 878 | } else if (nlist.pext() or (nlist.n_desc.weak_def_or_ref_to_weak and nlist.n_desc.weak_ref) or self.hidden) { | 878 | } 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) { |
| 879 | symbol.visibility = .hidden; | 879 | symbol.visibility = .hidden; |
| 880 | } else { | 880 | } else { |
| 881 | symbol.visibility = .global; | 881 | symbol.visibility = .global; |
| ... | @@ -919,7 +919,7 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f | ... | @@ -919,7 +919,7 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f |
| 919 | var addr_lookup = std.StringHashMap(u64).init(allocator); | 919 | var addr_lookup = std.StringHashMap(u64).init(allocator); |
| 920 | defer addr_lookup.deinit(); | 920 | defer addr_lookup.deinit(); |
| 921 | for (syms) |sym| { | 921 | for (syms) |sym| { |
| 922 | if (sym.n_type.type == .sect and (sym.ext() or sym.pext())) { | 922 | if (sym.n_type.bits.type == .sect and (sym.n_type.bits.ext or sym.n_type.bits.pext)) { |
| 923 | try addr_lookup.putNoClobber(self.getNStrx(sym.n_strx), sym.n_value); | 923 | try addr_lookup.putNoClobber(self.getNStrx(sym.n_strx), sym.n_value); |
| 924 | } | 924 | } |
| 925 | } | 925 | } |
| ... | @@ -927,41 +927,43 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f | ... | @@ -927,41 +927,43 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f |
| 927 | var i: u32 = start; | 927 | var i: u32 = start; |
| 928 | while (i < end) : (i += 1) { | 928 | while (i < end) : (i += 1) { |
| 929 | const open = syms[i]; | 929 | const open = syms[i]; |
| 930 | if (open.n_type != macho.N_SO) { | 930 | if (open.n_type.stab != .so) { |
| 931 | try macho_file.reportParseError2(self.index, "unexpected symbol stab type 0x{x} as the first entry", .{ | 931 | try macho_file.reportParseError2(self.index, "unexpected symbol stab type 0x{x} as the first entry", .{ |
| 932 | open.n_type, | 932 | @intFromEnum(open.n_type.stab), |
| 933 | }); | 933 | }); |
| 934 | return error.MalformedObject; | 934 | return error.MalformedObject; |
| 935 | } | 935 | } |
| 936 | 936 | ||
| 937 | while (i < end and syms[i].n_type == macho.N_SO and syms[i].n_sect != 0) : (i += 1) {} | 937 | while (i < end and syms[i].n_type.stab == .so and syms[i].n_sect != 0) : (i += 1) {} |
| 938 | 938 | ||
| 939 | var sf: StabFile = .{ .comp_dir = i }; | 939 | var sf: StabFile = .{ .comp_dir = i }; |
| 940 | // TODO validate | 940 | // TODO validate |
| 941 | i += 3; | 941 | i += 3; |
| 942 | 942 | ||
| 943 | while (i < end and syms[i].n_type != macho.N_SO) : (i += 1) { | 943 | while (i < end and syms[i].n_type.stab != .so) : (i += 1) { |
| 944 | const nlist = syms[i]; | 944 | const nlist = syms[i]; |
| 945 | var stab: StabFile.Stab = .{}; | 945 | var stab: StabFile.Stab = .{}; |
| 946 | switch (nlist.n_type) { | 946 | switch (nlist.n_type.stab) { |
| 947 | macho.N_BNSYM => { | 947 | .bnsym => { |
| 948 | stab.is_func = true; | 948 | stab.is_func = true; |
| 949 | stab.index = sym_lookup.find(nlist.n_value); | 949 | stab.index = sym_lookup.find(nlist.n_value); |
| 950 | // TODO validate | 950 | // TODO validate |
| 951 | i += 3; | 951 | i += 3; |
| 952 | }, | 952 | }, |
| 953 | macho.N_GSYM => { | 953 | .gsym => { |
| 954 | stab.is_func = false; | 954 | stab.is_func = false; |
| 955 | stab.index = sym_lookup.find(addr_lookup.get(self.getNStrx(nlist.n_strx)).?); | 955 | stab.index = sym_lookup.find(addr_lookup.get(self.getNStrx(nlist.n_strx)).?); |
| 956 | }, | 956 | }, |
| 957 | macho.N_STSYM => { | 957 | .stsym => { |
| 958 | stab.is_func = false; | 958 | stab.is_func = false; |
| 959 | stab.index = sym_lookup.find(nlist.n_value); | 959 | stab.index = sym_lookup.find(nlist.n_value); |
| 960 | }, | 960 | }, |
| 961 | _ => { | ||
| 962 | try macho_file.reportParseError2(self.index, "unhandled symbol stab type 0x{x}", .{@intFromEnum(nlist.n_type.stab)}); | ||
| 963 | return error.MalformedObject; | ||
| 964 | }, | ||
| 961 | else => { | 965 | else => { |
| 962 | try macho_file.reportParseError2(self.index, "unhandled symbol stab type 0x{x}", .{ | 966 | try macho_file.reportParseError2(self.index, "unhandled symbol stab type '{t}'", .{nlist.n_type.stab}); |
| 963 | nlist.n_type, | ||
| 964 | }); | ||
| 965 | return error.MalformedObject; | 967 | return error.MalformedObject; |
| 966 | }, | 968 | }, |
| 967 | } | 969 | } |
| ... | @@ -1132,7 +1134,7 @@ fn initUnwindRecords(self: *Object, allocator: Allocator, sect_id: u8, file: Fil | ... | @@ -1132,7 +1134,7 @@ fn initUnwindRecords(self: *Object, allocator: Allocator, sect_id: u8, file: Fil |
| 1132 | fn find(fs: @This(), addr: u64) ?Symbol.Index { | 1134 | fn find(fs: @This(), addr: u64) ?Symbol.Index { |
| 1133 | for (0..fs.ctx.symbols.items.len) |i| { | 1135 | for (0..fs.ctx.symbols.items.len) |i| { |
| 1134 | const nlist = fs.ctx.symtab.items(.nlist)[i]; | 1136 | const nlist = fs.ctx.symtab.items(.nlist)[i]; |
| 1135 | if (nlist.ext() and nlist.n_value == addr) return @intCast(i); | 1137 | if (nlist.n_type.bits.ext and nlist.n_value == addr) return @intCast(i); |
| 1136 | } | 1138 | } |
| 1137 | return null; | 1139 | return null; |
| 1138 | } | 1140 | } |
| ... | @@ -1242,7 +1244,7 @@ fn parseUnwindRecords(self: *Object, allocator: Allocator, cpu_arch: std.Target. | ... | @@ -1242,7 +1244,7 @@ fn parseUnwindRecords(self: *Object, allocator: Allocator, cpu_arch: std.Target. |
| 1242 | const slice = self.symtab.slice(); | 1244 | const slice = self.symtab.slice(); |
| 1243 | for (slice.items(.nlist), slice.items(.atom), slice.items(.size)) |nlist, atom, size| { | 1245 | for (slice.items(.nlist), slice.items(.atom), slice.items(.size)) |nlist, atom, size| { |
| 1244 | if (nlist.n_type.bits.is_stab != 0) continue; | 1246 | if (nlist.n_type.bits.is_stab != 0) continue; |
| 1245 | if (nlist.n_type.type != .sect) continue; | 1247 | if (nlist.n_type.bits.type != .sect) continue; |
| 1246 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; | 1248 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; |
| 1247 | if (sect.isCode() and sect.size > 0) { | 1249 | if (sect.isCode() and sect.size > 0) { |
| 1248 | try superposition.ensureUnusedCapacity(1); | 1250 | try superposition.ensureUnusedCapacity(1); |
| ... | @@ -1458,8 +1460,8 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { | ... | @@ -1458,8 +1460,8 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { |
| 1458 | const gpa = macho_file.base.comp.gpa; | 1460 | const gpa = macho_file.base.comp.gpa; |
| 1459 | 1461 | ||
| 1460 | for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { | 1462 | for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { |
| 1461 | if (!nlist.ext()) continue; | 1463 | if (!nlist.n_type.bits.ext) continue; |
| 1462 | if (nlist.n_type.type == .sect) { | 1464 | if (nlist.n_type.bits.type == .sect) { |
| 1463 | const atom = self.getAtom(atom_index).?; | 1465 | const atom = self.getAtom(atom_index).?; |
| 1464 | if (!atom.isAlive()) continue; | 1466 | if (!atom.isAlive()) continue; |
| 1465 | } | 1467 | } |
| ... | @@ -1473,7 +1475,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { | ... | @@ -1473,7 +1475,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { |
| 1473 | } | 1475 | } |
| 1474 | global.* = gop.index; | 1476 | global.* = gop.index; |
| 1475 | 1477 | ||
| 1476 | if (nlist.n_type.type == .undf and !nlist.tentative()) continue; | 1478 | if (nlist.n_type.bits.type == .undf and !nlist.tentative()) continue; |
| 1477 | if (gop.ref.getFile(macho_file) == null) { | 1479 | if (gop.ref.getFile(macho_file) == null) { |
| 1478 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; | 1480 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| 1479 | continue; | 1481 | continue; |
| ... | @@ -1495,12 +1497,12 @@ pub fn markLive(self: *Object, macho_file: *MachO) void { | ... | @@ -1495,12 +1497,12 @@ pub fn markLive(self: *Object, macho_file: *MachO) void { |
| 1495 | 1497 | ||
| 1496 | for (0..self.symbols.items.len) |i| { | 1498 | for (0..self.symbols.items.len) |i| { |
| 1497 | const nlist = self.symtab.items(.nlist)[i]; | 1499 | const nlist = self.symtab.items(.nlist)[i]; |
| 1498 | if (!nlist.ext()) continue; | 1500 | if (!nlist.n_type.bits.ext) continue; |
| 1499 | 1501 | ||
| 1500 | const ref = self.getSymbolRef(@intCast(i), macho_file); | 1502 | const ref = self.getSymbolRef(@intCast(i), macho_file); |
| 1501 | const file = ref.getFile(macho_file) orelse continue; | 1503 | const file = ref.getFile(macho_file) orelse continue; |
| 1502 | const sym = ref.getSymbol(macho_file).?; | 1504 | const sym = ref.getSymbol(macho_file).?; |
| 1503 | const should_keep = nlist.n_type.type == .undf or (nlist.tentative() and !sym.flags.tentative); | 1505 | const should_keep = nlist.n_type.bits.type == .undf or (nlist.tentative() and !sym.flags.tentative); |
| 1504 | if (should_keep and file == .object and !file.object.alive) { | 1506 | if (should_keep and file == .object and !file.object.alive) { |
| 1505 | file.object.alive = true; | 1507 | file.object.alive = true; |
| 1506 | file.object.markLive(macho_file); | 1508 | file.object.markLive(macho_file); |
| ... | @@ -1565,7 +1567,7 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { | ... | @@ -1565,7 +1567,7 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { |
| 1565 | const name = try std.fmt.allocPrintSentinel(gpa, "__DATA$__common${s}", .{sym.getName(macho_file)}, 0); | 1567 | const name = try std.fmt.allocPrintSentinel(gpa, "__DATA$__common${s}", .{sym.getName(macho_file)}, 0); |
| 1566 | defer gpa.free(name); | 1568 | defer gpa.free(name); |
| 1567 | 1569 | ||
| 1568 | const alignment = (nlist.n_desc >> 8) & 0x0f; | 1570 | const alignment = (@as(u16, @bitCast(nlist.n_desc)) >> 8) & 0x0f; |
| 1569 | const n_sect = try self.addSection(gpa, "__DATA", "__common"); | 1571 | const n_sect = try self.addSection(gpa, "__DATA", "__common"); |
| 1570 | const atom_index = try self.addAtom(gpa, .{ | 1572 | const atom_index = try self.addAtom(gpa, .{ |
| 1571 | .name = try self.addString(gpa, name), | 1573 | .name = try self.addString(gpa, name), |
| ... | @@ -1589,9 +1591,9 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { | ... | @@ -1589,9 +1591,9 @@ pub fn convertTentativeDefinitions(self: *Object, macho_file: *MachO) !void { |
| 1589 | sym.visibility = .global; | 1591 | sym.visibility = .global; |
| 1590 | 1592 | ||
| 1591 | nlist.n_value = 0; | 1593 | nlist.n_value = 0; |
| 1592 | nlist.n_type = macho.N_EXT | macho.N_SECT; | 1594 | nlist.n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 1593 | nlist.n_sect = 0; | 1595 | nlist.n_sect = 0; |
| 1594 | nlist.n_desc = 0; | 1596 | nlist.n_desc = @bitCast(@as(u16, 0)); |
| 1595 | nlist_atom.* = atom_index; | 1597 | nlist_atom.* = atom_index; |
| 1596 | } | 1598 | } |
| 1597 | } | 1599 | } |
| ... | @@ -1685,7 +1687,7 @@ pub fn parseAr(self: *Object, macho_file: *MachO) !void { | ... | @@ -1685,7 +1687,7 @@ pub fn parseAr(self: *Object, macho_file: *MachO) !void { |
| 1685 | pub fn updateArSymtab(self: Object, ar_symtab: *Archive.ArSymtab, macho_file: *MachO) error{OutOfMemory}!void { | 1687 | pub fn updateArSymtab(self: Object, ar_symtab: *Archive.ArSymtab, macho_file: *MachO) error{OutOfMemory}!void { |
| 1686 | const gpa = macho_file.base.comp.gpa; | 1688 | const gpa = macho_file.base.comp.gpa; |
| 1687 | for (self.symtab.items(.nlist)) |nlist| { | 1689 | for (self.symtab.items(.nlist)) |nlist| { |
| 1688 | if (!nlist.ext() or (nlist.n_type.type == .undf and !nlist.tentative())) continue; | 1690 | if (!nlist.n_type.bits.ext or (nlist.n_type.bits.type == .undf and !nlist.tentative())) continue; |
| 1689 | const off = try ar_symtab.strtab.insert(gpa, self.getNStrx(nlist.n_strx)); | 1691 | const off = try ar_symtab.strtab.insert(gpa, self.getNStrx(nlist.n_strx)); |
| 1690 | try ar_symtab.entries.append(gpa, .{ .off = off, .file = self.index }); | 1692 | try ar_symtab.entries.append(gpa, .{ .off = off, .file = self.index }); |
| 1691 | } | 1693 | } |
| ... | @@ -2028,30 +2030,30 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2028,30 +2030,30 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2028 | ) void { | 2030 | ) void { |
| 2029 | context.symtab.items[index] = .{ | 2031 | context.symtab.items[index] = .{ |
| 2030 | .n_strx = 0, | 2032 | .n_strx = 0, |
| 2031 | .n_type = macho.N_BNSYM, | 2033 | .n_type = .{ .stab = .bnsym }, |
| 2032 | .n_sect = n_sect, | 2034 | .n_sect = n_sect, |
| 2033 | .n_desc = 0, | 2035 | .n_desc = @bitCast(@as(u16, 0)), |
| 2034 | .n_value = n_value, | 2036 | .n_value = n_value, |
| 2035 | }; | 2037 | }; |
| 2036 | context.symtab.items[index + 1] = .{ | 2038 | context.symtab.items[index + 1] = .{ |
| 2037 | .n_strx = n_strx, | 2039 | .n_strx = n_strx, |
| 2038 | .n_type = macho.N_FUN, | 2040 | .n_type = .{ .stab = .fun }, |
| 2039 | .n_sect = n_sect, | 2041 | .n_sect = n_sect, |
| 2040 | .n_desc = 0, | 2042 | .n_desc = @bitCast(@as(u16, 0)), |
| 2041 | .n_value = n_value, | 2043 | .n_value = n_value, |
| 2042 | }; | 2044 | }; |
| 2043 | context.symtab.items[index + 2] = .{ | 2045 | context.symtab.items[index + 2] = .{ |
| 2044 | .n_strx = 0, | 2046 | .n_strx = 0, |
| 2045 | .n_type = macho.N_FUN, | 2047 | .n_type = .{ .stab = .fun }, |
| 2046 | .n_sect = 0, | 2048 | .n_sect = 0, |
| 2047 | .n_desc = 0, | 2049 | .n_desc = @bitCast(@as(u16, 0)), |
| 2048 | .n_value = size, | 2050 | .n_value = size, |
| 2049 | }; | 2051 | }; |
| 2050 | context.symtab.items[index + 3] = .{ | 2052 | context.symtab.items[index + 3] = .{ |
| 2051 | .n_strx = 0, | 2053 | .n_strx = 0, |
| 2052 | .n_type = macho.N_ENSYM, | 2054 | .n_type = .{ .stab = .ensym }, |
| 2053 | .n_sect = n_sect, | 2055 | .n_sect = n_sect, |
| 2054 | .n_desc = 0, | 2056 | .n_desc = @bitCast(@as(u16, 0)), |
| 2055 | .n_value = size, | 2057 | .n_value = size, |
| 2056 | }; | 2058 | }; |
| 2057 | } | 2059 | } |
| ... | @@ -2068,9 +2070,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2068,9 +2070,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2068 | // N_SO comp_dir | 2070 | // N_SO comp_dir |
| 2069 | ctx.symtab.items[index] = .{ | 2071 | ctx.symtab.items[index] = .{ |
| 2070 | .n_strx = n_strx, | 2072 | .n_strx = n_strx, |
| 2071 | .n_type = macho.N_SO, | 2073 | .n_type = .{ .stab = .so }, |
| 2072 | .n_sect = 0, | 2074 | .n_sect = 0, |
| 2073 | .n_desc = 0, | 2075 | .n_desc = @bitCast(@as(u16, 0)), |
| 2074 | .n_value = 0, | 2076 | .n_value = 0, |
| 2075 | }; | 2077 | }; |
| 2076 | index += 1; | 2078 | index += 1; |
| ... | @@ -2081,9 +2083,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2081,9 +2083,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2081 | // N_SO tu_name | 2083 | // N_SO tu_name |
| 2082 | macho_file.symtab.items[index] = .{ | 2084 | macho_file.symtab.items[index] = .{ |
| 2083 | .n_strx = n_strx, | 2085 | .n_strx = n_strx, |
| 2084 | .n_type = macho.N_SO, | 2086 | .n_type = .{ .stab = .so }, |
| 2085 | .n_sect = 0, | 2087 | .n_sect = 0, |
| 2086 | .n_desc = 0, | 2088 | .n_desc = @bitCast(@as(u16, 0)), |
| 2087 | .n_value = 0, | 2089 | .n_value = 0, |
| 2088 | }; | 2090 | }; |
| 2089 | index += 1; | 2091 | index += 1; |
| ... | @@ -2094,9 +2096,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2094,9 +2096,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2094 | // N_OSO path | 2096 | // N_OSO path |
| 2095 | ctx.symtab.items[index] = .{ | 2097 | ctx.symtab.items[index] = .{ |
| 2096 | .n_strx = n_strx, | 2098 | .n_strx = n_strx, |
| 2097 | .n_type = macho.N_OSO, | 2099 | .n_type = .{ .stab = .oso }, |
| 2098 | .n_sect = 0, | 2100 | .n_sect = 0, |
| 2099 | .n_desc = 1, | 2101 | .n_desc = @bitCast(@as(u16, 1)), |
| 2100 | .n_value = self.mtime, | 2102 | .n_value = self.mtime, |
| 2101 | }; | 2103 | }; |
| 2102 | index += 1; | 2104 | index += 1; |
| ... | @@ -2159,18 +2161,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2159,18 +2161,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2159 | } else if (sym.visibility == .global) { | 2161 | } else if (sym.visibility == .global) { |
| 2160 | ctx.symtab.items[index] = .{ | 2162 | ctx.symtab.items[index] = .{ |
| 2161 | .n_strx = sym_n_strx, | 2163 | .n_strx = sym_n_strx, |
| 2162 | .n_type = macho.N_GSYM, | 2164 | .n_type = .{ .stab = .gsym }, |
| 2163 | .n_sect = sym_n_sect, | 2165 | .n_sect = sym_n_sect, |
| 2164 | .n_desc = 0, | 2166 | .n_desc = @bitCast(@as(u16, 0)), |
| 2165 | .n_value = 0, | 2167 | .n_value = 0, |
| 2166 | }; | 2168 | }; |
| 2167 | index += 1; | 2169 | index += 1; |
| 2168 | } else { | 2170 | } else { |
| 2169 | ctx.symtab.items[index] = .{ | 2171 | ctx.symtab.items[index] = .{ |
| 2170 | .n_strx = sym_n_strx, | 2172 | .n_strx = sym_n_strx, |
| 2171 | .n_type = macho.N_STSYM, | 2173 | .n_type = .{ .stab = .stsym }, |
| 2172 | .n_sect = sym_n_sect, | 2174 | .n_sect = sym_n_sect, |
| 2173 | .n_desc = 0, | 2175 | .n_desc = @bitCast(@as(u16, 0)), |
| 2174 | .n_value = sym_n_value, | 2176 | .n_value = sym_n_value, |
| 2175 | }; | 2177 | }; |
| 2176 | index += 1; | 2178 | index += 1; |
| ... | @@ -2181,9 +2183,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2181,9 +2183,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2181 | // N_SO | 2183 | // N_SO |
| 2182 | ctx.symtab.items[index] = .{ | 2184 | ctx.symtab.items[index] = .{ |
| 2183 | .n_strx = 0, | 2185 | .n_strx = 0, |
| 2184 | .n_type = macho.N_SO, | 2186 | .n_type = .{ .stab = .so }, |
| 2185 | .n_sect = 0, | 2187 | .n_sect = 0, |
| 2186 | .n_desc = 0, | 2188 | .n_desc = @bitCast(@as(u16, 0)), |
| 2187 | .n_value = 0, | 2189 | .n_value = 0, |
| 2188 | }; | 2190 | }; |
| 2189 | } else { | 2191 | } else { |
| ... | @@ -2198,9 +2200,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2198,9 +2200,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2198 | // N_SO comp_dir | 2200 | // N_SO comp_dir |
| 2199 | ctx.symtab.items[index] = .{ | 2201 | ctx.symtab.items[index] = .{ |
| 2200 | .n_strx = n_strx, | 2202 | .n_strx = n_strx, |
| 2201 | .n_type = macho.N_SO, | 2203 | .n_type = .{ .stab = .so }, |
| 2202 | .n_sect = 0, | 2204 | .n_sect = 0, |
| 2203 | .n_desc = 0, | 2205 | .n_desc = @bitCast(@as(u16, 0)), |
| 2204 | .n_value = 0, | 2206 | .n_value = 0, |
| 2205 | }; | 2207 | }; |
| 2206 | index += 1; | 2208 | index += 1; |
| ... | @@ -2211,9 +2213,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2211,9 +2213,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2211 | // N_SO tu_name | 2213 | // N_SO tu_name |
| 2212 | ctx.symtab.items[index] = .{ | 2214 | ctx.symtab.items[index] = .{ |
| 2213 | .n_strx = n_strx, | 2215 | .n_strx = n_strx, |
| 2214 | .n_type = macho.N_SO, | 2216 | .n_type = .{ .stab = .so }, |
| 2215 | .n_sect = 0, | 2217 | .n_sect = 0, |
| 2216 | .n_desc = 0, | 2218 | .n_desc = @bitCast(@as(u16, 0)), |
| 2217 | .n_value = 0, | 2219 | .n_value = 0, |
| 2218 | }; | 2220 | }; |
| 2219 | index += 1; | 2221 | index += 1; |
| ... | @@ -2224,9 +2226,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2224,9 +2226,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2224 | // N_OSO path | 2226 | // N_OSO path |
| 2225 | ctx.symtab.items[index] = .{ | 2227 | ctx.symtab.items[index] = .{ |
| 2226 | .n_strx = n_strx, | 2228 | .n_strx = n_strx, |
| 2227 | .n_type = macho.N_OSO, | 2229 | .n_type = .{ .stab = .so }, |
| 2228 | .n_sect = 0, | 2230 | .n_sect = 0, |
| 2229 | .n_desc = 1, | 2231 | .n_desc = @bitCast(@as(u16, 1)), |
| 2230 | .n_value = sf.getOsoModTime(self), | 2232 | .n_value = sf.getOsoModTime(self), |
| 2231 | }; | 2233 | }; |
| 2232 | index += 1; | 2234 | index += 1; |
| ... | @@ -2254,18 +2256,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2254,18 +2256,18 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2254 | } else if (sym.visibility == .global) { | 2256 | } else if (sym.visibility == .global) { |
| 2255 | ctx.symtab.items[index] = .{ | 2257 | ctx.symtab.items[index] = .{ |
| 2256 | .n_strx = sym_n_strx, | 2258 | .n_strx = sym_n_strx, |
| 2257 | .n_type = macho.N_GSYM, | 2259 | .n_type = .{ .stab = .gsym }, |
| 2258 | .n_sect = sym_n_sect, | 2260 | .n_sect = sym_n_sect, |
| 2259 | .n_desc = 0, | 2261 | .n_desc = @bitCast(@as(u16, 0)), |
| 2260 | .n_value = 0, | 2262 | .n_value = 0, |
| 2261 | }; | 2263 | }; |
| 2262 | index += 1; | 2264 | index += 1; |
| 2263 | } else { | 2265 | } else { |
| 2264 | ctx.symtab.items[index] = .{ | 2266 | ctx.symtab.items[index] = .{ |
| 2265 | .n_strx = sym_n_strx, | 2267 | .n_strx = sym_n_strx, |
| 2266 | .n_type = macho.N_STSYM, | 2268 | .n_type = .{ .stab = .stsym }, |
| 2267 | .n_sect = sym_n_sect, | 2269 | .n_sect = sym_n_sect, |
| 2268 | .n_desc = 0, | 2270 | .n_desc = @bitCast(@as(u16, 0)), |
| 2269 | .n_value = sym_n_value, | 2271 | .n_value = sym_n_value, |
| 2270 | }; | 2272 | }; |
| 2271 | index += 1; | 2273 | index += 1; |
| ... | @@ -2276,9 +2278,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v | ... | @@ -2276,9 +2278,9 @@ pub fn writeStabs(self: Object, stroff: u32, macho_file: *MachO, ctx: anytype) v |
| 2276 | // N_SO | 2278 | // N_SO |
| 2277 | ctx.symtab.items[index] = .{ | 2279 | ctx.symtab.items[index] = .{ |
| 2278 | .n_strx = 0, | 2280 | .n_strx = 0, |
| 2279 | .n_type = macho.N_SO, | 2281 | .n_type = .{ .stab = .so }, |
| 2280 | .n_sect = 0, | 2282 | .n_sect = 0, |
| 2281 | .n_desc = 0, | 2283 | .n_desc = @bitCast(@as(u16, 0)), |
| 2282 | .n_value = 0, | 2284 | .n_value = 0, |
| 2283 | }; | 2285 | }; |
| 2284 | index += 1; | 2286 | index += 1; |
src/link/MachO/Symbol.zig+28-14| ... | @@ -36,7 +36,7 @@ pub fn isLocal(symbol: Symbol) bool { | ... | @@ -36,7 +36,7 @@ pub fn isLocal(symbol: Symbol) bool { |
| 36 | pub fn isSymbolStab(symbol: Symbol, macho_file: *MachO) bool { | 36 | pub fn isSymbolStab(symbol: Symbol, macho_file: *MachO) bool { |
| 37 | const file = symbol.getFile(macho_file) orelse return false; | 37 | const file = symbol.getFile(macho_file) orelse return false; |
| 38 | return switch (file) { | 38 | return switch (file) { |
| 39 | .object => symbol.getNlist(macho_file).stab(), | 39 | .object => symbol.getNlist(macho_file).n_type.bits.is_stab != 0, |
| 40 | else => false, | 40 | else => false, |
| 41 | }; | 41 | }; |
| 42 | } | 42 | } |
| ... | @@ -233,35 +233,49 @@ pub inline fn setExtra(symbol: Symbol, extra: Extra, macho_file: *MachO) void { | ... | @@ -233,35 +233,49 @@ pub inline fn setExtra(symbol: Symbol, extra: Extra, macho_file: *MachO) void { |
| 233 | 233 | ||
| 234 | pub fn setOutputSym(symbol: Symbol, macho_file: *MachO, out: *macho.nlist_64) void { | 234 | pub fn setOutputSym(symbol: Symbol, macho_file: *MachO, out: *macho.nlist_64) void { |
| 235 | if (symbol.isLocal()) { | 235 | if (symbol.isLocal()) { |
| 236 | out.n_type = if (symbol.flags.abs) macho.N_ABS else macho.N_SECT; | 236 | out.n_type = .{ .bits = .{ |
| 237 | .ext = false, | ||
| 238 | .type = if (symbol.flags.abs) .abs else .sect, | ||
| 239 | .pext = false, | ||
| 240 | .is_stab = 0, | ||
| 241 | } }; | ||
| 237 | out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); | 242 | out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); |
| 238 | out.n_desc = 0; | 243 | out.n_desc = @bitCast(@as(u16, 0)); |
| 239 | out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); | 244 | out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); |
| 240 | 245 | ||
| 241 | switch (symbol.visibility) { | 246 | switch (symbol.visibility) { |
| 242 | .hidden => out.n_type |= macho.N_PEXT, | 247 | .hidden => out.n_type.bits.pext = true, |
| 243 | else => {}, | 248 | else => {}, |
| 244 | } | 249 | } |
| 245 | } else if (symbol.flags.@"export") { | 250 | } else if (symbol.flags.@"export") { |
| 246 | assert(symbol.visibility == .global); | 251 | assert(symbol.visibility == .global); |
| 247 | out.n_type = macho.N_EXT; | 252 | out.n_type = .{ .bits = .{ |
| 248 | out.n_type |= if (symbol.flags.abs) macho.N_ABS else macho.N_SECT; | 253 | .ext = true, |
| 254 | .type = if (symbol.flags.abs) .abs else .sect, | ||
| 255 | .pext = false, | ||
| 256 | .is_stab = 0, | ||
| 257 | } }; | ||
| 249 | out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); | 258 | out.n_sect = if (symbol.flags.abs) 0 else @intCast(symbol.getOutputSectionIndex(macho_file) + 1); |
| 250 | out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); | 259 | out.n_value = symbol.getAddress(.{ .stubs = false }, macho_file); |
| 251 | out.n_desc = 0; | 260 | out.n_desc = @bitCast(@as(u16, 0)); |
| 252 | 261 | ||
| 253 | if (symbol.flags.weak) { | 262 | if (symbol.flags.weak) { |
| 254 | out.n_desc |= macho.N_WEAK_DEF; | 263 | out.n_desc.weak_def_or_ref_to_weak = true; |
| 255 | } | 264 | } |
| 256 | if (symbol.flags.dyn_ref) { | 265 | if (symbol.flags.dyn_ref) { |
| 257 | out.n_desc |= macho.REFERENCED_DYNAMICALLY; | 266 | out.n_desc.referenced_dynamically = true; |
| 258 | } | 267 | } |
| 259 | } else { | 268 | } else { |
| 260 | assert(symbol.visibility == .global); | 269 | assert(symbol.visibility == .global); |
| 261 | out.n_type = macho.N_EXT; | 270 | out.n_type = .{ .bits = .{ |
| 271 | .ext = true, | ||
| 272 | .type = .undf, | ||
| 273 | .pext = false, | ||
| 274 | .is_stab = 0, | ||
| 275 | } }; | ||
| 262 | out.n_sect = 0; | 276 | out.n_sect = 0; |
| 263 | out.n_value = 0; | 277 | out.n_value = 0; |
| 264 | out.n_desc = 0; | 278 | out.n_desc = @bitCast(@as(u16, 0)); |
| 265 | 279 | ||
| 266 | // TODO: | 280 | // TODO: |
| 267 | // const ord: u16 = if (macho_file.options.namespace == .flat) | 281 | // 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 | ... | @@ -274,14 +288,14 @@ pub fn setOutputSym(symbol: Symbol, macho_file: *MachO, out: *macho.nlist_64) vo |
| 274 | ord | 288 | ord |
| 275 | else | 289 | else |
| 276 | macho.BIND_SPECIAL_DYLIB_SELF; | 290 | macho.BIND_SPECIAL_DYLIB_SELF; |
| 277 | out.n_desc = macho.N_SYMBOL_RESOLVER * ord; | 291 | out.n_desc = @bitCast(macho.N_SYMBOL_RESOLVER * ord); |
| 278 | 292 | ||
| 279 | if (symbol.flags.weak) { | 293 | if (symbol.flags.weak) { |
| 280 | out.n_desc |= macho.N_WEAK_DEF; | 294 | out.n_desc.weak_def_or_ref_to_weak = true; |
| 281 | } | 295 | } |
| 282 | 296 | ||
| 283 | if (symbol.weakRef(macho_file)) { | 297 | if (symbol.weakRef(macho_file)) { |
| 284 | out.n_desc |= macho.N_WEAK_REF; | 298 | out.n_desc.weak_ref = true; |
| 285 | } | 299 | } |
| 286 | } | 300 | } |
| 287 | } | 301 | } |
src/link/MachO/Thunk.zig+2-2| ... | @@ -56,10 +56,10 @@ pub fn writeSymtab(thunk: Thunk, macho_file: *MachO, ctx: anytype) void { | ... | @@ -56,10 +56,10 @@ pub fn writeSymtab(thunk: Thunk, macho_file: *MachO, ctx: anytype) void { |
| 56 | n_strx += @intCast("__thunk".len); | 56 | n_strx += @intCast("__thunk".len); |
| 57 | ctx.strtab.items[n_strx] = 0; | 57 | ctx.strtab.items[n_strx] = 0; |
| 58 | n_strx += 1; | 58 | n_strx += 1; |
| 59 | out_sym.n_type = macho.N_SECT; | 59 | out_sym.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 60 | out_sym.n_sect = @intCast(thunk.out_n_sect + 1); | 60 | out_sym.n_sect = @intCast(thunk.out_n_sect + 1); |
| 61 | out_sym.n_value = @intCast(thunk.getTargetAddress(ref, macho_file)); | 61 | out_sym.n_value = @intCast(thunk.getTargetAddress(ref, macho_file)); |
| 62 | out_sym.n_desc = 0; | 62 | out_sym.n_desc = @bitCast(@as(u16, 0)); |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 |
src/link/MachO/ZigObject.zig+16-16| ... | @@ -123,9 +123,9 @@ fn newSymbol(self: *ZigObject, allocator: Allocator, name: MachO.String, args: s | ... | @@ -123,9 +123,9 @@ fn newSymbol(self: *ZigObject, allocator: Allocator, name: MachO.String, args: s |
| 123 | self.symtab.set(nlist_idx, .{ | 123 | self.symtab.set(nlist_idx, .{ |
| 124 | .nlist = .{ | 124 | .nlist = .{ |
| 125 | .n_strx = name.pos, | 125 | .n_strx = name.pos, |
| 126 | .n_type = args.type, | 126 | .n_type = @bitCast(args.type), |
| 127 | .n_sect = 0, | 127 | .n_sect = 0, |
| 128 | .n_desc = args.desc, | 128 | .n_desc = @bitCast(args.desc), |
| 129 | .n_value = 0, | 129 | .n_value = 0, |
| 130 | }, | 130 | }, |
| 131 | .size = 0, | 131 | .size = 0, |
| ... | @@ -206,8 +206,8 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { | ... | @@ -206,8 +206,8 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { |
| 206 | const gpa = macho_file.base.comp.gpa; | 206 | const gpa = macho_file.base.comp.gpa; |
| 207 | 207 | ||
| 208 | for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { | 208 | for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { |
| 209 | if (!nlist.ext()) continue; | 209 | if (!nlist.n_type.bits.ext) continue; |
| 210 | if (nlist.sect()) { | 210 | if (nlist.n_type.bits.type == .sect) { |
| 211 | const atom = self.getAtom(atom_index).?; | 211 | const atom = self.getAtom(atom_index).?; |
| 212 | if (!atom.isAlive()) continue; | 212 | if (!atom.isAlive()) continue; |
| 213 | } | 213 | } |
| ... | @@ -221,7 +221,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { | ... | @@ -221,7 +221,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { |
| 221 | } | 221 | } |
| 222 | global.* = gop.index; | 222 | global.* = gop.index; |
| 223 | 223 | ||
| 224 | if (nlist.undf() and !nlist.tentative()) continue; | 224 | if (nlist.n_type.bits.type == .undf and !nlist.tentative()) continue; |
| 225 | if (gop.ref.getFile(macho_file) == null) { | 225 | if (gop.ref.getFile(macho_file) == null) { |
| 226 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; | 226 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| 227 | continue; | 227 | continue; |
| ... | @@ -229,7 +229,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { | ... | @@ -229,7 +229,7 @@ pub fn resolveSymbols(self: *ZigObject, macho_file: *MachO) !void { |
| 229 | 229 | ||
| 230 | if (self.asFile().getSymbolRank(.{ | 230 | if (self.asFile().getSymbolRank(.{ |
| 231 | .archive = false, | 231 | .archive = false, |
| 232 | .weak = nlist.weakDef(), | 232 | .weak = nlist.n_desc.weak_def_or_ref_to_weak, |
| 233 | .tentative = nlist.tentative(), | 233 | .tentative = nlist.tentative(), |
| 234 | }) < gop.ref.getSymbol(macho_file).?.getSymbolRank(macho_file)) { | 234 | }) < gop.ref.getSymbol(macho_file).?.getSymbolRank(macho_file)) { |
| 235 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; | 235 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| ... | @@ -243,12 +243,12 @@ pub fn markLive(self: *ZigObject, macho_file: *MachO) void { | ... | @@ -243,12 +243,12 @@ pub fn markLive(self: *ZigObject, macho_file: *MachO) void { |
| 243 | 243 | ||
| 244 | for (0..self.symbols.items.len) |i| { | 244 | for (0..self.symbols.items.len) |i| { |
| 245 | const nlist = self.symtab.items(.nlist)[i]; | 245 | const nlist = self.symtab.items(.nlist)[i]; |
| 246 | if (!nlist.ext()) continue; | 246 | if (!nlist.n_type.bits.ext) continue; |
| 247 | 247 | ||
| 248 | const ref = self.getSymbolRef(@intCast(i), macho_file); | 248 | const ref = self.getSymbolRef(@intCast(i), macho_file); |
| 249 | const file = ref.getFile(macho_file) orelse continue; | 249 | const file = ref.getFile(macho_file) orelse continue; |
| 250 | const sym = ref.getSymbol(macho_file).?; | 250 | const sym = ref.getSymbol(macho_file).?; |
| 251 | const should_keep = nlist.undf() or (nlist.tentative() and !sym.flags.tentative); | 251 | const should_keep = nlist.n_type.bits.type == .undf or (nlist.tentative() and !sym.flags.tentative); |
| 252 | if (should_keep and file == .object and !file.object.alive) { | 252 | if (should_keep and file == .object and !file.object.alive) { |
| 253 | file.object.alive = true; | 253 | file.object.alive = true; |
| 254 | file.object.markLive(macho_file); | 254 | file.object.markLive(macho_file); |
| ... | @@ -331,8 +331,8 @@ pub fn claimUnresolved(self: *ZigObject, macho_file: *MachO) void { | ... | @@ -331,8 +331,8 @@ pub fn claimUnresolved(self: *ZigObject, macho_file: *MachO) void { |
| 331 | 331 | ||
| 332 | for (self.symbols.items, 0..) |*sym, i| { | 332 | for (self.symbols.items, 0..) |*sym, i| { |
| 333 | const nlist = self.symtab.items(.nlist)[i]; | 333 | const nlist = self.symtab.items(.nlist)[i]; |
| 334 | if (!nlist.ext()) continue; | 334 | if (!nlist.n_type.bits.ext) continue; |
| 335 | if (!nlist.undf()) continue; | 335 | if (nlist.n_type.bits.type != .undf) continue; |
| 336 | 336 | ||
| 337 | if (self.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; | 337 | if (self.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; |
| 338 | 338 | ||
| ... | @@ -974,7 +974,7 @@ fn updateNavCode( | ... | @@ -974,7 +974,7 @@ fn updateNavCode( |
| 974 | atom.setAlive(true); | 974 | atom.setAlive(true); |
| 975 | atom.name = sym.name; | 975 | atom.name = sym.name; |
| 976 | nlist.n_strx = sym.name.pos; | 976 | nlist.n_strx = sym.name.pos; |
| 977 | nlist.n_type = macho.N_SECT; | 977 | nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 978 | nlist.n_sect = sect_index + 1; | 978 | nlist.n_sect = sect_index + 1; |
| 979 | self.symtab.items(.size)[sym.nlist_idx] = code.len; | 979 | self.symtab.items(.size)[sym.nlist_idx] = code.len; |
| 980 | 980 | ||
| ... | @@ -1115,7 +1115,7 @@ fn createTlvDescriptor( | ... | @@ -1115,7 +1115,7 @@ fn createTlvDescriptor( |
| 1115 | atom.name = sym.name; | 1115 | atom.name = sym.name; |
| 1116 | nlist.n_strx = sym.name.pos; | 1116 | nlist.n_strx = sym.name.pos; |
| 1117 | nlist.n_sect = sect_index + 1; | 1117 | nlist.n_sect = sect_index + 1; |
| 1118 | nlist.n_type = macho.N_SECT; | 1118 | nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 1119 | nlist.n_value = 0; | 1119 | nlist.n_value = 0; |
| 1120 | self.symtab.items(.size)[sym.nlist_idx] = size; | 1120 | self.symtab.items(.size)[sym.nlist_idx] = size; |
| 1121 | 1121 | ||
| ... | @@ -1322,7 +1322,7 @@ pub fn updateExports( | ... | @@ -1322,7 +1322,7 @@ pub fn updateExports( |
| 1322 | const global_sym = &self.symbols.items[global_nlist_index]; | 1322 | const global_sym = &self.symbols.items[global_nlist_index]; |
| 1323 | global_nlist.n_value = nlist.n_value; | 1323 | global_nlist.n_value = nlist.n_value; |
| 1324 | global_nlist.n_sect = nlist.n_sect; | 1324 | global_nlist.n_sect = nlist.n_sect; |
| 1325 | global_nlist.n_type = macho.N_EXT | macho.N_SECT; | 1325 | global_nlist.n_type = .{ .bits = .{ .ext = true, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 1326 | self.symtab.items(.size)[global_nlist_index] = self.symtab.items(.size)[nlist_idx]; | 1326 | self.symtab.items(.size)[global_nlist_index] = self.symtab.items(.size)[nlist_idx]; |
| 1327 | self.symtab.items(.atom)[global_nlist_index] = atom_index; | 1327 | self.symtab.items(.atom)[global_nlist_index] = atom_index; |
| 1328 | global_sym.atom_ref = .{ .index = atom_index, .file = self.index }; | 1328 | global_sym.atom_ref = .{ .index = atom_index, .file = self.index }; |
| ... | @@ -1330,7 +1330,7 @@ pub fn updateExports( | ... | @@ -1330,7 +1330,7 @@ pub fn updateExports( |
| 1330 | switch (exp.opts.linkage) { | 1330 | switch (exp.opts.linkage) { |
| 1331 | .internal => { | 1331 | .internal => { |
| 1332 | // Symbol should be hidden, or in MachO lingo, private extern. | 1332 | // Symbol should be hidden, or in MachO lingo, private extern. |
| 1333 | global_nlist.n_type |= macho.N_PEXT; | 1333 | global_nlist.n_type.bits.pext = true; |
| 1334 | global_sym.visibility = .hidden; | 1334 | global_sym.visibility = .hidden; |
| 1335 | }, | 1335 | }, |
| 1336 | .strong => { | 1336 | .strong => { |
| ... | @@ -1339,7 +1339,7 @@ pub fn updateExports( | ... | @@ -1339,7 +1339,7 @@ pub fn updateExports( |
| 1339 | .weak => { | 1339 | .weak => { |
| 1340 | // Weak linkage is specified as part of n_desc field. | 1340 | // Weak linkage is specified as part of n_desc field. |
| 1341 | // Symbol's n_type is like for a symbol with strong linkage. | 1341 | // Symbol's n_type is like for a symbol with strong linkage. |
| 1342 | global_nlist.n_desc |= macho.N_WEAK_DEF; | 1342 | global_nlist.n_desc.weak_def_or_ref_to_weak = true; |
| 1343 | global_sym.visibility = .global; | 1343 | global_sym.visibility = .global; |
| 1344 | global_sym.flags.weak = true; | 1344 | global_sym.flags.weak = true; |
| 1345 | }, | 1345 | }, |
| ... | @@ -1394,7 +1394,7 @@ fn updateLazySymbol( | ... | @@ -1394,7 +1394,7 @@ fn updateLazySymbol( |
| 1394 | 1394 | ||
| 1395 | const nlist = &self.symtab.items(.nlist)[sym.nlist_idx]; | 1395 | const nlist = &self.symtab.items(.nlist)[sym.nlist_idx]; |
| 1396 | nlist.n_strx = name_str.pos; | 1396 | nlist.n_strx = name_str.pos; |
| 1397 | nlist.n_type = macho.N_SECT; | 1397 | nlist.n_type = .{ .bits = .{ .ext = false, .type = .sect, .pext = false, .is_stab = 0 } }; |
| 1398 | nlist.n_sect = output_section_index + 1; | 1398 | nlist.n_sect = output_section_index + 1; |
| 1399 | self.symtab.items(.size)[sym.nlist_idx] = code.len; | 1399 | self.symtab.items(.size)[sym.nlist_idx] = code.len; |
| 1400 | 1400 |
src/link/MachO/eh_frame.zig+10-10| ... | @@ -26,24 +26,24 @@ pub const Cie = struct { | ... | @@ -26,24 +26,24 @@ pub const Cie = struct { |
| 26 | 26 | ||
| 27 | for (aug[1..]) |ch| switch (ch) { | 27 | for (aug[1..]) |ch| switch (ch) { |
| 28 | 'R' => { | 28 | 'R' => { |
| 29 | const enc = try reader.takeByte(); | 29 | const enc: DW.EH.PE = @bitCast(try reader.takeByte()); |
| 30 | if (enc != DW_EH_PE.pcrel | DW_EH_PE.absptr) { | 30 | if (enc != @as(DW.EH.PE, .{ .type = .absptr, .rel = .pcrel })) { |
| 31 | @panic("unexpected pointer encoding"); // TODO error | 31 | @panic("unexpected pointer encoding"); // TODO error |
| 32 | } | 32 | } |
| 33 | }, | 33 | }, |
| 34 | 'P' => { | 34 | 'P' => { |
| 35 | const enc = try reader.takeByte(); | 35 | const enc: DW.EH.PE = @bitCast(try reader.takeByte()); |
| 36 | if (enc != DW_EH_PE.pcrel | DW_EH_PE.indirect | DW_EH_PE.sdata4) { | 36 | if (enc != @as(DW.EH.PE, .{ .type = .sdata4, .rel = .pcrel, .indirect = true })) { |
| 37 | @panic("unexpected personality pointer encoding"); // TODO error | 37 | @panic("unexpected personality pointer encoding"); // TODO error |
| 38 | } | 38 | } |
| 39 | _ = try reader.takeInt(u32, .little); // personality pointer | 39 | _ = try reader.takeInt(u32, .little); // personality pointer |
| 40 | }, | 40 | }, |
| 41 | 'L' => { | 41 | 'L' => { |
| 42 | const enc = try reader.takeByte(); | 42 | const enc: DW.EH.PE = @bitCast(try reader.takeByte()); |
| 43 | switch (enc & DW_EH_PE.type_mask) { | 43 | switch (enc.type) { |
| 44 | DW_EH_PE.sdata4 => cie.lsda_size = .p32, | 44 | .sdata4 => cie.lsda_size = .p32, |
| 45 | DW_EH_PE.absptr => cie.lsda_size = .p64, | 45 | .absptr => cie.lsda_size = .p64, |
| 46 | else => unreachable, // TODO error | 46 | else => @panic("unexpected lsda encoding"), // TODO error |
| 47 | } | 47 | } |
| 48 | }, | 48 | }, |
| 49 | else => @panic("unexpected augmentation string"), // TODO error | 49 | else => @panic("unexpected augmentation string"), // TODO error |
| ... | @@ -505,7 +505,7 @@ const Writer = std.Io.Writer; | ... | @@ -505,7 +505,7 @@ const Writer = std.Io.Writer; |
| 505 | 505 | ||
| 506 | const Allocator = std.mem.Allocator; | 506 | const Allocator = std.mem.Allocator; |
| 507 | const Atom = @import("Atom.zig"); | 507 | const Atom = @import("Atom.zig"); |
| 508 | const DW_EH_PE = std.dwarf.EH.PE; | 508 | const DW = std.dwarf; |
| 509 | const File = @import("file.zig").File; | 509 | const File = @import("file.zig").File; |
| 510 | const MachO = @import("../MachO.zig"); | 510 | const MachO = @import("../MachO.zig"); |
| 511 | const Object = @import("Object.zig"); | 511 | const Object = @import("Object.zig"); |
src/link/MachO/file.zig+8-8| ... | @@ -192,21 +192,21 @@ pub const File = union(enum) { | ... | @@ -192,21 +192,21 @@ pub const File = union(enum) { |
| 192 | assert(file == .object or file == .zig_object); | 192 | assert(file == .object or file == .zig_object); |
| 193 | 193 | ||
| 194 | for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { | 194 | for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { |
| 195 | if (!nlist.ext()) continue; | 195 | if (!nlist.n_type.bits.ext) continue; |
| 196 | if (!nlist.undf()) continue; | 196 | if (nlist.n_type.bits.type != .undf) continue; |
| 197 | 197 | ||
| 198 | if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; | 198 | if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; |
| 199 | 199 | ||
| 200 | const is_import = switch (macho_file.undefined_treatment) { | 200 | const is_import = switch (macho_file.undefined_treatment) { |
| 201 | .@"error" => false, | 201 | .@"error" => false, |
| 202 | .warn, .suppress => nlist.weakRef(), | 202 | .warn, .suppress => nlist.n_desc.weak_ref, |
| 203 | .dynamic_lookup => true, | 203 | .dynamic_lookup => true, |
| 204 | }; | 204 | }; |
| 205 | if (is_import) { | 205 | if (is_import) { |
| 206 | sym.value = 0; | 206 | sym.value = 0; |
| 207 | sym.atom_ref = .{ .index = 0, .file = 0 }; | 207 | sym.atom_ref = .{ .index = 0, .file = 0 }; |
| 208 | sym.flags.weak = false; | 208 | sym.flags.weak = false; |
| 209 | sym.flags.weak_ref = nlist.weakRef(); | 209 | sym.flags.weak_ref = nlist.n_desc.weak_ref; |
| 210 | sym.flags.import = is_import; | 210 | sym.flags.import = is_import; |
| 211 | sym.visibility = .global; | 211 | sym.visibility = .global; |
| 212 | 212 | ||
| ... | @@ -223,13 +223,13 @@ pub const File = union(enum) { | ... | @@ -223,13 +223,13 @@ pub const File = union(enum) { |
| 223 | assert(file == .object or file == .zig_object); | 223 | assert(file == .object or file == .zig_object); |
| 224 | 224 | ||
| 225 | for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { | 225 | for (file.getSymbols(), file.getNlists(), 0..) |*sym, nlist, i| { |
| 226 | if (!nlist.ext()) continue; | 226 | if (!nlist.n_type.bits.ext) continue; |
| 227 | if (!nlist.undf()) continue; | 227 | if (nlist.n_type.bits.type != .undf) continue; |
| 228 | if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; | 228 | if (file.getSymbolRef(@intCast(i), macho_file).getFile(macho_file) != null) continue; |
| 229 | 229 | ||
| 230 | sym.value = 0; | 230 | sym.value = 0; |
| 231 | sym.atom_ref = .{ .index = 0, .file = 0 }; | 231 | sym.atom_ref = .{ .index = 0, .file = 0 }; |
| 232 | sym.flags.weak_ref = nlist.weakRef(); | 232 | sym.flags.weak_ref = nlist.n_desc.weak_ref; |
| 233 | sym.flags.import = true; | 233 | sym.flags.import = true; |
| 234 | sym.visibility = .global; | 234 | sym.visibility = .global; |
| 235 | 235 | ||
| ... | @@ -247,7 +247,7 @@ pub const File = union(enum) { | ... | @@ -247,7 +247,7 @@ pub const File = union(enum) { |
| 247 | for (file.getSymbols(), file.getNlists(), 0..) |sym, nlist, i| { | 247 | for (file.getSymbols(), file.getNlists(), 0..) |sym, nlist, i| { |
| 248 | if (sym.visibility != .global) continue; | 248 | if (sym.visibility != .global) continue; |
| 249 | if (sym.flags.weak) continue; | 249 | if (sym.flags.weak) continue; |
| 250 | if (nlist.undf()) continue; | 250 | if (nlist.n_type.bits.type == .undf) continue; |
| 251 | const ref = file.getSymbolRef(@intCast(i), macho_file); | 251 | const ref = file.getSymbolRef(@intCast(i), macho_file); |
| 252 | const ref_file = ref.getFile(macho_file) orelse continue; | 252 | const ref_file = ref.getFile(macho_file) orelse continue; |
| 253 | if (ref_file.getIndex() == file.getIndex()) continue; | 253 | if (ref_file.getIndex() == file.getIndex()) continue; |