[PATCH 1/2] sparc: Fix static IFUNC startup crash by redirecting __mempcpy (BZ #34396)

Adhemerval Zanella <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
After commit b75ad99d45b, __libc_setup_tls -> _dl_allocate_tls_init copies
the TLS init image with the IFUNC __mempcpy before ARCH_SETUP_IREL resolves
it, so on a multi-arch sparcv9/sparc64 static build the call jumps through an
unrelocated PLT slot and the process dies with SIGILL.

The sparc dl-symbol-redir-ifunc.h only redirected memset.  Redirect
memcpy, memmove, mempcpy and __mempcpy to the ultra1 routines as well,
and merge the identical sparc64 and sparc32/sparcv9 copies into a single
sysdeps/sparc file.  The redirection is guarded by __sparc_v9__ &&
USE_MULTIARCH so that sparcv8 (leon) and --disable-multi-arch builds,
which have no __*_ultra1 routines, are left untouched.

Checked with elf tests for sparc32 and sparc64 on qemu system.
---
 .../multiarch => }/dl-symbol-redir-ifunc.h    | 13 +++++++++-
 .../sparc64/multiarch/dl-symbol-redir-ifunc.h | 24 -------------------
 2 files changed, 12 insertions(+), 25 deletions(-)
 rename sysdeps/sparc/{sparc32/sparcv9/multiarch => }/dl-symbol-redir-ifunc.h (70%)
 delete mode 100644 sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h

diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/dl-symbol-redir-ifunc.h
similarity index 70%
rename from sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h
rename to sysdeps/sparc/dl-symbol-redir-ifunc.h
index ffe1eee87d5..8b90c847f68 100644
--- a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h
+++ b/sysdeps/sparc/dl-symbol-redir-ifunc.h
@@ -1,4 +1,4 @@
-/* Symbol rediretion for loader/static initialization code.
+/* Symbol redirection for loader/static initialization code.  SPARC version.
    Copyright (C) 2022-2026 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -19,6 +19,17 @@
 #ifndef _DL_IFUNC_GENERIC_H
 #define _DL_IFUNC_GENERIC_H
 
+/* The mem* IFUNCs only exist on a multi-arch sparcv9/sparc64 build.  */
+#if defined (__sparc_v9__) && defined (USE_MULTIARCH)
+
 asm ("memset = __memset_ultra1");
+# ifndef SHARED
+asm ("memcpy = __memcpy_ultra1");
+asm ("memmove = __memmove_ultra1");
+asm ("mempcpy = __mempcpy_ultra1");
+asm ("__mempcpy = __mempcpy_ultra1");
+# endif
+
+#endif
 
 #endif
diff --git a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h
deleted file mode 100644
index ffe1eee87d5..00000000000
--- a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Symbol rediretion for loader/static initialization code.
-   Copyright (C) 2022-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/>.  */
-
-#ifndef _DL_IFUNC_GENERIC_H
-#define _DL_IFUNC_GENERIC_H
-
-asm ("memset = __memset_ultra1");
-
-#endif
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.