diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2022-11-01 01:42:50 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2023-03-11 22:50:04 +0000 |
commit | 0303938539f3f12da65128fc67f883efe82dc125 (patch) | |
tree | 632e7d1a7f8891fea5f571d3b2e379ceddaec771 /lib/libc | |
parent | 51015e6d0f570239b0c2088dc6cf2b018928375d (diff) | |
download | src-0303938539f3f12da65128fc67f883efe82dc125.tar.gz src-0303938539f3f12da65128fc67f883efe82dc125.zip |
x86: microoptimize static PIE startup
Do not call CPUID on each ireloc, instead call it once and cache
results, similar to how it is done on powerpc64.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 3 weeks
Differential revision: https://reviews.freebsd.org/D37220
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/csu/amd64/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/csu/amd64/reloc.c | 14 | ||||
-rw-r--r-- | lib/libc/csu/i386/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/csu/i386/reloc.c | 14 |
4 files changed, 22 insertions, 10 deletions
diff --git a/lib/libc/csu/amd64/Makefile.inc b/lib/libc/csu/amd64/Makefile.inc index b3420a638164..f14033217580 100644 --- a/lib/libc/csu/amd64/Makefile.inc +++ b/lib/libc/csu/amd64/Makefile.inc @@ -1,4 +1,4 @@ # CFLAGS+= -DCRT_IRELOC_RELA \ - -DINIT_IRELOCS="" + -DINIT_IRELOCS="init_cpu_features()" diff --git a/lib/libc/csu/amd64/reloc.c b/lib/libc/csu/amd64/reloc.c index adb52e42a32c..0a5a24929954 100644 --- a/lib/libc/csu/amd64/reloc.c +++ b/lib/libc/csu/amd64/reloc.c @@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$"); #include <machine/specialreg.h> #include <machine/cpufunc.h> +static uint32_t cpu_feature, cpu_feature2; +static uint32_t cpu_stdext_feature, cpu_stdext_feature2; + static void -crt1_handle_rela(const Elf_Rela *r) +init_cpu_features(void) { - Elf_Addr *ptr, *where, target; u_int p[4]; - uint32_t cpu_feature, cpu_feature2; - uint32_t cpu_stdext_feature, cpu_stdext_feature2; do_cpuid(1, p); cpu_feature = p[3]; @@ -49,6 +49,12 @@ crt1_handle_rela(const Elf_Rela *r) cpu_stdext_feature = 0; cpu_stdext_feature2 = 0; } +} + +static void +crt1_handle_rela(const Elf_Rela *r) +{ + Elf_Addr *ptr, *where, target; switch (ELF_R_TYPE(r->r_info)) { case R_X86_64_IRELATIVE: diff --git a/lib/libc/csu/i386/Makefile.inc b/lib/libc/csu/i386/Makefile.inc index ac0984df2349..f3f8c2b176ce 100644 --- a/lib/libc/csu/i386/Makefile.inc +++ b/lib/libc/csu/i386/Makefile.inc @@ -1,4 +1,4 @@ # CFLAGS+= -DCRT_IRELOC_REL \ - -DINIT_IRELOCS="" + -DINIT_IRELOCS="init_cpu_features()" diff --git a/lib/libc/csu/i386/reloc.c b/lib/libc/csu/i386/reloc.c index 13438035841d..f99b1089cf47 100644 --- a/lib/libc/csu/i386/reloc.c +++ b/lib/libc/csu/i386/reloc.c @@ -29,13 +29,13 @@ __FBSDID("$FreeBSD$"); #include <machine/specialreg.h> #include <machine/cpufunc.h> +static uint32_t cpu_feature, cpu_feature2; +static uint32_t cpu_stdext_feature, cpu_stdext_feature2; + static void -crt1_handle_rel(const Elf_Rel *r) +init_cpu_features(void) { - Elf_Addr *where, target; u_int cpuid_supported, p[4]; - uint32_t cpu_feature, cpu_feature2; - uint32_t cpu_stdext_feature, cpu_stdext_feature2; __asm __volatile( " pushfl\n" @@ -72,6 +72,12 @@ crt1_handle_rel(const Elf_Rel *r) cpu_stdext_feature = 0; cpu_stdext_feature2 = 0; } +} + +static void +crt1_handle_rel(const Elf_Rel *r) +{ + Elf_Addr *where, target; switch (ELF_R_TYPE(r->r_info)) { case R_386_IRELATIVE: |