|
| 1 | +From 841366f6c53387fd598a9f5b47f50a5334bb9b95 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ryan Zezeski < [email protected]> |
| 3 | +Date: Fri, 14 Mar 2025 16:27:14 -0400 |
| 4 | +Subject: [PATCH] add arc4random_buf |
| 5 | + |
| 6 | +Add support for arc4random_buf to avoid relying on zig's internal |
| 7 | +tlcsprng implementation as there seems to be some flakiness with it's |
| 8 | +use of threadlocal when using the build runner to build the zig stage3 |
| 9 | +compiler (see error below). This only works when the program is linked |
| 10 | +with libc, as should always be the case on illumos. |
| 11 | + |
| 12 | +[19/19] Building stage3 |
| 13 | +FAILED: stage3/bin/zig /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build/build.amd64/stage3/bin/zig |
| 14 | + |
| 15 | +cd /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0 && /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-b |
| 16 | +uild/build.amd64/zig2 build --prefix /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build/build.amd64/ |
| 17 | +stage3 --zig-lib-dir /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib -Dversion-string=0.14.0 -Dtarg |
| 18 | +et=native -Dcpu=baseline -Denable-llvm -Dconfig_h=/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build |
| 19 | +/build.amd64/config.h -Dno-langref -Doptimize=ReleaseFast |
| 20 | +Segmentation fault at address 0xfffffc7feeccf448 |
| 21 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/crypto/tlcsprng.zig:59:9: 0x1593a4f in tlsCsprn |
| 22 | +gFill (build) |
| 23 | + if (wipe_mem.len == 0) { |
| 24 | + ^ |
| 25 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Random.zig:58:13: 0x15efbe1 in bytes (build) |
| 26 | + r.fillFn(r.ptr, buf); |
| 27 | + ^ |
| 28 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/fs/AtomicFile.zig:26:32: 0x15e84d5 in init (bui |
| 29 | +ld) |
| 30 | + std.crypto.random.bytes(rand_buf[0..]); |
| 31 | + ^ |
| 32 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/fs/Dir.zig:2657:31: 0x15e8099 in atomicFile (bu |
| 33 | +ild) |
| 34 | + return AtomicFile.init(fs.path.basename(dest_path), options.mode, dir, true); |
| 35 | + ^ |
| 36 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/fs/Dir.zig:2541:46: 0x15e8ca0 in updateFile (bu |
| 37 | +ild) |
| 38 | + var atomic_file = try dest_dir.atomicFile(dest_path, .{ .mode = actual_mode }); |
| 39 | + ^ |
| 40 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Build/Step/InstallDir.zig:111:54: 0x1574176 in |
| 41 | +make (build) |
| 42 | + const prev_status = fs.Dir.updateFile( |
| 43 | + ^ |
| 44 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Build/Step.zig:231:13: 0x15545ff in make (build |
| 45 | +) |
| 46 | + s.makeFn(s, options) catch |err| switch (err) { |
| 47 | + ^ |
| 48 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/compiler/build_runner.zig:1105:31: 0x151ca08 in workerMakeOneStep (build) |
| 49 | + const make_result = s.make(.{ |
| 50 | + ^ |
| 51 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Thread/Pool.zig:119:39: 0x151d3d3 in runFn (build) |
| 52 | + @call(.auto, func, closure.arguments); |
| 53 | + ^ |
| 54 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Thread/Pool.zig:295:32: 0x159da4c in worker (build) |
| 55 | + run_node.data.runFn(&run_node.data, id); |
| 56 | + ^ |
| 57 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Thread.zig:488:13: 0x155323a in callFn__anon_100548 (build) |
| 58 | + @call(.auto, f, args); |
| 59 | + ^ |
| 60 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib/std/Thread.zig:757:30: 0x151c29e in entryFn (build) |
| 61 | + return callFn(f, args_ptr.*); |
| 62 | + ^ |
| 63 | +???:?:?: 0xfffffc7fef057326 in ??? (libc.so.1) |
| 64 | +Unwind information for `libc.so.1:0xfffffc7fef057326` was not available, trace may be incomplete |
| 65 | + |
| 66 | +???:?:?: 0xfffffc7fef05766f in ??? (libc.so.1) |
| 67 | +???:?:?: 0x0 in ??? (???) |
| 68 | +error: the following build command crashed: |
| 69 | +/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/.zig-cache/o/7d72ec58c6f1742b1ecb4d994da3a6df/build /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build/build.amd64/zig2 /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/lib /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0 /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0/.zig-cache /export/home/rpz/.cache/zig --seed 0x97ac69e3 -Zb9a9429c1f2e840d --prefix /tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build/build.amd64/stage3 -Dversion-string=0.14.0 -Dtarget=native -Dcpu=baseline -Denable-llvm -Dconfig_h=/tmp/build_rpz/zig-0.14.0/zig-0.14.0/zig-0.14.0-build/build.amd64/config.h -Dno-langref -Doptimize=ReleaseFast |
| 70 | +ninja: build stopped: subcommand failed. |
| 71 | +--- Make failed |
| 72 | +--- |
| 73 | + lib/std/c.zig | 2 +- |
| 74 | + 1 file changed, 1 insertion(+), 1 deletion(-) |
| 75 | + |
| 76 | +diff --git a/lib/std/c.zig b/lib/std/c.zig |
| 77 | +index 9b7d36cb32..ad741407fd 100644 |
| 78 | +--- a/lib/std/c.zig |
| 79 | ++++ b/lib/std/c.zig |
| 80 | +@@ -9327,7 +9327,7 @@ pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: us |
| 81 | + pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int; |
| 82 | + |
| 83 | + pub const arc4random_buf = switch (native_os) { |
| 84 | +- .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf, |
| 85 | ++ .dragonfly, .netbsd, .freebsd, .illumos, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf, |
| 86 | + else => {}, |
| 87 | + }; |
| 88 | + pub const getentropy = switch (native_os) { |
| 89 | +-- |
| 90 | +2.43.0 |
| 91 | + |
0 commit comments