mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-07 13:14:51 +00:00
Pass CPUID[1] %edx (cpu_feature), %ecx (cpu_feature2) and
CPUID[7].%ebx (cpu_stdext_feature), %ecx (cpu_stdext_feature2) to the ifunc resolvers on x86. It is much more clean to use CPUID instruction in usermode to retrieve this information than to pass AT_HWCAP aux vector from kernel, on x86. Still, the change does allow for use of AT_HWCAP on arches where it is needed, by passing aux array to ifunc_init() initializer which should prepare arguments for ifunc resolvers. Current signature for resolvers on x86 is func_t iresolve(uint32_t cpu_feature, uint32_t cpu_feature2, uint32_t cpu_stdext_feature, uint32_t cpu_stdext_feature2); where arguments have identical meaning as the kernel variables of the same name. The ABIs allow to use resolvers with the void or shortened list of arguments. Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D8448
This commit is contained in:
parent
4562cfc40e
commit
4352999e0e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=308689
@ -299,6 +299,11 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const Obj_Entry *defobj,
|
||||
return target;
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Process non-PLT relocations
|
||||
*/
|
||||
|
@ -61,7 +61,10 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define round(size, align) \
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
#define round(size, align) \
|
||||
(((size) + (align) - 1) & ~((align) - 1))
|
||||
#define calculate_first_tls_offset(size, align) \
|
||||
round(16, align)
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <machine/cpufunc.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <err.h>
|
||||
@ -406,7 +407,7 @@ reloc_iresolve(Obj_Entry *obj, RtldLockState *lockstate)
|
||||
ptr = (Elf_Addr *)(obj->relocbase + rela->r_addend);
|
||||
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
|
||||
lock_release(rtld_bind_lock, lockstate);
|
||||
target = ((Elf_Addr (*)(void))ptr)();
|
||||
target = call_ifunc_resolver(ptr);
|
||||
wlock_acquire(rtld_bind_lock, lockstate);
|
||||
*where = target;
|
||||
break;
|
||||
@ -450,6 +451,25 @@ reloc_gnu_ifunc(Obj_Entry *obj, int flags, RtldLockState *lockstate)
|
||||
return (0);
|
||||
}
|
||||
|
||||
uint32_t cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2;
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
u_int p[4], cpu_high;
|
||||
|
||||
do_cpuid(1, p);
|
||||
cpu_feature = p[3];
|
||||
cpu_feature2 = p[2];
|
||||
do_cpuid(0, p);
|
||||
cpu_high = p[0];
|
||||
if (cpu_high >= 7) {
|
||||
cpuid_count(7, 0, p);
|
||||
cpu_stdext_feature = p[1];
|
||||
cpu_stdext_feature2 = p[2];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *objs)
|
||||
{
|
||||
|
@ -61,6 +61,14 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
extern uint32_t cpu_feature;
|
||||
extern uint32_t cpu_feature2;
|
||||
extern uint32_t cpu_stdext_feature;
|
||||
extern uint32_t cpu_stdext_feature2;
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))ptr)( \
|
||||
cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2))
|
||||
|
||||
#define round(size, align) \
|
||||
(((size) + (align) - 1) & ~((align) - 1))
|
||||
#define calculate_first_tls_offset(size, align) \
|
||||
|
@ -479,6 +479,11 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const Obj_Entry *defobj,
|
||||
return target;
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *objs)
|
||||
{
|
||||
|
@ -51,6 +51,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
#define TLS_TCB_SIZE 8
|
||||
typedef struct {
|
||||
unsigned long ti_module;
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <machine/segments.h>
|
||||
#include <machine/sysarch.h>
|
||||
|
||||
@ -359,7 +360,7 @@ reloc_iresolve(Obj_Entry *obj, RtldLockState *lockstate)
|
||||
case R_386_IRELATIVE:
|
||||
where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
|
||||
lock_release(rtld_bind_lock, lockstate);
|
||||
target = ((Elf_Addr (*)(void))(obj->relocbase + *where))();
|
||||
target = call_ifunc_resolver(obj->relocbase + *where);
|
||||
wlock_acquire(rtld_bind_lock, lockstate);
|
||||
*where = target;
|
||||
break;
|
||||
@ -404,6 +405,45 @@ reloc_gnu_ifunc(Obj_Entry *obj, int flags, RtldLockState *lockstate)
|
||||
return (0);
|
||||
}
|
||||
|
||||
uint32_t cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2;
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
u_int p[4], cpu_high;
|
||||
int cpuid_supported;
|
||||
|
||||
__asm __volatile(
|
||||
" pushfl\n"
|
||||
" popl %%eax\n"
|
||||
" movl %%eax,%%ecx\n"
|
||||
" xorl $0x200000,%%eax\n"
|
||||
" pushl %%eax\n"
|
||||
" popfl\n"
|
||||
" pushfl\n"
|
||||
" popl %%eax\n"
|
||||
" xorl %%eax,%%ecx\n"
|
||||
" je 1f\n"
|
||||
" movl $1,%0\n"
|
||||
" jmp 2f\n"
|
||||
"1: movl $0,%0\n"
|
||||
"2:\n"
|
||||
: "=r" (cpuid_supported) : : "eax", "ecx");
|
||||
if (!cpuid_supported)
|
||||
return;
|
||||
|
||||
do_cpuid(1, p);
|
||||
cpu_feature = p[3];
|
||||
cpu_feature2 = p[2];
|
||||
do_cpuid(0, p);
|
||||
cpu_high = p[0];
|
||||
if (cpu_high >= 7) {
|
||||
cpuid_count(7, 0, p);
|
||||
cpu_stdext_feature = p[1];
|
||||
cpu_stdext_feature2 = p[2];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *objs)
|
||||
{
|
||||
|
@ -61,6 +61,14 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
extern uint32_t cpu_feature;
|
||||
extern uint32_t cpu_feature2;
|
||||
extern uint32_t cpu_stdext_feature;
|
||||
extern uint32_t cpu_stdext_feature2;
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))ptr)( \
|
||||
cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2))
|
||||
|
||||
#define round(size, align) \
|
||||
(((size) + (align) - 1) & ~((align) - 1))
|
||||
#define calculate_first_tls_offset(size, align) \
|
||||
|
@ -617,6 +617,11 @@ reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const Obj_Entry *defobj,
|
||||
return target;
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *objs)
|
||||
{
|
||||
|
@ -52,6 +52,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
typedef struct {
|
||||
unsigned long ti_module;
|
||||
unsigned long ti_offset;
|
||||
|
@ -619,6 +619,11 @@ init_pltgot(Obj_Entry *obj)
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *list)
|
||||
{
|
||||
|
@ -51,6 +51,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
/*
|
||||
* Lazy binding entry point, called via PLT.
|
||||
*/
|
||||
|
@ -523,6 +523,11 @@ init_pltgot(Obj_Entry *obj)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *list)
|
||||
{
|
||||
|
@ -51,6 +51,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
/*
|
||||
* Lazy binding entry point, called via PLT.
|
||||
*/
|
||||
|
@ -366,6 +366,11 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
allocate_initial_tls(Obj_Entry *objs)
|
||||
{
|
||||
|
@ -78,6 +78,9 @@ Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
|
||||
__asm __volatile("mv gp, %0" :: "r"(old1)); \
|
||||
})
|
||||
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
/*
|
||||
* Lazy binding entry point, called via PLT.
|
||||
*/
|
||||
|
@ -642,6 +642,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
|
||||
r_debug_state(NULL, &obj_main->linkmap); /* say hello to gdb! */
|
||||
|
||||
map_stacks_exec(NULL);
|
||||
ifunc_init(aux);
|
||||
|
||||
dbg("resolving ifuncs");
|
||||
if (resolve_objects_ifunc(obj_main,
|
||||
@ -690,7 +691,7 @@ rtld_resolve_ifunc(const Obj_Entry *obj, const Elf_Sym *def)
|
||||
Elf_Addr target;
|
||||
|
||||
ptr = (void *)make_function_pointer(def, obj);
|
||||
target = ((Elf_Addr (*)(void))ptr)();
|
||||
target = call_ifunc_resolver(ptr);
|
||||
return ((void *)target);
|
||||
}
|
||||
|
||||
|
@ -367,6 +367,7 @@ void dump_Elf_Rela(Obj_Entry *, const Elf_Rela *, u_long);
|
||||
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[static AT_COUNT]);
|
||||
void init_pltgot(Obj_Entry *);
|
||||
void lockdflt_init(void);
|
||||
void digest_notes(Obj_Entry *, Elf_Addr, Elf_Addr);
|
||||
|
@ -786,6 +786,11 @@ reloc_jmpslot(Elf_Addr *wherep, Elf_Addr target, const Obj_Entry *obj,
|
||||
return (target);
|
||||
}
|
||||
|
||||
void
|
||||
ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Install rtld function call into this PLT slot.
|
||||
*/
|
||||
|
@ -53,7 +53,10 @@ Elf_Addr reloc_jmpslot(Elf_Addr *, Elf_Addr,
|
||||
#define call_init_pointer(obj, target) \
|
||||
(((InitArrFunc)(target))(main_argc, main_argv, environ))
|
||||
|
||||
#define round(size, align) \
|
||||
#define call_ifunc_resolver(ptr) \
|
||||
(((Elf_Addr (*)(void))ptr)())
|
||||
|
||||
#define round(size, align) \
|
||||
(((size) + (align) - 1) & ~((align) - 1))
|
||||
#define calculate_first_tls_offset(size, align) \
|
||||
round(size, align)
|
||||
|
Loading…
Reference in New Issue
Block a user