| ... | ... | @@ -9,7 +9,7 @@ index: File.Index, |
| 9 | 9 | |
| 10 | 10 | local_esyms: std.MultiArrayList(ElfSym) = .{}, |
| 11 | 11 | global_esyms: std.MultiArrayList(ElfSym) = .{}, |
| 12 | | strtab: std.ArrayListUnmanaged(u8) = .{}, |
| 12 | strtab: StringTable = .{}, |
| 13 | 13 | local_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 14 | 14 | global_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 15 | 15 | globals_lookup: std.AutoHashMapUnmanaged(u32, Symbol.Index) = .{}, |
| ... | ... | @@ -75,9 +75,9 @@ pub fn init(self: *ZigObject, elf_file: *Elf) !void { |
| 75 | 75 | const gpa = elf_file.base.allocator; |
| 76 | 76 | |
| 77 | 77 | try self.atoms.append(gpa, 0); // null input section |
| 78 | | try self.strtab.append(gpa, 0); |
| 78 | try self.strtab.buffer.append(gpa, 0); |
| 79 | 79 | |
| 80 | | const name_off = try self.insertString(gpa, std.fs.path.stem(self.path)); |
| 80 | const name_off = try self.strtab.insert(gpa, std.fs.path.stem(self.path)); |
| 81 | 81 | const symbol_index = try elf_file.addSymbol(); |
| 82 | 82 | try self.local_symbols.append(gpa, symbol_index); |
| 83 | 83 | const symbol_ptr = elf_file.symbol(symbol_index); |
| ... | ... | @@ -864,7 +864,7 @@ fn updateDeclCode( |
| 864 | 864 | sym.output_section_index = shdr_index; |
| 865 | 865 | atom_ptr.output_section_index = shdr_index; |
| 866 | 866 | |
| 867 | | sym.name_offset = try self.insertString(gpa, decl_name); |
| 867 | sym.name_offset = try self.strtab.insert(gpa, decl_name); |
| 868 | 868 | atom_ptr.flags.alive = true; |
| 869 | 869 | atom_ptr.name_offset = sym.name_offset; |
| 870 | 870 | esym.st_name = sym.name_offset; |
| ... | ... | @@ -1106,7 +1106,7 @@ fn updateLazySymbol( |
| 1106 | 1106 | sym.ty.fmt(mod), |
| 1107 | 1107 | }); |
| 1108 | 1108 | defer gpa.free(name); |
| 1109 | | break :blk try self.insertString(gpa, name); |
| 1109 | break :blk try self.strtab.insert(gpa, name); |
| 1110 | 1110 | }; |
| 1111 | 1111 | |
| 1112 | 1112 | const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl| |
| ... | ... | @@ -1239,7 +1239,7 @@ fn lowerConst( |
| 1239 | 1239 | }; |
| 1240 | 1240 | |
| 1241 | 1241 | const local_sym = elf_file.symbol(sym_index); |
| 1242 | | const name_str_index = try self.insertString(gpa, name); |
| 1242 | const name_str_index = try self.strtab.insert(gpa, name); |
| 1243 | 1243 | local_sym.name_offset = name_str_index; |
| 1244 | 1244 | local_sym.output_section_index = output_section_index; |
| 1245 | 1245 | const local_esym = &self.local_esyms.items(.elf_sym)[local_sym.esym_index]; |
| ... | ... | @@ -1334,18 +1334,12 @@ pub fn updateExports( |
| 1334 | 1334 | }; |
| 1335 | 1335 | const stt_bits: u8 = @as(u4, @truncate(esym.st_info)); |
| 1336 | 1336 | const exp_name = mod.intern_pool.stringToSlice(exp.opts.name); |
| 1337 | | const name_off = try self.insertString(gpa, exp_name); |
| 1337 | const name_off = try self.strtab.insert(gpa, exp_name); |
| 1338 | 1338 | const global_esym_index = if (metadata.@"export"(self, exp_name)) |exp_index| |
| 1339 | 1339 | exp_index.* |
| 1340 | 1340 | else blk: { |
| 1341 | | const global_esym_index = try self.addGlobalEsym(gpa); |
| 1342 | | const lookup_gop = try self.globals_lookup.getOrPut(gpa, name_off); |
| 1343 | | const global_esym = self.elfSym(global_esym_index); |
| 1344 | | global_esym.st_name = name_off; |
| 1345 | | lookup_gop.value_ptr.* = global_esym_index; |
| 1341 | const global_esym_index = try self.getGlobalSymbol(elf_file, exp_name, null); |
| 1346 | 1342 | try metadata.exports.append(gpa, global_esym_index); |
| 1347 | | const gop = try elf_file.getOrPutGlobal(exp_name); |
| 1348 | | try self.global_symbols.append(gpa, gop.index); |
| 1349 | 1343 | break :blk global_esym_index; |
| 1350 | 1344 | }; |
| 1351 | 1345 | |
| ... | ... | @@ -1405,7 +1399,7 @@ pub fn deleteDeclExport( |
| 1405 | 1399 | pub fn getGlobalSymbol(self: *ZigObject, elf_file: *Elf, name: []const u8, lib_name: ?[]const u8) !u32 { |
| 1406 | 1400 | _ = lib_name; |
| 1407 | 1401 | const gpa = elf_file.base.allocator; |
| 1408 | | const off = try self.insertString(gpa, name); |
| 1402 | const off = try self.strtab.insert(gpa, name); |
| 1409 | 1403 | const lookup_gop = try self.globals_lookup.getOrPut(gpa, off); |
| 1410 | 1404 | if (!lookup_gop.found_existing) { |
| 1411 | 1405 | const esym_index = try self.addGlobalEsym(gpa); |
| ... | ... | @@ -1419,15 +1413,7 @@ pub fn getGlobalSymbol(self: *ZigObject, elf_file: *Elf, name: []const u8, lib_n |
| 1419 | 1413 | } |
| 1420 | 1414 | |
| 1421 | 1415 | pub fn getString(self: ZigObject, off: u32) [:0]const u8 { |
| 1422 | | assert(off < self.strtab.items.len); |
| 1423 | | return mem.sliceTo(@as([*:0]const u8, @ptrCast(self.strtab.items.ptr + off)), 0); |
| 1424 | | } |
| 1425 | | |
| 1426 | | pub fn insertString(self: *ZigObject, allocator: Allocator, name: []const u8) error{OutOfMemory}!u32 { |
| 1427 | | const off = @as(u32, @intCast(self.strtab.items.len)); |
| 1428 | | try self.strtab.ensureUnusedCapacity(allocator, name.len + 1); |
| 1429 | | self.strtab.writer(allocator).print("{s}\x00", .{name}) catch unreachable; |
| 1430 | | return off; |
| 1416 | return self.strtab.getAssumeExists(off); |
| 1431 | 1417 | } |
| 1432 | 1418 | |
| 1433 | 1419 | pub fn fmtSymtab(self: *ZigObject, elf_file: *Elf) std.fmt.Formatter(formatSymtab) { |
| ... | ... | @@ -1538,5 +1524,6 @@ const Liveness = @import("../../Liveness.zig"); |
| 1538 | 1524 | const Module = @import("../../Module.zig"); |
| 1539 | 1525 | const Object = @import("Object.zig"); |
| 1540 | 1526 | const Symbol = @import("Symbol.zig"); |
| 1527 | const StringTable = @import("../StringTable.zig"); |
| 1541 | 1528 | const TypedValue = @import("../../TypedValue.zig"); |
| 1542 | 1529 | const ZigObject = @This(); |