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
437437 .loongarch64 => "elf64loongarch",
438438 .mips => "elf32btsmip",
439439 .mipsel => "elf32ltsmip",
440 .mips64 => if (target.abi == .gnuabin32) "elf32btsmipn32" else "elf64btsmip",
441 .mips64el => if (target.abi == .gnuabin32) "elf32ltsmipn32" else "elf64ltsmip",
442 .x86_64 => if (target.abi == .gnux32 or target.abi == .muslx32) "elf32_x86_64" else "elf_x86_64",
440 .mips64 => switch (target.abi) {
441 .gnuabin32, .muslabin32 => "elf32btsmipn32",
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 },
443452 .ve => "elf64ve",
444453 .csky => "cskyelf_linux",
445454 else => null,
......@@ -691,6 +700,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
691700 .android => "android",
692701 .androideabi => "androideabi",
693702 .musl => "musl",
703 .muslabin32 => "muslabin32",
704 .muslabi64 => "muslabi64",
694705 .musleabi => "musleabi",
695706 .musleabihf => "musleabihf",
696707 .muslx32 => "muslx32",
lib/std/Target.zig+22-6
......@@ -761,6 +761,8 @@ pub const Abi = enum {
761761 android,
762762 androideabi,
763763 musl,
764 muslabin32,
765 muslabi64,
764766 musleabi,
765767 musleabihf,
766768 muslx32,
......@@ -931,6 +933,8 @@ pub const Abi = enum {
931933 pub inline fn isMusl(abi: Abi) bool {
932934 return switch (abi) {
933935 .musl,
936 .muslabin32,
937 .muslabi64,
934938 .musleabi,
935939 .musleabihf,
936940 .muslx32,
......@@ -2287,9 +2291,9 @@ pub const DynamicLinker = struct {
22872291 .mips64,
22882292 .mips64el,
22892293 => |arch| initFmt("/lib/ld-musl-mips{s}{s}{s}.so.1", .{
2290 // TODO: `n32` ABI support in LLVM 20.
22912294 switch (abi) {
2292 .musl => "64",
2295 .muslabi64 => "64",
2296 .muslabin32 => "n32",
22932297 else => return none,
22942298 },
22952299 if (mips.featureSetHas(cpu.features, .mips64r6)) "r6" else "",
......@@ -2584,8 +2588,8 @@ pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {
25842588
25852589pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
25862590 switch (abi) {
2587 .gnux32, .muslx32, .gnuabin32, .gnuilp32, .ilp32 => return 32,
2588 .gnuabi64 => return 64,
2591 .gnux32, .muslx32, .gnuabin32, .muslabin32, .gnuilp32, .ilp32 => return 32,
2592 .gnuabi64, .muslabi64 => return 64,
25892593 else => {},
25902594 }
25912595 return switch (cpu.arch) {
......@@ -2788,7 +2792,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
27882792 .char => return 8,
27892793 .short, .ushort => return 16,
27902794 .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 },
27922799 .longlong, .ulonglong, .double => return 64,
27932800 .longdouble => return 128,
27942801 },
......@@ -2821,6 +2828,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
28212828 .powerpc64le,
28222829 => switch (target.abi) {
28232830 .musl,
2831 .muslabin32,
2832 .muslabi64,
28242833 .musleabi,
28252834 .musleabihf,
28262835 .muslx32,
......@@ -2876,7 +2885,10 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
28762885 .char => return 8,
28772886 .short, .ushort => return 16,
28782887 .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 },
28802892 .longlong, .ulonglong, .double => return 64,
28812893 .longdouble => if (target.os.tag == .freebsd) return 64 else return 128,
28822894 },
......@@ -2907,6 +2919,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
29072919 .powerpcle,
29082920 => switch (target.abi) {
29092921 .musl,
2922 .muslabin32,
2923 .muslabi64,
29102924 .musleabi,
29112925 .musleabihf,
29122926 .muslx32,
......@@ -2921,6 +2935,8 @@ pub fn cTypeBitSize(target: Target, c_type: CType) u16 {
29212935 .powerpc64le,
29222936 => switch (target.abi) {
29232937 .musl,
2938 .muslabin32,
2939 .muslabi64,
29242940 .musleabi,
29252941 .musleabihf,
29262942 .muslx32,
lib/std/os/linux.zig+6-6
......@@ -136,10 +136,10 @@ pub const SYS = switch (@import("builtin").cpu.arch) {
136136 .loongarch64 => syscalls.LoongArch64,
137137 .m68k => syscalls.M68k,
138138 .mips, .mipsel => syscalls.MipsO32,
139 .mips64, .mips64el => if (builtin.abi == .gnuabin32)
140 syscalls.MipsN32
141 else
142 syscalls.MipsN64,
139 .mips64, .mips64el => switch (builtin.abi) {
140 .gnuabin32, .muslabin32 => syscalls.MipsN32,
141 else => syscalls.MipsN64,
142 },
143143 .powerpc, .powerpcle => syscalls.PowerPC,
144144 .powerpc64, .powerpc64le => syscalls.PowerPC64,
145145 .s390x => syscalls.S390x,
......@@ -8657,11 +8657,11 @@ pub const AUDIT = struct {
86578657 .mips => .MIPS,
86588658 .mipsel => .MIPSEL,
86598659 .mips64 => switch (native_abi) {
8660 .gnuabin32 => .MIPS64N32,
8660 .gnuabin32, .muslabin32 => .MIPS64N32,
86618661 else => .MIPS64,
86628662 },
86638663 .mips64el => switch (native_abi) {
8664 .gnuabin32 => .MIPSEL64N32,
8664 .gnuabin32, .muslabin32 => .MIPSEL64N32,
86658665 else => .MIPSEL64,
86668666 },
86678667 .powerpc => .PPC,
lib/std/zig/LibCDirs.zig+2
......@@ -232,6 +232,8 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
232232 .gnuilp32,
233233 => return "glibc",
234234 .musl,
235 .muslabin32,
236 .muslabi64,
235237 .musleabi,
236238 .musleabihf,
237239 .muslx32,
lib/std/zig/system.zig+8-8
......@@ -91,16 +91,16 @@ pub fn getExternalExecutor(
9191 .mips => Executor{ .qemu = "qemu-mips" },
9292 .mipsel => Executor{ .qemu = "qemu-mipsel" },
9393 .mips64 => Executor{
94 .qemu = if (candidate.abi == .gnuabin32)
95 "qemu-mipsn32"
96 else
97 "qemu-mips64",
94 .qemu = switch (candidate.abi) {
95 .gnuabin32, .muslabin32 => "qemu-mipsn32",
96 else => "qemu-mips64",
97 },
9898 },
9999 .mips64el => Executor{
100 .qemu = if (candidate.abi == .gnuabin32)
101 "qemu-mipsn32el"
102 else
103 "qemu-mips64el",
100 .qemu = switch (candidate.abi) {
101 .gnuabin32, .muslabin32 => "qemu-mipsn32el",
102 else => "qemu-mips64el",
103 },
104104 },
105105 .powerpc => Executor{ .qemu = "qemu-ppc" },
106106 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
lib/std/zig/target.zig+2
......@@ -99,6 +99,7 @@ pub fn canBuildLibC(target: std.Target) bool {
9999
100100pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 {
101101 return switch (abi) {
102 .muslabin32 => "mipsn32",
102103 .muslx32 => "x32",
103104 else => switch (arch) {
104105 .arm, .armeb, .thumb, .thumbeb => "arm",
......@@ -129,6 +130,7 @@ pub fn muslArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {
129130
130131pub fn muslAbiNameHeaders(abi: std.Target.Abi) [:0]const u8 {
131132 return switch (abi) {
133 .muslabin32 => "mipsn32",
132134 .muslx32 => "muslx32",
133135 else => "musl",
134136 };
src/codegen/llvm.zig+2
......@@ -270,6 +270,8 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
270270 .android => "android",
271271 .androideabi => "androideabi",
272272 .musl => "musl",
273 .muslabin32 => "musl", // Should be muslabin32 in LLVM 20.
274 .muslabi64 => "musl", // Should be muslabi64 in LLVM 20.
273275 .musleabi => "musleabi",
274276 .musleabihf => "musleabihf",
275277 .muslx32 => "muslx32",
src/link/Elf.zig+4-4
......@@ -4100,21 +4100,21 @@ fn getLDMOption(target: std.Target) ?[]const u8 {
41004100 },
41014101 .mips64 => switch (target.os.tag) {
41024102 .freebsd => switch (target.abi) {
4103 .gnuabin32 => "elf32btsmipn32_fbsd",
4103 .gnuabin32, .muslabin32 => "elf32btsmipn32_fbsd",
41044104 else => "elf64btsmip_fbsd",
41054105 },
41064106 else => switch (target.abi) {
4107 .gnuabin32 => "elf32btsmipn32",
4107 .gnuabin32, .muslabin32 => "elf32btsmipn32",
41084108 else => "elf64btsmip",
41094109 },
41104110 },
41114111 .mips64el => switch (target.os.tag) {
41124112 .freebsd => switch (target.abi) {
4113 .gnuabin32 => "elf32ltsmipn32_fbsd",
4113 .gnuabin32, .muslabin32 => "elf32ltsmipn32_fbsd",
41144114 else => "elf64ltsmip_fbsd",
41154115 },
41164116 else => switch (target.abi) {
4117 .gnuabin32 => "elf32ltsmipn32",
4117 .gnuabin32, .muslabin32 => "elf32ltsmipn32",
41184118 else => "elf64ltsmip",
41194119 },
41204120 },
src/target.zig+10
......@@ -438,6 +438,16 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
438438}
439439
440440pub 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
441451 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
442452 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
443453 // 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{
161161 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabi64 },
162162 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .gnuabin32 },
163163 .{ .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 },
164166 .{ .cpu_arch = .mips64, .os_tag = .linux, .abi = .none },
165167 .{ .cpu_arch = .mips64, .os_tag = .netbsd, .abi = .none },
166168 .{ .cpu_arch = .mips64, .os_tag = .openbsd, .abi = .none },
......@@ -170,6 +172,8 @@ const targets = [_]std.Target.Query{
170172 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabi64 },
171173 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .gnuabin32 },
172174 .{ .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 },
173177 .{ .cpu_arch = .mips64el, .os_tag = .linux, .abi = .none },
174178 .{ .cpu_arch = .mips64el, .os_tag = .netbsd, .abi = .none },
175179 .{ .cpu_arch = .mips64el, .os_tag = .openbsd, .abi = .none },