| ... | ... | @@ -6,6 +6,7 @@ symtab: std.MultiArrayList(Nlist) = .{}, |
| 6 | 6 | |
| 7 | 7 | symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 8 | 8 | atoms: std.ArrayListUnmanaged(Atom.Index) = .{}, |
| 9 | globals_lookup: std.AutoHashMapUnmanaged(u32, Symbol.Index) = .{}, |
| 9 | 10 | |
| 10 | 11 | /// Table of tracked LazySymbols. |
| 11 | 12 | lazy_syms: LazySymbolTable = .{}, |
| ... | ... | @@ -53,6 +54,7 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void { |
| 53 | 54 | self.symtab.deinit(allocator); |
| 54 | 55 | self.symbols.deinit(allocator); |
| 55 | 56 | self.atoms.deinit(allocator); |
| 57 | self.globals_lookup.deinit(allocator); |
| 56 | 58 | |
| 57 | 59 | { |
| 58 | 60 | var it = self.decls.iterator(); |
| ... | ... | @@ -918,20 +920,44 @@ pub fn deleteDeclExport( |
| 918 | 920 | macho_file: *MachO, |
| 919 | 921 | decl_index: InternPool.DeclIndex, |
| 920 | 922 | name: InternPool.NullTerminatedString, |
| 921 | | ) void { |
| 922 | | _ = self; |
| 923 | | _ = macho_file; |
| 924 | | _ = decl_index; |
| 925 | | _ = name; |
| 926 | | @panic("TODO deleteDeclExport"); |
| 923 | ) Allocator.Error!void { |
| 924 | const metadata = self.decls.getPtr(decl_index) orelse return; |
| 925 | |
| 926 | const gpa = macho_file.base.comp.gpa; |
| 927 | const mod = macho_file.base.comp.module.?; |
| 928 | const exp_name = try std.fmt.allocPrint(gpa, "_{s}", .{mod.intern_pool.stringToSlice(name)}); |
| 929 | defer gpa.free(exp_name); |
| 930 | const nlist_index = metadata.@"export"(self, macho_file, exp_name) orelse return; |
| 931 | |
| 932 | log.debug("deleting export '{s}'", .{exp_name}); |
| 933 | |
| 934 | const nlist = &self.symtab.items(.nlist)[nlist_index.*]; |
| 935 | self.symtab.items(.size)[nlist_index.*] = 0; |
| 936 | _ = self.globals_lookup.remove(nlist.n_strx); |
| 937 | const sym_index = macho_file.globals.get(nlist.n_strx).?; |
| 938 | const sym = macho_file.getSymbol(sym_index); |
| 939 | if (sym.file == self.index) { |
| 940 | _ = macho_file.globals.swapRemove(nlist.n_strx); |
| 941 | sym.* = .{}; |
| 942 | } |
| 943 | nlist.* = MachO.null_sym; |
| 927 | 944 | } |
| 928 | 945 | |
| 929 | 946 | pub fn getGlobalSymbol(self: *ZigObject, macho_file: *MachO, name: []const u8, lib_name: ?[]const u8) !u32 { |
| 930 | | _ = self; |
| 931 | | _ = macho_file; |
| 932 | | _ = name; |
| 933 | 947 | _ = lib_name; |
| 934 | | @panic("TODO getGlobalSymbol"); |
| 948 | const gpa = macho_file.base.comp.gpa; |
| 949 | const off = try macho_file.strings.insert(gpa, name); |
| 950 | const lookup_gop = try self.globals_lookup.getOrPut(gpa, off); |
| 951 | if (!lookup_gop.found_existing) { |
| 952 | const nlist_index = try self.addNlist(gpa); |
| 953 | const nlist = &self.symtab.items(.nlist)[nlist_index]; |
| 954 | nlist.n_strx = off; |
| 955 | nlist.n_type = macho.N_EXT; |
| 956 | lookup_gop.value_ptr.* = nlist_index; |
| 957 | const gop = try macho_file.getOrCreateGlobal(off); |
| 958 | try self.symbols.append(gpa, gop.index); |
| 959 | } |
| 960 | return lookup_gop.value_ptr.*; |
| 935 | 961 | } |
| 936 | 962 | |
| 937 | 963 | pub fn getOrCreateMetadataForDecl( |