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