| author | |
| committer | |
| log | ff38f560402aa61ce8e4ae38b4fa0ff2ddbaede6 |
| tree | cc248ce8fc3c3d76d968cb348fc8d130a7e40366 |
| parent | 84704ef43e5414860aa9d3dc0f94f9737404f6e5 |
The target abi can also be set in build.zig via LibExeObjStep.target_abi
The value passed in is checked that it is a valid value in
std.Target.TargetAbi
The target abi is also validated against the target cpu15 files changed, 141 insertions(+), 31 deletions(-)
lib/std/build.zig+4| ... | @@ -1474,6 +1474,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1474,6 +1474,7 @@ 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, | ||
| 1477 | code_model: std.builtin.CodeModel = .default, | 1478 | code_model: std.builtin.CodeModel = .default, |
| 1478 | wasi_exec_model: ?std.builtin.WasiExecModel = null, | 1479 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 1479 | 1480 | ||
| ... | @@ -2458,6 +2459,9 @@ pub const LibExeObjStep = struct { | ... | @@ -2458,6 +2459,9 @@ pub const LibExeObjStep = struct { |
| 2458 | try zig_args.append(builder.fmt("--global-base={d}", .{global_base})); | 2459 | try zig_args.append(builder.fmt("--global-base={d}", .{global_base})); |
| 2459 | } | 2460 | } |
| 2460 | 2461 | ||
| 2462 | if (self.target_abi) |target_abi| { | ||
| 2463 | try zig_args.append(builder.fmt("-mabi={s}", .{@tagName(target_abi)})); | ||
| 2464 | } | ||
| 2461 | if (self.code_model != .default) { | 2465 | if (self.code_model != .default) { |
| 2462 | try zig_args.append("-mcmodel"); | 2466 | try zig_args.append("-mcmodel"); |
| 2463 | try zig_args.append(@tagName(self.code_model)); | 2467 | try zig_args.append(@tagName(self.code_model)); |
lib/std/target.zig+78| ... | @@ -560,6 +560,84 @@ pub const Target = struct { | ... | @@ -560,6 +560,84 @@ pub const Target = struct { |
| 560 | } | 560 | } |
| 561 | }; | 561 | }; |
| 562 | 562 | ||
| 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 | |||
| 563 | pub const ObjectFormat = enum { | 641 | pub const ObjectFormat = enum { |
| 564 | /// Common Object File Format (Windows) | 642 | /// Common Object File Format (Windows) |
| 565 | coff, | 643 | coff, |
src/Compilation.zig+30-16| ... | @@ -767,6 +767,7 @@ pub const InitOptions = struct { | ... | @@ -767,6 +767,7 @@ 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, | ||
| 770 | clang_preprocessor_mode: ClangPreprocessorMode = .no, | 771 | clang_preprocessor_mode: ClangPreprocessorMode = .no, |
| 771 | /// This is for stage1 and should be deleted upon completion of self-hosting. | 772 | /// This is for stage1 and should be deleted upon completion of self-hosting. |
| 772 | color: @import("main.zig").Color = .auto, | 773 | color: @import("main.zig").Color = .auto, |
| ... | @@ -1176,6 +1177,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1176,6 +1177,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1176 | cache.hash.add(options.target.os.getVersionRange()); | 1177 | cache.hash.add(options.target.os.getVersionRange()); |
| 1177 | cache.hash.add(options.is_native_os); | 1178 | cache.hash.add(options.is_native_os); |
| 1178 | cache.hash.add(options.target.abi); | 1179 | cache.hash.add(options.target.abi); |
| 1180 | cache.hash.addOptionalBytes(if (options.target_abi) |t| @tagName(t) else null); | ||
| 1179 | cache.hash.add(ofmt); | 1181 | cache.hash.add(ofmt); |
| 1180 | cache.hash.add(pic); | 1182 | cache.hash.add(pic); |
| 1181 | cache.hash.add(pie); | 1183 | cache.hash.add(pie); |
| ... | @@ -1488,6 +1490,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1488,6 +1490,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1488 | .single_threaded = single_threaded, | 1490 | .single_threaded = single_threaded, |
| 1489 | .verbose_link = options.verbose_link, | 1491 | .verbose_link = options.verbose_link, |
| 1490 | .machine_code_model = options.machine_code_model, | 1492 | .machine_code_model = options.machine_code_model, |
| 1493 | .target_abi = options.target_abi, | ||
| 1491 | .dll_export_fns = dll_export_fns, | 1494 | .dll_export_fns = dll_export_fns, |
| 1492 | .error_return_tracing = error_return_tracing, | 1495 | .error_return_tracing = error_return_tracing, |
| 1493 | .llvm_cpu_features = llvm_cpu_features, | 1496 | .llvm_cpu_features = llvm_cpu_features, |
| ... | @@ -1780,8 +1783,8 @@ pub fn getTarget(self: Compilation) Target { | ... | @@ -1780,8 +1783,8 @@ pub fn getTarget(self: Compilation) Target { |
| 1780 | 1783 | ||
| 1781 | /// Detect changes to source files, perform semantic analysis, and update the output files. | 1784 | /// Detect changes to source files, perform semantic analysis, and update the output files. |
| 1782 | pub fn update(self: *Compilation) !void { | 1785 | pub fn update(self: *Compilation) !void { |
| 1783 | const t = trace(@src()); | 1786 | const tracy_trace = trace(@src()); |
| 1784 | defer t.end(); | 1787 | defer tracy_trace.end(); |
| 1785 | 1788 | ||
| 1786 | self.clearMiscFailures(); | 1789 | self.clearMiscFailures(); |
| 1787 | 1790 | ||
| ... | @@ -2822,8 +2825,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { | ... | @@ -2822,8 +2825,8 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { |
| 2822 | if (!build_options.have_llvm) | 2825 | if (!build_options.have_llvm) |
| 2823 | return error.ZigCompilerNotBuiltWithLLVMExtensions; | 2826 | return error.ZigCompilerNotBuiltWithLLVMExtensions; |
| 2824 | 2827 | ||
| 2825 | const t = trace(@src()); | 2828 | const tracy_trace = trace(@src()); |
| 2826 | defer t.end(); | 2829 | defer tracy_trace.end(); |
| 2827 | 2830 | ||
| 2828 | const cimport_zig_basename = "cimport.zig"; | 2831 | const cimport_zig_basename = "cimport.zig"; |
| 2829 | 2832 | ||
| ... | @@ -3077,8 +3080,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P | ... | @@ -3077,8 +3080,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 3077 | const self_exe_path = comp.self_exe_path orelse | 3080 | const self_exe_path = comp.self_exe_path orelse |
| 3078 | return comp.failCObj(c_object, "clang compilation disabled", .{}); | 3081 | return comp.failCObj(c_object, "clang compilation disabled", .{}); |
| 3079 | 3082 | ||
| 3080 | const t = trace(@src()); | 3083 | const tracy_trace = trace(@src()); |
| 3081 | defer t.end(); | 3084 | defer tracy_trace.end(); |
| 3082 | 3085 | ||
| 3083 | log.debug("updating C object: {s}", .{c_object.src.src_path}); | 3086 | log.debug("updating C object: {s}", .{c_object.src.src_path}); |
| 3084 | 3087 | ||
| ... | @@ -3451,6 +3454,9 @@ pub fn addCCArgs( | ... | @@ -3451,6 +3454,9 @@ pub fn addCCArgs( |
| 3451 | try argv.append("-mthumb"); | 3454 | try argv.append("-mthumb"); |
| 3452 | } | 3455 | } |
| 3453 | 3456 | ||
| 3457 | if (comp.bin_file.options.target_abi) |target_abi| { | ||
| 3458 | try argv.append(try std.fmt.allocPrint(arena, "-mabi={s}", .{@tagName(target_abi)})); | ||
| 3459 | } | ||
| 3454 | if (comp.sanitize_c and !comp.bin_file.options.tsan) { | 3460 | if (comp.sanitize_c and !comp.bin_file.options.tsan) { |
| 3455 | try argv.append("-fsanitize=undefined"); | 3461 | try argv.append("-fsanitize=undefined"); |
| 3456 | try argv.append("-fsanitize-trap=undefined"); | 3462 | try argv.append("-fsanitize-trap=undefined"); |
| ... | @@ -3583,6 +3589,11 @@ pub fn addCCArgs( | ... | @@ -3583,6 +3589,11 @@ pub fn addCCArgs( |
| 3583 | // TODO | 3589 | // TODO |
| 3584 | }, | 3590 | }, |
| 3585 | } | 3591 | } |
| 3592 | |||
| 3593 | if (comp.bin_file.options.target_abi) |target_abi| { | ||
| 3594 | try argv.append(try std.fmt.allocPrint(arena, "-mabi={s}", .{@tagName(target_abi)})); | ||
| 3595 | } | ||
| 3596 | |||
| 3586 | if (target_util.clangAssemblerSupportsMcpuArg(target)) { | 3597 | if (target_util.clangAssemblerSupportsMcpuArg(target)) { |
| 3587 | if (target.cpu.model.llvm_name) |llvm_name| { | 3598 | if (target.cpu.model.llvm_name) |llvm_name| { |
| 3588 | try argv.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{llvm_name})); | 3599 | try argv.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{llvm_name})); |
| ... | @@ -4036,8 +4047,8 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { | ... | @@ -4036,8 +4047,8 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { |
| 4036 | } | 4047 | } |
| 4037 | 4048 | ||
| 4038 | fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { | 4049 | fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { |
| 4039 | const t = trace(@src()); | 4050 | const tracy_trace = trace(@src()); |
| 4040 | defer t.end(); | 4051 | defer tracy_trace.end(); |
| 4041 | 4052 | ||
| 4042 | const source = try comp.generateBuiltinZigSource(comp.gpa); | 4053 | const source = try comp.generateBuiltinZigSource(comp.gpa); |
| 4043 | defer comp.gpa.free(source); | 4054 | defer comp.gpa.free(source); |
| ... | @@ -4074,8 +4085,8 @@ pub fn dump_argv(argv: []const []const u8) void { | ... | @@ -4074,8 +4085,8 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 4074 | } | 4085 | } |
| 4075 | 4086 | ||
| 4076 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![]u8 { | 4087 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![]u8 { |
| 4077 | const t = trace(@src()); | 4088 | const tracy_trace = trace(@src()); |
| 4078 | defer t.end(); | 4089 | defer tracy_trace.end(); |
| 4079 | 4090 | ||
| 4080 | var buffer = std.ArrayList(u8).init(allocator); | 4091 | var buffer = std.ArrayList(u8).init(allocator); |
| 4081 | defer buffer.deinit(); | 4092 | defer buffer.deinit(); |
| ... | @@ -4320,8 +4331,8 @@ fn buildOutputFromZig( | ... | @@ -4320,8 +4331,8 @@ fn buildOutputFromZig( |
| 4320 | out: *?CRTFile, | 4331 | out: *?CRTFile, |
| 4321 | misc_task_tag: MiscTask, | 4332 | misc_task_tag: MiscTask, |
| 4322 | ) !void { | 4333 | ) !void { |
| 4323 | const t = trace(@src()); | 4334 | const tracy_trace = trace(@src()); |
| 4324 | defer t.end(); | 4335 | defer tracy_trace.end(); |
| 4325 | 4336 | ||
| 4326 | std.debug.assert(output_mode != .Exe); | 4337 | std.debug.assert(output_mode != .Exe); |
| 4327 | const special_sub = "std" ++ std.fs.path.sep_str ++ "special"; | 4338 | const special_sub = "std" ++ std.fs.path.sep_str ++ "special"; |
| ... | @@ -4378,6 +4389,7 @@ fn buildOutputFromZig( | ... | @@ -4378,6 +4389,7 @@ fn buildOutputFromZig( |
| 4378 | .strip = comp.compilerRtStrip(), | 4389 | .strip = comp.compilerRtStrip(), |
| 4379 | .is_native_os = comp.bin_file.options.is_native_os, | 4390 | .is_native_os = comp.bin_file.options.is_native_os, |
| 4380 | .is_native_abi = comp.bin_file.options.is_native_abi, | 4391 | .is_native_abi = comp.bin_file.options.is_native_abi, |
| 4392 | .target_abi = comp.bin_file.options.target_abi, | ||
| 4381 | .self_exe_path = comp.self_exe_path, | 4393 | .self_exe_path = comp.self_exe_path, |
| 4382 | .verbose_cc = comp.verbose_cc, | 4394 | .verbose_cc = comp.verbose_cc, |
| 4383 | .verbose_link = comp.bin_file.options.verbose_link, | 4395 | .verbose_link = comp.bin_file.options.verbose_link, |
| ... | @@ -4419,8 +4431,8 @@ fn buildOutputFromZig( | ... | @@ -4419,8 +4431,8 @@ fn buildOutputFromZig( |
| 4419 | } | 4431 | } |
| 4420 | 4432 | ||
| 4421 | fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void { | 4433 | fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void { |
| 4422 | const t = trace(@src()); | 4434 | const tracy_trace = trace(@src()); |
| 4423 | defer t.end(); | 4435 | defer tracy_trace.end(); |
| 4424 | 4436 | ||
| 4425 | var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa); | 4437 | var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa); |
| 4426 | defer arena_allocator.deinit(); | 4438 | defer arena_allocator.deinit(); |
| ... | @@ -4566,6 +4578,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node | ... | @@ -4566,6 +4578,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node |
| 4566 | .is_native_cpu = false, // Only true when bootstrapping the compiler. | 4578 | .is_native_cpu = false, // Only true when bootstrapping the compiler. |
| 4567 | .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null, | 4579 | .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null, |
| 4568 | .llvm_cpu_features = comp.bin_file.options.llvm_cpu_features.?, | 4580 | .llvm_cpu_features = comp.bin_file.options.llvm_cpu_features.?, |
| 4581 | .llvm_target_abi = if (comp.bin_file.options.target_abi) |t| @tagName(t) else null, | ||
| 4569 | }; | 4582 | }; |
| 4570 | 4583 | ||
| 4571 | comp.stage1_cache_manifest = &man; | 4584 | comp.stage1_cache_manifest = &man; |
| ... | @@ -4773,8 +4786,8 @@ pub fn build_crt_file( | ... | @@ -4773,8 +4786,8 @@ pub fn build_crt_file( |
| 4773 | output_mode: std.builtin.OutputMode, | 4786 | output_mode: std.builtin.OutputMode, |
| 4774 | c_source_files: []const Compilation.CSourceFile, | 4787 | c_source_files: []const Compilation.CSourceFile, |
| 4775 | ) !void { | 4788 | ) !void { |
| 4776 | const t = trace(@src()); | 4789 | const tracy_trace = trace(@src()); |
| 4777 | defer t.end(); | 4790 | defer tracy_trace.end(); |
| 4778 | 4791 | ||
| 4779 | const target = comp.getTarget(); | 4792 | const target = comp.getTarget(); |
| 4780 | const basename = try std.zig.binNameAlloc(comp.gpa, .{ | 4793 | const basename = try std.zig.binNameAlloc(comp.gpa, .{ |
| ... | @@ -4817,6 +4830,7 @@ pub fn build_crt_file( | ... | @@ -4817,6 +4830,7 @@ pub fn build_crt_file( |
| 4817 | .strip = comp.compilerRtStrip(), | 4830 | .strip = comp.compilerRtStrip(), |
| 4818 | .is_native_os = comp.bin_file.options.is_native_os, | 4831 | .is_native_os = comp.bin_file.options.is_native_os, |
| 4819 | .is_native_abi = comp.bin_file.options.is_native_abi, | 4832 | .is_native_abi = comp.bin_file.options.is_native_abi, |
| 4833 | .target_abi = comp.bin_file.options.target_abi, | ||
| 4820 | .self_exe_path = comp.self_exe_path, | 4834 | .self_exe_path = comp.self_exe_path, |
| 4821 | .c_source_files = c_source_files, | 4835 | .c_source_files = c_source_files, |
| 4822 | .verbose_cc = comp.verbose_cc, | 4836 | .verbose_cc = comp.verbose_cc, |
src/codegen/llvm.zig+1-12| ... | @@ -244,18 +244,7 @@ pub const Object = struct { | ... | @@ -244,18 +244,7 @@ pub const Object = struct { |
| 244 | // TODO handle float ABI better- it should depend on the ABI portion of std.Target | 244 | // TODO handle float ABI better- it should depend on the ABI portion of std.Target |
| 245 | const float_abi: llvm.ABIType = .Default; | 245 | const float_abi: llvm.ABIType = .Default; |
| 246 | 246 | ||
| 247 | // TODO a way to override this as part of std.Target ABI? | 247 | const abi_name: ?[*:0]const u8 = if (options.target_abi) |t| @tagName(t) else null; |
| 248 | const abi_name: ?[*:0]const u8 = switch (options.target.cpu.arch) { | ||
| 249 | .riscv32 => switch (options.target.os.tag) { | ||
| 250 | .linux => "ilp32d", | ||
| 251 | else => "ilp32", | ||
| 252 | }, | ||
| 253 | .riscv64 => switch (options.target.os.tag) { | ||
| 254 | .linux => "lp64d", | ||
| 255 | else => "lp64", | ||
| 256 | }, | ||
| 257 | else => null, | ||
| 258 | }; | ||
| 259 | 248 | ||
| 260 | const target_machine = llvm.TargetMachine.create( | 249 | const target_machine = llvm.TargetMachine.create( |
| 261 | target, | 250 | target, |
src/glibc.zig+1| ... | @@ -961,6 +961,7 @@ fn buildSharedLib( | ... | @@ -961,6 +961,7 @@ 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, | ||
| 964 | .self_exe_path = comp.self_exe_path, | 965 | .self_exe_path = comp.self_exe_path, |
| 965 | .verbose_cc = comp.verbose_cc, | 966 | .verbose_cc = comp.verbose_cc, |
| 966 | .verbose_link = comp.bin_file.options.verbose_link, | 967 | .verbose_link = comp.bin_file.options.verbose_link, |
src/libcxx.zig+2| ... | @@ -200,6 +200,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { | ... | @@ -200,6 +200,7 @@ 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, | ||
| 203 | .self_exe_path = comp.self_exe_path, | 204 | .self_exe_path = comp.self_exe_path, |
| 204 | .c_source_files = c_source_files.items, | 205 | .c_source_files = c_source_files.items, |
| 205 | .verbose_cc = comp.verbose_cc, | 206 | .verbose_cc = comp.verbose_cc, |
| ... | @@ -332,6 +333,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { | ... | @@ -332,6 +333,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { |
| 332 | .strip = comp.compilerRtStrip(), | 333 | .strip = comp.compilerRtStrip(), |
| 333 | .is_native_os = comp.bin_file.options.is_native_os, | 334 | .is_native_os = comp.bin_file.options.is_native_os, |
| 334 | .is_native_abi = comp.bin_file.options.is_native_abi, | 335 | .is_native_abi = comp.bin_file.options.is_native_abi, |
| 336 | .target_abi = comp.bin_file.options.target_abi, | ||
| 335 | .self_exe_path = comp.self_exe_path, | 337 | .self_exe_path = comp.self_exe_path, |
| 336 | .c_source_files = c_source_files.items, | 338 | .c_source_files = c_source_files.items, |
| 337 | .verbose_cc = comp.verbose_cc, | 339 | .verbose_cc = comp.verbose_cc, |
src/libtsan.zig+1| ... | @@ -218,6 +218,7 @@ pub fn buildTsan(comp: *Compilation) !void { | ... | @@ -218,6 +218,7 @@ 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, | ||
| 221 | .self_exe_path = comp.self_exe_path, | 222 | .self_exe_path = comp.self_exe_path, |
| 222 | .c_source_files = c_source_files.items, | 223 | .c_source_files = c_source_files.items, |
| 223 | .verbose_cc = comp.verbose_cc, | 224 | .verbose_cc = comp.verbose_cc, |
src/libunwind.zig+1| ... | @@ -124,6 +124,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { | ... | @@ -124,6 +124,7 @@ 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, | ||
| 127 | .self_exe_path = comp.self_exe_path, | 128 | .self_exe_path = comp.self_exe_path, |
| 128 | .c_source_files = &c_source_files, | 129 | .c_source_files = &c_source_files, |
| 129 | .verbose_cc = comp.verbose_cc, | 130 | .verbose_cc = comp.verbose_cc, |
src/link.zig+1| ... | @@ -134,6 +134,7 @@ pub const Options = struct { | ... | @@ -134,6 +134,7 @@ 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, | ||
| 137 | 138 | ||
| 138 | objects: []const []const u8, | 139 | objects: []const []const u8, |
| 139 | framework_dirs: []const []const u8, | 140 | framework_dirs: []const []const u8, |
src/main.zig+16| ... | @@ -328,6 +328,7 @@ const usage_build_generic = | ... | @@ -328,6 +328,7 @@ const usage_build_generic = |
| 328 | \\Compile Options: | 328 | \\Compile Options: |
| 329 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command | 329 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command |
| 330 | \\ -mcpu [cpu] Specify target CPU and feature set | 330 | \\ -mcpu [cpu] Specify target CPU and feature set |
| 331 | \\ -mabi [target-abi] Specify processor specific target-abi | ||
| 331 | \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses | 332 | \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses |
| 332 | \\ small|kernel| | 333 | \\ small|kernel| |
| 333 | \\ medium|large] | 334 | \\ medium|large] |
| ... | @@ -653,6 +654,7 @@ fn buildOutputType( | ... | @@ -653,6 +654,7 @@ fn buildOutputType( |
| 653 | var sysroot: ?[]const u8 = null; | 654 | var sysroot: ?[]const u8 = null; |
| 654 | var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); | 655 | var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); |
| 655 | var machine_code_model: std.builtin.CodeModel = .default; | 656 | var machine_code_model: std.builtin.CodeModel = .default; |
| 657 | var target_abi_str: ?[]const u8 = null; | ||
| 656 | var runtime_args_start: ?usize = null; | 658 | var runtime_args_start: ?usize = null; |
| 657 | var test_filter: ?[]const u8 = null; | 659 | var test_filter: ?[]const u8 = null; |
| 658 | var test_name_prefix: ?[]const u8 = null; | 660 | var test_name_prefix: ?[]const u8 = null; |
| ... | @@ -926,6 +928,12 @@ fn buildOutputType( | ... | @@ -926,6 +928,12 @@ fn buildOutputType( |
| 926 | target_mcpu = arg["-mcpu=".len..]; | 928 | target_mcpu = arg["-mcpu=".len..]; |
| 927 | } else if (mem.startsWith(u8, arg, "-mcmodel=")) { | 929 | } else if (mem.startsWith(u8, arg, "-mcmodel=")) { |
| 928 | machine_code_model = parseCodeModel(arg["-mcmodel=".len..]); | 930 | 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..]; | ||
| 929 | } else if (mem.startsWith(u8, arg, "-O")) { | 937 | } else if (mem.startsWith(u8, arg, "-O")) { |
| 930 | optimize_mode_string = arg["-O".len..]; | 938 | optimize_mode_string = arg["-O".len..]; |
| 931 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { | 939 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| ... | @@ -1872,6 +1880,12 @@ fn buildOutputType( | ... | @@ -1872,6 +1880,12 @@ fn buildOutputType( |
| 1872 | const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options); | 1880 | const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options); |
| 1873 | const target_info = try detectNativeTargetInfo(gpa, cross_target); | 1881 | const target_info = try detectNativeTargetInfo(gpa, cross_target); |
| 1874 | 1882 | ||
| 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 | |||
| 1875 | if (target_info.target.os.tag != .freestanding) { | 1889 | if (target_info.target.os.tag != .freestanding) { |
| 1876 | if (ensure_libc_on_non_freestanding) | 1890 | if (ensure_libc_on_non_freestanding) |
| 1877 | link_libc = true; | 1891 | link_libc = true; |
| ... | @@ -2459,6 +2473,7 @@ fn buildOutputType( | ... | @@ -2459,6 +2473,7 @@ fn buildOutputType( |
| 2459 | .verbose_cimport = verbose_cimport, | 2473 | .verbose_cimport = verbose_cimport, |
| 2460 | .verbose_llvm_cpu_features = verbose_llvm_cpu_features, | 2474 | .verbose_llvm_cpu_features = verbose_llvm_cpu_features, |
| 2461 | .machine_code_model = machine_code_model, | 2475 | .machine_code_model = machine_code_model, |
| 2476 | .target_abi = target_abi, | ||
| 2462 | .color = color, | 2477 | .color = color, |
| 2463 | .time_report = time_report, | 2478 | .time_report = time_report, |
| 2464 | .stack_report = stack_report, | 2479 | .stack_report = stack_report, |
| ... | @@ -3382,6 +3397,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -3382,6 +3397,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 3382 | .target = target_info.target, | 3397 | .target = target_info.target, |
| 3383 | .is_native_os = cross_target.isNativeOs(), | 3398 | .is_native_os = cross_target.isNativeOs(), |
| 3384 | .is_native_abi = cross_target.isNativeAbi(), | 3399 | .is_native_abi = cross_target.isNativeAbi(), |
| 3400 | .target_abi = std.Target.TargetAbi.default(target_info.target.cpu.arch, target_info.target.cpu.features), | ||
| 3385 | .dynamic_linker = target_info.dynamic_linker.get(), | 3401 | .dynamic_linker = target_info.dynamic_linker.get(), |
| 3386 | .output_mode = .Exe, | 3402 | .output_mode = .Exe, |
| 3387 | .main_pkg = &main_pkg, | 3403 | .main_pkg = &main_pkg, |
src/musl.zig+1| ... | @@ -214,6 +214,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -214,6 +214,7 @@ 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, | ||
| 217 | .self_exe_path = comp.self_exe_path, | 218 | .self_exe_path = comp.self_exe_path, |
| 218 | .verbose_cc = comp.verbose_cc, | 219 | .verbose_cc = comp.verbose_cc, |
| 219 | .verbose_link = comp.bin_file.options.verbose_link, | 220 | .verbose_link = comp.bin_file.options.verbose_link, |
src/stage1.zig+1| ... | @@ -364,6 +364,7 @@ pub const Stage2Target = extern struct { | ... | @@ -364,6 +364,7 @@ pub const Stage2Target = extern struct { |
| 364 | 364 | ||
| 365 | llvm_cpu_name: ?[*:0]const u8, | 365 | llvm_cpu_name: ?[*:0]const u8, |
| 366 | llvm_cpu_features: ?[*:0]const u8, | 366 | llvm_cpu_features: ?[*:0]const u8, |
| 367 | llvm_target_abi: ?[*:0]const u8, | ||
| 367 | }; | 368 | }; |
| 368 | 369 | ||
| 369 | // ABI warning | 370 | // ABI warning |
src/stage1/codegen.cpp+2-3| ... | @@ -9487,9 +9487,8 @@ static void init(CodeGen *g) { | ... | @@ -9487,9 +9487,8 @@ static void init(CodeGen *g) { |
| 9487 | // TODO handle float ABI better- it should depend on the ABI portion of std.Target | 9487 | // TODO handle float ABI better- it should depend on the ABI portion of std.Target |
| 9488 | ZigLLVMABIType float_abi = ZigLLVMABITypeDefault; | 9488 | ZigLLVMABIType float_abi = ZigLLVMABITypeDefault; |
| 9489 | 9489 | ||
| 9490 | // TODO a way to override this as part of std.Target ABI? | 9490 | const char *abi_name = g->zig_target->llvm_target_abi; |
| 9491 | const char *abi_name = nullptr; | 9491 | if (abi_name == nullptr && target_is_riscv(g->zig_target)) { |
| 9492 | if (target_is_riscv(g->zig_target)) { | ||
| 9493 | // RISC-V Linux defaults to ilp32d/lp64d | 9492 | // RISC-V Linux defaults to ilp32d/lp64d |
| 9494 | if (g->zig_target->os == OsLinux) { | 9493 | if (g->zig_target->os == OsLinux) { |
| 9495 | abi_name = (g->zig_target->arch == ZigLLVM_riscv32) ? "ilp32d" : "lp64d"; | 9494 | abi_name = (g->zig_target->arch == ZigLLVM_riscv32) ? "ilp32d" : "lp64d"; |
src/stage1/stage1.h+1| ... | @@ -112,6 +112,7 @@ struct ZigTarget { | ... | @@ -112,6 +112,7 @@ struct ZigTarget { |
| 112 | 112 | ||
| 113 | const char *llvm_cpu_name; | 113 | const char *llvm_cpu_name; |
| 114 | const char *llvm_cpu_features; | 114 | const char *llvm_cpu_features; |
| 115 | const char *llvm_target_abi; | ||
| 115 | }; | 116 | }; |
| 116 | 117 | ||
| 117 | // ABI warning | 118 | // ABI warning |
src/test.zig+1| ... | @@ -907,6 +907,7 @@ pub const TestContext = struct { | ... | @@ -907,6 +907,7 @@ 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), | ||
| 910 | .dynamic_linker = target_info.dynamic_linker.get(), | 911 | .dynamic_linker = target_info.dynamic_linker.get(), |
| 911 | .link_libc = link_libc, | 912 | .link_libc = link_libc, |
| 912 | .use_llvm = use_llvm, | 913 | .use_llvm = use_llvm, |