authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-16 04:36:40+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-02 10:42:53+01:00
log270fbbcd86b02fcd02ad9b818d9de39dfe671754
treec81290bd31fdbfed3ba1a1d34394e271f30b80f2
parent8045268698bb46e954c886b913fe216c59f5824e
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: Add muslabin32 and muslabi64 tags to Abi.

Once we upgrade to LLVM 20, these should be lowered verbatim rather than to simply musl. Similarly, the special case in llvmMachineAbi() should go away.

10 files changed, 74 insertions(+), 27 deletions(-)

lib/compiler/aro/aro/target.zig+14-3
...@@ -437,9 +437,18 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian...@@ -437,9 +437,18 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian
437 .loongarch64 => "elf64loongarch",437 .loongarch64 => "elf64loongarch",
438 .mips => "elf32btsmip",438 .mips => "elf32btsmip",
439 .mipsel => "elf32ltsmip",439 .mipsel => "elf32ltsmip",
440 .mips64 => if (target.abi == .gnuabin32) "elf32btsmipn32" else "elf64btsmip",440 .mips64 => switch (target.abi) {
441 .mips64el => if (target.abi == .gnuabin32) "elf32ltsmipn32" else "elf64ltsmip",441 .gnuabin32, .muslabin32 => "elf32btsmipn32",
442 .x86_64 => if (target.abi == .gnux32 or target.abi == .muslx32) "elf32_x86_64" else "elf_x86_64",442 else => "elf64btsmip",
443 },
444 .mips64el => switch (target.abi) {
445 .gnuabin32, .muslabin32 => "elf32ltsmipn32",
446 else => "elf64ltsmip",
447 },
448 .x86_64 => switch (target.abi) {
449 .gnux32, .muslx32 => "elf32_x86_64",
450 else => "elf_x86_64",
451 },
443 .ve => "elf64ve",452 .ve => "elf64ve",
444 .csky => "cskyelf_linux",453 .csky => "cskyelf_linux",
445 else => null,454 else => null,
...@@ -691,6 +700,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {...@@ -691,6 +700,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
691 .android => "android",700 .android => "android",
692 .androideabi => "androideabi",701 .androideabi => "androideabi",
693 .musl => "musl",702 .musl => "musl",
703 .muslabin32 => "muslabin32",
704 .muslabi64 => "muslabi64",
694 .musleabi => "musleabi",705 .musleabi => "musleabi",
695 .musleabihf => "musleabihf",706 .musleabihf => "musleabihf",
696 .muslx32 => "muslx32",707 .muslx32 => "muslx32",
lib/std/Target.zig+22-6
...@@ -761,6 +761,8 @@ pub const Abi = enum {...@@ -761,6 +761,8 @@ pub const Abi = enum {
761 android,761 android,
762 androideabi,762 androideabi,
763 musl,763 musl,
764 muslabin32,
765 muslabi64,
764 musleabi,766 musleabi,
765 musleabihf,767 musleabihf,
766 muslx32,768 muslx32,
...@@ -931,6 +933,8 @@ pub const Abi = enum {...@@ -931,6 +933,8 @@ pub const Abi = enum {
931 pub inline fn isMusl(abi: Abi) bool {933 pub inline fn isMusl(abi: Abi) bool {
932 return switch (abi) {934 return switch (abi) {
933 .musl,935 .musl,
936 .muslabin32,
937 .muslabi64,
934 .musleabi,938 .musleabi,
935 .musleabihf,939 .musleabihf,
936 .muslx32,940 .muslx32,
...@@ -2287,9 +2291,9 @@ pub const DynamicLinker = struct {...@@ -2287,9 +2291,9 @@ pub const DynamicLinker = struct {
2287 .mips64,2291 .mips64,
2288 .mips64el,2292 .mips64el,
2289 => |arch| initFmt("/lib/ld-musl-mips{s}{s}{s}.so.1", .{2293 => |arch| initFmt("/lib/ld-musl-mips{s}{s}{s}.so.1", .{
2290 // TODO: `n32` ABI support in LLVM 20.
2291 switch (abi) {2294 switch (abi) {
2292 .musl => "64",2295 .muslabi64 => "64",
2296 .muslabin32 => "n32",
2293 else => return none,2297 else => return none,
2294 },2298 },
2295 if (mips.featureSetHas(cpu.features, .mips64r6)) "r6" else "",2299 if (mips.featureSetHas(cpu.features, .mips64r6)) "r6" else "",
...@@ -2584,8 +2588,8 @@ pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {...@@ -2584,8 +2588,8 @@ pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {
25842588
2585pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {2589pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
2586 switch (abi) {2590 switch (abi) {
2587 .gnux32, .muslx32, .gnuabin32, .gnuilp32, .ilp32 => return 32,2591 .gnux32, .muslx32, .gnuabin32, .muslabin32, .gnuilp32, .ilp32 => return 32,
2588 .gnuabi64 => return 64,2592 .gnuabi64, .muslabi64 => return 64,
2589 else => {},2593 else => {},
2590 }2594 }
2591 return switch (cpu.arch) {2595 return switch (cpu.arch) {
...@@ -2788,7 +2792,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -2788,7 +2792,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2788 .char => return 8,2792 .char => return 8,
2789 .short, .ushort => return 16,2793 .short, .ushort => return 16,
2790 .int, .uint, .float => return 32,2794 .int, .uint, .float => return 32,
2791 .long, .ulong => return if (target.abi != .gnuabin32) 64 else 32,2795 .long, .ulong => switch (target.abi) {
2796 .gnuabin32, .muslabin32 => return 32,
2797 else => return 64,
2798 },
2792 .longlong, .ulonglong, .double => return 64,2799 .longlong, .ulonglong, .double => return 64,
2793 .longdouble => return 128,2800 .longdouble => return 128,
2794 },2801 },
...@@ -2821,6 +2828,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -2821,6 +2828,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2821 .powerpc64le,2828 .powerpc64le,
2822 => switch (target.abi) {2829 => switch (target.abi) {
2823 .musl,2830 .musl,
2831 .muslabin32,
2832 .muslabi64,
2824 .musleabi,2833 .musleabi,
2825 .musleabihf,2834 .musleabihf,
2826 .muslx32,2835 .muslx32,
...@@ -2876,7 +2885,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -2876,7 +2885,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2876 .char => return 8,2885 .char => return 8,
2877 .short, .ushort => return 16,2886 .short, .ushort => return 16,
2878 .int, .uint, .float => return 32,2887 .int, .uint, .float => return 32,
2879 .long, .ulong => return if (target.abi != .gnuabin32) 64 else 32,2888 .long, .ulong => switch (target.abi) {
2889 .gnuabin32, .muslabin32 => return 32,
2890 else => return 64,
2891 },
2880 .longlong, .ulonglong, .double => return 64,2892 .longlong, .ulonglong, .double => return 64,
2881 .longdouble => if (target.os.tag == .freebsd) return 64 else return 128,2893 .longdouble => if (target.os.tag == .freebsd) return 64 else return 128,
2882 },2894 },
...@@ -2907,6 +2919,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -2907,6 +2919,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2907 .powerpcle,2919 .powerpcle,
2908 => switch (target.abi) {2920 => switch (target.abi) {
2909 .musl,2921 .musl,
2922 .muslabin32,
2923 .muslabi64,
2910 .musleabi,2924 .musleabi,
2911 .musleabihf,2925 .musleabihf,
2912 .muslx32,2926 .muslx32,
...@@ -2921,6 +2935,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {...@@ -2921,6 +2935,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
2921 .powerpc64le,2935 .powerpc64le,
2922 => switch (target.abi) {2936 => switch (target.abi) {
2923 .musl,2937 .musl,
2938 .muslabin32,
2939 .muslabi64,
2924 .musleabi,2940 .musleabi,
2925 .musleabihf,2941 .musleabihf,
2926 .muslx32,2942 .muslx32,
lib/std/os/linux.zig+6-6
...@@ -136,10 +136,10 @@ pub const SYS = switch (@import("builtin").cpu.arch) {...@@ -136,10 +136,10 @@ pub const SYS = switch (@import("builtin").cpu.arch) {
136 .loongarch64 => syscalls.LoongArch64,136 .loongarch64 => syscalls.LoongArch64,
137 .m68k => syscalls.M68k,137 .m68k => syscalls.M68k,
138 .mips, .mipsel => syscalls.MipsO32,138 .mips, .mipsel => syscalls.MipsO32,
139 .mips64, .mips64el => if (builtin.abi == .gnuabin32)139 .mips64, .mips64el => switch (builtin.abi) {
140 syscalls.MipsN32140 .gnuabin32, .muslabin32 => syscalls.MipsN32,
141 else141 else => syscalls.MipsN64,
142 syscalls.MipsN64,142 },
143 .powerpc, .powerpcle => syscalls.PowerPC,143 .powerpc, .powerpcle => syscalls.PowerPC,
144 .powerpc64, .powerpc64le => syscalls.PowerPC64,144 .powerpc64, .powerpc64le => syscalls.PowerPC64,
145 .s390x => syscalls.S390x,145 .s390x => syscalls.S390x,
...@@ -8657,11 +8657,11 @@ pub const AUDIT = struct {...@@ -8657,11 +8657,11 @@ pub const AUDIT = struct {
8657 .mips => .MIPS,8657 .mips => .MIPS,
8658 .mipsel => .MIPSEL,8658 .mipsel => .MIPSEL,
8659 .mips64 => switch (native_abi) {8659 .mips64 => switch (native_abi) {
8660 .gnuabin32 => .MIPS64N32,8660 .gnuabin32, .muslabin32 => .MIPS64N32,
8661 else => .MIPS64,8661 else => .MIPS64,
8662 },8662 },
8663 .mips64el => switch (native_abi) {8663 .mips64el => switch (native_abi) {
8664 .gnuabin32 => .MIPSEL64N32,8664 .gnuabin32, .muslabin32 => .MIPSEL64N32,
8665 else => .MIPSEL64,8665 else => .MIPSEL64,
8666 },8666 },
8667 .powerpc => .PPC,8667 .powerpc => .PPC,
lib/std/zig/LibCDirs.zig+2
...@@ -232,6 +232,8 @@ fn libCGenericName(target: std.Target) [:0]const u8 {...@@ -232,6 +232,8 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
232 .gnuilp32,232 .gnuilp32,
233 => return "glibc",233 => return "glibc",
234 .musl,234 .musl,
235 .muslabin32,
236 .muslabi64,
235 .musleabi,237 .musleabi,
236 .musleabihf,238 .musleabihf,
237 .muslx32,239 .muslx32,
lib/std/zig/system.zig+8-8
...@@ -91,16 +91,16 @@ pub fn getExternalExecutor(...@@ -91,16 +91,16 @@ pub fn getExternalExecutor(
91 .mips => Executor{ .qemu = "qemu-mips" },91 .mips => Executor{ .qemu = "qemu-mips" },
92 .mipsel => Executor{ .qemu = "qemu-mipsel" },92 .mipsel => Executor{ .qemu = "qemu-mipsel" },
93 .mips64 => Executor{93 .mips64 => Executor{
94 .qemu = if (candidate.abi == .gnuabin32)94 .qemu = switch (candidate.abi) {
95 "qemu-mipsn32"95 .gnuabin32, .muslabin32 => "qemu-mipsn32",
96 else96 else => "qemu-mips64",
97 "qemu-mips64",97 },
98 },98 },
99 .mips64el => Executor{99 .mips64el => Executor{
100 .qemu = if (candidate.abi == .gnuabin32)100 .qemu = switch (candidate.abi) {
101 "qemu-mipsn32el"101 .gnuabin32, .muslabin32 => "qemu-mipsn32el",
102 else102 else => "qemu-mips64el",
103 "qemu-mips64el",103 },
104 },104 },
105 .powerpc => Executor{ .qemu = "qemu-ppc" },105 .powerpc => Executor{ .qemu = "qemu-ppc" },
106 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },106 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
lib/std/zig/target.zig+2
...@@ -99,6 +99,7 @@ pub fn canBuildLibC(target: std.Target) bool {...@@ -99,6 +99,7 @@ pub fn canBuildLibC(target: std.Target) bool {
9999
100pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 {100pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 {
101 return switch (abi) {101 return switch (abi) {
102 .muslabin32 => "mipsn32",
102 .muslx32 => "x32",103 .muslx32 => "x32",
103 else => switch (arch) {104 else => switch (arch) {
104 .arm, .armeb, .thumb, .thumbeb => "arm",105 .arm, .armeb, .thumb, .thumbeb => "arm",
...@@ -129,6 +130,7 @@ pub fn muslArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {...@@ -129,6 +130,7 @@ pub fn muslArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {
129130
130pub fn muslAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {131pub fn muslAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {
131 return switch (abi) {132 return switch (abi) {
133 .muslabin32 => "mipsn32",
132 .muslx32 => "muslx32",134 .muslx32 => "muslx32",
133 else => "musl",135 else => "musl",
134 };136 };
src/codegen/llvm.zig+2
...@@ -270,6 +270,8 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {...@@ -270,6 +270,8 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
270 .android => "android",270 .android => "android",
271 .androideabi => "androideabi",271 .androideabi => "androideabi",
272 .musl => "musl",272 .musl => "musl",
273 .muslabin32 => "musl", // Should be muslabin32 in LLVM 20.
274 .muslabi64 => "musl", // Should be muslabi64 in LLVM 20.
273 .musleabi => "musleabi",275 .musleabi => "musleabi",
274 .musleabihf => "musleabihf",276 .musleabihf => "musleabihf",
275 .muslx32 => "muslx32",277 .muslx32 => "muslx32",
src/link/Elf.zig+4-4
...@@ -4100,21 +4100,21 @@ fn getLDMOption(target: std.Target) ?[]const u8 {...@@ -4100,21 +4100,21 @@ fn getLDMOption(target: std.Target) ?[]const u8 {
4100 },4100 },
4101 .mips64 => switch (target.os.tag) {4101 .mips64 => switch (target.os.tag) {
4102 .freebsd => switch (target.abi) {4102 .freebsd => switch (target.abi) {
4103 .gnuabin32 => "elf32btsmipn32_fbsd",4103 .gnuabin32, .muslabin32 => "elf32btsmipn32_fbsd",
4104 else => "elf64btsmip_fbsd",4104 else => "elf64btsmip_fbsd",
4105 },4105 },
4106 else => switch (target.abi) {4106 else => switch (target.abi) {
4107 .gnuabin32 => "elf32btsmipn32",4107 .gnuabin32, .muslabin32 => "elf32btsmipn32",
4108 else => "elf64btsmip",4108 else => "elf64btsmip",
4109 },4109 },
4110 },4110 },
4111 .mips64el => switch (target.os.tag) {4111 .mips64el => switch (target.os.tag) {
4112 .freebsd => switch (target.abi) {4112 .freebsd => switch (target.abi) {
4113 .gnuabin32 => "elf32ltsmipn32_fbsd",4113 .gnuabin32, .muslabin32 => "elf32ltsmipn32_fbsd",
4114 else => "elf64ltsmip_fbsd",4114 else => "elf64ltsmip_fbsd",
4115 },4115 },
4116 else => switch (target.abi) {4116 else => switch (target.abi) {
4117 .gnuabin32 => "elf32ltsmipn32",4117 .gnuabin32, .muslabin32 => "elf32ltsmipn32",
4118 else => "elf64ltsmip",4118 else => "elf64ltsmip",
4119 },4119 },
4120 },4120 },
src/target.zig+10
...@@ -438,6 +438,16 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {...@@ -438,6 +438,16 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
438}438}
439439
440pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {440pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
441 // This special-casing should be removed with LLVM 20.
442 switch (target.cpu.arch) {
443 .mips, .mipsel => return "o32",
444 .mips64, .mips64el => return switch (target.abi) {
445 .gnuabin32, .muslabin32 => "n32",
446 else => "n64",
447 },
448 else => {},
449 }
450
441 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it451 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
442 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc452 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
443 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about453 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about
test/llvm_targets.zig+4
...@@ -161,6 +161,8 @@ const targets = [_]std.Target.Query{...@@ -161,6 +161,8 @@ const targets = [_]std.Target.Query{
161 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 },161 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 },
162 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabin32 },162 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabin32 },
163 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .musl },163 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .musl },
164 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .muslabi64 },
165 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .muslabin32 },
164 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .none },166 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .none },
165 .{ .cpu_arch = .mips64, .os_tag = .netbsd, .abi = .none },167 .{ .cpu_arch = .mips64, .os_tag = .netbsd, .abi = .none },
166 .{ .cpu_arch = .mips64, .os_tag = .openbsd, .abi = .none },168 .{ .cpu_arch = .mips64, .os_tag = .openbsd, .abi = .none },
...@@ -170,6 +172,8 @@ const targets = [_]std.Target.Query{...@@ -170,6 +172,8 @@ const targets = [_]std.Target.Query{
170 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 },172 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 },
171 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabin32 },173 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabin32 },
172 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .musl },174 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .musl },
175 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .muslabi64 },
176 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .muslabin32 },
173 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .none },177 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .none },
174 .{ .cpu_arch = .mips64el, .os_tag = .netbsd, .abi = .none },178 .{ .cpu_arch = .mips64el, .os_tag = .netbsd, .abi = .none },
175 .{ .cpu_arch = .mips64el, .os_tag = .openbsd, .abi = .none },179 .{ .cpu_arch = .mips64el, .os_tag = .openbsd, .abi = .none },