]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Revert "Make cpuid_setup non-constructor"
authorBob Beck <beck@openssl.org>
Tue, 24 Mar 2026 18:26:37 +0000 (12:26 -0600)
committerTomas Mraz <tomas@openssl.foundation>
Thu, 2 Apr 2026 07:18:14 +0000 (09:18 +0200)
This reverts commit 1d770fc6a9a0a7d6e20f3232180b80c366c2d4df.

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
MergeDate: Thu Apr  2 07:18:05 2026
(Merged from https://github.com/openssl/openssl/pull/30557)

(cherry picked from commit 681b19bc7b1f917d4433bb36da503e3a7ca6dbf8)

crypto/armcap.c
crypto/dllmain.c
crypto/perlasm/x86gas.pl
crypto/perlasm/x86masm.pl
crypto/perlasm/x86nasm.pl
crypto/ppccap.c
crypto/riscvcap.c
crypto/s390xcpuid.pl
crypto/sparccpuid.S
crypto/x86_64cpuid.pl
crypto/x86cpuid.pl

index aa098a83ee5f98cbfdc7faac689e0fcc6e5f9bc8..e5ba2132ff713a2c28390bcebf0a2b94504555f5 100644 (file)
@@ -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 <sys/auxv.h>
index d6bee2d14ab184b4149ab626d2932a39b2e374a7..0ca19e63ec756835df4cdd53f0f8af0d19dfea3e 100644 (file)
@@ -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;
index d810fd5479b8fcca8be615c49c8beb41e038591d..04e0d043b401037425c8311eba5913763b043962 100644 (file)
@@ -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");   }
 
index 1c567f23ddab85933e478236c15dabb0ad0b4733..98dedec8ded41268f44c829ed3baccfbbe2e3aab 100644 (file)
@@ -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";   }
 
index 110ecddab36c975ebf4f1846ec098d306ba702e1..0d223a617be6c91400bc0dcae6fc948e8b213e55 100644 (file)
@@ -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"); }
index 91a3e0957330dd645f063cd0931e87c8d3dec209..69b3254b6dd01d46d300cf75574dcb26b42466df 100644 (file)
@@ -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;
index 8f62435d5b9d0b5cdab0ecaad3da4cdbf5d4fa70..b4cfbdc42983e30964eedb200b4f21bf482939b7 100644 (file)
@@ -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;
index 36457d798a1648b59b57a49b20081f95f10c4630..2860a170485d458c9f30cebb1b70930b0970e435 100755 (executable)
@@ -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
index fa58db98b47036acaeef96f1a14901e0e1829711..aa92241197fc1274e45527c5f3e7559c5586a053 100644 (file)
@@ -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
index 6bfe09084d1aff74b704b589549e67325faad67e..cf8a7605a636aab05a5e8e74d40462b786f37a70 100644 (file)
@@ -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
index 329a57618f7a500e8799580b8ffb9b2d6b07a348..32f6e4352395e8774fc6f629e6a1dccee27aa126 100644 (file)
@@ -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");