diff options
author | Florian Weimer <fweimer@redhat.com> | 2022-11-03 09:39:31 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2022-11-03 09:39:31 +0100 |
commit | ee1ada1bdb8074de6e1bdc956ab19aef7b6a7872 (patch) | |
tree | 4e70dfcb1c076da10542c08d7e0b3900a0a34adc /sysdeps | |
parent | f4ce325dfc50e13cf8240424fa0561fca78e72e7 (diff) | |
download | glibc-ee1ada1bdb8074de6e1bdc956ab19aef7b6a7872.tar.gz glibc-ee1ada1bdb8074de6e1bdc956ab19aef7b6a7872.tar.xz glibc-ee1ada1bdb8074de6e1bdc956ab19aef7b6a7872.zip |
elf: Rework exception handling in the dynamic loader [BZ #25486]
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. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'sysdeps')
27 files changed, 7 insertions, 133 deletions
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 2747f88d0e..9dae72b1ed 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -848,13 +848,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 @@ -906,11 +906,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, @@ -919,7 +915,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/loongarch/localplt.data b/sysdeps/unix/sysv/linux/loongarch/localplt.data index 817ab2659a..547b1c1b7f 100644 --- a/sysdeps/unix/sysv/linux/loongarch/localplt.data +++ b/sysdeps/unix/sysv/linux/loongarch/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/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/or1k/localplt.data b/sysdeps/unix/sysv/linux/or1k/localplt.data index 04eb9fc8dc..e7704955f1 100644 --- a/sysdeps/unix/sysv/linux/or1k/localplt.data +++ b/sysdeps/unix/sysv/linux/or1k/localplt.data @@ -7,8 +7,3 @@ libc.so: malloc libc.so: realloc # 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/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 |