authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-16 18:33:15+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-08-30 06:36:41+02:00
loge9ac2ce1167f0f2f86d824549b8ab04d1028129c
tree4a0323bfbcd819650b1701bdcca29cb676d5be7c
parentdfa55e193d04ad96c0049a48f58412ebb12c08ab
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler-rt: move strlen from libzigc to here

LLVM 21 has started recognizing strlen-like idioms and optimizing them to strlen calls, so we need this function provided in compiler-rt for libc-less compilations.

3 files changed, 12 insertions(+), 5 deletions(-)

lib/c/string.zig-5
...@@ -4,7 +4,6 @@ const common = @import("common.zig");...@@ -4,7 +4,6 @@ const common = @import("common.zig");
44
5comptime {5comptime {
6 @export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility });6 @export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility });
7 @export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility });
8 @export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility });7 @export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility });
9 @export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility });8 @export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility });
10 @export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility });9 @export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility });
...@@ -103,7 +102,3 @@ test strncmp {...@@ -103,7 +102,3 @@ test strncmp {
103 try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);102 try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
104 try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);103 try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
105}104}
106
107fn strlen(s: [*:0]const c_char) callconv(.c) usize {
108 return std.mem.len(s);
109}
lib/compiler_rt.zig+2
...@@ -263,6 +263,8 @@ comptime {...@@ -263,6 +263,8 @@ comptime {
263 _ = @import("compiler_rt/memcmp.zig");263 _ = @import("compiler_rt/memcmp.zig");
264 _ = @import("compiler_rt/bcmp.zig");264 _ = @import("compiler_rt/bcmp.zig");
265 _ = @import("compiler_rt/ssp.zig");265 _ = @import("compiler_rt/ssp.zig");
266
267 _ = @import("compiler_rt/strlen.zig");
266 }268 }
267269
268 // Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed.270 // Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed.
lib/compiler_rt/strlen.zig created+10
...@@ -0,0 +1,10 @@
1const std = @import("std");
2const common = @import("common.zig");
3
4comptime {
5 @export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility });
6}
7
8fn strlen(s: [*:0]const c_char) callconv(.c) usize {
9 return std.mem.len(s);
10}