authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 19:25:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 20:25:17-07:00
log30ef0336932cb2ec866a082b9b4584d08d179a55
tree8bb4bcf25626f781df4cce46c83b889a73cd40fa
parente4092d44426a471ee6097fae24069c72cffdc22a

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.

3 files changed, 32 insertions(+), 9 deletions(-)

lib/compiler_rt/common.zig+30-7
...@@ -1,7 +1,5 @@...@@ -1,7 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const math = std.math;
4const is_test = builtin.is_test;
53
6pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const want_aeabi = switch (builtin.abi) {5pub const want_aeabi = switch (builtin.abi) {
...@@ -18,19 +16,44 @@ pub const want_aeabi = switch (builtin.abi) {...@@ -18,19 +16,44 @@ pub const want_aeabi = switch (builtin.abi) {
18 else => false,16 else => false,
19};17};
20pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64();18pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64();
21pub const want_msvc_abi = builtin.abi == .msvc;19
22/// Example symbols:20/// This governs whether to use these symbol names for f16/f32 conversions
21/// rather than the standard names:
23/// * __gnu_f2h_ieee22/// * __gnu_f2h_ieee
24/// * __gnu_h2f_ieee23/// * __gnu_h2f_ieee
25pub const want_gnu_abi = builtin.abi.isGnu() or builtin.abi.isMusl();24/// Known correct configurations:
25/// x86_64-freestanding-none => true
26/// x86_64-linux-none => true
27/// x86_64-linux-gnu => true
28/// x86_64-linux-musl => true
29/// x86_64-linux-eabi => true
30/// arm-linux-musleabihf => true
31/// arm-linux-gnueabihf => true
32/// arm-linux-eabihf => false
33/// wasm32-wasi-musl => false
34/// wasm32-freestanding-none => false
35/// x86_64-windows-gnu => true
36/// x86_64-windows-msvc => true
37/// any-macos-any => doesn't matter; libSystem has both symbol flavors
38pub const gnu_f16_abi = switch (builtin.cpu.arch) {
39 .wasm32, .wasm64 => false,
40
41 .arm, .armeb, .thumb, .thumbeb => switch (builtin.abi) {
42 .eabi, .eabihf => false,
43 else => true,
44 },
45
46 else => true,
47};
48
26pub const want_sparc_abi = builtin.cpu.arch.isSPARC();49pub const want_sparc_abi = builtin.cpu.arch.isSPARC();
2750
28// Avoid dragging in the runtime safety mechanisms into this .o file,51// Avoid dragging in the runtime safety mechanisms into this .o file,
29// unless we're trying to test compiler-rt.52// unless we're trying to test compiler-rt.
30pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {53pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
31 _ = error_return_trace;54 _ = error_return_trace;
32 @setCold(true);55 if (builtin.is_test) {
33 if (is_test) {56 @setCold(true);
34 std.debug.panic("{s}", .{msg});57 std.debug.panic("{s}", .{msg});
35 } else {58 } else {
36 unreachable;59 unreachable;
lib/compiler_rt/extendhfsf2.zig+1-1
...@@ -4,7 +4,7 @@ const extendf = @import("./extendf.zig").extendf;...@@ -4,7 +4,7 @@ const extendf = @import("./extendf.zig").extendf;
4pub const panic = common.panic;4pub const panic = common.panic;
55
6comptime {6comptime {
7 if (common.want_gnu_abi) {7 if (common.gnu_f16_abi) {
8 @export(__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage });8 @export(__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage });
9 } else if (common.want_aeabi) {9 } else if (common.want_aeabi) {
10 @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = common.linkage });10 @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = common.linkage });
lib/compiler_rt/truncsfhf2.zig+1-1
...@@ -4,7 +4,7 @@ const truncf = @import("./truncf.zig").truncf;...@@ -4,7 +4,7 @@ const truncf = @import("./truncf.zig").truncf;
4pub const panic = common.panic;4pub const panic = common.panic;
55
6comptime {6comptime {
7 if (common.want_gnu_abi) {7 if (common.gnu_f16_abi) {
8 @export(__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage });8 @export(__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage });
9 } else if (common.want_aeabi) {9 } else if (common.want_aeabi) {
10 @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = common.linkage });10 @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = common.linkage });