From 30ef0336932cb2ec866a082b9b4584d08d179a55 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 17 Jun 2022 19:25:06 -0700 Subject: [PATCH] compiler-rt: fix logic for choosing `__gnu_{f2h,h2f}_ieee` wasm32-wasi-musl wants the standard symbol names however Linux requires the `__gnu_*` flavors. I did not find any authoritative source on what decides which symbol flavors to use. If we run into more trouble in the future we can go back to having both. --- lib/compiler_rt/common.zig | 37 ++++++++++++++++++++++++++------- lib/compiler_rt/extendhfsf2.zig | 2 +- lib/compiler_rt/truncsfhf2.zig | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index 6dc6ced926..8f9253b44b 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -1,7 +1,5 @@ const std = @import("std"); const builtin = @import("builtin"); -const math = std.math; -const is_test = builtin.is_test; pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak; pub const want_aeabi = switch (builtin.abi) { @@ -18,19 +16,44 @@ pub const want_aeabi = switch (builtin.abi) { else => false, }; pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64(); -pub const want_msvc_abi = builtin.abi == .msvc; -/// Example symbols: + +/// This governs whether to use these symbol names for f16/f32 conversions +/// rather than the standard names: /// * __gnu_f2h_ieee /// * __gnu_h2f_ieee -pub const want_gnu_abi = builtin.abi.isGnu() or builtin.abi.isMusl(); +/// Known correct configurations: +/// x86_64-freestanding-none => true +/// x86_64-linux-none => true +/// x86_64-linux-gnu => true +/// x86_64-linux-musl => true +/// x86_64-linux-eabi => true +/// arm-linux-musleabihf => true +/// arm-linux-gnueabihf => true +/// arm-linux-eabihf => false +/// wasm32-wasi-musl => false +/// wasm32-freestanding-none => false +/// x86_64-windows-gnu => true +/// x86_64-windows-msvc => true +/// any-macos-any => doesn't matter; libSystem has both symbol flavors +pub const gnu_f16_abi = switch (builtin.cpu.arch) { + .wasm32, .wasm64 => false, + + .arm, .armeb, .thumb, .thumbeb => switch (builtin.abi) { + .eabi, .eabihf => false, + else => true, + }, + + else => true, +}; + pub const want_sparc_abi = builtin.cpu.arch.isSPARC(); // Avoid dragging in the runtime safety mechanisms into this .o file, // unless we're trying to test compiler-rt. pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { _ = error_return_trace; - @setCold(true); - if (is_test) { + if (builtin.is_test) { + @setCold(true); std.debug.panic("{s}", .{msg}); } else { unreachable; diff --git a/lib/compiler_rt/extendhfsf2.zig b/lib/compiler_rt/extendhfsf2.zig index 56e6b9c01b..a6bf5f5be5 100644 --- a/lib/compiler_rt/extendhfsf2.zig +++ b/lib/compiler_rt/extendhfsf2.zig @@ -4,7 +4,7 @@ const extendf = @import("./extendf.zig").extendf; pub const panic = common.panic; comptime { - if (common.want_gnu_abi) { + if (common.gnu_f16_abi) { @export(__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage }); } else if (common.want_aeabi) { @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = common.linkage }); diff --git a/lib/compiler_rt/truncsfhf2.zig b/lib/compiler_rt/truncsfhf2.zig index 329b3332a2..489fb8658d 100644 --- a/lib/compiler_rt/truncsfhf2.zig +++ b/lib/compiler_rt/truncsfhf2.zig @@ -4,7 +4,7 @@ const truncf = @import("./truncf.zig").truncf; pub const panic = common.panic; comptime { - if (common.want_gnu_abi) { + if (common.gnu_f16_abi) { @export(__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage }); } else if (common.want_aeabi) { @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = common.linkage });