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 @@...@@ -1,26 +1,25 @@
1const std = @import("std");1const std = @import("std");
2const build_options = @import("build_options");
2const builtin = @import("builtin");3const builtin = @import("builtin");
4const assert = std.debug.assert;
5const leb128 = std.leb;
6const link = @import("link.zig");
7const log = std.log.scoped(.codegen);
3const mem = std.mem;8const mem = std.mem;
4const math = std.math;9const math = std.math;
5const assert = std.debug.assert;10const trace = @import("tracy.zig").trace;
11
6const Air = @import("Air.zig");12const Air = @import("Air.zig");
7const Zir = @import("Zir.zig");13const Allocator = mem.Allocator;
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");
14const Compilation = @import("Compilation.zig");14const Compilation = @import("Compilation.zig");
15const ErrorMsg = Module.ErrorMsg;15const ErrorMsg = Module.ErrorMsg;
16const Liveness = @import("Liveness.zig");
17const Module = @import("Module.zig");
16const Target = std.Target;18const Target = std.Target;
17const Allocator = mem.Allocator;19const Type = @import("type.zig").Type;
18const trace = @import("tracy.zig").trace;20const TypedValue = @import("TypedValue.zig");
19const DW = std.dwarf;21const Value = @import("value.zig").Value;
20const leb128 = std.leb;22const Zir = @import("Zir.zig");
21const log = std.log.scoped(.codegen);
22const build_options = @import("build_options");
23const RegisterManager = @import("register_manager.zig").RegisterManager;
2423
25pub const FnResult = union(enum) {24pub const FnResult = union(enum) {
26 /// The `code` parameter passed to `generateSymbol` has the value appended.25 /// The `code` parameter passed to `generateSymbol` has the value appended.
...@@ -46,7 +45,7 @@ pub const DebugInfoOutput = union(enum) {...@@ -46,7 +45,7 @@ pub const DebugInfoOutput = union(enum) {
46 dwarf: struct {45 dwarf: struct {
47 dbg_line: *std.ArrayList(u8),46 dbg_line: *std.ArrayList(u8),
48 dbg_info: *std.ArrayList(u8),47 dbg_info: *std.ArrayList(u8),
49 dbg_info_type_relocs: *link.File.DbgInfoTypeRelocsTable,48 dbg_info_type_relocs: *link.File.Dwarf.DbgInfoTypeRelocsTable,
50 },49 },
51 /// the plan9 debuginfo output is a bytecode with 4 opcodes50 /// the plan9 debuginfo output is a bytecode with 4 opcodes
52 /// assume all numbers/variables are bytes51 /// assume all numbers/variables are bytes
src/link.zig+10-28
...@@ -1,22 +1,22 @@...@@ -1,22 +1,22 @@
1const std = @import("std");1const std = @import("std");
2const build_options = @import("build_options");
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const mem = std.mem;4const assert = std.debug.assert;
4const Allocator = std.mem.Allocator;
5const fs = std.fs;5const fs = std.fs;
6const mem = std.mem;
6const log = std.log.scoped(.link);7const 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");
9const Compilation = @import("Compilation.zig");14const Compilation = @import("Compilation.zig");
15const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
16const Liveness = @import("Liveness.zig");
10const Module = @import("Module.zig");17const Module = @import("Module.zig");
11const trace = @import("tracy.zig").trace;
12const Package = @import("Package.zig");18const Package = @import("Package.zig");
13const Type = @import("type.zig").Type;19const 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");
20const TypedValue = @import("TypedValue.zig");20const TypedValue = @import("TypedValue.zig");
2121
22pub const SystemLib = struct {22pub const SystemLib = struct {
...@@ -245,24 +245,6 @@ pub const File = struct {...@@ -245,24 +245,6 @@ pub const File = struct {
245 nvptx: void,245 nvptx: void,
246 };246 };
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
266 /// Attempts incremental linking, if the file already exists. If248 /// Attempts incremental linking, if the file already exists. If
267 /// incremental linking fails, falls back to truncating the file and249 /// incremental linking fails, falls back to truncating the file and
268 /// rewriting it. A malicious file is detected as incremental link failure250 /// 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 {...@@ -82,6 +82,22 @@ pub const SrcFn = struct {
8282
83pub const PtrWidth = enum { p32, p64 };83pub 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
85pub const abbrev_compile_unit = 1;101pub const abbrev_compile_unit = 1;
86pub const abbrev_subprogram = 2;102pub const abbrev_subprogram = 2;
87pub const abbrev_subprogram_retvoid = 3;103pub const abbrev_subprogram_retvoid = 3;
...@@ -138,7 +154,7 @@ pub fn deinit(self: *Dwarf) void {...@@ -138,7 +154,7 @@ pub fn deinit(self: *Dwarf) void {
138pub const DeclDebugBuffers = struct {154pub const DeclDebugBuffers = struct {
139 dbg_line_buffer: std.ArrayList(u8),155 dbg_line_buffer: std.ArrayList(u8),
140 dbg_info_buffer: std.ArrayList(u8),156 dbg_info_buffer: std.ArrayList(u8),
141 dbg_info_type_relocs: File.DbgInfoTypeRelocsTable,157 dbg_info_type_relocs: DbgInfoTypeRelocsTable,
142};158};
143159
144pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {160pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
...@@ -153,7 +169,7 @@ pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {...@@ -153,7 +169,7 @@ pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers {
153 const gpa = self.allocator;169 const gpa = self.allocator;
154 var dbg_line_buffer = std.ArrayList(u8).init(gpa);170 var dbg_line_buffer = std.ArrayList(u8).init(gpa);
155 var dbg_info_buffer = std.ArrayList(u8).init(gpa);171 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
158 assert(decl.has_tv);174 assert(decl.has_tv);
159175
...@@ -890,7 +906,7 @@ fn addDbgInfoType(...@@ -890,7 +906,7 @@ fn addDbgInfoType(
890 module: *Module,906 module: *Module,
891 ty: Type,907 ty: Type,
892 dbg_info_buffer: *std.ArrayList(u8),908 dbg_info_buffer: *std.ArrayList(u8),
893 dbg_info_type_relocs: *File.DbgInfoTypeRelocsTable,909 dbg_info_type_relocs: *DbgInfoTypeRelocsTable,
894 nested_ref4_relocs: *std.ArrayList(u32),910 nested_ref4_relocs: *std.ArrayList(u32),
895) error{OutOfMemory}!void {911) error{OutOfMemory}!void {
896 const target = self.target;912 const target = self.target;
src/link/Elf.zig+1-1
...@@ -2232,7 +2232,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void {...@@ -2232,7 +2232,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void {
2232 }2232 }
2233}2233}
22342234
2235fn deinitRelocs(gpa: Allocator, table: *File.DbgInfoTypeRelocsTable) void {2235fn deinitRelocs(gpa: Allocator, table: *link.File.Dwarf.DbgInfoTypeRelocsTable) void {
2236 for (table.values()) |*value| {2236 for (table.values()) |*value| {
2237 value.relocs.deinit(gpa);2237 value.relocs.deinit(gpa);
2238 }2238 }