cc: Add support for -Wp,

This commit is contained in:
Maciej 'vesim' Kuliński 2024-09-18 05:10:36 +02:00 committed by Andrew Kelley
parent 41330c96ae
commit feaee2ba17
3 changed files with 39 additions and 1 deletions

View file

@ -7472,7 +7472,7 @@ joinpd1("mtp="),
.{ .{
.name = "Wp,", .name = "Wp,",
.syntax = .comma_joined, .syntax = .comma_joined,
.zig_equivalent = .other, .zig_equivalent = .wp,
.pd1 = true, .pd1 = true,
.pd2 = false, .pd2 = false,
.psl = false, .psl = false,

View file

@ -1791,6 +1791,7 @@ fn buildOutputType(
var c_out_mode: ?COutMode = null; var c_out_mode: ?COutMode = null;
var out_path: ?[]const u8 = null; var out_path: ?[]const u8 = null;
var is_shared_lib = false; var is_shared_lib = false;
var preprocessor_args = std.ArrayList([]const u8).init(arena);
var linker_args = std.ArrayList([]const u8).init(arena); var linker_args = std.ArrayList([]const u8).init(arena);
var it = ClangArgIterator.init(arena, all_args); var it = ClangArgIterator.init(arena, all_args);
var emit_llvm = false; var emit_llvm = false;
@ -1946,6 +1947,24 @@ fn buildOutputType(
is_shared_lib = true; is_shared_lib = true;
}, },
.rdynamic => create_module.opts.rdynamic = true, .rdynamic => create_module.opts.rdynamic = true,
.wp => {
var split_it = mem.splitScalar(u8, it.only_arg, ',');
while (split_it.next()) |preprocessor_arg| {
if (preprocessor_arg.len >= 3 and
preprocessor_arg[0] == '-' and
preprocessor_arg[2] != '-')
{
if (mem.indexOfScalar(u8, preprocessor_arg, '=')) |equals_pos| {
const key = preprocessor_arg[0..equals_pos];
const value = preprocessor_arg[equals_pos + 1 ..];
try preprocessor_args.append(key);
try preprocessor_args.append(value);
continue;
}
}
try preprocessor_args.append(preprocessor_arg);
}
},
.wl => { .wl => {
var split_it = mem.splitScalar(u8, it.only_arg, ','); var split_it = mem.splitScalar(u8, it.only_arg, ',');
while (split_it.next()) |linker_arg| { while (split_it.next()) |linker_arg| {
@ -2554,6 +2573,20 @@ fn buildOutputType(
} }
} }
// Parse preprocessor args.
var preprocessor_args_it = ArgsIterator{
.args = preprocessor_args.items,
};
while (preprocessor_args_it.next()) |arg| {
if (mem.eql(u8, arg, "-MD") or mem.eql(u8, arg, "-MMD") or mem.eql(u8, arg, "-MT")) {
disable_c_depfile = true;
const cc_arg = try std.fmt.allocPrint(arena, "-Wp,{s},{s}", .{ arg, preprocessor_args_it.nextOrFatal() });
try cc_argv.append(arena, cc_arg);
} else {
fatal("unsupported preprocessor arg: {s}", .{arg});
}
}
if (mod_opts.sanitize_c) |wsc| { if (mod_opts.sanitize_c) |wsc| {
if (wsc and mod_opts.optimize_mode == .ReleaseFast) { if (wsc and mod_opts.optimize_mode == .ReleaseFast) {
mod_opts.optimize_mode = .ReleaseSafe; mod_opts.optimize_mode = .ReleaseSafe;
@ -5771,6 +5804,7 @@ pub const ClangArgIterator = struct {
shared, shared,
rdynamic, rdynamic,
wl, wl,
wp,
preprocess_only, preprocess_only,
asm_only, asm_only,
optimize, optimize,

View file

@ -154,6 +154,10 @@ const known_options = [_]KnownOpt{
.name = "Wl,", .name = "Wl,",
.ident = "wl", .ident = "wl",
}, },
.{
.name = "Wp,",
.ident = "wp",
},
.{ .{
.name = "Xlinker", .name = "Xlinker",
.ident = "for_linker", .ident = "for_linker",