From e69c4ad82158038a1e47d5853384c1ddea4dfdce Mon Sep 17 00:00:00 2001 From: Chan Lee Date: Tue, 7 Jan 2025 16:24:58 +0800 Subject: [PATCH] windows-gnu: Add support for `-gcodeview` flag --- lib/std/Build/Step/Compile.zig | 6 +++++- src/Compilation.zig | 2 ++ src/Compilation/Config.zig | 1 - src/clang_options_data.zig | 9 ++++++++- src/main.zig | 7 +++++++ tools/update_clang_options.zig | 4 ++++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 240847354043..3c6b43e79a2b 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -657,7 +657,11 @@ pub fn producesPdbFile(compile: *Compile) bool { .windows, .uefi => {}, else => return false, } - if (target.abi.isGnu()) return false; + if (compile.root_module.debug_format) |fmt| { + if (fmt != .code_view) return false; + } else { + if (target.abi.isGnu()) return false; + } if (target.ofmt == .c) return false; if (compile.root_module.strip == true or (compile.root_module.strip == null and compile.root_module.optimize == .ReleaseSmall)) diff --git a/src/Compilation.zig b/src/Compilation.zig index 1b66f5da3321..e48bccf52616 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6321,6 +6321,7 @@ fn buildOutputFromZig( .emit_bin = true, .root_optimize_mode = optimize_mode, .root_strip = strip, + .debug_format = comp.config.debug_format, .link_libc = comp.config.link_libc, }); @@ -6457,6 +6458,7 @@ pub fn build_crt_file( .emit_bin = true, .root_optimize_mode = comp.compilerRtOptMode(), .root_strip = comp.compilerRtStrip(), + .debug_format = comp.config.debug_format, .link_libc = false, .lto = switch (output_mode) { .Lib => comp.config.lto, diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 5165b58666fd..909ddb9db23d 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -67,7 +67,6 @@ pub const CFrontend = enum { clang, aro }; pub const LtoMode = enum { none, full, thin }; - pub const Options = struct { output_mode: std.builtin.OutputMode, resolved_target: Module.ResolvedTarget, diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig index 89de37e8ac73..75a83bf61387 100644 --- a/src/clang_options_data.zig +++ b/src/clang_options_data.zig @@ -4148,7 +4148,14 @@ flagpd1("g3"), .pd2 = false, .psl = false, }, -flagpd1("gcodeview"), +.{ + .name = "gcodeview", + .syntax = .flag, + .zig_equivalent = .gcodeview, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("gcodeview-command-line"), flagpd1("gcodeview-ghash"), flagpd1("gcolumn-info"), diff --git a/src/main.zig b/src/main.zig index 31ee3d47acd1..f54ed41dee47 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1547,6 +1547,8 @@ fn buildOutputType( create_module.opts.debug_format = .{ .dwarf = .@"32" }; } else if (mem.eql(u8, arg, "-gdwarf64")) { create_module.opts.debug_format = .{ .dwarf = .@"64" }; + } else if (mem.eql(u8, arg, "-gcodeview")) { + create_module.opts.debug_format = .code_view; } else if (mem.eql(u8, arg, "-fformatted-panics")) { // Remove this after 0.15.0 is tagged. warn("-fformatted-panics is deprecated and does nothing", .{}); @@ -2181,6 +2183,10 @@ fn buildOutputType( try cc_argv.appendSlice(arena, it.other_args); } }, + .gcodeview => { + mod_opts.strip = false; + create_module.opts.debug_format = .code_view; + }, .gdwarf32 => { mod_opts.strip = false; create_module.opts.debug_format = .{ .dwarf = .@"32" }; @@ -5797,6 +5803,7 @@ pub const ClangArgIterator = struct { asm_only, optimize, debug, + gcodeview, gdwarf32, gdwarf64, sanitize, diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index b8916e5e6aac..de8caa1f59d9 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -252,6 +252,10 @@ const known_options = [_]KnownOpt{ .name = "debug", .ident = "debug", }, + .{ + .name = "gcodeview", + .ident = "gcodeview", + }, .{ .name = "gdwarf32", .ident = "gdwarf32",