Index: libexec/ld.elf_so/headers.c =================================================================== RCS file: /cvsroot/src/libexec/ld.elf_so/headers.c,v retrieving revision 1.69 diff -u -p -r1.69 headers.c --- libexec/ld.elf_so/headers.c 16 May 2020 16:43:15 -0000 1.69 +++ libexec/ld.elf_so/headers.c 2 Dec 2021 11:28:14 -0000 @@ -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: libexec/ld.elf_so/rtld.c =================================================================== RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v retrieving revision 1.209 diff -u -p -r1.209 rtld.c --- libexec/ld.elf_so/rtld.c 16 Jun 2021 21:53:51 -0000 1.209 +++ libexec/ld.elf_so/rtld.c 2 Dec 2021 11:28:14 -0000 @@ -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: libexec/ld.elf_so/rtld.h =================================================================== RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.h,v retrieving revision 1.141 diff -u -p -r1.141 rtld.h --- libexec/ld.elf_so/rtld.h 21 Sep 2020 16:08:57 -0000 1.141 +++ libexec/ld.elf_so/rtld.h 2 Dec 2021 11:28:14 -0000 @@ -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,16 @@ 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); +//void _rtld_call_function_void(const Obj_Entry *, Elf_Addr); Elf_Addr _rtld_call_function_addr(const Obj_Entry *, Elf_Addr); #else +#if 0 static inline void _rtld_call_function_void(const Obj_Entry *obj, Elf_Addr addr) { ((void (*)(void))addr)(); } +#endif static inline Elf_Addr _rtld_call_function_addr(const Obj_Entry *obj, Elf_Addr addr) {