From d8a728372d924a59e821c02139ecd7915c848b4d Mon Sep 17 00:00:00 2001 From: otto <> Date: Fri, 19 Sep 2008 06:09:01 +0000 Subject: fix some cause of bad TEXTREL on i386 and amd64 - global function calls in .init sections (diff makes them via PLT) - calls to global functions in aes-586.S (made static or local) - global variable accesses in rc4-x86_64.S (now made via GOT) from djm@large; ok miod@ --- src/lib/libcrypto/aes/asm/aes-586.pl | 8 ++-- src/lib/libcrypto/perlasm/x86_64-xlate.pl | 5 +- src/lib/libcrypto/perlasm/x86unix.pl | 56 +++++++++++++++++++++-- src/lib/libcrypto/rc4/asm/rc4-x86_64.pl | 5 +- src/lib/libcrypto/x86_64cpuid.pl | 4 +- src/lib/libssl/src/crypto/aes/asm/aes-586.pl | 8 ++-- src/lib/libssl/src/crypto/perlasm/x86_64-xlate.pl | 5 +- src/lib/libssl/src/crypto/perlasm/x86unix.pl | 56 +++++++++++++++++++++-- src/lib/libssl/src/crypto/rc4/asm/rc4-x86_64.pl | 5 +- src/lib/libssl/src/crypto/x86_64cpuid.pl | 4 +- 10 files changed, 128 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/aes/asm/aes-586.pl b/src/lib/libcrypto/aes/asm/aes-586.pl index 89fa261794..3da307bef9 100644 --- a/src/lib/libcrypto/aes/asm/aes-586.pl +++ b/src/lib/libcrypto/aes/asm/aes-586.pl @@ -250,7 +250,7 @@ sub enclast() sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } } &public_label("AES_Te"); -&function_begin_B("_x86_AES_encrypt"); +&function_begin_C("_x86_AES_encrypt"); if ($vertical_spin) { # I need high parts of volatile registers to be accessible... &exch ($s1="edi",$key="ebx"); @@ -539,7 +539,7 @@ sub declast() } &public_label("AES_Td"); -&function_begin_B("_x86_AES_decrypt"); +&function_begin_C("_x86_AES_decrypt"); # note that caller is expected to allocate stack frame for me! &mov (&DWP(12,"esp"),$key); # save key @@ -1240,7 +1240,7 @@ sub enckey() # int AES_set_encrypt_key(const unsigned char *userKey, const int bits, # AES_KEY *key) &public_label("AES_Te"); -&function_begin("AES_set_encrypt_key"); +&function_begin("AES_set_encrypt_key", "", "_x86_AES_set_encrypt_key"); &mov ("esi",&wparam(0)); # user supplied key &mov ("edi",&wparam(2)); # private key schedule @@ -1467,7 +1467,7 @@ sub deckey() &mov (&DWP(0,"esp"),"eax"); &mov (&DWP(4,"esp"),"ecx"); &mov (&DWP(8,"esp"),"edx"); - &call ("AES_set_encrypt_key"); + &call ("_x86_AES_set_encrypt_key"); &add ("esp",12); &cmp ("eax",0); &je (&label("proceed")); diff --git a/src/lib/libcrypto/perlasm/x86_64-xlate.pl b/src/lib/libcrypto/perlasm/x86_64-xlate.pl index a4af769b4a..74153b017d 100755 --- a/src/lib/libcrypto/perlasm/x86_64-xlate.pl +++ b/src/lib/libcrypto/perlasm/x86_64-xlate.pl @@ -163,7 +163,8 @@ my $current_function; local *line = shift; undef $ret; - if ($line =~ /^([^\(,]*)\(([%\w,]+)\)/) { + if ($line =~ /^([^\(,]*)\(([%\w,]+)\)/ && + !($line =~ /^PIC_(GOT|PLT)/)) { $self->{label} = $1; ($self->{base},$self->{index},$self->{scale})=split(/,/,$2); $self->{scale} = 1 if (!defined($self->{scale})); @@ -429,6 +430,8 @@ my $current_function; } } +print "#include \n"; + while($line=<>) { chomp($line); diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl index 02d72a32bc..ae8f0964dc 100644 --- a/src/lib/libcrypto/perlasm/x86unix.pl +++ b/src/lib/libcrypto/perlasm/x86unix.pl @@ -345,7 +345,7 @@ sub main'file local($file)=@_; if ($main'openbsd) - { push(@out,"#include \n"); return; } + { push(@out,"#include \n"); } local($tmp)=<<"EOF"; .file "$file.s" @@ -355,13 +355,17 @@ EOF sub main'function_begin { - local($func)=@_; + local($func,$junk,$llabel)=@_; &main'external_label($func); $func=$under.$func; if ($main'openbsd) - { push (@out, "\nENTRY($func)\n"); goto skip; } + { + push (@out, "\nENTRY($func)\n"); + push (@out, "$llabel:\n") if $llabel; + goto skip; + } local($tmp)=<<"EOF"; .text @@ -417,6 +421,44 @@ skip: $stack=4; } +# Like function_begin_B but with static linkage +sub main'function_begin_C + { + local($func,$extra)=@_; + + &main'external_label($func); + $func=$under.$func; + + if ($main'openbsd) + { + local($tmp)=<<"EOF"; +.text +_ALIGN_TEXT +.type $func,\@function +$func: +EOF + push(@out, $tmp); + goto skip; + } + + local($tmp)=<<"EOF"; +.text +.globl $func +EOF + push(@out,$tmp); + if ($main'cpp) + { push(@out,"TYPE($func,\@function)\n"); } + elsif ($main'coff) + { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } + elsif ($main'aout and !$main'pic) + { } + else { push(@out,".type $func,\@function\n"); } + push(@out,".align\t$align\n"); + push(@out,"$func:\n"); +skip: + $stack=4; + } + sub main'function_end { local($func)=@_; @@ -474,6 +516,8 @@ sub main'function_end_B %label=(); } +sub main'function_end_C { function_end_B(@_); } + sub main'wparam { local($num)=@_; @@ -510,7 +554,7 @@ sub main'swtmp sub main'comment { - if (!defined($com_start) or $main'elf) + if (!defined($com_start) or (!$main'openbsd && $main'elf)) { # Regarding $main'elf above... # GNU and SVR4 as'es use different comment delimiters, push(@out,"\n"); # so we just skip ELF comments... @@ -731,7 +775,9 @@ sub main'initseg { $tmp=<<___; .section .init - call $under$f + PIC_PROLOGUE + call PIC_PLT($under$f) + PIC_EPILOGUE jmp .Linitalign .align $align .Linitalign: diff --git a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl b/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl index 2d47320485..92c52f3433 100755 --- a/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl +++ b/src/lib/libcrypto/rc4/asm/rc4-x86_64.pl @@ -269,8 +269,7 @@ RC4_set_key: xor $ido,$ido xor %r10,%r10 xor %r11,%r11 - - mov OPENSSL_ia32cap_P(%rip),$idx#d + mov PIC_GOT(OPENSSL_ia32cap_P),$idx#d bt \$20,$idx#d jnc .Lw1stloop bt \$30,$idx#d @@ -338,7 +337,7 @@ RC4_set_key: RC4_options: .picmeup %rax lea .Lopts-.(%rax),%rax - mov OPENSSL_ia32cap_P(%rip),%edx + mov PIC_GOT(OPENSSL_ia32cap_P),%edx bt \$20,%edx jnc .Ldone add \$12,%rax diff --git a/src/lib/libcrypto/x86_64cpuid.pl b/src/lib/libcrypto/x86_64cpuid.pl index 2616a03da6..8946b464a8 100644 --- a/src/lib/libcrypto/x86_64cpuid.pl +++ b/src/lib/libcrypto/x86_64cpuid.pl @@ -47,6 +47,8 @@ CRT\$XIU ENDS ___ print<<___ if(!defined($masm)); +#include + .text .globl OPENSSL_atomic_add @@ -95,7 +97,7 @@ OPENSSL_wipe_cpu: .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu .section .init - call OPENSSL_cpuid_setup + call PIC_PLT(OPENSSL_cpuid_setup) ___ diff --git a/src/lib/libssl/src/crypto/aes/asm/aes-586.pl b/src/lib/libssl/src/crypto/aes/asm/aes-586.pl index 89fa261794..3da307bef9 100644 --- a/src/lib/libssl/src/crypto/aes/asm/aes-586.pl +++ b/src/lib/libssl/src/crypto/aes/asm/aes-586.pl @@ -250,7 +250,7 @@ sub enclast() sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } } &public_label("AES_Te"); -&function_begin_B("_x86_AES_encrypt"); +&function_begin_C("_x86_AES_encrypt"); if ($vertical_spin) { # I need high parts of volatile registers to be accessible... &exch ($s1="edi",$key="ebx"); @@ -539,7 +539,7 @@ sub declast() } &public_label("AES_Td"); -&function_begin_B("_x86_AES_decrypt"); +&function_begin_C("_x86_AES_decrypt"); # note that caller is expected to allocate stack frame for me! &mov (&DWP(12,"esp"),$key); # save key @@ -1240,7 +1240,7 @@ sub enckey() # int AES_set_encrypt_key(const unsigned char *userKey, const int bits, # AES_KEY *key) &public_label("AES_Te"); -&function_begin("AES_set_encrypt_key"); +&function_begin("AES_set_encrypt_key", "", "_x86_AES_set_encrypt_key"); &mov ("esi",&wparam(0)); # user supplied key &mov ("edi",&wparam(2)); # private key schedule @@ -1467,7 +1467,7 @@ sub deckey() &mov (&DWP(0,"esp"),"eax"); &mov (&DWP(4,"esp"),"ecx"); &mov (&DWP(8,"esp"),"edx"); - &call ("AES_set_encrypt_key"); + &call ("_x86_AES_set_encrypt_key"); &add ("esp",12); &cmp ("eax",0); &je (&label("proceed")); diff --git a/src/lib/libssl/src/crypto/perlasm/x86_64-xlate.pl b/src/lib/libssl/src/crypto/perlasm/x86_64-xlate.pl index a4af769b4a..74153b017d 100755 --- a/src/lib/libssl/src/crypto/perlasm/x86_64-xlate.pl +++ b/src/lib/libssl/src/crypto/perlasm/x86_64-xlate.pl @@ -163,7 +163,8 @@ my $current_function; local *line = shift; undef $ret; - if ($line =~ /^([^\(,]*)\(([%\w,]+)\)/) { + if ($line =~ /^([^\(,]*)\(([%\w,]+)\)/ && + !($line =~ /^PIC_(GOT|PLT)/)) { $self->{label} = $1; ($self->{base},$self->{index},$self->{scale})=split(/,/,$2); $self->{scale} = 1 if (!defined($self->{scale})); @@ -429,6 +430,8 @@ my $current_function; } } +print "#include \n"; + while($line=<>) { chomp($line); diff --git a/src/lib/libssl/src/crypto/perlasm/x86unix.pl b/src/lib/libssl/src/crypto/perlasm/x86unix.pl index 02d72a32bc..ae8f0964dc 100644 --- a/src/lib/libssl/src/crypto/perlasm/x86unix.pl +++ b/src/lib/libssl/src/crypto/perlasm/x86unix.pl @@ -345,7 +345,7 @@ sub main'file local($file)=@_; if ($main'openbsd) - { push(@out,"#include \n"); return; } + { push(@out,"#include \n"); } local($tmp)=<<"EOF"; .file "$file.s" @@ -355,13 +355,17 @@ EOF sub main'function_begin { - local($func)=@_; + local($func,$junk,$llabel)=@_; &main'external_label($func); $func=$under.$func; if ($main'openbsd) - { push (@out, "\nENTRY($func)\n"); goto skip; } + { + push (@out, "\nENTRY($func)\n"); + push (@out, "$llabel:\n") if $llabel; + goto skip; + } local($tmp)=<<"EOF"; .text @@ -417,6 +421,44 @@ skip: $stack=4; } +# Like function_begin_B but with static linkage +sub main'function_begin_C + { + local($func,$extra)=@_; + + &main'external_label($func); + $func=$under.$func; + + if ($main'openbsd) + { + local($tmp)=<<"EOF"; +.text +_ALIGN_TEXT +.type $func,\@function +$func: +EOF + push(@out, $tmp); + goto skip; + } + + local($tmp)=<<"EOF"; +.text +.globl $func +EOF + push(@out,$tmp); + if ($main'cpp) + { push(@out,"TYPE($func,\@function)\n"); } + elsif ($main'coff) + { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } + elsif ($main'aout and !$main'pic) + { } + else { push(@out,".type $func,\@function\n"); } + push(@out,".align\t$align\n"); + push(@out,"$func:\n"); +skip: + $stack=4; + } + sub main'function_end { local($func)=@_; @@ -474,6 +516,8 @@ sub main'function_end_B %label=(); } +sub main'function_end_C { function_end_B(@_); } + sub main'wparam { local($num)=@_; @@ -510,7 +554,7 @@ sub main'swtmp sub main'comment { - if (!defined($com_start) or $main'elf) + if (!defined($com_start) or (!$main'openbsd && $main'elf)) { # Regarding $main'elf above... # GNU and SVR4 as'es use different comment delimiters, push(@out,"\n"); # so we just skip ELF comments... @@ -731,7 +775,9 @@ sub main'initseg { $tmp=<<___; .section .init - call $under$f + PIC_PROLOGUE + call PIC_PLT($under$f) + PIC_EPILOGUE jmp .Linitalign .align $align .Linitalign: diff --git a/src/lib/libssl/src/crypto/rc4/asm/rc4-x86_64.pl b/src/lib/libssl/src/crypto/rc4/asm/rc4-x86_64.pl index 2d47320485..92c52f3433 100755 --- a/src/lib/libssl/src/crypto/rc4/asm/rc4-x86_64.pl +++ b/src/lib/libssl/src/crypto/rc4/asm/rc4-x86_64.pl @@ -269,8 +269,7 @@ RC4_set_key: xor $ido,$ido xor %r10,%r10 xor %r11,%r11 - - mov OPENSSL_ia32cap_P(%rip),$idx#d + mov PIC_GOT(OPENSSL_ia32cap_P),$idx#d bt \$20,$idx#d jnc .Lw1stloop bt \$30,$idx#d @@ -338,7 +337,7 @@ RC4_set_key: RC4_options: .picmeup %rax lea .Lopts-.(%rax),%rax - mov OPENSSL_ia32cap_P(%rip),%edx + mov PIC_GOT(OPENSSL_ia32cap_P),%edx bt \$20,%edx jnc .Ldone add \$12,%rax diff --git a/src/lib/libssl/src/crypto/x86_64cpuid.pl b/src/lib/libssl/src/crypto/x86_64cpuid.pl index 2616a03da6..8946b464a8 100644 --- a/src/lib/libssl/src/crypto/x86_64cpuid.pl +++ b/src/lib/libssl/src/crypto/x86_64cpuid.pl @@ -47,6 +47,8 @@ CRT\$XIU ENDS ___ print<<___ if(!defined($masm)); +#include + .text .globl OPENSSL_atomic_add @@ -95,7 +97,7 @@ OPENSSL_wipe_cpu: .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu .section .init - call OPENSSL_cpuid_setup + call PIC_PLT(OPENSSL_cpuid_setup) ___ -- cgit v1.2.3-55-g6feb