[glibc] sparc: Fix static IFUNC startup crash by redirecting __mempcpy (BZ #34396)

Adhemerval Zanella via Glibc-cvs <[email protected]> Thu, 16 Jul 2026 20:20:47 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c82b6095964105156606af35b1ca1a08af230a2d

commit c82b6095964105156606af35b1ca1a08af230a2d
Author: Adhemerval Zanella <[email protected]>
Date:   Tue Jul 14 09:07:27 2026 -0300

    sparc: Fix static IFUNC startup crash by redirecting __mempcpy (BZ #34396)
    
    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.
    
    Tested-by: Andreas K. Hüttel <[email protected]>

Diff:
---
 .../sparcv9/multiarch => }/dl-symbol-redir-ifunc.h | 13 +++++++++++-
 .../sparc64/multiarch/dl-symbol-redir-ifunc.h      | 24 ----------------------
 2 files changed, 12 insertions(+), 25 deletions(-)

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 ffe1eee87d..8b90c847f6 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 ffe1eee87d..0000000000
--- 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