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