authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 11:49:07+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-02-01 11:49:07+01:00
logd98fc53b8fbe479f828114b0276d5290146cc2a3
tree446b6e4a430ee44d10fca677af4add27a804614a
parentb3277c893691c462ec2e82577a78e7baafb42bf6

link: use strtab.StringTable in Dwarf


3 files changed, 17 insertions(+), 25 deletions(-)

src/link/Dwarf.zig+6-14
......@@ -18,8 +18,9 @@ const LinkBlock = File.LinkBlock;
1818const LinkFn = File.LinkFn;
1919const LinkerLoad = @import("../codegen.zig").LinkerLoad;
2020const Module = @import("../Module.zig");
21const Value = @import("../value.zig").Value;
21const StringTable = @import("strtab.zig").StringTable;
2222const Type = @import("../type.zig").Type;
23const Value = @import("../value.zig").Value;
2324
2425allocator: Allocator,
2526bin_file: *File,
......@@ -42,7 +43,7 @@ abbrev_table_offset: ?u64 = null,
4243
4344/// TODO replace with InternPool
4445/// Table of debug symbol names.
45strtab: std.ArrayListUnmanaged(u8) = .{},
46strtab: StringTable(.strtab) = .{},
4647
4748/// Quick lookup array of all defined source files referenced by at least one Decl.
4849/// They will end up in the DWARF debug_line header as two lists:
......@@ -1770,11 +1771,11 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
17701771 },
17711772 }
17721773 // Write the form for the compile unit, which must match the abbrev table above.
1773 const name_strp = try self.makeString(module.root_pkg.root_src_path);
1774 const name_strp = try self.strtab.insert(self.allocator, module.root_pkg.root_src_path);
17741775 var compile_unit_dir_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
17751776 const compile_unit_dir = resolveCompilationDir(module, &compile_unit_dir_buffer);
1776 const comp_dir_strp = try self.makeString(compile_unit_dir);
1777 const producer_strp = try self.makeString(link.producer_string);
1777 const comp_dir_strp = try self.strtab.insert(self.allocator, compile_unit_dir);
1778 const producer_strp = try self.strtab.insert(self.allocator, link.producer_string);
17781779
17791780 di_buf.appendAssumeCapacity(@enumToInt(AbbrevKind.compile_unit));
17801781 if (self.bin_file.tag == .macho) {
......@@ -2435,15 +2436,6 @@ fn getRelocDbgInfoSubprogramHighPC(self: Dwarf) u32 {
24352436 return dbg_info_low_pc_reloc_index + self.ptrWidthBytes();
24362437}
24372438
2438/// TODO Improve this to use a table.
2439fn makeString(self: *Dwarf, bytes: []const u8) !u32 {
2440 try self.strtab.ensureUnusedCapacity(self.allocator, bytes.len + 1);
2441 const result = self.strtab.items.len;
2442 self.strtab.appendSliceAssumeCapacity(bytes);
2443 self.strtab.appendAssumeCapacity(0);
2444 return @intCast(u32, result);
2445}
2446
24472439fn padToIdeal(actual_size: anytype) @TypeOf(actual_size) {
24482440 return actual_size +| (actual_size / ideal_factor);
24492441}
src/link/Elf.zig+5-5
......@@ -688,8 +688,8 @@ pub fn populateMissingMetadata(self: *Elf) !void {
688688 // if (self.dwarf) |*dw| {
689689 // if (self.debug_str_section_index == null) {
690690 // self.debug_str_section_index = @intCast(u16, self.sections.slice().len);
691 // assert(dw.strtab.items.len == 0);
692 // try dw.strtab.append(gpa, 0);
691 // assert(dw.strtab.buffer.items.len == 0);
692 // try dw.strtab.buffer.append(gpa, 0);
693693 // try self.sections.append(gpa, .{
694694 // .shdr = .{
695695 // .sh_name = try self.shstrtab.insert(gpa, ".debug_str"),
......@@ -1164,10 +1164,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11641164
11651165 // if (self.dwarf) |dwarf| {
11661166 // const shdr_index = self.debug_str_section_index.?;
1167 // if (self.debug_strtab_dirty or dwarf.strtab.items.len != self.sections.items(.shdr)[shdr_index].sh_size) {
1168 // try self.growNonAllocSection(shdr_index, dwarf.strtab.items.len, 1, false);
1167 // if (self.debug_strtab_dirty or dwarf.strtab.buffer.items.len != self.sections.items(.shdr)[shdr_index].sh_size) {
1168 // try self.growNonAllocSection(shdr_index, dwarf.strtab.buffer.items.len, 1, false);
11691169 // const debug_strtab_sect = self.sections.items(.shdr)[shdr_index];
1170 // try self.base.file.?.pwriteAll(dwarf.strtab.items, debug_strtab_sect.sh_offset);
1170 // try self.base.file.?.pwriteAll(dwarf.strtab.buffer.items, debug_strtab_sect.sh_offset);
11711171 // self.debug_strtab_dirty = false;
11721172 // }
11731173 // }
src/link/MachO/DebugSymbols.zig+6-6
......@@ -82,11 +82,11 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
8282 }
8383
8484 if (self.debug_str_section_index == null) {
85 assert(self.dwarf.strtab.items.len == 0);
86 try self.dwarf.strtab.append(self.allocator, 0);
85 assert(self.dwarf.strtab.buffer.items.len == 0);
86 try self.dwarf.strtab.buffer.append(self.allocator, 0);
8787 self.debug_str_section_index = try self.allocateSection(
8888 "__debug_str",
89 @intCast(u32, self.dwarf.strtab.items.len),
89 @intCast(u32, self.dwarf.strtab.buffer.items.len),
9090 0,
9191 );
9292 self.debug_string_table_dirty = true;
......@@ -291,10 +291,10 @@ pub fn flushModule(self: *DebugSymbols, macho_file: *MachO) !void {
291291
292292 {
293293 const sect_index = self.debug_str_section_index.?;
294 if (self.debug_string_table_dirty or self.dwarf.strtab.items.len != self.getSection(sect_index).size) {
295 const needed_size = @intCast(u32, self.dwarf.strtab.items.len);
294 if (self.debug_string_table_dirty or self.dwarf.strtab.buffer.items.len != self.getSection(sect_index).size) {
295 const needed_size = @intCast(u32, self.dwarf.strtab.buffer.items.len);
296296 try self.growSection(sect_index, needed_size, false);
297 try self.file.pwriteAll(self.dwarf.strtab.items, self.getSection(sect_index).offset);
297 try self.file.pwriteAll(self.dwarf.strtab.buffer.items, self.getSection(sect_index).offset);
298298 self.debug_string_table_dirty = false;
299299 }
300300 }