public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>
Subject: [PATCH v10 2/5] Use _dl_writev on __libc_message_impl
Date: Tue, 23 Jun 2026 09:47:43 -0300	[thread overview]
Message-ID: <20260623124831.2165041-3-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.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 <fweimer@redhat.com>
---
 {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 <ldsodefs.h>
 #include <libc-lock.h>
 
-/* 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
    <https://www.gnu.org/licenses/>.  */
 
+#include <dl-writev.h>
 #include <assert.h>
 #include <ldsodefs.h>
 #include <setvmaname.h>
@@ -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 <sys/uio.h>
 #include <sysdep.h>
 
-/* 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
-   <https://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/uio.h>
-#include <stdbool.h>
-#include <sysdep.h>
-
-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 <sysdeps/posix/libc_fatal.c>
-- 
2.43.0


  parent reply	other threads:[~2026-06-23 12:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 12:47 [PATCH v10 0/5] elf: Allow RPATH/RUNPATH for static-pie Adhemerval Zanella
2026-06-23 12:47 ` [PATCH v10 1/5] nptl: Add __raise_direct Adhemerval Zanella
2026-07-09 10:01   ` Florian Weimer
2026-07-09 12:46     ` Adhemerval Zanella Netto
2026-06-23 12:47 ` Adhemerval Zanella [this message]
2026-06-23 12:47 ` [PATCH v10 3/5] Fix assert during static startup (BZ 33326) Adhemerval Zanella
2026-07-09 13:00   ` Florian Weimer
2026-06-23 12:47 ` [PATCH v10 4/5] elf: Allow RPATH/RUNPATH for static-pie " Adhemerval Zanella
2026-06-23 12:47 ` [PATCH v10 5/5] elf: Remove __chk_fail from dl-minimal.c Adhemerval Zanella
2026-07-09 10:03   ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260623124831.2165041-3-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).