svn commit: r328834 - in head: lib/libc/sparc64/sys libexec/rtld-elf libexec/rtld-elf/aarch64 libexec/rtld-elf/amd64 libexec/rtld-elf/arm libexec/rtld-elf/i386 libexec/rtld-elf/mips libexec/rtld-el...
Marius Strobl
marius at FreeBSD.org
Sat Feb 3 23:14:13 UTC 2018
Author: marius
Date: Sat Feb 3 23:14:11 2018
New Revision: 328834
URL: https://svnweb.freebsd.org/changeset/base/328834
Log:
o Let rtld(1) set up psABI user trap handlers prior to executing the
objects' init functions instead of doing the setup via a constructor
in libc as the init functions may already depend on these handlers
to be in place. This gets us rid of:
- the undefined order in which libc constructors as __guard_setup()
and jemalloc_constructor() are executed WRT __sparc_utrap_setup(),
- the requirement to link libc last so __sparc_utrap_setup() gets
called prior to constructors in other libraries (see r122883).
For static binaries, crt1.o still sets up the user trap handlers.
o Move misplaced prototypes for MD functions in to the MD prototype
section of rtld.h.
o Sprinkle nitems().
Modified:
head/lib/libc/sparc64/sys/__sparc_utrap_setup.c
head/libexec/rtld-elf/aarch64/reloc.c
head/libexec/rtld-elf/amd64/reloc.c
head/libexec/rtld-elf/arm/reloc.c
head/libexec/rtld-elf/i386/reloc.c
head/libexec/rtld-elf/mips/reloc.c
head/libexec/rtld-elf/powerpc/reloc.c
head/libexec/rtld-elf/powerpc64/reloc.c
head/libexec/rtld-elf/riscv/reloc.c
head/libexec/rtld-elf/rtld.c
head/libexec/rtld-elf/rtld.h
head/libexec/rtld-elf/sparc64/reloc.c
Modified: head/lib/libc/sparc64/sys/__sparc_utrap_setup.c
==============================================================================
--- head/lib/libc/sparc64/sys/__sparc_utrap_setup.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/lib/libc/sparc64/sys/__sparc_utrap_setup.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -29,13 +29,11 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
+#include <sys/param.h>
#include <machine/utrap.h>
#include <machine/sysarch.h>
-#include <stdlib.h>
-
#include "__sparc_utrap_private.h"
static const struct sparc_utrap_args ua[] = {
@@ -47,10 +45,10 @@ static const struct sparc_utrap_args ua[] = {
};
static const struct sparc_utrap_install_args uia[] = {
- { sizeof (ua) / sizeof (*ua), ua }
+ { nitems(ua), ua }
};
-void __sparc_utrap_setup(void) __attribute__((constructor));
+void __sparc_utrap_setup(void);
void
__sparc_utrap_setup(void)
Modified: head/libexec/rtld-elf/aarch64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/aarch64/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/aarch64/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -306,6 +306,13 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
/*
Modified: head/libexec/rtld-elf/amd64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/amd64/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/amd64/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -487,6 +487,12 @@ ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)]
}
void
+pre_init(void)
+{
+
+}
+
+void
allocate_initial_tls(Obj_Entry *objs)
{
/*
Modified: head/libexec/rtld-elf/arm/reloc.c
==============================================================================
--- head/libexec/rtld-elf/arm/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/arm/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -478,6 +478,13 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
void
Modified: head/libexec/rtld-elf/i386/reloc.c
==============================================================================
--- head/libexec/rtld-elf/i386/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/i386/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -473,6 +473,12 @@ ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)]
}
void
+pre_init(void)
+{
+
+}
+
+void
allocate_initial_tls(Obj_Entry *objs)
{
void* tls;
Modified: head/libexec/rtld-elf/mips/reloc.c
==============================================================================
--- head/libexec/rtld-elf/mips/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/mips/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -745,6 +745,13 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
void
Modified: head/libexec/rtld-elf/powerpc/reloc.c
==============================================================================
--- head/libexec/rtld-elf/powerpc/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/powerpc/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -628,6 +628,13 @@ init_pltgot(Obj_Entry *obj)
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
void
Modified: head/libexec/rtld-elf/powerpc64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/powerpc64/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/powerpc64/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -533,6 +533,13 @@ init_pltgot(Obj_Entry *obj)
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
void
Modified: head/libexec/rtld-elf/riscv/reloc.c
==============================================================================
--- head/libexec/rtld-elf/riscv/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/riscv/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -368,6 +368,13 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
+}
+
+void
+pre_init(void)
+{
+
}
void
Modified: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/rtld.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -755,6 +755,12 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
obj_main->fini_array = (Elf_Addr)NULL;
}
+ /*
+ * Execute MD initializers required before we call the objects'
+ * init functions.
+ */
+ pre_init();
+
wlock_acquire(rtld_bind_lock, &lockstate);
if (obj_main->crt_no_init)
preinit_main();
Modified: head/libexec/rtld-elf/rtld.h
==============================================================================
--- head/libexec/rtld-elf/rtld.h Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/rtld.h Sat Feb 3 23:14:11 2018 (r328834)
@@ -374,8 +374,6 @@ void dump_Elf_Rela(Obj_Entry *, const Elf_Rela *, u_lo
unsigned long elf_hash(const char *);
const Elf_Sym *find_symdef(unsigned long, const Obj_Entry *,
const Obj_Entry **, int, SymCache *, struct Struct_RtldLockState *);
-void ifunc_init(Elf_Auxinfo[__min_size(AT_COUNT)]);
-void init_pltgot(Obj_Entry *);
void lockdflt_init(void);
void digest_notes(Obj_Entry *, Elf_Addr, Elf_Addr);
Obj_Entry *globallist_curr(const Obj_Entry *obj);
@@ -405,6 +403,9 @@ int reloc_plt(Obj_Entry *);
int reloc_jmpslots(Obj_Entry *, int flags, struct Struct_RtldLockState *);
int reloc_iresolve(Obj_Entry *, struct Struct_RtldLockState *);
int reloc_gnu_ifunc(Obj_Entry *, int flags, struct Struct_RtldLockState *);
+void ifunc_init(Elf_Auxinfo[__min_size(AT_COUNT)]);
+void pre_init(void);
+void init_pltgot(Obj_Entry *);
void allocate_initial_tls(Obj_Entry *);
#endif /* } */
Modified: head/libexec/rtld-elf/sparc64/reloc.c
==============================================================================
--- head/libexec/rtld-elf/sparc64/reloc.c Sat Feb 3 21:56:38 2018 (r328833)
+++ head/libexec/rtld-elf/sparc64/reloc.c Sat Feb 3 23:14:11 2018 (r328834)
@@ -367,8 +367,7 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rela *re
* Note: R_SPARC_TLS_TPOFF64 must be the numerically largest
* relocation type.
*/
- if (type >= sizeof(reloc_target_bitmask) /
- sizeof(*reloc_target_bitmask)) {
+ if (type >= nitems(reloc_target_bitmask)) {
_rtld_error("%s: Unsupported relocation type %d in non-PLT "
"object\n", obj->path, type);
return (-1);
@@ -793,8 +792,18 @@ reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const
void
ifunc_init(Elf_Auxinfo aux_info[__min_size(AT_COUNT)] __unused)
{
+
}
+extern void __sparc_utrap_setup(void);
+
+void
+pre_init(void)
+{
+
+ __sparc_utrap_setup();
+}
+
/*
* Install rtld function call into this PLT slot.
*/
@@ -823,6 +832,7 @@ init_pltgot(Obj_Entry *obj)
static void
install_plt(Elf_Word *pltgot, Elf_Addr proc)
{
+
pltgot[0] = SAVE;
flush(pltgot, 0);
pltgot[1] = SETHI_l0 | HIVAL(proc, 42);
More information about the svn-src-head
mailing list