From eb03cb28a74308a0f9b33ae7034eb771c4bf1ee6 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Sun, 19 Apr 2026 17:41:52 -0300 Subject: [PATCH] toolchain: fix libgloss/adros build errors - Add sys/uio.h compat header (struct iovec + readv/writev declarations) needed by posix_stubs.c which was missing from sysroot_headers - Remove duplicate fcntl() definition in posix_stubs.c (line 541 was identical to line 256, causing redefinition error with newlib headers) - Move libgloss/adros source sync outside patch_newlib() marker guard so edits to stubs are always picked up on rebuild (cp -f instead of cp -u); keep mkdir -p inside patch_newlib() for autoconf file creation --- newlib/libgloss/adros/posix_stubs.c | 8 -------- newlib/sysroot_headers/sys/uio.h | 25 +++++++++++++++++++++++++ toolchain/build.sh | 13 ++++++++----- 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 newlib/sysroot_headers/sys/uio.h diff --git a/newlib/libgloss/adros/posix_stubs.c b/newlib/libgloss/adros/posix_stubs.c index 4952bfd8..ea391696 100644 --- a/newlib/libgloss/adros/posix_stubs.c +++ b/newlib/libgloss/adros/posix_stubs.c @@ -537,14 +537,6 @@ int gethostname(char *name, size_t len) { * Additional POSIX wrappers (previously missing) * ================================================================ */ -int fcntl(int fd, int cmd, ...) { - va_list ap; - va_start(ap, cmd); - int arg = va_arg(ap, int); - va_end(ap); - return _check(_sc3(SYS_FCNTL, fd, cmd, arg)); -} - int rename(const char *oldpath, const char *newpath) { return _check(_sc2(SYS_RENAME, (int)oldpath, (int)newpath)); } diff --git a/newlib/sysroot_headers/sys/uio.h b/newlib/sysroot_headers/sys/uio.h new file mode 100644 index 00000000..157c35af --- /dev/null +++ b/newlib/sysroot_headers/sys/uio.h @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A. M. Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + +/* sys/uio.h — Scatter/gather I/O (POSIX compat header for AdrOS/newlib) */ + +#ifndef _SYS_UIO_H +#define _SYS_UIO_H + +#include + +struct iovec { + void *iov_base; + size_t iov_len; +}; + +ssize_t readv(int fd, const struct iovec *iov, int iovcnt); +ssize_t writev(int fd, const struct iovec *iov, int iovcnt); + +#endif diff --git a/toolchain/build.sh b/toolchain/build.sh index 4c95ec73..117d3c05 100755 --- a/toolchain/build.sh +++ b/toolchain/build.sh @@ -390,12 +390,8 @@ EOF step "Patched libgloss/configure.ac" fi - # Copy/sync our libgloss/adros stubs into the Newlib source tree + # Create libgloss/adros directory and autoconf files if not present mkdir -p "$d/libgloss/adros" - cp -u "$ADROS_ROOT/newlib/libgloss/adros/"*.c "$ADROS_ROOT/newlib/libgloss/adros/"*.S "$d/libgloss/adros/" 2>/dev/null || true - step "Synced libgloss/adros/ stubs" - - # Create libgloss/adros autoconf files if not present if [[ ! -f "$d/libgloss/adros/configure.in" ]]; then cat > "$d/libgloss/adros/configure.in" <<'EOF' dnl AdrOS libgloss configure @@ -490,6 +486,13 @@ patch_gcc patch_newlib patch_bash +# Always sync libgloss/adros source files (even if patches are already applied) +# so that edits to our stubs are picked up on rebuild. +_gloss_dir="$SRC_DIR/newlib-${NEWLIB_VER}/libgloss/adros" +mkdir -p "$_gloss_dir" +cp -f "$ADROS_ROOT/newlib/libgloss/adros/"*.c "$ADROS_ROOT/newlib/libgloss/adros/"*.S "$_gloss_dir/" 2>/dev/null || true +step "Synced libgloss/adros/ stubs (forced)" + # ================================================================== # STEP 1: Build Binutils # ================================================================== -- 2.43.0