| author | |
| committer | |
| log | 4ca9b4c44a4fbe2b64b11d2c8a951c2c3e961619 |
| tree | 210ed90046909bef6a650a0f74fc94935212f513 |
| parent | 1a80315836f77e38eee3e4c0a646b82febbc3604 |
4 files changed, 45 insertions(+), 48 deletions(-)
src/codegen.zig+15-16| ... | @@ -1,26 +1,25 @@ | ... | @@ -1,26 +1,25 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const build_options = @import("build_options"); | ||
| 2 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const assert = std.debug.assert; | ||
| 5 | const leb128 = std.leb; | ||
| 6 | const link = @import("link.zig"); | ||
| 7 | const log = std.log.scoped(.codegen); | ||
| 3 | const mem = std.mem; | 8 | const mem = std.mem; |
| 4 | const math = std.math; | 9 | const math = std.math; |
| 5 | const assert = std.debug.assert; | 10 | const trace = @import("tracy.zig").trace; |
| 11 | |||
| 6 | const Air = @import("Air.zig"); | 12 | const Air = @import("Air.zig"); |
| 7 | const Zir = @import("Zir.zig"); | 13 | const Allocator = mem.Allocator; |
| 8 | const Liveness = @import("Liveness.zig"); | ||
| 9 | const Type = @import("type.zig").Type; | ||
| 10 | const Value = @import("value.zig").Value; | ||
| 11 | const TypedValue = @import("TypedValue.zig"); | ||
| 12 | const link = @import("link.zig"); | ||
| 13 | const Module = @import("Module.zig"); | ||
| 14 | const Compilation = @import("Compilation.zig"); | 14 | const Compilation = @import("Compilation.zig"); |
| 15 | const ErrorMsg = Module.ErrorMsg; | 15 | const ErrorMsg = Module.ErrorMsg; |
| 16 | const Liveness = @import("Liveness.zig"); | ||
| 17 | const Module = @import("Module.zig"); | ||
| 16 | const Target = std.Target; | 18 | const Target = std.Target; |
| 17 | const Allocator = mem.Allocator; | 19 | const Type = @import("type.zig").Type; |
| 18 | const trace = @import("tracy.zig").trace; | 20 | const TypedValue = @import("TypedValue.zig"); |
| 19 | const DW = std.dwarf; | 21 | const Value = @import("value.zig").Value; |
| 20 | const leb128 = std.leb; | 22 | const Zir = @import("Zir.zig"); |
| 21 | const log = std.log.scoped(.codegen); | ||
| 22 | const build_options = @import("build_options"); | ||
| 23 | const RegisterManager = @import("register_manager.zig").RegisterManager; | ||
| 24 | 23 | ||
| 25 | pub const FnResult = union(enum) { | 24 | pub 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 opcodes | 50 | /// the plan9 debuginfo output is a bytecode with 4 opcodes |
| 52 | /// assume all numbers/variables are bytes | 51 | /// assume all numbers/variables are bytes |
src/link.zig+10-28| ... | @@ -1,22 +1,22 @@ | ... | @@ -1,22 +1,22 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const build_options = @import("build_options"); | ||
| 2 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 3 | const mem = std.mem; | 4 | const assert = std.debug.assert; |
| 4 | const Allocator = std.mem.Allocator; | ||
| 5 | const fs = std.fs; | 5 | const fs = std.fs; |
| 6 | const mem = std.mem; | ||
| 6 | const log = std.log.scoped(.link); | 7 | const log = std.log.scoped(.link); |
| 7 | const assert = std.debug.assert; | 8 | const trace = @import("tracy.zig").trace; |
| 9 | const wasi_libc = @import("wasi_libc.zig"); | ||
| 8 | 10 | ||
| 11 | const Air = @import("Air.zig"); | ||
| 12 | const Allocator = std.mem.Allocator; | ||
| 13 | const Cache = @import("Cache.zig"); | ||
| 9 | const Compilation = @import("Compilation.zig"); | 14 | const Compilation = @import("Compilation.zig"); |
| 15 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; | ||
| 16 | const Liveness = @import("Liveness.zig"); | ||
| 10 | const Module = @import("Module.zig"); | 17 | const Module = @import("Module.zig"); |
| 11 | const trace = @import("tracy.zig").trace; | ||
| 12 | const Package = @import("Package.zig"); | 18 | const Package = @import("Package.zig"); |
| 13 | const Type = @import("type.zig").Type; | 19 | const Type = @import("type.zig").Type; |
| 14 | const Cache = @import("Cache.zig"); | ||
| 15 | const build_options = @import("build_options"); | ||
| 16 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; | ||
| 17 | const wasi_libc = @import("wasi_libc.zig"); | ||
| 18 | const Air = @import("Air.zig"); | ||
| 19 | const Liveness = @import("Liveness.zig"); | ||
| 20 | const TypedValue = @import("TypedValue.zig"); | 20 | const TypedValue = @import("TypedValue.zig"); |
| 21 | 21 | ||
| 22 | pub const SystemLib = struct { | 22 | pub 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 | }; |
| 247 | 247 | ||
| 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. If | 248 | /// Attempts incremental linking, if the file already exists. If |
| 267 | /// incremental linking fails, falls back to truncating the file and | 249 | /// incremental linking fails, falls back to truncating the file and |
| 268 | /// rewriting it. A malicious file is detected as incremental link failure | 250 | /// 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 { |
| 82 | 82 | ||
| 83 | pub const PtrWidth = enum { p32, p64 }; | 83 | pub const PtrWidth = enum { p32, p64 }; |
| 84 | 84 | ||
| 85 | pub const DbgInfoTypeRelocsTable = std.ArrayHashMapUnmanaged( | ||
| 86 | Type, | ||
| 87 | DbgInfoTypeReloc, | ||
| 88 | Type.HashContext32, | ||
| 89 | true, | ||
| 90 | ); | ||
| 91 | |||
| 92 | pub 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 | |||
| 85 | pub const abbrev_compile_unit = 1; | 101 | pub const abbrev_compile_unit = 1; |
| 86 | pub const abbrev_subprogram = 2; | 102 | pub const abbrev_subprogram = 2; |
| 87 | pub const abbrev_subprogram_retvoid = 3; | 103 | pub 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 { |
| 138 | pub const DeclDebugBuffers = struct { | 154 | pub 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 | }; |
| 143 | 159 | ||
| 144 | pub fn initDeclDebugInfo(self: *Dwarf, decl: *Module.Decl) !DeclDebugBuffers { | 160 | pub 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 = .{}; |
| 157 | 173 | ||
| 158 | assert(decl.has_tv); | 174 | assert(decl.has_tv); |
| 159 | 175 | ||
| ... | @@ -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 | } |
| 2234 | 2234 | ||
| 2235 | fn deinitRelocs(gpa: Allocator, table: *File.DbgInfoTypeRelocsTable) void { | 2235 | fn 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 | } |