Page MenuHomeFreeBSD

D8448.id22215.diff
No OneTemporary

D8448.id22215.diff

Index: head/libexec/rtld-elf/aarch64/reloc.c
===================================================================
--- head/libexec/rtld-elf/aarch64/reloc.c
+++ head/libexec/rtld-elf/aarch64/reloc.c
@@ -299,6 +299,11 @@
return target;
}
+void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
/*
* Process non-PLT relocations
*/
Index: head/libexec/rtld-elf/aarch64/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/aarch64/rtld_machdep.h
+++ head/libexec/rtld-elf/aarch64/rtld_machdep.h
@@ -61,7 +61,10 @@
#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)
Index: head/libexec/rtld-elf/amd64/reloc.c
===================================================================
--- head/libexec/rtld-elf/amd64/reloc.c
+++ head/libexec/rtld-elf/amd64/reloc.c
@@ -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 @@
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 @@
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)
{
Index: head/libexec/rtld-elf/amd64/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/amd64/rtld_machdep.h
+++ head/libexec/rtld-elf/amd64/rtld_machdep.h
@@ -61,6 +61,14 @@
#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) \
Index: head/libexec/rtld-elf/arm/reloc.c
===================================================================
--- head/libexec/rtld-elf/arm/reloc.c
+++ head/libexec/rtld-elf/arm/reloc.c
@@ -480,6 +480,11 @@
}
void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
+void
allocate_initial_tls(Obj_Entry *objs)
{
#ifdef ARM_TP_ADDRESS
Index: head/libexec/rtld-elf/arm/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/arm/rtld_machdep.h
+++ head/libexec/rtld-elf/arm/rtld_machdep.h
@@ -51,6 +51,9 @@
#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;
Index: head/libexec/rtld-elf/i386/reloc.c
===================================================================
--- head/libexec/rtld-elf/i386/reloc.c
+++ head/libexec/rtld-elf/i386/reloc.c
@@ -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 @@
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 @@
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)
{
Index: head/libexec/rtld-elf/i386/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/i386/rtld_machdep.h
+++ head/libexec/rtld-elf/i386/rtld_machdep.h
@@ -61,6 +61,14 @@
#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) \
Index: head/libexec/rtld-elf/mips/reloc.c
===================================================================
--- head/libexec/rtld-elf/mips/reloc.c
+++ head/libexec/rtld-elf/mips/reloc.c
@@ -618,6 +618,11 @@
}
void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
+void
allocate_initial_tls(Obj_Entry *objs)
{
char *tls;
Index: head/libexec/rtld-elf/mips/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/mips/rtld_machdep.h
+++ head/libexec/rtld-elf/mips/rtld_machdep.h
@@ -52,6 +52,9 @@
#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;
Index: head/libexec/rtld-elf/powerpc/reloc.c
===================================================================
--- head/libexec/rtld-elf/powerpc/reloc.c
+++ head/libexec/rtld-elf/powerpc/reloc.c
@@ -620,6 +620,11 @@
}
void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
+void
allocate_initial_tls(Obj_Entry *list)
{
Elf_Addr **tp;
Index: head/libexec/rtld-elf/powerpc/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/powerpc/rtld_machdep.h
+++ head/libexec/rtld-elf/powerpc/rtld_machdep.h
@@ -51,6 +51,9 @@
#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.
*/
Index: head/libexec/rtld-elf/powerpc64/reloc.c
===================================================================
--- head/libexec/rtld-elf/powerpc64/reloc.c
+++ head/libexec/rtld-elf/powerpc64/reloc.c
@@ -524,6 +524,11 @@
}
void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
+void
allocate_initial_tls(Obj_Entry *list)
{
Elf_Addr **tp;
Index: head/libexec/rtld-elf/powerpc64/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/powerpc64/rtld_machdep.h
+++ head/libexec/rtld-elf/powerpc64/rtld_machdep.h
@@ -51,6 +51,9 @@
#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.
*/
Index: head/libexec/rtld-elf/riscv/reloc.c
===================================================================
--- head/libexec/rtld-elf/riscv/reloc.c
+++ head/libexec/rtld-elf/riscv/reloc.c
@@ -367,6 +367,11 @@
}
void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
+void
allocate_initial_tls(Obj_Entry *objs)
{
Elf_Addr **tp;
Index: head/libexec/rtld-elf/riscv/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/riscv/rtld_machdep.h
+++ head/libexec/rtld-elf/riscv/rtld_machdep.h
@@ -78,6 +78,9 @@
__asm __volatile("mv gp, %0" :: "r"(old1)); \
})
+#define call_ifunc_resolver(ptr) \
+ (((Elf_Addr (*)(void))ptr)())
+
/*
* Lazy binding entry point, called via PLT.
*/
Index: head/libexec/rtld-elf/rtld.h
===================================================================
--- head/libexec/rtld-elf/rtld.h
+++ head/libexec/rtld-elf/rtld.h
@@ -367,6 +367,7 @@
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);
Index: head/libexec/rtld-elf/rtld.c
===================================================================
--- head/libexec/rtld-elf/rtld.c
+++ head/libexec/rtld-elf/rtld.c
@@ -642,6 +642,7 @@
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 @@
Elf_Addr target;
ptr = (void *)make_function_pointer(def, obj);
- target = ((Elf_Addr (*)(void))ptr)();
+ target = call_ifunc_resolver(ptr);
return ((void *)target);
}
Index: head/libexec/rtld-elf/sparc64/reloc.c
===================================================================
--- head/libexec/rtld-elf/sparc64/reloc.c
+++ head/libexec/rtld-elf/sparc64/reloc.c
@@ -786,6 +786,11 @@
return (target);
}
+void
+ifunc_init(Elf_Auxinfo aux_info[static AT_COUNT] __unused)
+{
+}
+
/*
* Install rtld function call into this PLT slot.
*/
Index: head/libexec/rtld-elf/sparc64/rtld_machdep.h
===================================================================
--- head/libexec/rtld-elf/sparc64/rtld_machdep.h
+++ head/libexec/rtld-elf/sparc64/rtld_machdep.h
@@ -53,7 +53,10 @@
#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)

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 17, 2:49 PM (1 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31665400
Default Alt Text
D8448.id22215.diff (11 KB)

Event Timeline