diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-10-14 13:50:10 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-10-22 12:50:25 +0200 |
| commit | d0dceae736edb43d4c217306a2b0445277f184ce (patch) | |
| tree | d6bad107975e61e360a50de5436fb297a97435fb /src/main.zig | |
| parent | 912e7dc54b9b49d96123ffd398e6d40b455997fe (diff) | |
| download | zig-d0dceae736edb43d4c217306a2b0445277f184ce.tar.gz zig-d0dceae736edb43d4c217306a2b0445277f184ce.zip | |
macho: dump linker's state as JSON
Each element of the output JSON has the VM address of the generated
binary nondecreasing (some elements might occupy the same VM address
for example the atom and the relocation might coincide in the address
space).
The generated JSON can be inspected manually or via a preview tool
`zig-snapshots` that I am currently working on and will allow the user
to inspect interactively the state of the linker together with the
positioning of sections, symbols, atoms and relocations within each
snapshot state, and in the future, between snapshots too. This should
allow for quicker debugging of the linker which is nontrivial when
run in the incremental mode.
Note that the state will only be dumped if the compiler is built with
`-Dlink-snapshot` flag on, and then the compiler is passed `--debug-link-snapshot`
flag upon compiling a source/project.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig index fbe388ed47..3fc2be7e30 100644 --- a/src/main.zig +++ b/src/main.zig @@ -434,6 +434,7 @@ const usage_build_generic = \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features \\ --debug-log [scope] Enable printing debug/info log messages for scope \\ --debug-compile-errors Crash with helpful diagnostics at the first compile error + \\ --debug-link-snapshot Enable dumping of the linker's state in JSON format \\ ; @@ -632,6 +633,7 @@ fn buildOutputType( var major_subsystem_version: ?u32 = null; var minor_subsystem_version: ?u32 = null; var wasi_exec_model: ?std.builtin.WasiExecModel = null; + var enable_link_snapshots: bool = false; var system_libs = std.ArrayList([]const u8).init(gpa); defer system_libs.deinit(); @@ -929,6 +931,12 @@ fn buildOutputType( } else { try log_scopes.append(gpa, args[i]); } + } else if (mem.eql(u8, arg, "--debug-link-snapshot")) { + if (!build_options.enable_link_snapshots) { + std.log.warn("Zig was compiled without linker snapshots enabled (-Dlink-snapshot). --debug-link-snapshot has no effect.", .{}); + } else { + enable_link_snapshots = true; + } } else if (mem.eql(u8, arg, "-fcompiler-rt")) { want_compiler_rt = true; } else if (mem.eql(u8, arg, "-fno-compiler-rt")) { @@ -2139,6 +2147,7 @@ fn buildOutputType( .subsystem = subsystem, .wasi_exec_model = wasi_exec_model, .debug_compile_errors = debug_compile_errors, + .enable_link_snapshots = enable_link_snapshots, }) catch |err| { fatal("unable to create compilation: {s}", .{@errorName(err)}); }; |
