| ... | ... | @@ -2940,12 +2940,6 @@ fn createTentativeDefAtoms(self: *MachO) !void { |
| 2940 | 2940 | |
| 2941 | 2941 | if (global.file) |file| { |
| 2942 | 2942 | const object = &self.objects.items[file]; |
| 2943 | | |
| 2944 | | try atom.contained.append(gpa, .{ |
| 2945 | | .sym_index = global.sym_index, |
| 2946 | | .offset = 0, |
| 2947 | | }); |
| 2948 | | |
| 2949 | 2943 | try object.managed_atoms.append(gpa, atom); |
| 2950 | 2944 | try object.atom_by_index_table.putNoClobber(gpa, global.sym_index, atom); |
| 2951 | 2945 | } else { |
| ... | ... | @@ -5594,6 +5588,7 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void { |
| 5594 | 5588 | |
| 5595 | 5589 | const global = atom.getSymbolWithLoc(); |
| 5596 | 5590 | const sym = atom.getSymbolPtr(self); |
| 5591 | const match = self.getMatchingSectionFromOrdinal(sym.n_sect); |
| 5597 | 5592 | |
| 5598 | 5593 | if (sym.n_desc == N_DESC_GCED) continue; |
| 5599 | 5594 | if (!sym.ext()) { |
| ... | ... | @@ -5605,15 +5600,6 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void { |
| 5605 | 5600 | } else continue; |
| 5606 | 5601 | } |
| 5607 | 5602 | |
| 5608 | | loop = true; |
| 5609 | | const match = self.getMatchingSectionFromOrdinal(sym.n_sect); |
| 5610 | | |
| 5611 | | // TODO don't dedup eh_frame info yet until we actually implement parsing unwind records |
| 5612 | | if (match.eql(.{ |
| 5613 | | .seg = self.text_segment_cmd_index, |
| 5614 | | .sect = self.eh_frame_section_index, |
| 5615 | | })) continue; |
| 5616 | | |
| 5617 | 5603 | self.logAtom(atom); |
| 5618 | 5604 | sym.n_desc = N_DESC_GCED; |
| 5619 | 5605 | self.removeAtomFromSection(atom, match); |
| ... | ... | @@ -5644,6 +5630,8 @@ fn gcAtoms(self: *MachO, gc_roots: *std.AutoHashMap(*Atom, void)) !void { |
| 5644 | 5630 | const tlv_ptr_sym = tlv_ptr_atom.getSymbolPtr(self); |
| 5645 | 5631 | tlv_ptr_sym.n_desc = N_DESC_GCED; |
| 5646 | 5632 | } |
| 5633 | |
| 5634 | loop = true; |
| 5647 | 5635 | } |
| 5648 | 5636 | } |
| 5649 | 5637 | } |
| ... | ... | @@ -6831,7 +6819,6 @@ pub fn generateSymbolStabs( |
| 6831 | 6819 | }; |
| 6832 | 6820 | const tu_name = try compile_unit.die.getAttrString(&debug_info.inner, dwarf.AT.name); |
| 6833 | 6821 | const tu_comp_dir = try compile_unit.die.getAttrString(&debug_info.inner, dwarf.AT.comp_dir); |
| 6834 | | const source_symtab = object.getSourceSymtab(); |
| 6835 | 6822 | |
| 6836 | 6823 | // Open scope |
| 6837 | 6824 | try locals.ensureUnusedCapacity(3); |
| ... | ... | @@ -6857,71 +6844,27 @@ pub fn generateSymbolStabs( |
| 6857 | 6844 | .n_value = object.mtime, |
| 6858 | 6845 | }); |
| 6859 | 6846 | |
| 6847 | var stabs_buf: [4]macho.nlist_64 = undefined; |
| 6848 | |
| 6860 | 6849 | for (object.managed_atoms.items) |atom| { |
| 6850 | const stabs = try self.generateSymbolStabsForSymbol( |
| 6851 | atom.getSymbolWithLoc(), |
| 6852 | debug_info, |
| 6853 | &stabs_buf, |
| 6854 | ); |
| 6855 | try locals.appendSlice(stabs); |
| 6856 | |
| 6861 | 6857 | for (atom.contained.items) |sym_at_off| { |
| 6862 | 6858 | const sym_loc = SymbolWithLoc{ |
| 6863 | 6859 | .sym_index = sym_at_off.sym_index, |
| 6864 | 6860 | .file = atom.file, |
| 6865 | 6861 | }; |
| 6866 | | const sym = self.getSymbol(sym_loc); |
| 6867 | | const sym_name = self.getSymbolName(sym_loc); |
| 6868 | | if (sym.n_strx == 0) continue; |
| 6869 | | if (sym.n_desc == N_DESC_GCED) continue; |
| 6870 | | if (self.symbolIsTemp(sym_loc)) continue; |
| 6871 | | if (sym_at_off.sym_index >= source_symtab.len) continue; // synthetic, linker generated |
| 6872 | | |
| 6873 | | const source_sym = source_symtab[sym_at_off.sym_index]; |
| 6874 | | const size: ?u64 = size: { |
| 6875 | | if (source_sym.tentative()) break :size null; |
| 6876 | | for (debug_info.inner.func_list.items) |func| { |
| 6877 | | if (func.pc_range) |range| { |
| 6878 | | if (source_sym.n_value >= range.start and source_sym.n_value < range.end) { |
| 6879 | | break :size range.end - range.start; |
| 6880 | | } |
| 6881 | | } |
| 6882 | | } |
| 6883 | | break :size null; |
| 6884 | | }; |
| 6885 | | |
| 6886 | | if (size) |ss| { |
| 6887 | | try locals.ensureUnusedCapacity(4); |
| 6888 | | locals.appendAssumeCapacity(.{ |
| 6889 | | .n_strx = 0, |
| 6890 | | .n_type = macho.N_BNSYM, |
| 6891 | | .n_sect = sym.n_sect, |
| 6892 | | .n_desc = 0, |
| 6893 | | .n_value = sym.n_value, |
| 6894 | | }); |
| 6895 | | locals.appendAssumeCapacity(.{ |
| 6896 | | .n_strx = try self.strtab.insert(gpa, sym_name), |
| 6897 | | .n_type = macho.N_FUN, |
| 6898 | | .n_sect = sym.n_sect, |
| 6899 | | .n_desc = 0, |
| 6900 | | .n_value = sym.n_value, |
| 6901 | | }); |
| 6902 | | locals.appendAssumeCapacity(.{ |
| 6903 | | .n_strx = 0, |
| 6904 | | .n_type = macho.N_FUN, |
| 6905 | | .n_sect = 0, |
| 6906 | | .n_desc = 0, |
| 6907 | | .n_value = ss, |
| 6908 | | }); |
| 6909 | | locals.appendAssumeCapacity(.{ |
| 6910 | | .n_strx = 0, |
| 6911 | | .n_type = macho.N_ENSYM, |
| 6912 | | .n_sect = sym.n_sect, |
| 6913 | | .n_desc = 0, |
| 6914 | | .n_value = ss, |
| 6915 | | }); |
| 6916 | | } else { |
| 6917 | | try locals.append(.{ |
| 6918 | | .n_strx = try self.strtab.insert(gpa, sym_name), |
| 6919 | | .n_type = macho.N_STSYM, |
| 6920 | | .n_sect = sym.n_sect, |
| 6921 | | .n_desc = 0, |
| 6922 | | .n_value = sym.n_value, |
| 6923 | | }); |
| 6924 | | } |
| 6862 | const contained_stabs = try self.generateSymbolStabsForSymbol( |
| 6863 | sym_loc, |
| 6864 | debug_info, |
| 6865 | &stabs_buf, |
| 6866 | ); |
| 6867 | try locals.appendSlice(contained_stabs); |
| 6925 | 6868 | } |
| 6926 | 6869 | } |
| 6927 | 6870 | |
| ... | ... | @@ -6935,6 +6878,78 @@ pub fn generateSymbolStabs( |
| 6935 | 6878 | }); |
| 6936 | 6879 | } |
| 6937 | 6880 | |
| 6881 | fn generateSymbolStabsForSymbol( |
| 6882 | self: *MachO, |
| 6883 | sym_loc: SymbolWithLoc, |
| 6884 | debug_info: DebugInfo, |
| 6885 | buf: *[4]macho.nlist_64, |
| 6886 | ) ![]const macho.nlist_64 { |
| 6887 | const gpa = self.base.allocator; |
| 6888 | const object = self.objects.items[sym_loc.file.?]; |
| 6889 | const source_symtab = object.getSourceSymtab(); |
| 6890 | const sym = self.getSymbol(sym_loc); |
| 6891 | const sym_name = self.getSymbolName(sym_loc); |
| 6892 | |
| 6893 | if (sym.n_strx == 0) return buf[0..0]; |
| 6894 | if (sym.n_desc == N_DESC_GCED) return buf[0..0]; |
| 6895 | if (self.symbolIsTemp(sym_loc)) return buf[0..0]; |
| 6896 | if (sym_loc.sym_index >= source_symtab.len) return buf[0..0]; // synthetic, linker generated |
| 6897 | |
| 6898 | const source_sym = source_symtab[sym_loc.sym_index]; |
| 6899 | const size: ?u64 = size: { |
| 6900 | if (source_sym.tentative()) break :size null; |
| 6901 | for (debug_info.inner.func_list.items) |func| { |
| 6902 | if (func.pc_range) |range| { |
| 6903 | if (source_sym.n_value >= range.start and source_sym.n_value < range.end) { |
| 6904 | break :size range.end - range.start; |
| 6905 | } |
| 6906 | } |
| 6907 | } |
| 6908 | break :size null; |
| 6909 | }; |
| 6910 | |
| 6911 | if (size) |ss| { |
| 6912 | buf[0] = .{ |
| 6913 | .n_strx = 0, |
| 6914 | .n_type = macho.N_BNSYM, |
| 6915 | .n_sect = sym.n_sect, |
| 6916 | .n_desc = 0, |
| 6917 | .n_value = sym.n_value, |
| 6918 | }; |
| 6919 | buf[1] = .{ |
| 6920 | .n_strx = try self.strtab.insert(gpa, sym_name), |
| 6921 | .n_type = macho.N_FUN, |
| 6922 | .n_sect = sym.n_sect, |
| 6923 | .n_desc = 0, |
| 6924 | .n_value = sym.n_value, |
| 6925 | }; |
| 6926 | buf[2] = .{ |
| 6927 | .n_strx = 0, |
| 6928 | .n_type = macho.N_FUN, |
| 6929 | .n_sect = 0, |
| 6930 | .n_desc = 0, |
| 6931 | .n_value = ss, |
| 6932 | }; |
| 6933 | buf[3] = .{ |
| 6934 | .n_strx = 0, |
| 6935 | .n_type = macho.N_ENSYM, |
| 6936 | .n_sect = sym.n_sect, |
| 6937 | .n_desc = 0, |
| 6938 | .n_value = ss, |
| 6939 | }; |
| 6940 | return buf; |
| 6941 | } else { |
| 6942 | buf[0] = .{ |
| 6943 | .n_strx = try self.strtab.insert(gpa, sym_name), |
| 6944 | .n_type = macho.N_STSYM, |
| 6945 | .n_sect = sym.n_sect, |
| 6946 | .n_desc = 0, |
| 6947 | .n_value = sym.n_value, |
| 6948 | }; |
| 6949 | return buf[0..1]; |
| 6950 | } |
| 6951 | } |
| 6952 | |
| 6938 | 6953 | fn snapshotState(self: *MachO) !void { |
| 6939 | 6954 | const emit = self.base.options.emit orelse { |
| 6940 | 6955 | log.debug("no emit directory found; skipping snapshot...", .{}); |