From f1a72f8f11617390b8d3f68c339677fb403f0360 Mon Sep 17 00:00:00 2001 From: kilian-ai Date: Tue, 29 Sep 2026 12:04:40 -0700 Subject: [PATCH] wasm: build usr/gen_init_cpio on macOS hosts Darwin lacks copy_file_range() and O_LARGEFILE, so the gen_init_cpio host program fails to build and a macOS build of vmlinux.wasm stops in usr/. Force-include a small compat header for that host program on Darwin only: copy_file_range() becomes a read/write loop with the same return contract, and O_LARGEFILE is 0 (off_t is already 64-bit there). Other hosts are unchanged. Tested on macOS 26 (Apple Silicon) with GNU Make 4.4.1 and Homebrew LLVM 19.1.7 (matching flake.nix): defconfig + vmlinux.wasm builds on top of f2a512c0d4a3, which no longer needs scripts/mod. Co-Authored-By: Claude Opus 5.5 --- arch/wasm/scripts/macos-host-compat.h | 48 +++++++++++++++++++++++++++ usr/Makefile | 4 +++ 2 files changed, 52 insertions(+) create mode 100644 arch/wasm/scripts/macos-host-compat.h diff --git a/arch/wasm/scripts/macos-host-compat.h b/arch/wasm/scripts/macos-host-compat.h new file mode 100644 index 00000000000000..f5976634d79245 --- /dev/null +++ b/arch/wasm/scripts/macos-host-compat.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Host-tool compatibility for building the wasm kernel on a macOS host. + * Included via -include for usr/gen_init_cpio only (see usr/Makefile). + * Darwin has neither O_LARGEFILE (files are always large-file capable) + * nor copy_file_range(); provide a plain read/write loop with the same + * contract gen_init_cpio relies on (returns bytes copied, -1 on error). + */ +#ifndef _WASM_MACOS_HOST_COMPAT_H +#define _WASM_MACOS_HOST_COMPAT_H +#ifdef __APPLE__ +#include +#include +#include +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif +static inline ssize_t copy_file_range(int fd_in, off_t *off_in, int fd_out, + off_t *off_out, size_t len, unsigned int flags) +{ + char buf[65536]; + size_t total = 0; + (void)off_in; (void)off_out; (void)flags; + while (total < len) { + size_t want = len - total < sizeof(buf) ? len - total : sizeof(buf); + ssize_t n = read(fd_in, buf, want); + if (n < 0) { + if (errno == EINTR) + continue; + return total ? (ssize_t)total : -1; + } + if (n == 0) + break; + for (ssize_t done = 0; done < n;) { + ssize_t w = write(fd_out, buf + done, n - done); + if (w < 0) { + if (errno == EINTR) + continue; + return -1; + } + done += w; + } + total += n; + } + return total; +} +#endif /* __APPLE__ */ +#endif diff --git a/usr/Makefile b/usr/Makefile index e8f42478a0b765..7ae048c8d74c5c 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -17,6 +17,10 @@ obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o $(obj)/initramfs_data.o: $(obj)/initramfs_inc_data hostprogs := gen_init_cpio +# macOS hosts lack copy_file_range()/O_LARGEFILE; see the compat header. +ifeq ($(shell uname -s),Darwin) +HOSTCFLAGS_gen_init_cpio.o += -include $(srctree)/arch/wasm/scripts/macos-host-compat.h +endif ramfs-input := $(CONFIG_INITRAMFS_SOURCE) cpio-data :=