From patchwork Tue Jun 23 12:47:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 137633 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D1B84BA2E13 for ; Tue, 23 Jun 2026 12:49:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D1B84BA2E13 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=mlSCIi69 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1234.google.com (mail-dl1-x1234.google.com [IPv6:2607:f8b0:4864:20::1234]) by sourceware.org (Postfix) with ESMTPS id 66E6A4BA23C2 for ; Tue, 23 Jun 2026 12:48:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66E6A4BA23C2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 66E6A4BA23C2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218920; cv=none; b=YRNMfo8od/7ix23aecVPZPonsddtV9jWQi6O7ikfmYAgb0MjwzmgH1oSaKoKq8ZhV1VEM6vmSMAztKQMjx+jv9x+Px0lNc2fVIJuZm7W8r3IEoBEANq9QLXSelrZ9TGO2HeDDLXg78faQPL3yG9IQxkD0cq73iixGyyX7LVnMoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218920; c=relaxed/simple; bh=2BGnApCh370oQtrwcTR/Rq0zmb2q5Z6FG6b/q5smIrU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nZQEsmXfyX9EvvScPxunkbzq6d8pr0UCsDg69wDyb4AMLB4jXkTWyIU8FDyEM4ba/wxIOTE58WnvPdjWMd/qbAZJ+Ku9M9qZiNNs/Qaycq88NIJHLzAa5z5Gg06ICmM1g2K3ReLjzM17P5N8J2/kbyADoOKBCYWDTciyNpcoFmU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=mlSCIi69 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66E6A4BA23C2 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-139cc9b208aso175821c88.0 for ; Tue, 23 Jun 2026 05:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218919; x=1782823719; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t6jBoOv71GQfUsgQfTkYl10ba3lVOgJr9i4OSKn40YA=; b=mlSCIi69WPjzAk170o1tJpN5MaBHIBpAVrQ5lN3ZDOXR+oY4JQPnEk5gZOrdQ/tq0o HisoQeF07fKeS16cQip0pJ/6ydqv49VqIcSsCR5+4Qh8OhAx/8Rj07EtH4lB6mPzyTIM GPKxwSc1BGGv5uiqavY9WDwTw0vRgShqleJ4KM9URJvv0QH8MLMCMsB0YdDTb1VdqF8Y thKHrMIkX3FjOnmVPyKr8j1CZahAuF09rtjnIhZ+/yVYDUcd6Zi6pBM3MAO257x+pRxl QprCcgJnl9otIpij+1SkKfxAQQpvpgH9bCJyplh1p7OtpNEMtfyfFqxHl9r3HBsvzauy k+1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218919; x=1782823719; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=t6jBoOv71GQfUsgQfTkYl10ba3lVOgJr9i4OSKn40YA=; b=KGYpIDr2XicGeG9mv6UGlaKg4b6E9P4JSHmhOFUJHD37ncsPv0JH9lGaJc+D0lCSXq 9ux2Kggdku/rxoEgS4b/FzXxOjbsQijmtq1eTjHtodj0ep0KR9CAPTmjO/7/bZ+IzLuz m5mpR20RiqNzimNqw1yWSeqcS7UJqjLHavOySmJ+y5gvfExNOvAVADAU+D21K5hQFb/a tUcXi2l/DLP52H54aoZC0ws/5Q+aRSvTtw1RDH7oAGoA+wnJ6NEK7sdZCB17Xys6AZCi FwnnTELa4NRKRdRRcxhWxvpE/rexgkO2x4UFWfdjUj4tf1LksfZbwrgZxg1gagJS5tyA TbqA== X-Gm-Message-State: AOJu0YzCNCOY97zFgJHy0+9quy/jaEJHmYCQDLbbTxxYe64IOLtwlfAl Za342J69nMwoql/Tu8hjm1eI8Q96wEswW+NKNaS5YfFsqOAKkygyJj2MnpFI6ER8kS2mN0fPXT7 XkyxM X-Gm-Gg: AfdE7ckLGchfVm4kBTNjPjic1mbkMNO6+BrdFkbIEclEzSKLs5ZgMnGmTbHM1tEdI9u P2QHMFN3U1yI+eWnBBm9Qj9izo/iAiF8c4HasQnoNhGDxCQVQ9IgvkqN5CR6wInQjDW0ZaxFwRj sXWNUvijnkAnCJ8z5wOwyS+jHIuC08DC7JP80oMw/WkoXVg/TPLexhdeN+7I54b2PzFMxjgW7j+ 0MfgEBu7YTctJwnZ5hCgpXBINV6WcV2X84oMUPAgn1EwU0XUJ8RUaS1Y5EMvYiqxiQeJ7PdBXg+ xLk9muuMqofkiAHqqXzF/BiBh51p35AVK07U+fz/BloqwU7oeexo0eaUoFsJRq0Q04E/8axNf3C JIrIoQna15FJywB1bnH5SBVnHhS5fgWkwaTyesob+c+suQ+8fMV4Sq/m/BeZ4zL5CXqpxaC+zCT x099JpIDmBEoBrN7E4WXpOycN+ X-Received: by 2002:a05:7022:20d:b0:139:7bac:db41 with SMTP id a92af1059eb24-139c705bb41mr1572516c88.28.1782218919093; Tue, 23 Jun 2026 05:48:39 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:38 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 2/5] Use _dl_writev on __libc_message_impl Date: Tue, 23 Jun 2026 09:47:43 -0300 Message-ID: <20260623124831.2165041-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org And change _dl_writev to return a negative errno in case of failure. This keeps the required semantics for not setting errno on failure and allows removing the Linux libc_fatal.c implementation. It also makes it simple to use the writev syscall during process startup, especially on i386, where it requires disabling vDSO. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Florian Weimer --- {elf => sysdeps/generic}/dl-writev.h | 18 +++++++------- sysdeps/posix/libc_fatal.c | 15 ++++++------ sysdeps/unix/sysv/linux/dl-writev.h | 12 ++++------ sysdeps/unix/sysv/linux/libc_fatal.c | 36 ---------------------------- 4 files changed, 20 insertions(+), 61 deletions(-) rename {elf => sysdeps/generic}/dl-writev.h (80%) delete mode 100644 sysdeps/unix/sysv/linux/libc_fatal.c diff --git a/elf/dl-writev.h b/sysdeps/generic/dl-writev.h similarity index 80% rename from elf/dl-writev.h rename to sysdeps/generic/dl-writev.h index a2359426059..613384fac6b 100644 --- a/elf/dl-writev.h +++ b/sysdeps/generic/dl-writev.h @@ -20,37 +20,35 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { /* Note that if __writev is an implementation that calls malloc, this will cause linking problems building the dynamic linker. */ + ssize_t r; #if RTLD_PRIVATE_ERRNO /* We have to take this lock just to be sure we don't clobber the private errno when it's being used by another thread that cares about it. Yet we must be sure not to try calling the lock functions before the thread library is fully initialized. */ if (__glibc_unlikely (_dl_starting_up)) - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); else { __rtld_lock_lock_recursive (GL(dl_load_lock)); - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); __rtld_lock_unlock_recursive (GL(dl_load_lock)); } #else - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); #endif + return r == -1 ? -errno : r; } diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 4f11315c2a7..3f0e302b5ea 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -28,14 +29,14 @@ #include FATAL_PREPARE_INCLUDE #endif -#ifndef WRITEV_FOR_FATAL -# define WRITEV_FOR_FATAL writev_for_fatal -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) +static void +writev_for_fatal (int fd, const struct iovec *iov, size_t niov) { - return TEMP_FAILURE_RETRY (__writev (fd, iov, niov)) == total; + ssize_t cnt; + do + cnt = _dl_writev (fd, iov, niov); + while (cnt == -EINTR); } -#endif /* At most a substring before each conversion specification and the trailing substring (the plus one). */ @@ -108,7 +109,7 @@ __libc_message_impl (const char *vma_name, const char *fmt, ...) if (iovcnt > 0) { - WRITEV_FOR_FATAL (fd, iov, iovcnt, total); + writev_for_fatal (fd, iov, iovcnt); total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1, GLRO(dl_pagesize)); diff --git a/sysdeps/unix/sysv/linux/dl-writev.h b/sysdeps/unix/sysv/linux/dl-writev.h index 89f69f8ab1c..ceb98a35e66 100644 --- a/sysdeps/unix/sysv/linux/dl-writev.h +++ b/sysdeps/unix/sysv/linux/dl-writev.h @@ -19,19 +19,15 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { - INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); + return INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); } diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c deleted file mode 100644 index 120cdffaf95..00000000000 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Catastrophic failure reports. Linux version. - Copyright (C) 1993-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) -{ - ssize_t cnt; - do - cnt = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); - while (INTERNAL_SYSCALL_ERROR_P (cnt) - && INTERNAL_SYSCALL_ERRNO (cnt) == EINTR); - return cnt == total; -} -#define WRITEV_FOR_FATAL writev_for_fatal - -#include