Module Name: src Committed By: skrll Date: Sat Dec 4 14:39:08 UTC 2021
Modified Files: src/libexec/ld.elf_so: headers.c rtld.c rtld.h src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c Log Message: Restore the fptr_t type of {init,fini}{,_array} that was removed when initial support for indirect functions was added. This fixes {init,fini}_array support on hppa where each member of the array is (already) a plabel. Discussed with joerg. 4 files changed, 29 insertions(+), 39 deletions(-) : ---------------------------------------------------------------------- To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/libexec/ld.elf_so/headers.c cvs rdiff -u -r1.209 -r1.210 src/libexec/ld.elf_so/rtld.c cvs rdiff -u -r1.141 -r1.142 src/libexec/ld.elf_so/rtld.h cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/libexec/ld.elf_so/headers.c diff -u src/libexec/ld.elf_so/headers.c:1.69 src/libexec/ld.elf_so/headers.c:1.70 --- src/libexec/ld.elf_so/headers.c:1.69 Sat May 16 16:43:15 2020 +++ src/libexec/ld.elf_so/headers.c Sat Dec 4 14:39:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: headers.c,v 1.69 2020/05/16 16:43:15 skrll Exp $ */ +/* $NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: headers.c,v 1.69 2020/05/16 16:43:15 skrll Exp $"); +__RCSID("$NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $"); #endif /* not lint */ #include <err.h> @@ -299,7 +299,7 @@ _rtld_digest_dynamic(const char *execnam #ifdef HAVE_INITFINI_ARRAY case DT_INIT_ARRAY: obj->init_array = - (Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr); + (fptr_t *)(obj->relocbase + dynp->d_un.d_ptr); dbg(("headers: DT_INIT_ARRAY at %p", obj->init_array)); break; @@ -320,7 +320,7 @@ _rtld_digest_dynamic(const char *execnam #ifdef HAVE_INITFINI_ARRAY case DT_FINI_ARRAY: obj->fini_array = - (Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr); + (fptr_t *)(obj->relocbase + dynp->d_un.d_ptr); dbg(("headers: DT_FINI_ARRAY at %p", obj->fini_array)); break; @@ -434,10 +434,19 @@ _rtld_digest_dynamic(const char *execnam } #ifdef RTLD_LOADER +#if defined(__HAVE_FUNCTION_DESCRIPTORS) + if (init != 0) + obj->init = (void (*)(void)) + _rtld_function_descriptor_alloc(obj, NULL, init); + if (fini != 0) + obj->fini = (void (*)(void)) + _rtld_function_descriptor_alloc(obj, NULL, fini); +#else if (init != 0) - obj->init = (Elf_Addr) obj->relocbase + init; + obj->init = (void (*)(void)) (obj->relocbase + init); if (fini != 0) - obj->fini = (Elf_Addr) obj->relocbase + fini; + obj->fini = (void (*)(void)) (obj->relocbase + fini); +#endif #endif if (dyn_rpath != NULL) { Index: src/libexec/ld.elf_so/rtld.c diff -u src/libexec/ld.elf_so/rtld.c:1.209 src/libexec/ld.elf_so/rtld.c:1.210 --- src/libexec/ld.elf_so/rtld.c:1.209 Wed Jun 16 21:53:51 2021 +++ src/libexec/ld.elf_so/rtld.c Sat Dec 4 14:39:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $ */ +/* $NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $"); +__RCSID("$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -137,25 +137,25 @@ static Obj_Entry *_rtld_obj_from_addr(co static void _rtld_fill_dl_phdr_info(const Obj_Entry *, struct dl_phdr_info *); static inline void -_rtld_call_initfini_function(const Obj_Entry *obj, Elf_Addr func, sigset_t *mask) +_rtld_call_initfini_function(fptr_t func, sigset_t *mask) { _rtld_exclusive_exit(mask); - _rtld_call_function_void(obj, func); + (*func)(); _rtld_exclusive_enter(mask); } static void _rtld_call_fini_function(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen) { - if (obj->fini_arraysz == 0 && (obj->fini == 0 || obj->fini_called)) + if (obj->fini_arraysz == 0 && (obj->fini == NULL || obj->fini_called)) return; - if (obj->fini != 0 && !obj->fini_called) { + if (obj->fini != NULL && !obj->fini_called) { dbg (("calling fini function %s at %p%s", obj->path, (void *)obj->fini, obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); obj->fini_called = 1; - _rtld_call_initfini_function(obj, obj->fini, mask); + _rtld_call_initfini_function(obj->fini, mask); } #ifdef HAVE_INITFINI_ARRAY /* @@ -165,12 +165,12 @@ _rtld_call_fini_function(Obj_Entry *obj, * the loop. */ while (obj->fini_arraysz > 0 && _rtld_objgen == cur_objgen) { - Elf_Addr fini = *obj->fini_array++; + fptr_t fini = *obj->fini_array++; obj->fini_arraysz--; dbg (("calling fini array function %s at %p%s", obj->path, (void *)fini, obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); - _rtld_call_initfini_function(obj, fini, mask); + _rtld_call_initfini_function(fini, mask); } #endif /* HAVE_INITFINI_ARRAY */ } @@ -231,15 +231,15 @@ restart: static void _rtld_call_init_function(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen) { - if (obj->init_arraysz == 0 && (obj->init_called || obj->init == 0)) + if (obj->init_arraysz == 0 && (obj->init_called || obj->init == NULL)) return; - if (!obj->init_called && obj->init != 0) { + if (!obj->init_called && obj->init != NULL) { dbg (("calling init function %s at %p%s", obj->path, (void *)obj->init, obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); obj->init_called = 1; - _rtld_call_initfini_function(obj, obj->init, mask); + _rtld_call_initfini_function(obj->init, mask); } #ifdef HAVE_INITFINI_ARRAY @@ -250,12 +250,12 @@ _rtld_call_init_function(Obj_Entry *obj, * the loop. */ while (obj->init_arraysz > 0 && _rtld_objgen == cur_objgen) { - Elf_Addr init = *obj->init_array++; + fptr_t init = *obj->init_array++; obj->init_arraysz--; dbg (("calling init_array function %s at %p%s", obj->path, (void *)init, obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); - _rtld_call_initfini_function(obj, init, mask); + _rtld_call_initfini_function(init, mask); } #endif /* HAVE_INITFINI_ARRAY */ } Index: src/libexec/ld.elf_so/rtld.h diff -u src/libexec/ld.elf_so/rtld.h:1.141 src/libexec/ld.elf_so/rtld.h:1.142 --- src/libexec/ld.elf_so/rtld.h:1.141 Mon Sep 21 16:08:57 2020 +++ src/libexec/ld.elf_so/rtld.h Sat Dec 4 14:39:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.h,v 1.141 2020/09/21 16:08:57 kamil Exp $ */ +/* $NetBSD: rtld.h,v 1.142 2021/12/04 14:39:08 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -190,8 +190,8 @@ typedef struct Struct_Obj_Entry { Search_Path *rpaths; /* Search path specified in object */ Needed_Entry *needed; /* Shared objects needed by this (%) */ - Elf_Addr init; /* Initialization function to call */ - Elf_Addr fini; /* Termination function to call */ + fptr_t init; /* Initialization function to call */ + fptr_t fini; /* Termination function to call */ u_int32_t mainprog:1, /* True if this is the main program */ rtld:1, /* True if this is the dynamic linker */ @@ -296,9 +296,9 @@ typedef struct Struct_Obj_Entry { int vertabnum; /* Number of entries in vertab */ /* init_array/fini_array */ - Elf_Addr *init_array; /* start of init array */ + fptr_t *init_array; /* start of init array */ size_t init_arraysz; /* # of entries in it */ - Elf_Addr *fini_array; /* start of fini array */ + fptr_t *fini_array; /* start of fini array */ size_t fini_arraysz; /* # of entries in it */ /* IRELATIVE relocations */ size_t ifunc_remaining; @@ -505,14 +505,8 @@ Elf_Addr _rtld_function_descriptor_alloc const Elf_Sym *, Elf_Addr); const void *_rtld_function_descriptor_function(const void *); -void _rtld_call_function_void(const Obj_Entry *, Elf_Addr); Elf_Addr _rtld_call_function_addr(const Obj_Entry *, Elf_Addr); #else -static inline void -_rtld_call_function_void(const Obj_Entry *obj, Elf_Addr addr) -{ - ((void (*)(void))addr)(); -} static inline Elf_Addr _rtld_call_function_addr(const Obj_Entry *obj, Elf_Addr addr) { Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.47 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.48 --- src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.47 Sat May 16 16:43:00 2020 +++ src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c Sat Dec 4 14:39:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: hppa_reloc.c,v 1.47 2020/05/16 16:43:00 skrll Exp $ */ +/* $NetBSD: hppa_reloc.c,v 1.48 2021/12/04 14:39:08 skrll Exp $ */ /*- * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: hppa_reloc.c,v 1.47 2020/05/16 16:43:00 skrll Exp $"); +__RCSID("$NetBSD: hppa_reloc.c,v 1.48 2021/12/04 14:39:08 skrll Exp $"); #endif /* not lint */ #include <stdlib.h> @@ -726,19 +726,6 @@ _rtld_relocate_plt_objects(const Obj_Ent return 0; } -void -_rtld_call_function_void(const Obj_Entry *obj, Elf_Addr ptr) -{ - volatile hppa_plabel plabel; - void (*f)(void); - - plabel.hppa_plabel_pc = (Elf_Addr)ptr; - plabel.hppa_plabel_sl = (Elf_Addr)(obj->pltgot); - f = (void (*)(void))RTLD_MAKE_PLABEL(&plabel); - - f(); -} - Elf_Addr _rtld_call_function_addr(const Obj_Entry *obj, Elf_Addr ptr) {