[v8,2/6] Use _dl_writev on __libc_message_impl

Message ID 20260318193454.2466865-3-adhemerval.zanella@linaro.org (mailing list archive)
State New
Headers
Series elf: Allow RPATH/RUNPATH for static-pie |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Adhemerval Zanella Netto March 18, 2026, 7:34 p.m. UTC
  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
  

Patch

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 a235942605..024b780bf2 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 4f11315c2a..3f0e302b5e 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 89f69f8ab1..ceb98a35e6 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 120cdffaf9..0000000000
--- 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>