From: Mark Mentovai Date: Mon, 1 Jun 2026 13:16:59 +0000 (-0400) Subject: kernel: fix objtool build on macOS hosts X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0d2cee3ea070461dd147bbe4f5f49e3e0e7e138;p=thirdparty%2Fopenwrt.git kernel: fix objtool build on macOS hosts Since kernel 5a406031d0719 (2025-03-17, in 6.15), objtool calls sendfile, but sendfile is Linux-specific and a sendfile with the requisite capabilities is not available on other operating systems. Provide a more portable fallback implementation to be used when cross-building on non-Linux hosts. This fixes: CC …/linux-6.18.33/tools/objtool/builtin-check.o builtin-check.c:13:10: fatal error: 'sys/sendfile.h' file not found 13 | #include | ^~~~~~~~~~~~~~~~ 1 error generated. gmake[8]: *** […/linux-6.18.33/tools/build/Makefile.build:86: …/linux-6.18.33/tools/objtool/builtin-check.o] Error 1 Fixes: https://github.com/openwrt/openwrt/issues/23356 Signed-off-by: Mark Mentovai Link: https://github.com/openwrt/openwrt/pull/23612 Signed-off-by: Robert Marko --- diff --git a/target/linux/generic/hack-6.18/202-objtool_portability.patch b/target/linux/generic/hack-6.18/202-objtool_portability.patch new file mode 100644 index 00000000000..d8ba87bb84f --- /dev/null +++ b/target/linux/generic/hack-6.18/202-objtool_portability.patch @@ -0,0 +1,91 @@ +From dc5565c4478135999d8bb193bd9dfb4f8ef5f96b Mon Sep 17 00:00:00 2001 +From: Mark Mentovai +Date: Mon, 1 Jun 2026 09:11:43 -0400 +Subject: [PATCH] objtool: fix build on macOS hosts + +Since 5a406031d0719 (2025-03-17, in 6.15), objtool calls sendfile, but +sendfile is Linux-specific and a sendfile with the requisite +capabilities is not available on other operating systems. Provide a more +portable fallback implementation to be used when cross-building on +non-Linux hosts. + +Signed-off-by: Mark Mentovai +--- + tools/objtool/builtin-check.c | 40 +++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +--- a/tools/objtool/builtin-check.c ++++ b/tools/objtool/builtin-check.c +@@ -10,7 +10,9 @@ + #include + #include + #include ++#ifdef __linux__ + #include ++#endif + #include + #include + #include +@@ -187,12 +189,28 @@ static bool opts_valid(void) + return false; + } + ++#ifndef __linux__ ++#define RETRY_EINTR(x) \ ++ ({ \ ++ __typeof__(x) eintr_wrapper_result; \ ++ do { \ ++ eintr_wrapper_result = (x); \ ++ } while (eintr_wrapper_result == -1 && errno == EINTR); \ ++ eintr_wrapper_result; \ ++ }) ++#endif ++ + static int copy_file(const char *src, const char *dst) + { + size_t to_copy, copied; + int dst_fd, src_fd; + struct stat stat; ++#ifdef __linux__ + off_t offset = 0; ++#else ++ char buf[65536]; ++ ssize_t nread, nwrote; ++#endif + + src_fd = open(src, O_RDONLY); + if (src_fd == -1) { +@@ -217,11 +235,33 @@ static int copy_file(const char *src, co + } + + for (to_copy = stat.st_size; to_copy > 0; to_copy -= copied) { ++#ifdef __linux__ + copied = sendfile(dst_fd, src_fd, &offset, to_copy); + if (copied == -1) { + ERROR_GLIBC("sendfile"); + return 1; + } ++#else ++ nread = RETRY_EINTR( ++ read(src_fd, buf, ++ to_copy < sizeof(buf) ? to_copy : sizeof(buf))); ++ if (nread < 0) { ++ ERROR_GLIBC("read"); ++ return 1; ++ } ++ if (nread == 0) { ++ ERROR("unexpected premature EOF"); ++ return 1; ++ } ++ for (copied = 0; copied < nread; copied += nwrote) { ++ nwrote = RETRY_EINTR( ++ write(dst_fd, buf + copied, nread - copied)); ++ if (nwrote < 0) { ++ ERROR_GLIBC("write"); ++ return 1; ++ } ++ } ++#endif + } + + close(dst_fd);