authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-26 14:33:31+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-27 20:53:06+02:00
log4ca9b4c44a4fbe2b64b11d2c8a951c2c3e961619
tree210ed90046909bef6a650a0f74fc94935212f513
parent1a80315836f77e38eee3e4c0a646b82febbc3604

dwarf: move DbgInfoTypeRelocsTable into Dwarf module


4 files changed, 45 insertions(+), 48 deletions(-)

src/codegen.zig+15-16
......@@ -1,26 +1,25 @@
11const std = @import("std");
2const build_options = @import("build_options");
23const builtin = @import("builtin");
4const assert = std.debug.assert;
5const leb128 = std.leb;
6const link = @import("link.zig");
7const log = std.log.scoped(.codegen);
38const mem = std.mem;
49const math = std.math;
5const assert = std.debug.assert;
10const trace = @import("tracy.zig").trace;
11
612const Air = @import("Air.zig");
7const Zir = @import("Zir.zig");
8const Liveness = @import("Liveness.zig");
9const Type = @import("type.zig").Type;
10const Value = @import("value.zig").Value;
11const TypedValue = @import("TypedValue.zig");
12const link = @import("link.zig");
13const Module = @import("Module.zig");
13const Allocator = mem.Allocator;
1414const Compilation = @import("Compilation.zig");
1515const ErrorMsg = Module.ErrorMsg;
16const Liveness = @import("Liveness.zig");
17const Module = @import("Module.zig");
1618const Target = std.Target;
17const Allocator = mem.Allocator;
18const trace = @import("tracy.zig").trace;
19const DW = std.dwarf;
20const leb128 = std.leb;
21const log = std.log.scoped(.codegen);
22const build_options = @import("build_options");
23const RegisterManager = @import("register_manager.zig").RegisterManager;
19const Type = @import("type.zig").Type;
20const TypedValue = @import("TypedValue.zig");
21const Value = @import("value.zig").Value;
22const Zir = @import("Zir.zig");
2423
2524pub const FnResult = union(enum) {
2625 /// The `code` parameter passed to `generateSymbol` has the value appended.
......@@ -46,7 +45,7 @@ pub const DebugInfoOutput = union(enum) {
4645 dwarf: struct {
4746 dbg_line: *std.ArrayList(u8),
4847 dbg_info: *std.ArrayList(u8),
49 dbg_info_type_relocs: *link.File.DbgInfoTypeRelocsTable,
48 dbg_info_type_relocs: *link.File.Dwarf.DbgInfoTypeRelocsTable,
5049 },
5150 /// the plan9 debuginfo output is a bytecode with 4 opcodes
5251 /// assume all numbers/variables are bytes
src/link.zig+10-28
......@@ -1,22 +1,22 @@
11const std = @import("std");
2const build_options = @import("build_options");
23const builtin = @import("builtin");
3const mem = std.mem;
4const Allocator = std.mem.Allocator;
4const assert = std.debug.assert;
55const fs = std.fs;
6const mem = std.mem;
67const log = std.log.scoped(.link);
7const assert = std.debug.assert;
8const trace = @import("tracy.zig").trace;
9const wasi_libc = @import("wasi_libc.zig");
810
11const Air = @import("Air.zig");
12const Allocator = std.mem.Allocator;
13const Cache = @import("Cache.zig");
914const Compilation = @import("Compilation.zig");
15const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
16const Liveness = @import("Liveness.zig");
1017const Module = @import("Module.zig");
11const trace = @import("tracy.zig").trace;
1218const Package = @import("Package.zig");
1319const Type = @import("type.zig").Type;
14const Cache = @import("Cache.zig");
15const build_options = @import("build_options");
16const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
17const wasi_libc = @import("wasi_libc.zig");
18const Air = @import("Air.zig");
19const Liveness = @import("Liveness.zig");
2020const TypedValue = @import("TypedValue.zig");
2121
2222pub const SystemLib = struct {
......@@ -245,24 +245,6 @@ pub const File = struct {
245245 nvptx: void,
246246 };
247247
248 /// For DWARF .debug_info.
249 pub const DbgInfoTypeRelocsTable = std.ArrayHashMapUnmanaged(
250 Type,
251 DbgInfoTypeReloc,
252 Type.HashContext32,
253 true,
254 );
255
256 /// For DWARF .debug_info.
257 pub const DbgInfoTypeReloc = struct {
258 /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
259 /// This is where the .debug_info tag for the type is.
260 off: u32,
261 /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
262 /// List of DW.AT.type / DW.FORM.ref4 that points to the type.
263 relocs: std.ArrayListUnmanaged(u32),
264 };
265
266248 /// Attempts incremental linking, if the file already exists. If
267249 /// incremental linking fails, falls back to truncating the file and
268250 /// rewriting it. A malicious file is detected as incremental link failure
src/link/Dwarf.zig+19-3
......@@ -82,6 +82,22 @@ pub const SrcFn = struct {
8282
8383pub const PtrWidth = enum { p32, p64 };
8484
85pub const DbgInfoTypeRelocsTable = std.ArrayHashMapUnmanaged(
86 Type,
87 DbgInfoTypeReloc,
88 Type.HashContext32,
89 true,
90);
91
92pub const DbgInfoTypeReloc = struct {
93 /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
94 /// This is where the .debug_info tag for the type is.
95 off: u32,
96 /// Offset from `TextBlock.dbg_info_off` (the buffer that is local to a Decl).
97 /// List of DW.AT.type / DW.FORM.ref4 that points to the type.
98 relocs: std.ArrayListUnmanaged(u32),
99};
100
85101pub const abbrev_compile_unit = 1;
86102pub const abbrev_subprogram = 2;
87103pub const abbrev_subprogram_retvoid = 3;
......@@ -138,7 +154,7 @@ pub fn deinit(self: *Dwarf) void {
138154pub const DeclDebugBuffers = struct {
139155 dbg_line_buffer: std.ArrayList(u8),
140156 dbg_info_buffer: std.ArrayList(u8),
141 dbg_info_type_relocs: File.DbgInfoTypeRelocsTable,
157 dbg_info_type_relocs: DbgInfoTypeRelocsTable,
142158};
143159
144160pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
......@@ -153,7 +169,7 @@ pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
153169 const gpa = self.allocator;
154170 var dbg_line_buffer = std.ArrayList(u8).init(gpa);
155171 var dbg_info_buffer = std.ArrayList(u8).init(gpa);
156 var dbg_info_type_relocs: File.DbgInfoTypeRelocsTable = .{};
172 var dbg_info_type_relocs: DbgInfoTypeRelocsTable = .{};
157173
158174 assert(decl.has_tv);
159175
......@@ -890,7 +906,7 @@ fn addDbgInfoType(
890906 module: *Module,
891907 ty: Type,
892908 dbg_info_buffer: *std.ArrayList(u8),
893 dbg_info_type_relocs: *File.DbgInfoTypeRelocsTable,
909 dbg_info_type_relocs: *DbgInfoTypeRelocsTable,
894910 nested_ref4_relocs: *std.ArrayList(u32),
895911) error{OutOfMemory}!void {
896912 const target = self.target;
src/link/Elf.zig+1-1
......@@ -2232,7 +2232,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void {
22322232 }
22332233}
22342234
2235fn deinitRelocs(gpa: Allocator, table: *File.DbgInfoTypeRelocsTable) void {
2235fn deinitRelocs(gpa: Allocator, table: *link.File.Dwarf.DbgInfoTypeRelocsTable) void {
22362236 for (table.values()) |*value| {
22372237 value.relocs.deinit(gpa);
22382238 }