From: Bob Beck Date: Tue, 24 Mar 2026 18:26:37 +0000 (-0600) Subject: Revert "Make cpuid_setup non-constructor" X-Git-Tag: openssl-4.0.0~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=383508f52c2d0829a0f9bb3b534a34684cbe2bab;p=thirdparty%2Fopenssl.git Revert "Make cpuid_setup non-constructor" This reverts commit 1d770fc6a9a0a7d6e20f3232180b80c366c2d4df. Reviewed-by: Eugene Syromiatnikov Reviewed-by: Saša Nedvědický Reviewed-by: Paul Dale MergeDate: Thu Apr 2 07:18:05 2026 (Merged from https://github.com/openssl/openssl/pull/30557) (cherry picked from commit 681b19bc7b1f917d4433bb36da503e3a7ca6dbf8) --- diff --git a/crypto/armcap.c b/crypto/armcap.c index aa098a83ee5..e5ba2132ff7 100644 --- a/crypto/armcap.c +++ b/crypto/armcap.c @@ -69,6 +69,10 @@ uint32_t OPENSSL_rdtsc(void) /* First determine if getauxval() is available (OSSL_IMPLEMENT_GETAUXVAL) */ +#if defined(__GNUC__) && __GNUC__ >= 2 +void OPENSSL_cpuid_setup(void) __attribute__((constructor)); +#endif + #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 16) #include diff --git a/crypto/dllmain.c b/crypto/dllmain.c index d6bee2d14ab..0ca19e63ec7 100644 --- a/crypto/dllmain.c +++ b/crypto/dllmain.c @@ -30,6 +30,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: + OPENSSL_cpuid_setup(); break; case DLL_THREAD_ATTACH: break; diff --git a/crypto/perlasm/x86gas.pl b/crypto/perlasm/x86gas.pl index d810fd5479b..04e0d043b40 100644 --- a/crypto/perlasm/x86gas.pl +++ b/crypto/perlasm/x86gas.pl @@ -14,6 +14,8 @@ package x86gas; $::lbdecor=$::aout?"L":".L"; # local label decoration $nmdecor=($::aout or $::coff)?"_":""; # external name decoration +$initseg=""; + $align=16; $align=log($align)/log(2) if ($::aout); $com_start="#" if ($::aout or $::coff); @@ -171,6 +173,7 @@ sub ::file_end elsif ($::elf) { push (@out,"$tmp,4\n"); } else { push (@out,"$tmp\n"); } } + push(@out,$initseg) if ($initseg); if ($::elf) { push(@out," .section \".note.gnu.property\", \"a\" @@ -234,6 +237,48 @@ sub ::picmeup { &::lea($dst,&::DWP($sym)); } } +sub ::initseg +{ my $f=$nmdecor.shift; + + if ($::android) + { $initseg.=<<___; +.section .init_array +.align 4 +.long $f +___ + } + elsif ($::elf) + { $initseg.=<<___; +.section .init + call $f +___ + } + elsif ($::coff) + { $initseg.=<<___; # applies to both Cygwin and Mingw +.section .ctors +.long $f +___ + } + elsif ($::macosx) + { $initseg.=<<___; +.mod_init_func +.align 2 +.long $f +___ + } + elsif ($::aout) + { my $ctor="${nmdecor}_GLOBAL_\$I\$$f"; + $initseg.=".text\n"; + $initseg.=".type $ctor,\@function\n" if ($::pic); + $initseg.=<<___; # OpenBSD way... +.globl $ctor +.align 2 +$ctor: + jmp $f +___ + } +} + sub ::dataseg { push(@out,".data\n"); } diff --git a/crypto/perlasm/x86masm.pl b/crypto/perlasm/x86masm.pl index 1c567f23dda..98dedec8ded 100644 --- a/crypto/perlasm/x86masm.pl +++ b/crypto/perlasm/x86masm.pl @@ -14,6 +14,7 @@ package x86masm; $::lbdecor="\$L"; # local label decoration $nmdecor="_"; # external name decoration +$initseg=""; $segment=""; sub ::generic @@ -148,6 +149,7 @@ ___ grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; push (@out,$comm); } + push (@out,$initseg) if ($initseg); push (@out,"END\n"); } @@ -181,6 +183,17 @@ sub ::picmeup &::lea($dst,&::DWP($sym)); } +sub ::initseg +{ my $f=$nmdecor.shift; + + $initseg.=<<___; +.CRT\$XCU SEGMENT DWORD PUBLIC 'DATA' +EXTERN $f:NEAR +DD $f +.CRT\$XCU ENDS +___ +} + sub ::dataseg { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; } diff --git a/crypto/perlasm/x86nasm.pl b/crypto/perlasm/x86nasm.pl index 110ecddab36..0d223a617be 100644 --- a/crypto/perlasm/x86nasm.pl +++ b/crypto/perlasm/x86nasm.pl @@ -15,6 +15,8 @@ $::lbdecor="L\$"; # local label decoration $nmdecor="_"; # external name decoration $drdecor=$::mwerks?".":""; # directive decoration +$initseg=""; + sub ::generic { my $opcode=shift; my $tmp; @@ -131,6 +133,7 @@ ___ grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; push (@out,$comm) } + push (@out,$initseg) if ($initseg); } sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } } @@ -158,6 +161,17 @@ sub ::picmeup &::lea($dst,&::DWP($sym)); } +sub ::initseg +{ my $f=$nmdecor.shift; + if ($::win32) + { $initseg=<<___; +segment .CRT\$XCU data align=4 +extern $f +dd $f +___ + } +} + sub ::dataseg { if ($mwerks) { push(@out,".section\t.data,4\n"); } else { push(@out,"section\t.data align=4\n"); } diff --git a/crypto/ppccap.c b/crypto/ppccap.c index 91a3e095733..69b3254b6dd 100644 --- a/crypto/ppccap.c +++ b/crypto/ppccap.c @@ -134,6 +134,9 @@ static unsigned long getauxval(unsigned long key) #define HWCAP_ARCH_3_00 (1U << 23) #define HWCAP_ARCH_3_1 (1U << 18) +#if defined(__GNUC__) && __GNUC__ >= 2 +__attribute__((constructor)) +#endif void OPENSSL_cpuid_setup(void) { char *e; diff --git a/crypto/riscvcap.c b/crypto/riscvcap.c index 8f62435d5b9..b4cfbdc4298 100644 --- a/crypto/riscvcap.c +++ b/crypto/riscvcap.c @@ -129,6 +129,9 @@ size_t riscv_vlen(void) return vlen; } +#if defined(__GNUC__) && __GNUC__ >= 2 +__attribute__((constructor)) +#endif void OPENSSL_cpuid_setup(void) { char *e; diff --git a/crypto/s390xcpuid.pl b/crypto/s390xcpuid.pl index 36457d798a1..2860a170485 100755 --- a/crypto/s390xcpuid.pl +++ b/crypto/s390xcpuid.pl @@ -527,6 +527,11 @@ s390x_flip_endian64: ___ } +$code.=<<___; +.section .init + brasl $ra,OPENSSL_cpuid_setup +___ + $code =~ s/\`([^\`]*)\`/eval $1/gem; print $code; close STDOUT or die "error closing STDOUT: $!"; # force flush diff --git a/crypto/sparccpuid.S b/crypto/sparccpuid.S index fa58db98b47..aa92241197f 100644 --- a/crypto/sparccpuid.S +++ b/crypto/sparccpuid.S @@ -422,3 +422,7 @@ _sparcv9_vis1_instrument_bus2: sub %o3,%o1,%o0 .type _sparcv9_vis1_instrument_bus2,#function .size _sparcv9_vis1_instrument_bus2,.-_sparcv9_vis1_instrument_bus2 + +.section ".init",#alloc,#execinstr + call OPENSSL_cpuid_setup + nop diff --git a/crypto/x86_64cpuid.pl b/crypto/x86_64cpuid.pl index 6bfe09084d1..cf8a7605a63 100644 --- a/crypto/x86_64cpuid.pl +++ b/crypto/x86_64cpuid.pl @@ -30,6 +30,9 @@ print<<___; #include crypto/cryptlib.h .extern OPENSSL_cpuid_setup .hidden OPENSSL_cpuid_setup +.section .init + call OPENSSL_cpuid_setup + .hidden OPENSSL_ia32cap_P .comm OPENSSL_ia32cap_P,40,4 # <--Should match with internal/cryptlib.h OPENSSL_IA32CAP_P_MAX_INDEXES .text diff --git a/crypto/x86cpuid.pl b/crypto/x86cpuid.pl index 329a57618f7..32f6e435239 100644 --- a/crypto/x86cpuid.pl +++ b/crypto/x86cpuid.pl @@ -493,6 +493,8 @@ my $rdop = shift; &gen_random("rdrand"); &gen_random("rdseed"); +&initseg("OPENSSL_cpuid_setup"); + &hidden("OPENSSL_cpuid_setup"); &hidden("OPENSSL_ia32cap_P");