authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-05 14:52:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 14:58:38-07:00
log3bc70ea2dd392499d108f05c291adb155a057939
treed014b4e185fb0634b7e5fe9b77fe497bffa8c11d
parent9067daeb946201c204ef5556bc43a8845a0d5e3a

compiler_rt: avoid using weak aliases

This is a partial revert of 0d533433e21621177fb291e2a4901bee11834501, which regressed this behavior. The idea here is to avoid aliases, which happens when the same function is exported with multiple names. The problem with aliases is that weak aliases don't seem to work, causing symbol collisions when multiple of the same symbol are provided, despite the desired behavior that weak symbols are overridden. In this case we export redundant functions with different names. Thanks to -ffunction-sections, the unused functions will be garbage-collected at link time. This leaves us with the best of both worlds: Zig's compiler-rt will provide both sets of symbols, and it will be binary-compatible with different compilers that expect different names, while still resulting in binaries without garbage.

2 files changed, 10 insertions(+), 2 deletions(-)

lib/compiler_rt/extendhfsf2.zig+5-1
...@@ -5,7 +5,7 @@ pub const panic = common.panic;...@@ -5,7 +5,7 @@ pub const panic = common.panic;
55
6comptime {6comptime {
7 if (common.gnu_f16_abi) {7 if (common.gnu_f16_abi) {
8 @export(__extendhfsf2, .{ .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 });
11 }11 }
...@@ -16,6 +16,10 @@ pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 {...@@ -16,6 +16,10 @@ pub fn __extendhfsf2(a: common.F16T) callconv(.C) f32 {
16 return extendf(f32, f16, @bitCast(u16, a));16 return extendf(f32, f16, @bitCast(u16, a));
17}17}
1818
19fn __gnu_h2f_ieee(a: common.F16T) callconv(.C) f32 {
20 return extendf(f32, f16, @bitCast(u16, a));
21}
22
19fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 {23fn __aeabi_h2f(a: u16) callconv(.AAPCS) f32 {
20 return extendf(f32, f16, @bitCast(u16, a));24 return extendf(f32, f16, @bitCast(u16, a));
21}25}
lib/compiler_rt/truncsfhf2.zig+5-1
...@@ -5,7 +5,7 @@ pub const panic = common.panic;...@@ -5,7 +5,7 @@ pub const panic = common.panic;
55
6comptime {6comptime {
7 if (common.gnu_f16_abi) {7 if (common.gnu_f16_abi) {
8 @export(__truncsfhf2, .{ .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 });
11 }11 }
...@@ -16,6 +16,10 @@ pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T {...@@ -16,6 +16,10 @@ pub fn __truncsfhf2(a: f32) callconv(.C) common.F16T {
16 return @bitCast(common.F16T, truncf(f16, f32, a));16 return @bitCast(common.F16T, truncf(f16, f32, a));
17}17}
1818
19fn __gnu_f2h_ieee(a: f32) callconv(.C) common.F16T {
20 return @bitCast(common.F16T, truncf(f16, f32, a));
21}
22
19fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {23fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
20 return @bitCast(common.F16T, truncf(f16, f32, a));24 return @bitCast(common.F16T, truncf(f16, f32, a));
21}25}