One of my co-workers eats assembly language for breakfast.  He took a
look at this, whacked together a trivial test case, and handed me a
correction to the assembly code.  Credit for this fix should go to
Francis Dupont, not me.

Test case:

    $ cat >test.c <<EOF
    #include <openssl/x509.h>
    void foo(void) { X509_print(NULL, NULL); }
    EOF
    $ cc -g -O -fPIC -c test.c
    $ cc -shared test.o -o test.so /usr/lib64/libcrypto.a

Substitute location of libcrypto.a as needed if that's not where it
lives on your 64-bit Linux system or if you want to test against a
version you're certain was compile with -fPIC support.  Error message
should be something like:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: 
/usr/lib64/libcrypto.a(x86_64cpuid.o): relocation R_X86_64_PC32 against symbol 
`OPENSSL_cpuid_setup' can not be used when making a shared object; recompile 
with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: 
final link failed: Bad value
collect2: ld returned 1 exit status

Francis tells me that the correct way to do PIC on x86_64 is
@GOTPCREL.  Here's his patch:

diff -r -u bad/openssl-1.0.0b/crypto/aes/asm/aes-x86_64.pl 
fixed/openssl-1.0.0b/crypto/aes/asm/aes-x86_64.pl
--- bad/openssl-1.0.0b/crypto/aes/asm/aes-x86_64.pl     2008-12-27 
14:32:21.000000000 +0100
+++ fixed/openssl-1.0.0b/crypto/aes/asm/aes-x86_64.pl   2011-03-18 
21:10:47.000000000 +0100
@@ -1669,7 +1669,8 @@
        lea     .LAES_Td(%rip),$sbox
 .Lcbc_picked_te:
 
-       mov     OPENSSL_ia32cap_P(%rip),%r10d
+       mov     OPENSSL_ia32cap_P\@GOTPCREL(%rip),%r10d
+       mov     (%r10d),%r10d
        cmp     \$$speed_limit,%rdx
        jb      .Lcbc_slow_prologue
        test    \$15,%rdx
diff -r -u bad/openssl-1.0.0b/crypto/rc4/asm/rc4-x86_64.pl 
fixed/openssl-1.0.0b/crypto/rc4/asm/rc4-x86_64.pl
--- bad/openssl-1.0.0b/crypto/rc4/asm/rc4-x86_64.pl     2009-04-27 
21:31:04.000000000 +0200
+++ fixed/openssl-1.0.0b/crypto/rc4/asm/rc4-x86_64.pl   2011-03-18 
21:22:46.000000000 +0100
@@ -276,10 +276,11 @@
        mov     $len,%rcx
        xor     %eax,%eax
        xor     $ido,$ido
-       xor     %r10,%r10
        xor     %r11,%r11
 
-       mov     OPENSSL_ia32cap_P(%rip),$idx#d
+       mov     OPENSSL_ia32cap_P\@GOTPCREL(%rip),%r10d
+       mov     (%r10d),$idx#d
+       xor     %r10,%r10
        bt      \$20,$idx#d
        jnc     .Lw1stloop
        bt      \$30,$idx#d
@@ -346,7 +347,8 @@
 .align 16
 RC4_options:
        lea     .Lopts(%rip),%rax
-       mov     OPENSSL_ia32cap_P(%rip),%edx
+       mov     OPENSSL_ia32cap_P\@GOTPCREL(%rip),%edx
+       mov     (%edx),%edx
        bt      \$20,%edx
        jnc     .Ldone
        add     \$12,%rax
Only in fixed/openssl-1.0.0b/crypto/rc4/asm: x.c
Only in fixed/openssl-1.0.0b/crypto/rc4/asm: x.s
diff -r -u bad/openssl-1.0.0b/crypto/x86_64cpuid.pl 
fixed/openssl-1.0.0b/crypto/x86_64cpuid.pl
--- bad/openssl-1.0.0b/crypto/x86_64cpuid.pl    2010-04-14 21:25:09.000000000 
+0200
+++ fixed/openssl-1.0.0b/crypto/x86_64cpuid.pl  2011-03-18 20:46:42.000000000 
+0100
@@ -14,7 +14,7 @@
 print<<___;
 .extern                OPENSSL_cpuid_setup
 .section       .init
-       call    OPENSSL_cpuid_setup
+       call    OPENSSL_cpuid_setup\@PLT
 
 .text


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to