[PATCH v2 3/5] Use _dl_writev on __libc_message_impl
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Sep 2 19:26:55 GMT 2025
And change _dl_writev to return an negative errno in case of failure.
This keeps the required semantic on not setting errno in case of
failure and allow remove the Linux libc_fatal.c implementation.
It also makes is simple to use writev syscall during process startup,
specially on i386 where it requires to disable the vDSO usage.
---
{elf => sysdeps/generic}/dl-writev.h | 18 +++++++-------
sysdeps/posix/libc_fatal.c | 15 ++++++------
sysdeps/unix/sysv/linux/dl-writev.h | 13 ++++------
sysdeps/unix/sysv/linux/libc_fatal.c | 36 ----------------------------
4 files changed, 21 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 cf22367a82..0829da4ee9 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 6f75197e96..c36bd39c13 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 *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 f3fa5c777b..0abe28202f 100644
--- a/sysdeps/unix/sysv/linux/dl-writev.h
+++ b/sysdeps/unix/sysv/linux/dl-writev.h
@@ -19,19 +19,16 @@
#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);
+ int r = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov);
+ return INTERNAL_SYSCALL_ERROR_P (r) ? -INTERNAL_SYSCALL_ERRNO (r) : r;
}
diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c
deleted file mode 100644
index 72d7328a20..0000000000
--- a/sysdeps/unix/sysv/linux/libc_fatal.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Catastrophic failure reports. Linux version.
- Copyright (C) 1993-2025 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
More information about the Libc-alpha
mailing list