Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ld.elf_so Restore the fptr_t type of {init,fini}{,_a...
details: https://anonhg.NetBSD.org/src/rev/3f0efccad54b
branches: trunk
changeset: 1026654:3f0efccad54b
user: skrll <skrll%NetBSD.org@localhost>
date: Sat Dec 04 14:39:08 2021 +0000
description:
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(-)
: ----------------------------------------------------------------------
diffstat:
libexec/ld.elf_so/arch/hppa/hppa_reloc.c | 17 ++---------------
libexec/ld.elf_so/headers.c | 21 +++++++++++++++------
libexec/ld.elf_so/rtld.c | 28 ++++++++++++++--------------
libexec/ld.elf_so/rtld.h | 16 +++++-----------
4 files changed, 36 insertions(+), 46 deletions(-)
diffs (241 lines):
diff -r 8b766013ee17 -r 3f0efccad54b libexec/ld.elf_so/arch/hppa/hppa_reloc.c
--- a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c Sat Dec 04 13:34:35 2021 +0000
+++ b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c Sat Dec 04 14:39:08 2021 +0000
@@ -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 @@
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)
{
diff -r 8b766013ee17 -r 3f0efccad54b libexec/ld.elf_so/headers.c
--- a/libexec/ld.elf_so/headers.c Sat Dec 04 13:34:35 2021 +0000
+++ b/libexec/ld.elf_so/headers.c Sat Dec 04 14:39:08 2021 +0000
@@ -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 @@
#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 @@
#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 @@
}
#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) {
diff -r 8b766013ee17 -r 3f0efccad54b libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c Sat Dec 04 13:34:35 2021 +0000
+++ b/libexec/ld.elf_so/rtld.c Sat Dec 04 14:39:08 2021 +0000
@@ -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 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 @@
* 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 @@
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 @@
* 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 */
}
diff -r 8b766013ee17 -r 3f0efccad54b libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h Sat Dec 04 13:34:35 2021 +0000
+++ b/libexec/ld.elf_so/rtld.h Sat Dec 04 14:39:08 2021 +0000
@@ -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 @@
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 @@
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 @@
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)
{
Home |
Main Index |
Thread Index |
Old Index