From 1d770fc6a9a0a7d6e20f3232180b80c366c2d4df Mon Sep 17 00:00:00 2001 From: Hongren Zheng Date: Tue, 22 Apr 2025 18:49:45 +0800 Subject: [PATCH] Make cpuid_setup non-constructor Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27466) --- crypto/armcap.c | 4 ---- crypto/dllmain.c | 1 - crypto/perlasm/x86gas.pl | 45 --------------------------------------- crypto/perlasm/x86masm.pl | 13 ----------- crypto/perlasm/x86nasm.pl | 14 ------------ crypto/ppccap.c | 3 --- crypto/riscvcap.c | 3 --- crypto/s390xcpuid.pl | 5 ----- crypto/sparccpuid.S | 4 ---- crypto/x86_64cpuid.pl | 3 --- crypto/x86cpuid.pl | 2 -- 11 files changed, 97 deletions(-) diff --git a/crypto/armcap.c b/crypto/armcap.c index c64a3ca0fe5..c5f3624d034 100644 --- a/crypto/armcap.c +++ b/crypto/armcap.c @@ -62,10 +62,6 @@ 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 96198a93973..42c009bced4 100644 --- a/crypto/dllmain.c +++ b/crypto/dllmain.c @@ -30,7 +30,6 @@ 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 f3c01ea89b4..c6054953f7b 100644 --- a/crypto/perlasm/x86gas.pl +++ b/crypto/perlasm/x86gas.pl @@ -14,8 +14,6 @@ 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); @@ -173,7 +171,6 @@ 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\" @@ -237,48 +234,6 @@ 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 ccdba757dc2..5c4e687c0cb 100644 --- a/crypto/perlasm/x86masm.pl +++ b/crypto/perlasm/x86masm.pl @@ -14,7 +14,6 @@ package x86masm; $::lbdecor="\$L"; # local label decoration $nmdecor="_"; # external name decoration -$initseg=""; $segment=""; sub ::generic @@ -149,7 +148,6 @@ ___ grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; push (@out,$comm); } - push (@out,$initseg) if ($initseg); push (@out,"END\n"); } @@ -183,17 +181,6 @@ 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 a8cdd2d0bbe..82fcce6bbd9 100644 --- a/crypto/perlasm/x86nasm.pl +++ b/crypto/perlasm/x86nasm.pl @@ -15,8 +15,6 @@ $::lbdecor="L\$"; # local label decoration $nmdecor="_"; # external name decoration $drdecor=$::mwerks?".":""; # directive decoration -$initseg=""; - sub ::generic { my $opcode=shift; my $tmp; @@ -133,7 +131,6 @@ ___ 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"); } } @@ -161,17 +158,6 @@ 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 08794a3ba62..f42a43d4e12 100644 --- a/crypto/ppccap.c +++ b/crypto/ppccap.c @@ -135,9 +135,6 @@ 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 cf089be43b3..0c44b93eedb 100644 --- a/crypto/riscvcap.c +++ b/crypto/riscvcap.c @@ -120,9 +120,6 @@ 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 23ac82a9226..d9eb84bab13 100755 --- a/crypto/s390xcpuid.pl +++ b/crypto/s390xcpuid.pl @@ -531,11 +531,6 @@ 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 0487ce57689..7ced433c947 100644 --- a/crypto/sparccpuid.S +++ b/crypto/sparccpuid.S @@ -422,7 +422,3 @@ _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 3229d7d8fa6..ce4cf1f51b8 100644 --- a/crypto/x86_64cpuid.pl +++ b/crypto/x86_64cpuid.pl @@ -30,9 +30,6 @@ 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 2b05bc53dfe..f66c941b19c 100644 --- a/crypto/x86cpuid.pl +++ b/crypto/x86cpuid.pl @@ -493,8 +493,6 @@ my $rdop = shift; &gen_random("rdrand"); &gen_random("rdseed"); -&initseg("OPENSSL_cpuid_setup"); - &hidden("OPENSSL_cpuid_setup"); &hidden("OPENSSL_ia32cap_P"); -- 2.47.2