authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-03 17:33:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-03 17:33:20-07:00
log4c1a62326b5090fad67c004a6e58a6e4265a77ad
tree922d865e78b10012f773c292795b9d7479894bdd
parent9ede943e0753b250cb9a60a5b9b66ba9bff4a694

stage2: use Target.Abi instead of introducing Target.TargetAbi

This branch introduced std.Target.TargetAbi when we already had std.Target.Abi which was, unsurprisingly, already suited for this task. Also pull out the -mabi= cc flag addition to the common area instead of duplicating it for assembly and c files.

13 files changed, 43 insertions(+), 123 deletions(-)

lib/std/build.zig-4
...@@ -1474,7 +1474,6 @@ pub const LibExeObjStep = struct {...@@ -1474,7 +1474,6 @@ pub const LibExeObjStep = struct {
1474 name_prefix: []const u8,1474 name_prefix: []const u8,
1475 filter: ?[]const u8,1475 filter: ?[]const u8,
1476 test_evented_io: bool = false,1476 test_evented_io: bool = false,
1477 target_abi: ?std.Target.TargetAbi = null,
1478 code_model: std.builtin.CodeModel = .default,1477 code_model: std.builtin.CodeModel = .default,
1479 wasi_exec_model: ?std.builtin.WasiExecModel = null,1478 wasi_exec_model: ?std.builtin.WasiExecModel = null,
14801479
...@@ -2459,9 +2458,6 @@ pub const LibExeObjStep = struct {...@@ -2459,9 +2458,6 @@ pub const LibExeObjStep = struct {
2459 try zig_args.append(builder.fmt("--global-base={d}", .{global_base}));2458 try zig_args.append(builder.fmt("--global-base={d}", .{global_base}));
2460 }2459 }
24612460
2462 if (self.target_abi) |target_abi| {
2463 try zig_args.append(builder.fmt("-mabi={s}", .{@tagName(target_abi)}));
2464 }
2465 if (self.code_model != .default) {2461 if (self.code_model != .default) {
2466 try zig_args.append("-mcmodel");2462 try zig_args.append("-mcmodel");
2467 try zig_args.append(@tagName(self.code_model));2463 try zig_args.append(@tagName(self.code_model));
lib/std/target.zig-78
...@@ -560,84 +560,6 @@ pub const Target = struct {...@@ -560,84 +560,6 @@ pub const Target = struct {
560 }560 }
561 };561 };
562562
563 /// processor specific ABI
564 pub const TargetAbi = enum {
565 //TODO add ARM, Mips, and PowerPC
566 ilp32,
567 ilp32d,
568 ilp32e,
569 ilp32f,
570 lp64,
571 lp64d,
572 lp64f,
573
574 const Riscv32ABI = struct {
575 fn default(features: Cpu.Feature.Set) TargetAbi {
576 if (riscv.featureSetHas(features, .d)) {
577 return .ilp32d;
578 } else if (riscv.featureSetHas(features, .e)) {
579 return .ilp32e;
580 } else {
581 return .ilp32;
582 }
583 }
584 fn validate(target_abi: TargetAbi, features: Cpu.Feature.Set) ParseError!void {
585 const has_e = riscv.featureSetHas(features, .e);
586 const has_f = riscv.featureSetHas(features, .f);
587 const has_d = riscv.featureSetHas(features, .d);
588 return switch (target_abi) {
589 .ilp32e => if (has_e) {} else error.FeatureAbiMismatch,
590 .ilp32 => if (!has_e) {} else error.FeatureAbiMismatch,
591 .ilp32f => if (!has_e and has_f) {} else error.FeatureAbiMismatch,
592 .ilp32d => if (!has_e and has_d) {} else error.FeatureAbiMismatch,
593 else => error.ArchAbiMismatch,
594 };
595 }
596 };
597 const Riscv64ABI = struct {
598 fn default(features: Cpu.Feature.Set) TargetAbi {
599 if (riscv.featureSetHas(features, .d)) {
600 return .lp64d;
601 } else {
602 return .lp64;
603 }
604 }
605 fn validate(target_abi: TargetAbi, features: Cpu.Feature.Set) ParseError!void {
606 const has_f = riscv.featureSetHas(features, .f);
607 const has_d = riscv.featureSetHas(features, .d);
608 return switch (target_abi) {
609 .lp64 => {},
610 .lp64f => if (has_f) {} else error.FeatureAbiMismatch,
611 .lp64d => if (has_d) {} else error.FeatureAbiMismatch,
612 else => error.ArchAbiMismatch,
613 };
614 }
615 };
616 pub fn default(arch: Cpu.Arch, features: Cpu.Feature.Set) ?TargetAbi {
617 return switch (arch) {
618 .riscv32 => Riscv32ABI.default(features),
619 .riscv64 => Riscv64ABI.default(features),
620 else => null,
621 };
622 }
623
624 pub const ParseError = error{
625 InvalidAbi,
626 ArchAbiMismatch,
627 FeatureAbiMismatch,
628 };
629 pub fn parse(cpu: Cpu, abi_string: []const u8) ParseError!TargetAbi {
630 const target_abi = std.meta.stringToEnum(TargetAbi, abi_string) orelse return error.InvalidAbi;
631
632 switch (cpu.arch) {
633 .riscv32 => try Riscv32ABI.validate(target_abi, cpu.features),
634 .riscv64 => try Riscv64ABI.validate(target_abi, cpu.features),
635 else => return error.ArchAbiMismatch,
636 }
637 return target_abi;
638 }
639 };
640
641 pub const ObjectFormat = enum {563 pub const ObjectFormat = enum {
642 /// Common Object File Format (Windows)564 /// Common Object File Format (Windows)
643 coff,565 coff,
src/Compilation.zig+6-14
...@@ -767,7 +767,6 @@ pub const InitOptions = struct {...@@ -767,7 +767,6 @@ pub const InitOptions = struct {
767 compatibility_version: ?std.builtin.Version = null,767 compatibility_version: ?std.builtin.Version = null,
768 libc_installation: ?*const LibCInstallation = null,768 libc_installation: ?*const LibCInstallation = null,
769 machine_code_model: std.builtin.CodeModel = .default,769 machine_code_model: std.builtin.CodeModel = .default,
770 target_abi: ?std.Target.TargetAbi,
771 clang_preprocessor_mode: ClangPreprocessorMode = .no,770 clang_preprocessor_mode: ClangPreprocessorMode = .no,
772 /// This is for stage1 and should be deleted upon completion of self-hosting.771 /// This is for stage1 and should be deleted upon completion of self-hosting.
773 color: @import("main.zig").Color = .auto,772 color: @import("main.zig").Color = .auto,
...@@ -1183,7 +1182,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1183,7 +1182,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1183 cache.hash.add(options.target.os.getVersionRange());1182 cache.hash.add(options.target.os.getVersionRange());
1184 cache.hash.add(options.is_native_os);1183 cache.hash.add(options.is_native_os);
1185 cache.hash.add(options.target.abi);1184 cache.hash.add(options.target.abi);
1186 cache.hash.addOptionalBytes(if (options.target_abi) |t| @tagName(t) else null);
1187 cache.hash.add(ofmt);1185 cache.hash.add(ofmt);
1188 cache.hash.add(pic);1186 cache.hash.add(pic);
1189 cache.hash.add(pie);1187 cache.hash.add(pie);
...@@ -1496,7 +1494,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1496,7 +1494,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1496 .single_threaded = single_threaded,1494 .single_threaded = single_threaded,
1497 .verbose_link = options.verbose_link,1495 .verbose_link = options.verbose_link,
1498 .machine_code_model = options.machine_code_model,1496 .machine_code_model = options.machine_code_model,
1499 .target_abi = options.target_abi,
1500 .dll_export_fns = dll_export_fns,1497 .dll_export_fns = dll_export_fns,
1501 .error_return_tracing = error_return_tracing,1498 .error_return_tracing = error_return_tracing,
1502 .llvm_cpu_features = llvm_cpu_features,1499 .llvm_cpu_features = llvm_cpu_features,
...@@ -3460,9 +3457,6 @@ pub fn addCCArgs(...@@ -3460,9 +3457,6 @@ pub fn addCCArgs(
3460 try argv.append("-mthumb");3457 try argv.append("-mthumb");
3461 }3458 }
34623459
3463 if (comp.bin_file.options.target_abi) |target_abi| {
3464 try argv.append(try std.fmt.allocPrint(arena, "-mabi={s}", .{@tagName(target_abi)}));
3465 }
3466 if (comp.sanitize_c and !comp.bin_file.options.tsan) {3460 if (comp.sanitize_c and !comp.bin_file.options.tsan) {
3467 try argv.append("-fsanitize=undefined");3461 try argv.append("-fsanitize=undefined");
3468 try argv.append("-fsanitize-trap=undefined");3462 try argv.append("-fsanitize-trap=undefined");
...@@ -3595,11 +3589,6 @@ pub fn addCCArgs(...@@ -3595,11 +3589,6 @@ pub fn addCCArgs(
3595 // TODO3589 // TODO
3596 },3590 },
3597 }3591 }
3598
3599 if (comp.bin_file.options.target_abi) |target_abi| {
3600 try argv.append(try std.fmt.allocPrint(arena, "-mabi={s}", .{@tagName(target_abi)}));
3601 }
3602
3603 if (target_util.clangAssemblerSupportsMcpuArg(target)) {3592 if (target_util.clangAssemblerSupportsMcpuArg(target)) {
3604 if (target.cpu.model.llvm_name) |llvm_name| {3593 if (target.cpu.model.llvm_name) |llvm_name| {
3605 try argv.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{llvm_name}));3594 try argv.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{llvm_name}));
...@@ -3607,6 +3596,11 @@ pub fn addCCArgs(...@@ -3607,6 +3596,11 @@ pub fn addCCArgs(
3607 }3596 }
3608 },3597 },
3609 }3598 }
3599
3600 if (target_util.llvmMachineAbi(target)) |mabi| {
3601 try argv.append(try std.fmt.allocPrint(arena, "-mabi={s}", .{mabi}));
3602 }
3603
3610 if (out_dep_path) |p| {3604 if (out_dep_path) |p| {
3611 try argv.appendSlice(&[_][]const u8{ "-MD", "-MV", "-MF", p });3605 try argv.appendSlice(&[_][]const u8{ "-MD", "-MV", "-MF", p });
3612 }3606 }
...@@ -4395,7 +4389,6 @@ fn buildOutputFromZig(...@@ -4395,7 +4389,6 @@ fn buildOutputFromZig(
4395 .strip = comp.compilerRtStrip(),4389 .strip = comp.compilerRtStrip(),
4396 .is_native_os = comp.bin_file.options.is_native_os,4390 .is_native_os = comp.bin_file.options.is_native_os,
4397 .is_native_abi = comp.bin_file.options.is_native_abi,4391 .is_native_abi = comp.bin_file.options.is_native_abi,
4398 .target_abi = comp.bin_file.options.target_abi,
4399 .self_exe_path = comp.self_exe_path,4392 .self_exe_path = comp.self_exe_path,
4400 .verbose_cc = comp.verbose_cc,4393 .verbose_cc = comp.verbose_cc,
4401 .verbose_link = comp.bin_file.options.verbose_link,4394 .verbose_link = comp.bin_file.options.verbose_link,
...@@ -4584,7 +4577,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -4584,7 +4577,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
4584 .is_native_cpu = false, // Only true when bootstrapping the compiler.4577 .is_native_cpu = false, // Only true when bootstrapping the compiler.
4585 .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null,4578 .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null,
4586 .llvm_cpu_features = comp.bin_file.options.llvm_cpu_features.?,4579 .llvm_cpu_features = comp.bin_file.options.llvm_cpu_features.?,
4587 .llvm_target_abi = if (comp.bin_file.options.target_abi) |t| @tagName(t) else null,4580 .llvm_target_abi = if (target_util.llvmMachineAbi(target)) |s| s.ptr else null,
4588 };4581 };
45894582
4590 comp.stage1_cache_manifest = &man;4583 comp.stage1_cache_manifest = &man;
...@@ -4836,7 +4829,6 @@ pub fn build_crt_file(...@@ -4836,7 +4829,6 @@ pub fn build_crt_file(
4836 .strip = comp.compilerRtStrip(),4829 .strip = comp.compilerRtStrip(),
4837 .is_native_os = comp.bin_file.options.is_native_os,4830 .is_native_os = comp.bin_file.options.is_native_os,
4838 .is_native_abi = comp.bin_file.options.is_native_abi,4831 .is_native_abi = comp.bin_file.options.is_native_abi,
4839 .target_abi = comp.bin_file.options.target_abi,
4840 .self_exe_path = comp.self_exe_path,4832 .self_exe_path = comp.self_exe_path,
4841 .c_source_files = c_source_files,4833 .c_source_files = c_source_files,
4842 .verbose_cc = comp.verbose_cc,4834 .verbose_cc = comp.verbose_cc,
src/codegen/llvm.zig+2-3
...@@ -15,6 +15,7 @@ const TypedValue = @import("../TypedValue.zig");...@@ -15,6 +15,7 @@ const TypedValue = @import("../TypedValue.zig");
15const Zir = @import("../Zir.zig");15const Zir = @import("../Zir.zig");
16const Air = @import("../Air.zig");16const Air = @import("../Air.zig");
17const Liveness = @import("../Liveness.zig");17const Liveness = @import("../Liveness.zig");
18const target_util = @import("../target.zig");
1819
19const Value = @import("../value.zig").Value;20const Value = @import("../value.zig").Value;
20const Type = @import("../type.zig").Type;21const Type = @import("../type.zig").Type;
...@@ -244,8 +245,6 @@ pub const Object = struct {...@@ -244,8 +245,6 @@ pub const Object = struct {
244 // TODO handle float ABI better- it should depend on the ABI portion of std.Target245 // TODO handle float ABI better- it should depend on the ABI portion of std.Target
245 const float_abi: llvm.ABIType = .Default;246 const float_abi: llvm.ABIType = .Default;
246247
247 const abi_name: ?[*:0]const u8 = if (options.target_abi) |t| @tagName(t) else null;
248
249 const target_machine = llvm.TargetMachine.create(248 const target_machine = llvm.TargetMachine.create(
250 target,249 target,
251 llvm_target_triple.ptr,250 llvm_target_triple.ptr,
...@@ -256,7 +255,7 @@ pub const Object = struct {...@@ -256,7 +255,7 @@ pub const Object = struct {
256 code_model,255 code_model,
257 options.function_sections,256 options.function_sections,
258 float_abi,257 float_abi,
259 abi_name,258 if (target_util.llvmMachineAbi(options.target)) |s| s.ptr else null,
260 );259 );
261 errdefer target_machine.dispose();260 errdefer target_machine.dispose();
262261
src/glibc.zig-1
...@@ -961,7 +961,6 @@ fn buildSharedLib(...@@ -961,7 +961,6 @@ fn buildSharedLib(
961 .strip = comp.compilerRtStrip(),961 .strip = comp.compilerRtStrip(),
962 .is_native_os = false,962 .is_native_os = false,
963 .is_native_abi = false,963 .is_native_abi = false,
964 .target_abi = comp.bin_file.options.target_abi,
965 .self_exe_path = comp.self_exe_path,964 .self_exe_path = comp.self_exe_path,
966 .verbose_cc = comp.verbose_cc,965 .verbose_cc = comp.verbose_cc,
967 .verbose_link = comp.bin_file.options.verbose_link,966 .verbose_link = comp.bin_file.options.verbose_link,
src/libcxx.zig-2
...@@ -200,7 +200,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -200,7 +200,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
200 .strip = comp.compilerRtStrip(),200 .strip = comp.compilerRtStrip(),
201 .is_native_os = comp.bin_file.options.is_native_os,201 .is_native_os = comp.bin_file.options.is_native_os,
202 .is_native_abi = comp.bin_file.options.is_native_abi,202 .is_native_abi = comp.bin_file.options.is_native_abi,
203 .target_abi = comp.bin_file.options.target_abi,
204 .self_exe_path = comp.self_exe_path,203 .self_exe_path = comp.self_exe_path,
205 .c_source_files = c_source_files.items,204 .c_source_files = c_source_files.items,
206 .verbose_cc = comp.verbose_cc,205 .verbose_cc = comp.verbose_cc,
...@@ -333,7 +332,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -333,7 +332,6 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
333 .strip = comp.compilerRtStrip(),332 .strip = comp.compilerRtStrip(),
334 .is_native_os = comp.bin_file.options.is_native_os,333 .is_native_os = comp.bin_file.options.is_native_os,
335 .is_native_abi = comp.bin_file.options.is_native_abi,334 .is_native_abi = comp.bin_file.options.is_native_abi,
336 .target_abi = comp.bin_file.options.target_abi,
337 .self_exe_path = comp.self_exe_path,335 .self_exe_path = comp.self_exe_path,
338 .c_source_files = c_source_files.items,336 .c_source_files = c_source_files.items,
339 .verbose_cc = comp.verbose_cc,337 .verbose_cc = comp.verbose_cc,
src/libtsan.zig-1
...@@ -218,7 +218,6 @@ pub fn buildTsan(comp: *Compilation) !void {...@@ -218,7 +218,6 @@ pub fn buildTsan(comp: *Compilation) !void {
218 .strip = comp.compilerRtStrip(),218 .strip = comp.compilerRtStrip(),
219 .is_native_os = comp.bin_file.options.is_native_os,219 .is_native_os = comp.bin_file.options.is_native_os,
220 .is_native_abi = comp.bin_file.options.is_native_abi,220 .is_native_abi = comp.bin_file.options.is_native_abi,
221 .target_abi = comp.bin_file.options.target_abi,
222 .self_exe_path = comp.self_exe_path,221 .self_exe_path = comp.self_exe_path,
223 .c_source_files = c_source_files.items,222 .c_source_files = c_source_files.items,
224 .verbose_cc = comp.verbose_cc,223 .verbose_cc = comp.verbose_cc,
src/libunwind.zig-1
...@@ -124,7 +124,6 @@ pub fn buildStaticLib(comp: *Compilation) !void {...@@ -124,7 +124,6 @@ pub fn buildStaticLib(comp: *Compilation) !void {
124 .strip = comp.compilerRtStrip(),124 .strip = comp.compilerRtStrip(),
125 .is_native_os = comp.bin_file.options.is_native_os,125 .is_native_os = comp.bin_file.options.is_native_os,
126 .is_native_abi = comp.bin_file.options.is_native_abi,126 .is_native_abi = comp.bin_file.options.is_native_abi,
127 .target_abi = comp.bin_file.options.target_abi,
128 .self_exe_path = comp.self_exe_path,127 .self_exe_path = comp.self_exe_path,
129 .c_source_files = &c_source_files,128 .c_source_files = &c_source_files,
130 .verbose_cc = comp.verbose_cc,129 .verbose_cc = comp.verbose_cc,
src/link.zig-1
...@@ -134,7 +134,6 @@ pub const Options = struct {...@@ -134,7 +134,6 @@ pub const Options = struct {
134 version_script: ?[]const u8,134 version_script: ?[]const u8,
135 soname: ?[]const u8,135 soname: ?[]const u8,
136 llvm_cpu_features: ?[*:0]const u8,136 llvm_cpu_features: ?[*:0]const u8,
137 target_abi: ?std.Target.TargetAbi,
138137
139 objects: []const []const u8,138 objects: []const []const u8,
140 framework_dirs: []const []const u8,139 framework_dirs: []const []const u8,
src/main.zig-16
...@@ -328,7 +328,6 @@ const usage_build_generic =...@@ -328,7 +328,6 @@ const usage_build_generic =
328 \\Compile Options:328 \\Compile Options:
329 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command329 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
330 \\ -mcpu [cpu] Specify target CPU and feature set330 \\ -mcpu [cpu] Specify target CPU and feature set
331 \\ -mabi [target-abi] Specify processor specific target-abi
332 \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses331 \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses
333 \\ small|kernel|332 \\ small|kernel|
334 \\ medium|large]333 \\ medium|large]
...@@ -654,7 +653,6 @@ fn buildOutputType(...@@ -654,7 +653,6 @@ fn buildOutputType(
654 var sysroot: ?[]const u8 = null;653 var sysroot: ?[]const u8 = null;
655 var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC");654 var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC");
656 var machine_code_model: std.builtin.CodeModel = .default;655 var machine_code_model: std.builtin.CodeModel = .default;
657 var target_abi_str: ?[]const u8 = null;
658 var runtime_args_start: ?usize = null;656 var runtime_args_start: ?usize = null;
659 var test_filter: ?[]const u8 = null;657 var test_filter: ?[]const u8 = null;
660 var test_name_prefix: ?[]const u8 = null;658 var test_name_prefix: ?[]const u8 = null;
...@@ -928,12 +926,6 @@ fn buildOutputType(...@@ -928,12 +926,6 @@ fn buildOutputType(
928 target_mcpu = arg["-mcpu=".len..];926 target_mcpu = arg["-mcpu=".len..];
929 } else if (mem.startsWith(u8, arg, "-mcmodel=")) {927 } else if (mem.startsWith(u8, arg, "-mcmodel=")) {
930 machine_code_model = parseCodeModel(arg["-mcmodel=".len..]);928 machine_code_model = parseCodeModel(arg["-mcmodel=".len..]);
931 } else if (mem.eql(u8, arg, "-mabi")) {
932 if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg});
933 i += 1;
934 target_abi_str = args[i];
935 } else if (mem.startsWith(u8, arg, "-mabi=")) {
936 target_abi_str = arg["-mabi=".len..];
937 } else if (mem.startsWith(u8, arg, "-O")) {929 } else if (mem.startsWith(u8, arg, "-O")) {
938 optimize_mode_string = arg["-O".len..];930 optimize_mode_string = arg["-O".len..];
939 } else if (mem.eql(u8, arg, "--dynamic-linker")) {931 } else if (mem.eql(u8, arg, "--dynamic-linker")) {
...@@ -1880,12 +1872,6 @@ fn buildOutputType(...@@ -1880,12 +1872,6 @@ fn buildOutputType(
1880 const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options);1872 const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options);
1881 const target_info = try detectNativeTargetInfo(gpa, cross_target);1873 const target_info = try detectNativeTargetInfo(gpa, cross_target);
18821874
1883 const target_abi = if (target_abi_str) |s| std.Target.TargetAbi.parse(target_info.target.cpu, s) catch |err| switch (err) {
1884 error.InvalidAbi => fatal("invalid target-abi value '{s}'", .{target_abi_str}),
1885 error.ArchAbiMismatch => fatal("target-abi {s} is not valid for arch {s}", .{ target_abi_str, target_info.target.cpu.arch }),
1886 error.FeatureAbiMismatch => fatal("target-abi {s} is not compatible with CPU features", .{target_abi_str}),
1887 } else std.Target.TargetAbi.default(target_info.target.cpu.arch, target_info.target.cpu.features);
1888
1889 if (target_info.target.os.tag != .freestanding) {1875 if (target_info.target.os.tag != .freestanding) {
1890 if (ensure_libc_on_non_freestanding)1876 if (ensure_libc_on_non_freestanding)
1891 link_libc = true;1877 link_libc = true;
...@@ -2473,7 +2459,6 @@ fn buildOutputType(...@@ -2473,7 +2459,6 @@ fn buildOutputType(
2473 .verbose_cimport = verbose_cimport,2459 .verbose_cimport = verbose_cimport,
2474 .verbose_llvm_cpu_features = verbose_llvm_cpu_features,2460 .verbose_llvm_cpu_features = verbose_llvm_cpu_features,
2475 .machine_code_model = machine_code_model,2461 .machine_code_model = machine_code_model,
2476 .target_abi = target_abi,
2477 .color = color,2462 .color = color,
2478 .time_report = time_report,2463 .time_report = time_report,
2479 .stack_report = stack_report,2464 .stack_report = stack_report,
...@@ -3397,7 +3382,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -3397,7 +3382,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
3397 .target = target_info.target,3382 .target = target_info.target,
3398 .is_native_os = cross_target.isNativeOs(),3383 .is_native_os = cross_target.isNativeOs(),
3399 .is_native_abi = cross_target.isNativeAbi(),3384 .is_native_abi = cross_target.isNativeAbi(),
3400 .target_abi = std.Target.TargetAbi.default(target_info.target.cpu.arch, target_info.target.cpu.features),
3401 .dynamic_linker = target_info.dynamic_linker.get(),3385 .dynamic_linker = target_info.dynamic_linker.get(),
3402 .output_mode = .Exe,3386 .output_mode = .Exe,
3403 .main_pkg = &main_pkg,3387 .main_pkg = &main_pkg,
src/musl.zig-1
...@@ -214,7 +214,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -214,7 +214,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
214 .strip = comp.compilerRtStrip(),214 .strip = comp.compilerRtStrip(),
215 .is_native_os = false,215 .is_native_os = false,
216 .is_native_abi = false,216 .is_native_abi = false,
217 .target_abi = comp.bin_file.options.target_abi,
218 .self_exe_path = comp.self_exe_path,217 .self_exe_path = comp.self_exe_path,
219 .verbose_cc = comp.verbose_cc,218 .verbose_cc = comp.verbose_cc,
220 .verbose_link = comp.bin_file.options.verbose_link,219 .verbose_link = comp.bin_file.options.verbose_link,
src/target.zig+35
...@@ -599,3 +599,38 @@ pub fn defaultAddressSpace(...@@ -599,3 +599,38 @@ pub fn defaultAddressSpace(
599 _ = context;599 _ = context;
600 return .generic;600 return .generic;
601}601}
602
603pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
604 const have_float = switch (target.abi) {
605 .gnuilp32 => return "ilp32",
606 .gnueabihf, .musleabihf, .eabihf => true,
607 else => false,
608 };
609
610 switch (target.cpu.arch) {
611 .riscv64 => {
612 const featureSetHas = std.Target.riscv.featureSetHas;
613 if (featureSetHas(target.cpu.features, .d)) {
614 return "lp64d";
615 } else if (have_float) {
616 return "lp64f";
617 } else {
618 return "lp64";
619 }
620 },
621 .riscv32 => {
622 const featureSetHas = std.Target.riscv.featureSetHas;
623 if (featureSetHas(target.cpu.features, .d)) {
624 return "ilp32d";
625 } else if (have_float) {
626 return "ilp32f";
627 } else if (featureSetHas(target.cpu.features, .e)) {
628 return "ilp32e";
629 } else {
630 return "ilp32";
631 }
632 },
633 //TODO add ARM, Mips, and PowerPC
634 else => return null,
635 }
636}
src/test.zig-1
...@@ -907,7 +907,6 @@ pub const TestContext = struct {...@@ -907,7 +907,6 @@ pub const TestContext = struct {
907 .object_format = case.object_format,907 .object_format = case.object_format,
908 .is_native_os = case.target.isNativeOs(),908 .is_native_os = case.target.isNativeOs(),
909 .is_native_abi = case.target.isNativeAbi(),909 .is_native_abi = case.target.isNativeAbi(),
910 .target_abi = std.Target.TargetAbi.default(target.cpu.arch, target.cpu.features),
911 .dynamic_linker = target_info.dynamic_linker.get(),910 .dynamic_linker = target_info.dynamic_linker.get(),
912 .link_libc = link_libc,911 .link_libc = link_libc,
913 .use_llvm = use_llvm,912 .use_llvm = use_llvm,