public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Rework exception handling in the dynamic loader [BZ #25486]
@ 2022-08-29 12:26 Florian Weimer
  2022-08-29 12:26 ` [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called Florian Weimer
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Florian Weimer @ 2022-08-29 12:26 UTC (permalink / raw)
  To: libc-alpha

This is a rebase on the current tree.  No real changed compared to the
previously posted version.  This change is a pre-requisite for moving
more loader functionality into ld.so.

Tested on x86_64-linux-gnu.

Thanks,
Florian

Florian Weimer (3):
  ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called
  scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)
  elf: Rework exception handling in the dynamic loader [BZ #25486]

 elf/Makefile                                  |   3 +-
 elf/Versions                                  |   8 +-
 elf/{dl-error-skeleton.c => dl-catch.c}       | 150 +++++++++---------
 elf/dl-error-minimal.c                        |  23 ---
 elf/dl-error.c                                |  27 ----
 elf/rtld.c                                    |  12 +-
 nptl/descr.h                                  |   3 +
 scripts/localplt.awk                          |  18 ++-
 sysdeps/generic/ldsodefs.h                    |  15 +-
 sysdeps/generic/localplt.data                 |   5 -
 sysdeps/mach/hurd/i386/localplt.data          |   5 -
 sysdeps/mach/hurd/i386/tls.h                  |   3 +
 sysdeps/unix/sysv/linux/aarch64/localplt.data |   5 -
 sysdeps/unix/sysv/linux/alpha/localplt.data   |   5 -
 sysdeps/unix/sysv/linux/arc/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/arm/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/csky/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/hppa/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/i386/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/ia64/localplt.data    |   5 -
 .../sysv/linux/m68k/coldfire/localplt.data    |   5 -
 .../unix/sysv/linux/m68k/m680x0/localplt.data |   5 -
 .../unix/sysv/linux/microblaze/localplt.data  |   5 -
 sysdeps/unix/sysv/linux/nios2/localplt.data   |   5 -
 .../linux/powerpc/powerpc32/fpu/localplt.data |   5 -
 .../powerpc/powerpc32/nofpu/localplt.data     |   5 -
 .../linux/powerpc/powerpc64/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/riscv/localplt.data   |   5 -
 sysdeps/unix/sysv/linux/s390/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/sh/localplt.data      |   5 -
 .../sysv/linux/sparc/sparc32/localplt.data    |   5 -
 .../sysv/linux/sparc/sparc64/localplt.data    |   5 -
 sysdeps/x86_64/localplt.data                  |   5 -
 33 files changed, 108 insertions(+), 269 deletions(-)
 rename elf/{dl-error-skeleton.c => dl-catch.c} (76%)
 delete mode 100644 elf/dl-error-minimal.c
 delete mode 100644 elf/dl-error.c


base-commit: d0e357ff45a75553dee3b17ed7d303bfa544f6fe
-- 
2.37.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called
  2022-08-29 12:26 [PATCH v4 0/3] Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
@ 2022-08-29 12:26 ` Florian Weimer
  2022-10-26 20:34   ` Siddhesh Poyarekar
  2022-08-29 12:26 ` [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY) Florian Weimer
  2022-08-29 12:27 ` [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
  2 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2022-08-29 12:26 UTC (permalink / raw)
  To: libc-alpha

This allows the rest of dynamic loader to check whether the TCB
has been set up (and THREAD_GETMEM and THREAD_SETMEM will work).
---
 elf/rtld.c                 | 10 +++++-----
 sysdeps/generic/ldsodefs.h |  3 +++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index cbbaf4a331..714434b21d 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -730,7 +730,7 @@ match_version (const char *string, struct link_map *map)
   return 0;
 }
 
-static bool tls_init_tp_called;
+bool __rtld_tls_init_tp_called;
 
 static void *
 init_tls (size_t naudit)
@@ -800,7 +800,7 @@ cannot allocate TLS data structures for initial thread\n");
   if (__glibc_unlikely (lossage != NULL))
     _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);
   __tls_init_tp ();
-  tls_init_tp_called = true;
+  __rtld_tls_init_tp_called = true;
 
   return tcbp;
 }
@@ -2050,7 +2050,7 @@ dl_main (const ElfW(Phdr) *phdr,
      an old kernel that can't perform TLS_INIT_TP, even if no TLS is ever
      used.  Trying to do it lazily is too hairy to try when there could be
      multiple threads (from a non-TLS-using libpthread).  */
-  bool was_tls_init_tp_called = tls_init_tp_called;
+  bool was_tls_init_tp_called = __rtld_tls_init_tp_called;
   if (tcbp == NULL)
     tcbp = init_tls (0);
 
@@ -2315,7 +2315,7 @@ dl_main (const ElfW(Phdr) *phdr,
 			       consider_profiling);
 
 	/* Add object to slot information data if necessasy.  */
-	if (l->l_tls_blocksize != 0 && tls_init_tp_called)
+	if (l->l_tls_blocksize != 0 && __rtld_tls_init_tp_called)
 	  _dl_add_to_slotinfo (l, true);
       }
   }
@@ -2341,7 +2341,7 @@ dl_main (const ElfW(Phdr) *phdr,
   _dl_allocate_tls_init (tcbp, false);
 
   /* And finally install it for the main thread.  */
-  if (! tls_init_tp_called)
+  if (! __rtld_tls_init_tp_called)
     {
       const char *lossage = TLS_INIT_TP (tcbp);
       if (__glibc_unlikely (lossage != NULL))
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 050a3032de..fc81affed0 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1217,6 +1217,9 @@ extern void *_dl_allocate_tls_storage (void) attribute_hidden;
 extern void *_dl_allocate_tls_init (void *, bool);
 rtld_hidden_proto (_dl_allocate_tls_init)
 
+/* True if the TCB has been set up.  */
+extern bool __rtld_tls_init_tp_called attribute_hidden;
+
 /* Deallocate memory allocated with _dl_allocate_tls.  */
 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
 rtld_hidden_proto (_dl_deallocate_tls)
-- 
2.37.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)
  2022-08-29 12:26 [PATCH v4 0/3] Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
  2022-08-29 12:26 ` [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called Florian Weimer
@ 2022-08-29 12:26 ` Florian Weimer
  2022-10-26 20:34   ` Siddhesh Poyarekar
  2022-08-29 12:27 ` [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
  2 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2022-08-29 12:26 UTC (permalink / raw)
  To: libc-alpha

On csky-linux-gnuabiv2, binutils 2.33 produces a DT_JMPREL entry
for the dynamic loader if it does not contain any PLT relocations:

Dynamic section at offset 0x1df48 contains 19 entries:
  Tag        Type                         Name/Value
 0x0000000e (SONAME)                     Library soname: [ld-linux-cskyv2-hf.so.1]
 0x00000004 (HASH)                       0xd4
 0x6ffffef5 (GNU_HASH)                   0x1a8
 0x00000005 (STRTAB)                     0x4ac
 0x00000006 (SYMTAB)                     0x28c
 0x0000000a (STRSZ)                      527 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000003 (PLTGOT)                     0x1f000
 0x00000002 (PLTRELSZ)                   0 (bytes)
 0x00000014 (PLTREL)                     RELA
 0x00000017 (JMPREL)                     0xaa4
 0x00000007 (RELA)                       0x75c
 0x00000008 (RELASZ)                     840 (bytes)
 0x00000009 (RELAENT)                    12 (bytes)
 0x6ffffffc (VERDEF)                     0x700
 0x6ffffffd (VERDEFNUM)                  3
 0x6ffffff0 (VERSYM)                     0x6bc
 0x6ffffff9 (RELACOUNT)                  68
 0x00000000 (NULL)                       0x0

This confuses the script:

Unexpected output from check-localplt: …/elf/ld.so.jmprel:
*** DT_JMPREL does not match any section's address

This commit changes the script to record the DT_PLTRELSZ value and
reject DT_JMPREL values not a section boundary only if DT_PLTRELSZ
is present with a non-zero value.
---
 scripts/localplt.awk | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/scripts/localplt.awk b/scripts/localplt.awk
index beaa342922..fe79ca01ab 100644
--- a/scripts/localplt.awk
+++ b/scripts/localplt.awk
@@ -4,17 +4,25 @@
 # It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a
 # symbol defined in the same object.
 
-BEGIN { result = 0 }
+BEGIN {
+  result = 0;
+  pltrelsize = -1;
+}
 
 FILENAME != lastfile {
   if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) {
     print FILENAME ": *** failed to find expected output (readelf -WSdr)";
     result = 2;
   }
+  if (pltrelsz > 0 && jmprel_offset == -1) {
+    print FILENAME ": Could not find section for DT_JMPREL";
+    result = 2;
+  }
   lastfile = FILENAME;
   jmprel_offset = 0;
   rela_offset = 0;
   rel_offset = 0;
+  pltrelsz = -1;
   delete section_offset_by_address;
 }
 
@@ -82,12 +90,16 @@ $2 == "(JMPREL)" {
   if (jmprel_addr in section_offset_by_address) {
     jmprel_offset = section_offset_by_address[jmprel_addr];
   } else {
-    print FILENAME ": *** DT_JMPREL does not match any section's address";
-    result = 2;
+    jmprel_offset = -1
   }
   next
 }
 
+$2 == "(PLTRELSZ)" {
+  pltrelsz = strtonum($3);
+  next
+}
+
 $2 == "(RELA)" {
   rela_addr = strtonum($3);
   if (rela_addr in section_offset_by_address) {
-- 
2.37.2



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486]
  2022-08-29 12:26 [PATCH v4 0/3] Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
  2022-08-29 12:26 ` [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called Florian Weimer
  2022-08-29 12:26 ` [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY) Florian Weimer
@ 2022-08-29 12:27 ` Florian Weimer
  2022-10-26 20:34   ` Siddhesh Poyarekar
  2 siblings, 1 reply; 8+ messages in thread
From: Florian Weimer @ 2022-08-29 12:27 UTC (permalink / raw)
  To: libc-alpha

The old exception handling implementation used function interposition
to replace the dynamic loader implementation (no TLS support) with the
libc implementation (TLS support).  This results in problems if the
link order between the dynamic loader and libc is reversed (bug 25486).

The new implementation moves the entire implementation of the
exception handling functions back into the dynamic loader, using
THREAD_GETMEM and THREAD_SETMEM for thread-local data support.
These depends on Hurd support for these macros, added in commit
b65a82e4e757c1e6cb7073916 ("hurd: Add THREAD_GET/SETMEM/_NC").

One small obstacle is that the exception handling facilities are used
before the TCB has been set up, so a check is needed if the TCB is
available.  If not, a regular global variable is used to store the
exception handling information.

Also rename dl-error.c to dl-catch.c, to avoid confusion with the
dlerror function.
---
 elf/Makefile                                  |   3 +-
 elf/Versions                                  |   8 +-
 elf/{dl-error-skeleton.c => dl-catch.c}       | 150 +++++++++---------
 elf/dl-error-minimal.c                        |  23 ---
 elf/dl-error.c                                |  27 ----
 elf/rtld.c                                    |   2 +-
 nptl/descr.h                                  |   3 +
 sysdeps/generic/ldsodefs.h                    |  12 +-
 sysdeps/generic/localplt.data                 |   5 -
 sysdeps/mach/hurd/i386/localplt.data          |   5 -
 sysdeps/mach/hurd/i386/tls.h                  |   3 +
 sysdeps/unix/sysv/linux/aarch64/localplt.data |   5 -
 sysdeps/unix/sysv/linux/alpha/localplt.data   |   5 -
 sysdeps/unix/sysv/linux/arc/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/arm/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/csky/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/hppa/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/i386/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/ia64/localplt.data    |   5 -
 .../sysv/linux/m68k/coldfire/localplt.data    |   5 -
 .../unix/sysv/linux/m68k/m680x0/localplt.data |   5 -
 .../unix/sysv/linux/microblaze/localplt.data  |   5 -
 sysdeps/unix/sysv/linux/nios2/localplt.data   |   5 -
 .../linux/powerpc/powerpc32/fpu/localplt.data |   5 -
 .../powerpc/powerpc32/nofpu/localplt.data     |   5 -
 .../linux/powerpc/powerpc64/localplt.data     |   5 -
 sysdeps/unix/sysv/linux/riscv/localplt.data   |   5 -
 sysdeps/unix/sysv/linux/s390/localplt.data    |   5 -
 sysdeps/unix/sysv/linux/sh/localplt.data      |   5 -
 .../sysv/linux/sparc/sparc32/localplt.data    |   5 -
 .../sysv/linux/sparc/sparc64/localplt.data    |   5 -
 sysdeps/x86_64/localplt.data                  |   5 -
 32 files changed, 85 insertions(+), 261 deletions(-)
 rename elf/{dl-error-skeleton.c => dl-catch.c} (76%)
 delete mode 100644 elf/dl-error-minimal.c
 delete mode 100644 elf/dl-error.c

diff --git a/elf/Makefile b/elf/Makefile
index 008770bfaf..d702d6bd79 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -34,7 +34,6 @@ routines = \
   dl-addr \
   dl-addr-obj \
   dl-early_allocate \
-  dl-error \
   dl-iteratephdr \
   dl-libc \
   dl-origin \
@@ -53,6 +52,7 @@ routines = \
 # profiled libraries.
 dl-routines = \
   dl-call-libc-early-init \
+  dl-catch \
   dl-close \
   dl-debug \
   dl-debug-symbols \
@@ -133,7 +133,6 @@ rtld-routines = \
   dl-diagnostics-cpu \
   dl-diagnostics-kernel \
   dl-environ \
-  dl-error-minimal \
   dl-hwcaps \
   dl-hwcaps-subdirs \
   dl-hwcaps_split \
diff --git a/elf/Versions b/elf/Versions
index a9ff278de7..4614acea3e 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -31,10 +31,6 @@ libc {
   GLIBC_PRIVATE {
     # functions used in other libraries
     __libc_early_init;
-
-    # Internal error handling support.  Interposes the functions in ld.so.
-    _dl_signal_exception; _dl_catch_exception;
-    _dl_signal_error; _dl_catch_error;
   }
 }
 
@@ -77,10 +73,8 @@ ld {
 
     # Internal error handling support.
     _dl_exception_create; _dl_exception_create_format; _dl_exception_free;
-
-    # Internal error handling support.  Interposed by libc.so.
     _dl_signal_exception; _dl_catch_exception;
-    _dl_signal_error; _dl_catch_error;
+    _dl_signal_error;
 
     # Set value of a tunable.
     __tunable_get_val;
diff --git a/elf/dl-error-skeleton.c b/elf/dl-catch.c
similarity index 76%
rename from elf/dl-error-skeleton.c
rename to elf/dl-catch.c
index 8abf437f87..f7b8282a2c 100644
--- a/elf/dl-error-skeleton.c
+++ b/elf/dl-catch.c
@@ -1,4 +1,4 @@
-/* Template for error handling for runtime dynamic linker.
+/* Exception handling in the dynamic linker.
    Copyright (C) 1995-2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -16,16 +16,6 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-/* The following macro needs to be defined before including this
-   skeleton file:
-
-   DL_ERROR_BOOTSTRAP
-
-     If 1, do not use TLS and implement _dl_signal_cerror and
-     _dl_receive_error.  If 0, TLS is used, and the variants with
-     error callbacks are not provided.  */
-
-
 #include <libintl.h>
 #include <setjmp.h>
 #include <stdbool.h>
@@ -34,39 +24,50 @@
 #include <unistd.h>
 #include <ldsodefs.h>
 #include <stdio.h>
+#include <tls.h>
 
 /* This structure communicates state between _dl_catch_error and
    _dl_signal_error.  */
-struct catch
+struct rtld_catch
   {
     struct dl_exception *exception; /* The exception data is stored there.  */
     volatile int *errcode;	/* Return value of _dl_signal_error.  */
     jmp_buf env;		/* longjmp here on error.  */
   };
 
-/* Multiple threads at once can use the `_dl_catch_error' function.  The
-   calls can come from `_dl_map_object_deps', `_dlerror_run', or from
-   any of the libc functionality which loads dynamic objects (NSS, iconv).
-   Therefore we have to be prepared to save the state in thread-local
-   memory.  */
-#if !DL_ERROR_BOOTSTRAP
-static __thread struct catch *catch_hook attribute_tls_model_ie;
-#else
-/* The version of this code in ld.so cannot use thread-local variables
-   and is used during bootstrap only.  */
-static struct catch *catch_hook;
+/* Multiple threads at once can use the `_dl_catch_error' function.
+   The calls can come from `_dl_map_object_deps', `_dlerror_run', or
+   from any of the libc functionality which loads dynamic objects
+   (NSS, iconv).  Therefore we have to be prepared to save the state
+   in thread-local memory.  We use THREAD_GETMEM and THREAD_SETMEM
+   instead of ELF TLS because it exception handling must work before
+   the TCB and ELF TLS have been set up.  */
+
+#if IS_IN (rtld)
+static struct rtld_catch *rtld_catch_notls;
 #endif
 
-#if DL_ERROR_BOOTSTRAP
-/* This points to a function which is called when an continuable error is
-   received.  Unlike the handling of `catch' this function may return.
-   The arguments will be the `errstring' and `objname'.
+static struct rtld_catch *
+get_catch (void)
+{
+#if IS_IN (rtld)
+  if (!__rtld_tls_init_tp_called)
+    return rtld_catch_notls;
+  else
+#endif
+    return THREAD_GETMEM (THREAD_SELF, rtld_catch);
+}
 
-   Since this functionality is not used in normal programs (only in ld.so)
-   we do not care about multi-threaded programs here.  We keep this as a
-   global variable.  */
-static receiver_fct receiver;
-#endif /* DL_ERROR_BOOTSTRAP */
+static void
+set_catch (struct rtld_catch *catch)
+{
+#if IS_IN (rtld)
+  if (!__rtld_tls_init_tp_called)
+    rtld_catch_notls = catch;
+  else
+#endif
+    THREAD_SETMEM (THREAD_SELF, rtld_catch, catch);
+}
 
 /* Lossage while resolving the program's own symbols is always fatal.  */
 static void
@@ -89,7 +90,7 @@ void
 _dl_signal_exception (int errcode, struct dl_exception *exception,
 		      const char *occasion)
 {
-  struct catch *lcatch = catch_hook;
+  struct rtld_catch *lcatch = get_catch ();
   if (lcatch != NULL)
     {
       *lcatch->exception = *exception;
@@ -101,13 +102,13 @@ _dl_signal_exception (int errcode, struct dl_exception *exception,
   else
     fatal_error (errcode, exception->objname, occasion, exception->errstring);
 }
-libc_hidden_def (_dl_signal_exception)
+rtld_hidden_def (_dl_signal_exception)
 
 void
 _dl_signal_error (int errcode, const char *objname, const char *occation,
 		  const char *errstring)
 {
-  struct catch *lcatch = catch_hook;
+  struct rtld_catch *lcatch = get_catch ();
 
   if (! errstring)
     errstring = N_("DYNAMIC LINKER BUG!!!");
@@ -123,10 +124,18 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
   else
     fatal_error (errcode, objname, occation, errstring);
 }
-libc_hidden_def (_dl_signal_error)
+rtld_hidden_def (_dl_signal_error)
 
+#if IS_IN (rtld)
+/* This points to a function which is called when an continuable error is
+   received.  Unlike the handling of `catch' this function may return.
+   The arguments will be the `errstring' and `objname'.
+
+   Since this functionality is not used in normal programs (only in ld.so)
+   we do not care about multi-threaded programs here.  We keep this as a
+   global variable.  */
+static receiver_fct receiver;
 
-#if DL_ERROR_BOOTSTRAP
 void
 _dl_signal_cexception (int errcode, struct dl_exception *exception,
 		       const char *occasion)
@@ -167,7 +176,23 @@ _dl_signal_cerror (int errcode, const char *objname, const char *occation,
   else
     _dl_signal_error (errcode, objname, occation, errstring);
 }
-#endif /* DL_ERROR_BOOTSTRAP */
+
+void
+_dl_receive_error (receiver_fct fct, void (*operate) (void *), void *args)
+{
+  struct rtld_catch *old_catch = get_catch ();
+  receiver_fct old_receiver = receiver;
+
+  /* Set the new values.  */
+  set_catch (NULL);
+  receiver = fct;
+
+  (*operate) (args);
+
+  set_catch (old_catch);
+  receiver = old_receiver;
+}
+#endif
 
 int
 _dl_catch_exception (struct dl_exception *exception,
@@ -177,11 +202,11 @@ _dl_catch_exception (struct dl_exception *exception,
      Exceptions during operate (args) are fatal.  */
   if (exception == NULL)
     {
-      struct catch *const old = catch_hook;
-      catch_hook = NULL;
+      struct rtld_catch *old_catch = get_catch ();
+      set_catch (NULL);
       operate (args);
       /* If we get here, the operation was successful.  */
-      catch_hook = old;
+      set_catch (old_catch);
       return 0;
     }
 
@@ -194,19 +219,19 @@ _dl_catch_exception (struct dl_exception *exception,
      in _dl_signal_error (before longjmp).  */
   volatile int errcode;
 
-  struct catch c;
+  struct rtld_catch c;
   /* Don't use an initializer since we don't need to clear C.env.  */
   c.exception = exception;
   c.errcode = &errcode;
 
-  struct catch *const old = catch_hook;
-  catch_hook = &c;
+  struct rtld_catch *old = get_catch ();
+  set_catch (&c);
 
   /* Do not save the signal mask.  */
   if (__builtin_expect (__sigsetjmp (c.env, 0), 0) == 0)
     {
       (*operate) (args);
-      catch_hook = old;
+      set_catch (old);
       *exception = (struct dl_exception) { NULL };
       return 0;
     }
@@ -214,10 +239,10 @@ _dl_catch_exception (struct dl_exception *exception,
   /* We get here only if we longjmp'd out of OPERATE.
      _dl_signal_exception has already stored values into
      *EXCEPTION.  */
-  catch_hook = old;
+  set_catch (old);
   return errcode;
 }
-libc_hidden_def (_dl_catch_exception)
+rtld_hidden_def (_dl_catch_exception)
 
 int
 _dl_catch_error (const char **objname, const char **errstring,
@@ -230,34 +255,3 @@ _dl_catch_error (const char **objname, const char **errstring,
   *mallocedp = exception.message_buffer == exception.errstring;
   return errorcode;
 }
-libc_hidden_def (_dl_catch_error)
-
-#if DL_ERROR_BOOTSTRAP
-void
-_dl_receive_error (receiver_fct fct, void (*operate) (void *), void *args)
-{
-  struct catch *old_catch = catch_hook;
-  receiver_fct old_receiver = receiver;
-
-  /* Set the new values.  */
-  catch_hook = NULL;
-  receiver = fct;
-
-  (*operate) (args);
-
-  catch_hook = old_catch;
-  receiver = old_receiver;
-}
-
-/* Forwarder used for initializing GLRO (_dl_catch_error).  */
-int
-_rtld_catch_error (const char **objname, const char **errstring,
-		   bool *mallocedp, void (*operate) (void *),
-		   void *args)
-{
-  /* The reference to _dl_catch_error will eventually be relocated to
-     point to the implementation in libc.so.  */
-  return _dl_catch_error (objname, errstring, mallocedp, operate, args);
-}
-
-#endif /* DL_ERROR_BOOTSTRAP */
diff --git a/elf/dl-error-minimal.c b/elf/dl-error-minimal.c
deleted file mode 100644
index 9b833b90c0..0000000000
--- a/elf/dl-error-minimal.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Error handling for runtime dynamic linker, minimal version.
-   Copyright (C) 1995-2022 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/>.  */
-
-/* This version does lives in ld.so, does not use thread-local data
-   and supports _dl_signal_cerror and _dl_receive_error.  */
-
-#define DL_ERROR_BOOTSTRAP 1
-#include "dl-error-skeleton.c"
diff --git a/elf/dl-error.c b/elf/dl-error.c
deleted file mode 100644
index 0b7332a84f..0000000000
--- a/elf/dl-error.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Error handling for runtime dynamic linker, full version.
-   Copyright (C) 1995-2022 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/>.  */
-
-/* This implementation lives in libc.so because it uses thread-local
-   data, which is not available in ld.so.  It interposes the version
-   in dl-error-minimal.c after ld.so bootstrap.
-
-   The signal/catch mechanism is used by the audit framework, which
-   means that even in ld.so, not all errors are fatal.  */
-
-#define DL_ERROR_BOOTSTRAP 0
-#include "dl-error-skeleton.c"
diff --git a/elf/rtld.c b/elf/rtld.c
index 714434b21d..7254b6259e 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -370,7 +370,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_lookup_symbol_x = _dl_lookup_symbol_x,
     ._dl_open = _dl_open,
     ._dl_close = _dl_close,
-    ._dl_catch_error = _rtld_catch_error,
+    ._dl_catch_error = _dl_catch_error,
     ._dl_error_free = _dl_error_free,
     ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
     ._dl_libc_freeres = __rtld_libc_freeres,
diff --git a/nptl/descr.h b/nptl/descr.h
index 5cacb286f3..0fa0e48f39 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -390,6 +390,9 @@ struct pthread
      masked.)  */
   internal_sigset_t sigmask;
 
+  /* Used by the exception handling implementation in the dynamic loader.  */
+  struct rtld_catch *rtld_catch;
+
   /* Indicates whether is a C11 thread created by thrd_creat.  */
   bool c11;
 
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index fc81affed0..cb9969bcc4 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -845,13 +845,13 @@ rtld_hidden_proto (_dl_exception_free)
 void _dl_signal_exception (int errcode, struct dl_exception *,
 			   const char *occasion)
   __attribute__ ((__noreturn__));
-libc_hidden_proto (_dl_signal_exception)
+rtld_hidden_proto (_dl_signal_exception)
 
 /* Like _dl_signal_exception, but creates the exception first.  */
 extern void _dl_signal_error (int errcode, const char *object,
 			      const char *occasion, const char *errstring)
      __attribute__ ((__noreturn__));
-libc_hidden_proto (_dl_signal_error)
+rtld_hidden_proto (_dl_signal_error)
 
 /* Like _dl_signal_exception, but may return when called in the
    context of _dl_receive_error.  This is only used during ld.so
@@ -903,11 +903,7 @@ extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
    the returned string is allocated using the libc's malloc.  */
 extern int _dl_catch_error (const char **objname, const char **errstring,
 			    bool *mallocedp, void (*operate) (void *),
-			    void *args);
-libc_hidden_proto (_dl_catch_error)
-
-/* Used for initializing GLRO (_dl_catch_error).  */
-extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden;
+			    void *args) attribute_hidden;
 
 /* Call OPERATE (ARGS).  If no error occurs, set *EXCEPTION to zero.
    Otherwise, store a copy of the raised exception in *EXCEPTION,
@@ -916,7 +912,7 @@ extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden;
    disabled (so that exceptions are fatal).  */
 int _dl_catch_exception (struct dl_exception *exception,
 			 void (*operate) (void *), void *args);
-libc_hidden_proto (_dl_catch_exception)
+rtld_hidden_proto (_dl_catch_exception)
 
 /* Open the shared object NAME and map in its segments.
    LOADER's DT_RPATH is used in searching for NAME.
diff --git a/sysdeps/generic/localplt.data b/sysdeps/generic/localplt.data
index 9b4f35786a..afa03b0de1 100644
--- a/sysdeps/generic/localplt.data
+++ b/sysdeps/generic/localplt.data
@@ -6,8 +6,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
index fdff008abd..c01e4d81e4 100644
--- a/sysdeps/mach/hurd/i386/localplt.data
+++ b/sysdeps/mach/hurd/i386/localplt.data
@@ -8,11 +8,6 @@ libc.so: free + REL R_386_GLOB_DAT
 libc.so: malloc + REL R_386_GLOB_DAT
 libc.so: realloc + REL R_386_GLOB_DAT
 libm.so: matherr + REL R_386_GLOB_DAT
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error + REL R_386_GLOB_DAT
-ld.so: _dl_catch_error + REL R_386_GLOB_DAT
-ld.so: _dl_signal_exception + REL R_386_GLOB_DAT
-ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
 # The dynamic linker has its own versions of basic functions for initial loading
 # of shared libraries.  These need to be overriden by libc once loaded.
 ld.so: __open ?
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index 3817b7230d..602bacc0de 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -48,6 +48,9 @@ typedef struct
      compatible with the i386 Linux version.  */
   mach_port_t reply_port;      /* This thread's reply port.  */
   struct hurd_sigstate *_hurd_sigstate;
+
+  /* Used by the exception handling implementation in the dynamic loader.  */
+  struct rtld_catch *rtld_catch;
 } tcbhead_t;
 
 /* Return tcbhead_t from a TLS segment descriptor.  */
diff --git a/sysdeps/unix/sysv/linux/aarch64/localplt.data b/sysdeps/unix/sysv/linux/aarch64/localplt.data
index 348b3f3793..5d217cc50d 100644
--- a/sysdeps/unix/sysv/linux/aarch64/localplt.data
+++ b/sysdeps/unix/sysv/linux/aarch64/localplt.data
@@ -11,8 +11,3 @@ libm.so: matherr
 libc.so: __getauxval ?
 # The dynamic loader needs __tls_get_addr for TLS.
 ld.so: __tls_get_addr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/alpha/localplt.data b/sysdeps/unix/sysv/linux/alpha/localplt.data
index 44bf36f4f1..8548e0294b 100644
--- a/sysdeps/unix/sysv/linux/alpha/localplt.data
+++ b/sysdeps/unix/sysv/linux/alpha/localplt.data
@@ -25,8 +25,3 @@ libm.so: matherr + RELA R_ALPHA_GLOB_DAT
 libm.so: __atan2
 # The dynamic loader needs __tls_get_addr for TLS.
 ld.so: __tls_get_addr ?
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error + RELA R_ALPHA_GLOB_DAT
-ld.so: _dl_catch_error + RELA R_ALPHA_GLOB_DAT
-ld.so: _dl_signal_exception + RELA R_ALPHA_GLOB_DAT
-ld.so: _dl_catch_exception + RELA R_ALPHA_GLOB_DAT
diff --git a/sysdeps/unix/sysv/linux/arc/localplt.data b/sysdeps/unix/sysv/linux/arc/localplt.data
index ac5332caf7..8a13efc7d0 100644
--- a/sysdeps/unix/sysv/linux/arc/localplt.data
+++ b/sysdeps/unix/sysv/linux/arc/localplt.data
@@ -4,8 +4,3 @@ libc.so: calloc
 libc.so: free
 # At -Os, a struct assignment in libgcc-static pulls this in
 libc.so: memcpy ?
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/arm/localplt.data b/sysdeps/unix/sysv/linux/arm/localplt.data
index 78896444c6..162c664a01 100644
--- a/sysdeps/unix/sysv/linux/arm/localplt.data
+++ b/sysdeps/unix/sysv/linux/arm/localplt.data
@@ -6,8 +6,3 @@ libc.so: realloc
 libm.so: matherr
 # The dynamic loader needs __tls_get_addr for TLS.
 ld.so: __tls_get_addr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/csky/localplt.data b/sysdeps/unix/sysv/linux/csky/localplt.data
index 817ab2659a..547b1c1b7f 100644
--- a/sysdeps/unix/sysv/linux/csky/localplt.data
+++ b/sysdeps/unix/sysv/linux/csky/localplt.data
@@ -5,8 +5,3 @@ libc.so: calloc
 libc.so: free
 libc.so: malloc
 libc.so: realloc
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/hppa/localplt.data b/sysdeps/unix/sysv/linux/hppa/localplt.data
index baf857a750..f8582c08d2 100644
--- a/sysdeps/unix/sysv/linux/hppa/localplt.data
+++ b/sysdeps/unix/sysv/linux/hppa/localplt.data
@@ -9,8 +9,3 @@ libc.so: __sigsetjmp
 libc.so: _IO_funlockfile
 libc.so: __errno_location
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
index f9bf7fb410..a998772f04 100644
--- a/sysdeps/unix/sysv/linux/i386/localplt.data
+++ b/sysdeps/unix/sysv/linux/i386/localplt.data
@@ -6,8 +6,3 @@ libc.so: free + REL R_386_GLOB_DAT
 libc.so: malloc + REL R_386_GLOB_DAT
 libc.so: realloc + REL R_386_GLOB_DAT
 libm.so: matherr + REL R_386_GLOB_DAT
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error + REL R_386_GLOB_DAT
-ld.so: _dl_catch_error + REL R_386_GLOB_DAT
-ld.so: _dl_signal_exception + REL R_386_GLOB_DAT
-ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
diff --git a/sysdeps/unix/sysv/linux/ia64/localplt.data b/sysdeps/unix/sysv/linux/ia64/localplt.data
index 174fb88128..9673d4b20e 100644
--- a/sysdeps/unix/sysv/linux/ia64/localplt.data
+++ b/sysdeps/unix/sysv/linux/ia64/localplt.data
@@ -5,8 +5,3 @@ libc.so: realloc
 libm.so: matherr
 libm.so: matherrf
 libm.so: matherrl
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
index 42fa90508c..ea770469b6 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
@@ -4,8 +4,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
index 34bd4c1aca..8ffdf3bfb9 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
@@ -5,8 +5,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/microblaze/localplt.data b/sysdeps/unix/sysv/linux/microblaze/localplt.data
index c3801314c9..7cd3653372 100644
--- a/sysdeps/unix/sysv/linux/microblaze/localplt.data
+++ b/sysdeps/unix/sysv/linux/microblaze/localplt.data
@@ -6,8 +6,3 @@ libc.so: realloc
 libm.so: matherr
 # The dynamic loader needs __tls_get_addr for TLS.
 ld.so: __tls_get_addr ?
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/nios2/localplt.data b/sysdeps/unix/sysv/linux/nios2/localplt.data
index c9802cc8eb..f502a3f0f6 100644
--- a/sysdeps/unix/sysv/linux/nios2/localplt.data
+++ b/sysdeps/unix/sysv/linux/nios2/localplt.data
@@ -28,8 +28,3 @@ libc.so: __extendsfdf2
 libc.so: __floatundidf ?
 libc.so: __floatunsidf ?
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
index c0af84eef7..6c1efff68f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
@@ -4,8 +4,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
index 581e54b95c..eca59e1ed6 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
@@ -35,8 +35,3 @@ libc.so: realloc
 libm.so: copysignl ?
 libm.so: fabsl
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
index d69b7ae646..240d998f57 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
@@ -3,8 +3,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
index e6d5330d5b..ea887042e0 100644
--- a/sysdeps/unix/sysv/linux/riscv/localplt.data
+++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
@@ -6,8 +6,3 @@ libc.so: free
 libc.so: malloc
 libc.so: memset ?
 libc.so: realloc
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/s390/localplt.data b/sysdeps/unix/sysv/linux/s390/localplt.data
index c0af84eef7..6c1efff68f 100644
--- a/sysdeps/unix/sysv/linux/s390/localplt.data
+++ b/sysdeps/unix/sysv/linux/s390/localplt.data
@@ -4,8 +4,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/sh/localplt.data b/sysdeps/unix/sysv/linux/sh/localplt.data
index 6491b9e37b..3d2e4c1c28 100644
--- a/sysdeps/unix/sysv/linux/sh/localplt.data
+++ b/sysdeps/unix/sysv/linux/sh/localplt.data
@@ -11,8 +11,3 @@ libc.so: __errno_location
 libm.so: matherr
 # Generated by the compiler because there is no trap insn pattern.
 libc.so: abort ?
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
index 38309a1393..b5fc6d9c3a 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
@@ -18,8 +18,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
index 6a216f3a5a..12520b1586 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
@@ -17,8 +17,3 @@ libc.so: free
 libc.so: malloc
 libc.so: realloc
 libm.so: matherr
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error
-ld.so: _dl_catch_error
-ld.so: _dl_signal_exception
-ld.so: _dl_catch_exception
diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
index d1f2e26612..0d424a5c1f 100644
--- a/sysdeps/x86_64/localplt.data
+++ b/sysdeps/x86_64/localplt.data
@@ -8,8 +8,3 @@ libc.so: free + RELA R_X86_64_GLOB_DAT
 libc.so: malloc + RELA R_X86_64_GLOB_DAT
 libc.so: realloc + RELA R_X86_64_GLOB_DAT
 libm.so: matherr + RELA R_X86_64_GLOB_DAT
-# The TLS-enabled version of these functions is interposed from libc.so.
-ld.so: _dl_signal_error + RELA R_X86_64_GLOB_DAT
-ld.so: _dl_catch_error + RELA R_X86_64_GLOB_DAT
-ld.so: _dl_signal_exception + RELA R_X86_64_GLOB_DAT
-ld.so: _dl_catch_exception + RELA R_X86_64_GLOB_DAT
-- 
2.37.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486]
  2022-08-29 12:27 ` [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
@ 2022-10-26 20:34   ` Siddhesh Poyarekar
  2022-10-27  9:46     ` Florian Weimer
  0 siblings, 1 reply; 8+ messages in thread
From: Siddhesh Poyarekar @ 2022-10-26 20:34 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 2022-08-29 08:27, Florian Weimer via Libc-alpha wrote:
> The old exception handling implementation used function interposition
> to replace the dynamic loader implementation (no TLS support) with the
> libc implementation (TLS support).  This results in problems if the
> link order between the dynamic loader and libc is reversed (bug 25486).
> 
> The new implementation moves the entire implementation of the
> exception handling functions back into the dynamic loader, using
> THREAD_GETMEM and THREAD_SETMEM for thread-local data support.
> These depends on Hurd support for these macros, added in commit
> b65a82e4e757c1e6cb7073916 ("hurd: Add THREAD_GET/SETMEM/_NC").
> 
> One small obstacle is that the exception handling facilities are used
> before the TCB has been set up, so a check is needed if the TCB is
> available.  If not, a regular global variable is used to store the
> exception handling information.
> 
> Also rename dl-error.c to dl-catch.c, to avoid confusion with the
> dlerror function.
> ---
>   elf/Makefile                                  |   3 +-
>   elf/Versions                                  |   8 +-
>   elf/{dl-error-skeleton.c => dl-catch.c}       | 150 +++++++++---------
>   elf/dl-error-minimal.c                        |  23 ---
>   elf/dl-error.c                                |  27 ----
>   elf/rtld.c                                    |   2 +-
>   nptl/descr.h                                  |   3 +
>   sysdeps/generic/ldsodefs.h                    |  12 +-
>   sysdeps/generic/localplt.data                 |   5 -
>   sysdeps/mach/hurd/i386/localplt.data          |   5 -
>   sysdeps/mach/hurd/i386/tls.h                  |   3 +
>   sysdeps/unix/sysv/linux/aarch64/localplt.data |   5 -
>   sysdeps/unix/sysv/linux/alpha/localplt.data   |   5 -
>   sysdeps/unix/sysv/linux/arc/localplt.data     |   5 -
>   sysdeps/unix/sysv/linux/arm/localplt.data     |   5 -
>   sysdeps/unix/sysv/linux/csky/localplt.data    |   5 -
>   sysdeps/unix/sysv/linux/hppa/localplt.data    |   5 -
>   sysdeps/unix/sysv/linux/i386/localplt.data    |   5 -
>   sysdeps/unix/sysv/linux/ia64/localplt.data    |   5 -
>   .../sysv/linux/m68k/coldfire/localplt.data    |   5 -
>   .../unix/sysv/linux/m68k/m680x0/localplt.data |   5 -
>   .../unix/sysv/linux/microblaze/localplt.data  |   5 -
>   sysdeps/unix/sysv/linux/nios2/localplt.data   |   5 -
>   .../linux/powerpc/powerpc32/fpu/localplt.data |   5 -
>   .../powerpc/powerpc32/nofpu/localplt.data     |   5 -
>   .../linux/powerpc/powerpc64/localplt.data     |   5 -
>   sysdeps/unix/sysv/linux/riscv/localplt.data   |   5 -
>   sysdeps/unix/sysv/linux/s390/localplt.data    |   5 -
>   sysdeps/unix/sysv/linux/sh/localplt.data      |   5 -
>   .../sysv/linux/sparc/sparc32/localplt.data    |   5 -
>   .../sysv/linux/sparc/sparc64/localplt.data    |   5 -
>   sysdeps/x86_64/localplt.data                  |   5 -
>   32 files changed, 85 insertions(+), 261 deletions(-)
>   rename elf/{dl-error-skeleton.c => dl-catch.c} (76%)
>   delete mode 100644 elf/dl-error-minimal.c
>   delete mode 100644 elf/dl-error.c

A couple of nits to fix below, OK otherwise.

Thanks,
Sid

> 
> diff --git a/elf/Makefile b/elf/Makefile
> index 008770bfaf..d702d6bd79 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -34,7 +34,6 @@ routines = \
>     dl-addr \
>     dl-addr-obj \
>     dl-early_allocate \
> -  dl-error \
>     dl-iteratephdr \
>     dl-libc \
>     dl-origin \
> @@ -53,6 +52,7 @@ routines = \
>   # profiled libraries.
>   dl-routines = \
>     dl-call-libc-early-init \
> +  dl-catch \
>     dl-close \
>     dl-debug \
>     dl-debug-symbols \
> @@ -133,7 +133,6 @@ rtld-routines = \
>     dl-diagnostics-cpu \
>     dl-diagnostics-kernel \
>     dl-environ \
> -  dl-error-minimal \
>     dl-hwcaps \
>     dl-hwcaps-subdirs \
>     dl-hwcaps_split \
> diff --git a/elf/Versions b/elf/Versions
> index a9ff278de7..4614acea3e 100644
> --- a/elf/Versions
> +++ b/elf/Versions
> @@ -31,10 +31,6 @@ libc {
>     GLIBC_PRIVATE {
>       # functions used in other libraries
>       __libc_early_init;
> -
> -    # Internal error handling support.  Interposes the functions in ld.so.
> -    _dl_signal_exception; _dl_catch_exception;
> -    _dl_signal_error; _dl_catch_error;
>     }
>   }
>   
> @@ -77,10 +73,8 @@ ld {
>   
>       # Internal error handling support.
>       _dl_exception_create; _dl_exception_create_format; _dl_exception_free;
> -
> -    # Internal error handling support.  Interposed by libc.so.
>       _dl_signal_exception; _dl_catch_exception;
> -    _dl_signal_error; _dl_catch_error;
> +    _dl_signal_error;
>   
>       # Set value of a tunable.
>       __tunable_get_val;
> diff --git a/elf/dl-error-skeleton.c b/elf/dl-catch.c
> similarity index 76%
> rename from elf/dl-error-skeleton.c
> rename to elf/dl-catch.c
> index 8abf437f87..f7b8282a2c 100644
> --- a/elf/dl-error-skeleton.c
> +++ b/elf/dl-catch.c
> @@ -1,4 +1,4 @@
> -/* Template for error handling for runtime dynamic linker.
> +/* Exception handling in the dynamic linker.
>      Copyright (C) 1995-2022 Free Software Foundation, Inc.
>      This file is part of the GNU C Library.
>   
> @@ -16,16 +16,6 @@
>      License along with the GNU C Library; if not, see
>      <https://www.gnu.org/licenses/>.  */
>   
> -/* The following macro needs to be defined before including this
> -   skeleton file:
> -
> -   DL_ERROR_BOOTSTRAP
> -
> -     If 1, do not use TLS and implement _dl_signal_cerror and
> -     _dl_receive_error.  If 0, TLS is used, and the variants with
> -     error callbacks are not provided.  */
> -
> -
>   #include <libintl.h>
>   #include <setjmp.h>
>   #include <stdbool.h>
> @@ -34,39 +24,50 @@
>   #include <unistd.h>
>   #include <ldsodefs.h>
>   #include <stdio.h>
> +#include <tls.h>
>   
>   /* This structure communicates state between _dl_catch_error and
>      _dl_signal_error.  */
> -struct catch
> +struct rtld_catch
>     {
>       struct dl_exception *exception; /* The exception data is stored there.  */
>       volatile int *errcode;	/* Return value of _dl_signal_error.  */
>       jmp_buf env;		/* longjmp here on error.  */
>     };
>   
> -/* Multiple threads at once can use the `_dl_catch_error' function.  The
> -   calls can come from `_dl_map_object_deps', `_dlerror_run', or from
> -   any of the libc functionality which loads dynamic objects (NSS, iconv).
> -   Therefore we have to be prepared to save the state in thread-local
> -   memory.  */
> -#if !DL_ERROR_BOOTSTRAP
> -static __thread struct catch *catch_hook attribute_tls_model_ie;
> -#else
> -/* The version of this code in ld.so cannot use thread-local variables
> -   and is used during bootstrap only.  */
> -static struct catch *catch_hook;
> +/* Multiple threads at once can use the `_dl_catch_error' function.
> +   The calls can come from `_dl_map_object_deps', `_dlerror_run', or
> +   from any of the libc functionality which loads dynamic objects
> +   (NSS, iconv).  Therefore we have to be prepared to save the state
> +   in thread-local memory.  We use THREAD_GETMEM and THREAD_SETMEM
> +   instead of ELF TLS because it exception handling must work before

s/ it//

> +   the TCB and ELF TLS have been set up.  */
> +
> +#if IS_IN (rtld)
> +static struct rtld_catch *rtld_catch_notls;
>   #endif
>   
> -#if DL_ERROR_BOOTSTRAP
> -/* This points to a function which is called when an continuable error is
> -   received.  Unlike the handling of `catch' this function may return.
> -   The arguments will be the `errstring' and `objname'.
> +static struct rtld_catch *
> +get_catch (void)
> +{
> +#if IS_IN (rtld)
> +  if (!__rtld_tls_init_tp_called)
> +    return rtld_catch_notls;
> +  else
> +#endif
> +    return THREAD_GETMEM (THREAD_SELF, rtld_catch);
> +}
>   
> -   Since this functionality is not used in normal programs (only in ld.so)
> -   we do not care about multi-threaded programs here.  We keep this as a
> -   global variable.  */
> -static receiver_fct receiver;
> -#endif /* DL_ERROR_BOOTSTRAP */
> +static void
> +set_catch (struct rtld_catch *catch)
> +{
> +#if IS_IN (rtld)
> +  if (!__rtld_tls_init_tp_called)
> +    rtld_catch_notls = catch;
> +  else
> +#endif
> +    THREAD_SETMEM (THREAD_SELF, rtld_catch, catch);
> +}
>   
>   /* Lossage while resolving the program's own symbols is always fatal.  */
>   static void
> @@ -89,7 +90,7 @@ void
>   _dl_signal_exception (int errcode, struct dl_exception *exception,
>   		      const char *occasion)
>   {
> -  struct catch *lcatch = catch_hook;
> +  struct rtld_catch *lcatch = get_catch ();
>     if (lcatch != NULL)
>       {
>         *lcatch->exception = *exception;
> @@ -101,13 +102,13 @@ _dl_signal_exception (int errcode, struct dl_exception *exception,
>     else
>       fatal_error (errcode, exception->objname, occasion, exception->errstring);
>   }
> -libc_hidden_def (_dl_signal_exception)
> +rtld_hidden_def (_dl_signal_exception)
>   
>   void
>   _dl_signal_error (int errcode, const char *objname, const char *occation,
>   		  const char *errstring)
>   {
> -  struct catch *lcatch = catch_hook;
> +  struct rtld_catch *lcatch = get_catch ();
>   
>     if (! errstring)
>       errstring = N_("DYNAMIC LINKER BUG!!!");
> @@ -123,10 +124,18 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
>     else
>       fatal_error (errcode, objname, occation, errstring);
>   }
> -libc_hidden_def (_dl_signal_error)
> +rtld_hidden_def (_dl_signal_error)
>   
> +#if IS_IN (rtld)
> +/* This points to a function which is called when an continuable error is

s/an/a/

> +   received.  Unlike the handling of `catch' this function may return.
> +   The arguments will be the `errstring' and `objname'.
> +
> +   Since this functionality is not used in normal programs (only in ld.so)
> +   we do not care about multi-threaded programs here.  We keep this as a
> +   global variable.  */
> +static receiver_fct receiver;
>   
> -#if DL_ERROR_BOOTSTRAP
>   void
>   _dl_signal_cexception (int errcode, struct dl_exception *exception,
>   		       const char *occasion)
> @@ -167,7 +176,23 @@ _dl_signal_cerror (int errcode, const char *objname, const char *occation,
>     else
>       _dl_signal_error (errcode, objname, occation, errstring);
>   }
> -#endif /* DL_ERROR_BOOTSTRAP */
> +
> +void
> +_dl_receive_error (receiver_fct fct, void (*operate) (void *), void *args)
> +{
> +  struct rtld_catch *old_catch = get_catch ();
> +  receiver_fct old_receiver = receiver;
> +
> +  /* Set the new values.  */
> +  set_catch (NULL);
> +  receiver = fct;
> +
> +  (*operate) (args);
> +
> +  set_catch (old_catch);
> +  receiver = old_receiver;
> +}
> +#endif
>   
>   int
>   _dl_catch_exception (struct dl_exception *exception,
> @@ -177,11 +202,11 @@ _dl_catch_exception (struct dl_exception *exception,
>        Exceptions during operate (args) are fatal.  */
>     if (exception == NULL)
>       {
> -      struct catch *const old = catch_hook;
> -      catch_hook = NULL;
> +      struct rtld_catch *old_catch = get_catch ();
> +      set_catch (NULL);
>         operate (args);
>         /* If we get here, the operation was successful.  */
> -      catch_hook = old;
> +      set_catch (old_catch);
>         return 0;
>       }
>   
> @@ -194,19 +219,19 @@ _dl_catch_exception (struct dl_exception *exception,
>        in _dl_signal_error (before longjmp).  */
>     volatile int errcode;
>   
> -  struct catch c;
> +  struct rtld_catch c;
>     /* Don't use an initializer since we don't need to clear C.env.  */
>     c.exception = exception;
>     c.errcode = &errcode;
>   
> -  struct catch *const old = catch_hook;
> -  catch_hook = &c;
> +  struct rtld_catch *old = get_catch ();
> +  set_catch (&c);
>   
>     /* Do not save the signal mask.  */
>     if (__builtin_expect (__sigsetjmp (c.env, 0), 0) == 0)
>       {
>         (*operate) (args);
> -      catch_hook = old;
> +      set_catch (old);
>         *exception = (struct dl_exception) { NULL };
>         return 0;
>       }
> @@ -214,10 +239,10 @@ _dl_catch_exception (struct dl_exception *exception,
>     /* We get here only if we longjmp'd out of OPERATE.
>        _dl_signal_exception has already stored values into
>        *EXCEPTION.  */
> -  catch_hook = old;
> +  set_catch (old);
>     return errcode;
>   }
> -libc_hidden_def (_dl_catch_exception)
> +rtld_hidden_def (_dl_catch_exception)
>   
>   int
>   _dl_catch_error (const char **objname, const char **errstring,
> @@ -230,34 +255,3 @@ _dl_catch_error (const char **objname, const char **errstring,
>     *mallocedp = exception.message_buffer == exception.errstring;
>     return errorcode;
>   }
> -libc_hidden_def (_dl_catch_error)
> -
> -#if DL_ERROR_BOOTSTRAP
> -void
> -_dl_receive_error (receiver_fct fct, void (*operate) (void *), void *args)
> -{
> -  struct catch *old_catch = catch_hook;
> -  receiver_fct old_receiver = receiver;
> -
> -  /* Set the new values.  */
> -  catch_hook = NULL;
> -  receiver = fct;
> -
> -  (*operate) (args);
> -
> -  catch_hook = old_catch;
> -  receiver = old_receiver;
> -}
> -
> -/* Forwarder used for initializing GLRO (_dl_catch_error).  */
> -int
> -_rtld_catch_error (const char **objname, const char **errstring,
> -		   bool *mallocedp, void (*operate) (void *),
> -		   void *args)
> -{
> -  /* The reference to _dl_catch_error will eventually be relocated to
> -     point to the implementation in libc.so.  */
> -  return _dl_catch_error (objname, errstring, mallocedp, operate, args);
> -}
> -
> -#endif /* DL_ERROR_BOOTSTRAP */
> diff --git a/elf/dl-error-minimal.c b/elf/dl-error-minimal.c
> deleted file mode 100644
> index 9b833b90c0..0000000000
> --- a/elf/dl-error-minimal.c
> +++ /dev/null
> @@ -1,23 +0,0 @@
> -/* Error handling for runtime dynamic linker, minimal version.
> -   Copyright (C) 1995-2022 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/>.  */
> -
> -/* This version does lives in ld.so, does not use thread-local data
> -   and supports _dl_signal_cerror and _dl_receive_error.  */
> -
> -#define DL_ERROR_BOOTSTRAP 1
> -#include "dl-error-skeleton.c"
> diff --git a/elf/dl-error.c b/elf/dl-error.c
> deleted file mode 100644
> index 0b7332a84f..0000000000
> --- a/elf/dl-error.c
> +++ /dev/null
> @@ -1,27 +0,0 @@
> -/* Error handling for runtime dynamic linker, full version.
> -   Copyright (C) 1995-2022 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/>.  */
> -
> -/* This implementation lives in libc.so because it uses thread-local
> -   data, which is not available in ld.so.  It interposes the version
> -   in dl-error-minimal.c after ld.so bootstrap.
> -
> -   The signal/catch mechanism is used by the audit framework, which
> -   means that even in ld.so, not all errors are fatal.  */
> -
> -#define DL_ERROR_BOOTSTRAP 0
> -#include "dl-error-skeleton.c"
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 714434b21d..7254b6259e 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -370,7 +370,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
>       ._dl_lookup_symbol_x = _dl_lookup_symbol_x,
>       ._dl_open = _dl_open,
>       ._dl_close = _dl_close,
> -    ._dl_catch_error = _rtld_catch_error,
> +    ._dl_catch_error = _dl_catch_error,
>       ._dl_error_free = _dl_error_free,
>       ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
>       ._dl_libc_freeres = __rtld_libc_freeres,
> diff --git a/nptl/descr.h b/nptl/descr.h
> index 5cacb286f3..0fa0e48f39 100644
> --- a/nptl/descr.h
> +++ b/nptl/descr.h
> @@ -390,6 +390,9 @@ struct pthread
>        masked.)  */
>     internal_sigset_t sigmask;
>   
> +  /* Used by the exception handling implementation in the dynamic loader.  */
> +  struct rtld_catch *rtld_catch;
> +
>     /* Indicates whether is a C11 thread created by thrd_creat.  */
>     bool c11;
>   
> diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
> index fc81affed0..cb9969bcc4 100644
> --- a/sysdeps/generic/ldsodefs.h
> +++ b/sysdeps/generic/ldsodefs.h
> @@ -845,13 +845,13 @@ rtld_hidden_proto (_dl_exception_free)
>   void _dl_signal_exception (int errcode, struct dl_exception *,
>   			   const char *occasion)
>     __attribute__ ((__noreturn__));
> -libc_hidden_proto (_dl_signal_exception)
> +rtld_hidden_proto (_dl_signal_exception)
>   
>   /* Like _dl_signal_exception, but creates the exception first.  */
>   extern void _dl_signal_error (int errcode, const char *object,
>   			      const char *occasion, const char *errstring)
>        __attribute__ ((__noreturn__));
> -libc_hidden_proto (_dl_signal_error)
> +rtld_hidden_proto (_dl_signal_error)
>   
>   /* Like _dl_signal_exception, but may return when called in the
>      context of _dl_receive_error.  This is only used during ld.so
> @@ -903,11 +903,7 @@ extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
>      the returned string is allocated using the libc's malloc.  */
>   extern int _dl_catch_error (const char **objname, const char **errstring,
>   			    bool *mallocedp, void (*operate) (void *),
> -			    void *args);
> -libc_hidden_proto (_dl_catch_error)
> -
> -/* Used for initializing GLRO (_dl_catch_error).  */
> -extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden;
> +			    void *args) attribute_hidden;
>   
>   /* Call OPERATE (ARGS).  If no error occurs, set *EXCEPTION to zero.
>      Otherwise, store a copy of the raised exception in *EXCEPTION,
> @@ -916,7 +912,7 @@ extern __typeof__ (_dl_catch_error) _rtld_catch_error attribute_hidden;
>      disabled (so that exceptions are fatal).  */
>   int _dl_catch_exception (struct dl_exception *exception,
>   			 void (*operate) (void *), void *args);
> -libc_hidden_proto (_dl_catch_exception)
> +rtld_hidden_proto (_dl_catch_exception)
>   
>   /* Open the shared object NAME and map in its segments.
>      LOADER's DT_RPATH is used in searching for NAME.
> diff --git a/sysdeps/generic/localplt.data b/sysdeps/generic/localplt.data
> index 9b4f35786a..afa03b0de1 100644
> --- a/sysdeps/generic/localplt.data
> +++ b/sysdeps/generic/localplt.data
> @@ -6,8 +6,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
> index fdff008abd..c01e4d81e4 100644
> --- a/sysdeps/mach/hurd/i386/localplt.data
> +++ b/sysdeps/mach/hurd/i386/localplt.data
> @@ -8,11 +8,6 @@ libc.so: free + REL R_386_GLOB_DAT
>   libc.so: malloc + REL R_386_GLOB_DAT
>   libc.so: realloc + REL R_386_GLOB_DAT
>   libm.so: matherr + REL R_386_GLOB_DAT
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error + REL R_386_GLOB_DAT
> -ld.so: _dl_catch_error + REL R_386_GLOB_DAT
> -ld.so: _dl_signal_exception + REL R_386_GLOB_DAT
> -ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
>   # The dynamic linker has its own versions of basic functions for initial loading
>   # of shared libraries.  These need to be overriden by libc once loaded.
>   ld.so: __open ?
> diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
> index 3817b7230d..602bacc0de 100644
> --- a/sysdeps/mach/hurd/i386/tls.h
> +++ b/sysdeps/mach/hurd/i386/tls.h
> @@ -48,6 +48,9 @@ typedef struct
>        compatible with the i386 Linux version.  */
>     mach_port_t reply_port;      /* This thread's reply port.  */
>     struct hurd_sigstate *_hurd_sigstate;
> +
> +  /* Used by the exception handling implementation in the dynamic loader.  */
> +  struct rtld_catch *rtld_catch;
>   } tcbhead_t;
>   
>   /* Return tcbhead_t from a TLS segment descriptor.  */
> diff --git a/sysdeps/unix/sysv/linux/aarch64/localplt.data b/sysdeps/unix/sysv/linux/aarch64/localplt.data
> index 348b3f3793..5d217cc50d 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/aarch64/localplt.data
> @@ -11,8 +11,3 @@ libm.so: matherr
>   libc.so: __getauxval ?
>   # The dynamic loader needs __tls_get_addr for TLS.
>   ld.so: __tls_get_addr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/alpha/localplt.data b/sysdeps/unix/sysv/linux/alpha/localplt.data
> index 44bf36f4f1..8548e0294b 100644
> --- a/sysdeps/unix/sysv/linux/alpha/localplt.data
> +++ b/sysdeps/unix/sysv/linux/alpha/localplt.data
> @@ -25,8 +25,3 @@ libm.so: matherr + RELA R_ALPHA_GLOB_DAT
>   libm.so: __atan2
>   # The dynamic loader needs __tls_get_addr for TLS.
>   ld.so: __tls_get_addr ?
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error + RELA R_ALPHA_GLOB_DAT
> -ld.so: _dl_catch_error + RELA R_ALPHA_GLOB_DAT
> -ld.so: _dl_signal_exception + RELA R_ALPHA_GLOB_DAT
> -ld.so: _dl_catch_exception + RELA R_ALPHA_GLOB_DAT
> diff --git a/sysdeps/unix/sysv/linux/arc/localplt.data b/sysdeps/unix/sysv/linux/arc/localplt.data
> index ac5332caf7..8a13efc7d0 100644
> --- a/sysdeps/unix/sysv/linux/arc/localplt.data
> +++ b/sysdeps/unix/sysv/linux/arc/localplt.data
> @@ -4,8 +4,3 @@ libc.so: calloc
>   libc.so: free
>   # At -Os, a struct assignment in libgcc-static pulls this in
>   libc.so: memcpy ?
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/arm/localplt.data b/sysdeps/unix/sysv/linux/arm/localplt.data
> index 78896444c6..162c664a01 100644
> --- a/sysdeps/unix/sysv/linux/arm/localplt.data
> +++ b/sysdeps/unix/sysv/linux/arm/localplt.data
> @@ -6,8 +6,3 @@ libc.so: realloc
>   libm.so: matherr
>   # The dynamic loader needs __tls_get_addr for TLS.
>   ld.so: __tls_get_addr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/csky/localplt.data b/sysdeps/unix/sysv/linux/csky/localplt.data
> index 817ab2659a..547b1c1b7f 100644
> --- a/sysdeps/unix/sysv/linux/csky/localplt.data
> +++ b/sysdeps/unix/sysv/linux/csky/localplt.data
> @@ -5,8 +5,3 @@ libc.so: calloc
>   libc.so: free
>   libc.so: malloc
>   libc.so: realloc
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/hppa/localplt.data b/sysdeps/unix/sysv/linux/hppa/localplt.data
> index baf857a750..f8582c08d2 100644
> --- a/sysdeps/unix/sysv/linux/hppa/localplt.data
> +++ b/sysdeps/unix/sysv/linux/hppa/localplt.data
> @@ -9,8 +9,3 @@ libc.so: __sigsetjmp
>   libc.so: _IO_funlockfile
>   libc.so: __errno_location
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
> index f9bf7fb410..a998772f04 100644
> --- a/sysdeps/unix/sysv/linux/i386/localplt.data
> +++ b/sysdeps/unix/sysv/linux/i386/localplt.data
> @@ -6,8 +6,3 @@ libc.so: free + REL R_386_GLOB_DAT
>   libc.so: malloc + REL R_386_GLOB_DAT
>   libc.so: realloc + REL R_386_GLOB_DAT
>   libm.so: matherr + REL R_386_GLOB_DAT
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error + REL R_386_GLOB_DAT
> -ld.so: _dl_catch_error + REL R_386_GLOB_DAT
> -ld.so: _dl_signal_exception + REL R_386_GLOB_DAT
> -ld.so: _dl_catch_exception + REL R_386_GLOB_DAT
> diff --git a/sysdeps/unix/sysv/linux/ia64/localplt.data b/sysdeps/unix/sysv/linux/ia64/localplt.data
> index 174fb88128..9673d4b20e 100644
> --- a/sysdeps/unix/sysv/linux/ia64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/ia64/localplt.data
> @@ -5,8 +5,3 @@ libc.so: realloc
>   libm.so: matherr
>   libm.so: matherrf
>   libm.so: matherrl
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> index 42fa90508c..ea770469b6 100644
> --- a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> @@ -4,8 +4,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> index 34bd4c1aca..8ffdf3bfb9 100644
> --- a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> @@ -5,8 +5,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/microblaze/localplt.data b/sysdeps/unix/sysv/linux/microblaze/localplt.data
> index c3801314c9..7cd3653372 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/localplt.data
> +++ b/sysdeps/unix/sysv/linux/microblaze/localplt.data
> @@ -6,8 +6,3 @@ libc.so: realloc
>   libm.so: matherr
>   # The dynamic loader needs __tls_get_addr for TLS.
>   ld.so: __tls_get_addr ?
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/nios2/localplt.data b/sysdeps/unix/sysv/linux/nios2/localplt.data
> index c9802cc8eb..f502a3f0f6 100644
> --- a/sysdeps/unix/sysv/linux/nios2/localplt.data
> +++ b/sysdeps/unix/sysv/linux/nios2/localplt.data
> @@ -28,8 +28,3 @@ libc.so: __extendsfdf2
>   libc.so: __floatundidf ?
>   libc.so: __floatunsidf ?
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> index c0af84eef7..6c1efff68f 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> @@ -4,8 +4,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> index 581e54b95c..eca59e1ed6 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> @@ -35,8 +35,3 @@ libc.so: realloc
>   libm.so: copysignl ?
>   libm.so: fabsl
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> index d69b7ae646..240d998f57 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> @@ -3,8 +3,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
> index e6d5330d5b..ea887042e0 100644
> --- a/sysdeps/unix/sysv/linux/riscv/localplt.data
> +++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
> @@ -6,8 +6,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: memset ?
>   libc.so: realloc
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/s390/localplt.data b/sysdeps/unix/sysv/linux/s390/localplt.data
> index c0af84eef7..6c1efff68f 100644
> --- a/sysdeps/unix/sysv/linux/s390/localplt.data
> +++ b/sysdeps/unix/sysv/linux/s390/localplt.data
> @@ -4,8 +4,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/sh/localplt.data b/sysdeps/unix/sysv/linux/sh/localplt.data
> index 6491b9e37b..3d2e4c1c28 100644
> --- a/sysdeps/unix/sysv/linux/sh/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sh/localplt.data
> @@ -11,8 +11,3 @@ libc.so: __errno_location
>   libm.so: matherr
>   # Generated by the compiler because there is no trap insn pattern.
>   libc.so: abort ?
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> index 38309a1393..b5fc6d9c3a 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> @@ -18,8 +18,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> index 6a216f3a5a..12520b1586 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> @@ -17,8 +17,3 @@ libc.so: free
>   libc.so: malloc
>   libc.so: realloc
>   libm.so: matherr
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error
> -ld.so: _dl_catch_error
> -ld.so: _dl_signal_exception
> -ld.so: _dl_catch_exception
> diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
> index d1f2e26612..0d424a5c1f 100644
> --- a/sysdeps/x86_64/localplt.data
> +++ b/sysdeps/x86_64/localplt.data
> @@ -8,8 +8,3 @@ libc.so: free + RELA R_X86_64_GLOB_DAT
>   libc.so: malloc + RELA R_X86_64_GLOB_DAT
>   libc.so: realloc + RELA R_X86_64_GLOB_DAT
>   libm.so: matherr + RELA R_X86_64_GLOB_DAT
> -# The TLS-enabled version of these functions is interposed from libc.so.
> -ld.so: _dl_signal_error + RELA R_X86_64_GLOB_DAT
> -ld.so: _dl_catch_error + RELA R_X86_64_GLOB_DAT
> -ld.so: _dl_signal_exception + RELA R_X86_64_GLOB_DAT
> -ld.so: _dl_catch_exception + RELA R_X86_64_GLOB_DAT

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called
  2022-08-29 12:26 ` [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called Florian Weimer
@ 2022-10-26 20:34   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 8+ messages in thread
From: Siddhesh Poyarekar @ 2022-10-26 20:34 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 2022-08-29 08:26, Florian Weimer via Libc-alpha wrote:
> This allows the rest of dynamic loader to check whether the TCB
> has been set up (and THREAD_GETMEM and THREAD_SETMEM will work).
> ---
>   elf/rtld.c                 | 10 +++++-----
>   sysdeps/generic/ldsodefs.h |  3 +++
>   2 files changed, 8 insertions(+), 5 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@gotplt.org>

> 
> diff --git a/elf/rtld.c b/elf/rtld.c
> index cbbaf4a331..714434b21d 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -730,7 +730,7 @@ match_version (const char *string, struct link_map *map)
>     return 0;
>   }
>   
> -static bool tls_init_tp_called;
> +bool __rtld_tls_init_tp_called;
>   
>   static void *
>   init_tls (size_t naudit)
> @@ -800,7 +800,7 @@ cannot allocate TLS data structures for initial thread\n");
>     if (__glibc_unlikely (lossage != NULL))
>       _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage);
>     __tls_init_tp ();
> -  tls_init_tp_called = true;
> +  __rtld_tls_init_tp_called = true;
>   
>     return tcbp;
>   }
> @@ -2050,7 +2050,7 @@ dl_main (const ElfW(Phdr) *phdr,
>        an old kernel that can't perform TLS_INIT_TP, even if no TLS is ever
>        used.  Trying to do it lazily is too hairy to try when there could be
>        multiple threads (from a non-TLS-using libpthread).  */
> -  bool was_tls_init_tp_called = tls_init_tp_called;
> +  bool was_tls_init_tp_called = __rtld_tls_init_tp_called;
>     if (tcbp == NULL)
>       tcbp = init_tls (0);
>   
> @@ -2315,7 +2315,7 @@ dl_main (const ElfW(Phdr) *phdr,
>   			       consider_profiling);
>   
>   	/* Add object to slot information data if necessasy.  */
> -	if (l->l_tls_blocksize != 0 && tls_init_tp_called)
> +	if (l->l_tls_blocksize != 0 && __rtld_tls_init_tp_called)
>   	  _dl_add_to_slotinfo (l, true);
>         }
>     }
> @@ -2341,7 +2341,7 @@ dl_main (const ElfW(Phdr) *phdr,
>     _dl_allocate_tls_init (tcbp, false);
>   
>     /* And finally install it for the main thread.  */
> -  if (! tls_init_tp_called)
> +  if (! __rtld_tls_init_tp_called)
>       {
>         const char *lossage = TLS_INIT_TP (tcbp);
>         if (__glibc_unlikely (lossage != NULL))
> diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
> index 050a3032de..fc81affed0 100644
> --- a/sysdeps/generic/ldsodefs.h
> +++ b/sysdeps/generic/ldsodefs.h
> @@ -1217,6 +1217,9 @@ extern void *_dl_allocate_tls_storage (void) attribute_hidden;
>   extern void *_dl_allocate_tls_init (void *, bool);
>   rtld_hidden_proto (_dl_allocate_tls_init)
>   
> +/* True if the TCB has been set up.  */
> +extern bool __rtld_tls_init_tp_called attribute_hidden;
> +
>   /* Deallocate memory allocated with _dl_allocate_tls.  */
>   extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
>   rtld_hidden_proto (_dl_deallocate_tls)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY)
  2022-08-29 12:26 ` [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY) Florian Weimer
@ 2022-10-26 20:34   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 8+ messages in thread
From: Siddhesh Poyarekar @ 2022-10-26 20:34 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 2022-08-29 08:26, Florian Weimer via Libc-alpha wrote:
> On csky-linux-gnuabiv2, binutils 2.33 produces a DT_JMPREL entry
> for the dynamic loader if it does not contain any PLT relocations:
> 
> Dynamic section at offset 0x1df48 contains 19 entries:
>    Tag        Type                         Name/Value
>   0x0000000e (SONAME)                     Library soname: [ld-linux-cskyv2-hf.so.1]
>   0x00000004 (HASH)                       0xd4
>   0x6ffffef5 (GNU_HASH)                   0x1a8
>   0x00000005 (STRTAB)                     0x4ac
>   0x00000006 (SYMTAB)                     0x28c
>   0x0000000a (STRSZ)                      527 (bytes)
>   0x0000000b (SYMENT)                     16 (bytes)
>   0x00000003 (PLTGOT)                     0x1f000
>   0x00000002 (PLTRELSZ)                   0 (bytes)
>   0x00000014 (PLTREL)                     RELA
>   0x00000017 (JMPREL)                     0xaa4
>   0x00000007 (RELA)                       0x75c
>   0x00000008 (RELASZ)                     840 (bytes)
>   0x00000009 (RELAENT)                    12 (bytes)
>   0x6ffffffc (VERDEF)                     0x700
>   0x6ffffffd (VERDEFNUM)                  3
>   0x6ffffff0 (VERSYM)                     0x6bc
>   0x6ffffff9 (RELACOUNT)                  68
>   0x00000000 (NULL)                       0x0
> 
> This confuses the script:
> 
> Unexpected output from check-localplt: …/elf/ld.so.jmprel:
> *** DT_JMPREL does not match any section's address
> 
> This commit changes the script to record the DT_PLTRELSZ value and
> reject DT_JMPREL values not a section boundary only if DT_PLTRELSZ
> is present with a non-zero value.
> ---
>   scripts/localplt.awk | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> diff --git a/scripts/localplt.awk b/scripts/localplt.awk
> index beaa342922..fe79ca01ab 100644
> --- a/scripts/localplt.awk
> +++ b/scripts/localplt.awk
> @@ -4,17 +4,25 @@
>   # It writes "NAME: SYMBOL" for each PLT entry in NAME that refers to a
>   # symbol defined in the same object.
>   
> -BEGIN { result = 0 }
> +BEGIN {
> +  result = 0;
> +  pltrelsize = -1;
> +}
>   
>   FILENAME != lastfile {
>     if (lastfile && jmprel_offset == 0 && rela_offset == 0 && rel_offset == 0) {
>       print FILENAME ": *** failed to find expected output (readelf -WSdr)";
>       result = 2;
>     }
> +  if (pltrelsz > 0 && jmprel_offset == -1) {
> +    print FILENAME ": Could not find section for DT_JMPREL";
> +    result = 2;
> +  }
>     lastfile = FILENAME;
>     jmprel_offset = 0;
>     rela_offset = 0;
>     rel_offset = 0;
> +  pltrelsz = -1;
>     delete section_offset_by_address;
>   }
>   
> @@ -82,12 +90,16 @@ $2 == "(JMPREL)" {
>     if (jmprel_addr in section_offset_by_address) {
>       jmprel_offset = section_offset_by_address[jmprel_addr];
>     } else {
> -    print FILENAME ": *** DT_JMPREL does not match any section's address";
> -    result = 2;
> +    jmprel_offset = -1
>     }
>     next
>   }
>   
> +$2 == "(PLTRELSZ)" {
> +  pltrelsz = strtonum($3);
> +  next
> +}
> +
>   $2 == "(RELA)" {
>     rela_addr = strtonum($3);
>     if (rela_addr in section_offset_by_address) {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486]
  2022-10-26 20:34   ` Siddhesh Poyarekar
@ 2022-10-27  9:46     ` Florian Weimer
  0 siblings, 0 replies; 8+ messages in thread
From: Florian Weimer @ 2022-10-27  9:46 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

* Siddhesh Poyarekar:

>> +/* Multiple threads at once can use the `_dl_catch_error' function.
>> +   The calls can come from `_dl_map_object_deps', `_dlerror_run', or
>> +   from any of the libc functionality which loads dynamic objects
>> +   (NSS, iconv).  Therefore we have to be prepared to save the state
>> +   in thread-local memory.  We use THREAD_GETMEM and THREAD_SETMEM
>> +   instead of ELF TLS because it exception handling must work before
>
> s/ it//

There are other issues with the comment, I changed it to:

/* Multiple threads at once can use the `_dl_catch_error' function.
   The calls can come from `_dl_map_object_deps', `_dlerror_run', or
   from any of the libc functionality which loads dynamic objects
   (NSS, iconv).  Therefore we have to be prepared to save the state
   in thread-local memory.  We use THREAD_GETMEM and THREAD_SETMEM
   instead of ELF TLS because ELF TLS is not available in the dynamic
   loader.  Additionally, the exception handling mechanism must be
   usable before the TCB has been set up, which is why
   rtld_catch_notls is used if !__rtld_tls_init_tp_called.  This is
   not needed for static builds, where initialization completes before
   static dlopen etc. can be called.  */

>> -libc_hidden_def (_dl_signal_error)
>> +rtld_hidden_def (_dl_signal_error)
>>   +#if IS_IN (rtld)
>> +/* This points to a function which is called when an continuable error is
>
> s/an/a/

Fixed.

I'll repost after re-testing.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-27  9:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 12:26 [PATCH v4 0/3] Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
2022-08-29 12:26 ` [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called Florian Weimer
2022-10-26 20:34   ` Siddhesh Poyarekar
2022-08-29 12:26 ` [PATCH v4 2/3] scripts/localplt.awk: Handle DT_JMPREL with empty PLT (for C-SKY) Florian Weimer
2022-10-26 20:34   ` Siddhesh Poyarekar
2022-08-29 12:27 ` [PATCH v4 3/3] elf: Rework exception handling in the dynamic loader [BZ #25486] Florian Weimer
2022-10-26 20:34   ` Siddhesh Poyarekar
2022-10-27  9:46     ` Florian Weimer

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).