authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-27 18:14:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-27 18:14:44-07:00
log1ac21cdec5747e2c7788c566a2998b2bee54eb47
treed150cf91816e3d761d1b10ac3089a8347f29d67a
parentdc62dde9826a94c161e20bf56e23940dc3f2f0dc

compiler-rt: avoid symbol conflicts

Weak aliases don't work on Windows, so we avoid exporting the `l` alias on this platform for functions we know will collide.

2 files changed, 48 insertions(+), 53 deletions(-)

lib/std/special/compiler_rt.zig+29-25
......@@ -723,25 +723,25 @@ comptime {
723723 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
724724 }
725725
726 mathExport("ceil", @import("./compiler_rt/ceil.zig"));
727 mathExport("cos", @import("./compiler_rt/cos.zig"));
728 mathExport("exp", @import("./compiler_rt/exp.zig"));
729 mathExport("exp2", @import("./compiler_rt/exp2.zig"));
730 mathExport("fabs", @import("./compiler_rt/fabs.zig"));
731 mathExport("floor", @import("./compiler_rt/floor.zig"));
732 mathExport("fma", @import("./compiler_rt/fma.zig"));
733 mathExport("fmax", @import("./compiler_rt/fmax.zig"));
734 mathExport("fmin", @import("./compiler_rt/fmin.zig"));
735 mathExport("fmod", @import("./compiler_rt/fmod.zig"));
736 mathExport("log", @import("./compiler_rt/log.zig"));
737 mathExport("log10", @import("./compiler_rt/log10.zig"));
738 mathExport("log2", @import("./compiler_rt/log2.zig"));
739 mathExport("round", @import("./compiler_rt/round.zig"));
740 mathExport("sin", @import("./compiler_rt/sin.zig"));
741 mathExport("sincos", @import("./compiler_rt/sincos.zig"));
742 mathExport("sqrt", @import("./compiler_rt/sqrt.zig"));
743 mathExport("tan", @import("./compiler_rt/tan.zig"));
744 mathExport("trunc", @import("./compiler_rt/trunc.zig"));
726 mathExport("ceil", @import("./compiler_rt/ceil.zig"), true);
727 mathExport("cos", @import("./compiler_rt/cos.zig"), true);
728 mathExport("exp", @import("./compiler_rt/exp.zig"), true);
729 mathExport("exp2", @import("./compiler_rt/exp2.zig"), true);
730 mathExport("fabs", @import("./compiler_rt/fabs.zig"), true);
731 mathExport("floor", @import("./compiler_rt/floor.zig"), true);
732 mathExport("fma", @import("./compiler_rt/fma.zig"), true);
733 mathExport("fmax", @import("./compiler_rt/fmax.zig"), true);
734 mathExport("fmin", @import("./compiler_rt/fmin.zig"), true);
735 mathExport("fmod", @import("./compiler_rt/fmod.zig"), true);
736 mathExport("log", @import("./compiler_rt/log.zig"), true);
737 mathExport("log10", @import("./compiler_rt/log10.zig"), true);
738 mathExport("log2", @import("./compiler_rt/log2.zig"), true);
739 mathExport("round", @import("./compiler_rt/round.zig"), true);
740 mathExport("sin", @import("./compiler_rt/sin.zig"), true);
741 mathExport("sincos", @import("./compiler_rt/sincos.zig"), true);
742 mathExport("sqrt", @import("./compiler_rt/sqrt.zig"), true);
743 mathExport("tan", @import("./compiler_rt/tan.zig"), false);
744 mathExport("trunc", @import("./compiler_rt/trunc.zig"), true);
745745
746746 if (arch.isSPARC()) {
747747 // SPARC systems use a different naming scheme
......@@ -827,7 +827,7 @@ comptime {
827827 }
828828}
829829
830inline fn mathExport(double_name: []const u8, comptime import: type) void {
830inline fn mathExport(double_name: []const u8, comptime import: type, is_standard: bool) void {
831831 const half_name = "__" ++ double_name ++ "h";
832832 const half_fn = @field(import, half_name);
833833 const float_name = double_name ++ "f";
......@@ -853,11 +853,15 @@ inline fn mathExport(double_name: []const u8, comptime import: type) void {
853853 .{ f128, quad_fn },
854854 };
855855
856 inline for (pairs) |pair| {
857 const F = pair[0];
858 const func = pair[1];
859 if (builtin.target.longDoubleIs(F)) {
860 @export(func, .{ .name = long_double_name, .linkage = linkage });
856 // Weak aliases don't work on Windows, so we avoid exporting the `l` alias
857 // on this platform for functions we know will collide.
858 if (builtin.os.tag != .windows or !builtin.link_libc or !is_standard) {
859 inline for (pairs) |pair| {
860 const F = pair[0];
861 const func = pair[1];
862 if (builtin.target.longDoubleIs(F)) {
863 @export(func, .{ .name = long_double_name, .linkage = linkage });
864 }
861865 }
862866 }
863867}
src/stage1/codegen.cpp+19-28
......@@ -1630,37 +1630,28 @@ static const char *get_compiler_rt_type_abbrev(ZigType *type) {
16301630}
16311631
16321632static const char *libc_float_prefix(CodeGen *g, ZigType *float_type) {
1633 if (float_type == g->builtin_types.entry_f16)
1634 return "__";
1635 else if (float_type == g->builtin_types.entry_f32)
1636 return "";
1637 else if (float_type == g->builtin_types.entry_f64)
1638 return "";
1639 else if (float_type == g->builtin_types.entry_f80)
1640 return "__";
1641 else if (float_type == g->builtin_types.entry_c_longdouble)
1642 return "l";
1643 else if (float_type == g->builtin_types.entry_f128)
1644 return "";
1645 else
1646 zig_unreachable();
1633 switch (float_type->data.floating.bit_count) {
1634 case 16:
1635 case 80:
1636 return "__";
1637 case 32:
1638 case 64:
1639 case 128:
1640 return "";
1641 default:
1642 zig_unreachable();
1643 }
16471644}
16481645
16491646static const char *libc_float_suffix(CodeGen *g, ZigType *float_type) {
1650 if (float_type == g->builtin_types.entry_f16)
1651 return "h"; // Non-standard
1652 else if (float_type == g->builtin_types.entry_f32)
1653 return "f";
1654 else if (float_type == g->builtin_types.entry_f64)
1655 return "";
1656 else if (float_type == g->builtin_types.entry_f80)
1657 return "x"; // Non-standard
1658 else if (float_type == g->builtin_types.entry_c_longdouble)
1659 return "l";
1660 else if (float_type == g->builtin_types.entry_f128)
1661 return "q"; // Non-standard
1662 else
1663 zig_unreachable();
1647 switch (float_type->size_in_bits) {
1648 case 16: return "h"; // Non-standard
1649 case 32: return "f";
1650 case 64: return "";
1651 case 80: return "x"; // Non-standard
1652 case 128: return "q"; // Non-standard
1653 default: zig_unreachable();
1654 }
16641655}
16651656
16661657static LLVMValueRef gen_soft_float_widen_or_shorten(CodeGen *g, ZigType *actual_type,