Skip to content

Commit

Permalink
windows-gnu: Add support for -gcodeview flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Doekin committed Jan 7, 2025
1 parent 9bd0a5d commit 3867570
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
22 changes: 14 additions & 8 deletions lib/std/Build/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import_table: std.StringArrayHashMapUnmanaged(*Module),

resolved_target: ?std.Build.ResolvedTarget = null,
optimize: ?std.builtin.OptimizeMode = null,
dwarf_format: ?std.dwarf.Format,
debug_format: ?std.builtin.DebugFormat,

c_macros: std.ArrayListUnmanaged([]const u8),
include_dirs: std.ArrayListUnmanaged(IncludeDir),
Expand Down Expand Up @@ -219,7 +219,7 @@ pub const CreateOptions = struct {
single_threaded: ?bool = null,
strip: ?bool = null,
unwind_tables: ?std.builtin.UnwindTables = null,
dwarf_format: ?std.dwarf.Format = null,
debug_format: ?std.builtin.DebugFormat = null,
code_model: std.builtin.CodeModel = .default,
stack_protector: ?bool = null,
stack_check: ?bool = null,
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn init(
.optimize = options.optimize,
.link_libc = options.link_libc,
.link_libcpp = options.link_libcpp,
.dwarf_format = options.dwarf_format,
.debug_format = options.debug_format,
.c_macros = .{},
.include_dirs = .{},
.lib_paths = .{},
Expand Down Expand Up @@ -525,11 +525,17 @@ pub fn appendZigProcessFlags(
try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC");
try addFlag(zig_args, m.red_zone, "-mred-zone", "-mno-red-zone");

if (m.dwarf_format) |dwarf_format| {
try zig_args.append(switch (dwarf_format) {
.@"32" => "-gdwarf32",
.@"64" => "-gdwarf64",
});
if (m.debug_format) |debug_format| {
switch (debug_format) {
.strip => {},
.dwarf => |fmt| switch (fmt) {
.@"32" => try zig_args.append("-gdwarf32"),
.@"64" => try zig_args.append("-gdwarf64"),
},
.code_view => {
try zig_args.append("-gcodeview");
},
}
}

if (m.unwind_tables) |unwind_tables| {
Expand Down
1 change: 0 additions & 1 deletion lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ pub fn producesPdbFile(compile: *Compile) bool {
.windows, .uefi => {},
else => return false,
}
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))
Expand Down
8 changes: 8 additions & 0 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ pub const OptimizeMode = enum {
/// Deprecated; use OptimizeMode.
pub const Mode = OptimizeMode;

/// DebugFormat specifies which type of debug information to generate:
pub const DebugFormat = union(enum) {
/// No debug information.
strip,
dwarf: std.dwarf.Format,
code_view,
};

/// The calling convention of a function defines how arguments and return values are passed, as well
/// as any other requirements which callers and callees must respect, such as register preservation
/// and stack alignment.
Expand Down
6 changes: 3 additions & 3 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,13 @@ pub const cache_helpers = struct {
addEmitLoc(hh, optional_emit_loc orelse return);
}

pub fn addOptionalDebugFormat(hh: *Cache.HashHelper, x: ?Config.DebugFormat) void {
pub fn addOptionalDebugFormat(hh: *Cache.HashHelper, x: ?std.builtin.DebugFormat) void {
hh.add(x != null);
addDebugFormat(hh, x orelse return);
}

pub fn addDebugFormat(hh: *Cache.HashHelper, x: Config.DebugFormat) void {
const tag: @typeInfo(Config.DebugFormat).@"union".tag_type.? = x;
pub fn addDebugFormat(hh: *Cache.HashHelper, x: std.builtin.DebugFormat) void {
const tag: @typeInfo(std.builtin.DebugFormat).@"union".tag_type.? = x;
hh.add(tag);
switch (x) {
.strip, .code_view => {},
Expand Down
11 changes: 3 additions & 8 deletions src/Compilation/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import_memory: bool,
export_memory: bool,
shared_memory: bool,
is_test: bool,
debug_format: DebugFormat,
debug_format: std.builtin.DebugFormat,
root_strip: bool,
root_error_tracing: bool,
dll_export_fns: bool,
Expand All @@ -65,11 +65,6 @@ san_cov_trace_pc_guard: bool,

pub const CFrontend = enum { clang, aro };

pub const DebugFormat = union(enum) {
strip,
dwarf: std.dwarf.Format,
code_view,
};

pub const Options = struct {
output_mode: std.builtin.OutputMode,
Expand Down Expand Up @@ -107,7 +102,7 @@ pub const Options = struct {
import_memory: ?bool = null,
export_memory: ?bool = null,
shared_memory: ?bool = null,
debug_format: ?DebugFormat = null,
debug_format: ?std.builtin.DebugFormat = null,
dll_export_fns: ?bool = null,
rdynamic: ?bool = null,
san_cov_trace_pc_guard: bool = false,
Expand Down Expand Up @@ -439,7 +434,7 @@ pub fn resolve(options: Options) ResolveError!Config {
break :b false;
};

const debug_format: DebugFormat = b: {
const debug_format: std.builtin.DebugFormat = b: {
if (root_strip and !options.any_non_stripped) break :b .strip;
if (options.debug_format) |x| break :b x;
break :b switch (target.ofmt) {
Expand Down
9 changes: 8 additions & 1 deletion src/clang_options_data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
10 changes: 9 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,10 @@ 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, "-fformatted-panics")) {
} 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", .{});
} else if (mem.eql(u8, arg, "-fno-formatted-panics")) {
Expand Down Expand Up @@ -2160,6 +2163,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" };
Expand Down Expand Up @@ -5776,6 +5783,7 @@ pub const ClangArgIterator = struct {
asm_only,
optimize,
debug,
gcodeview,
gdwarf32,
gdwarf64,
sanitize,
Expand Down
4 changes: 4 additions & 0 deletions tools/update_clang_options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ const known_options = [_]KnownOpt{
.name = "debug",
.ident = "debug",
},
.{
.name = "gcodeview",
.ident = "gcodeview",
},
.{
.name = "gdwarf32",
.ident = "gdwarf32",
Expand Down

0 comments on commit 3867570

Please sign in to comment.