Static libraries with fPIC on x86

View: New views
2 Messages — Rating Filter:   Alert me  

Static libraries with fPIC on x86

by blair_boost :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have built openssl-0.9.8k and am trying to link libcrypto.a statically with my project.
For example, consider the following:
#include <openssl/des.h>
void foo(void) {
            DES_encrypt3(NULL, NULL, NULL, NULL);
            AES_encrypt(NULL, NULL);

}

$ gcc -fPIC -o libfoo.so -shared foo.c /usr/lib/libcrypto.a
$ eu-findtextrel libfoo.so
the file containing the function 'DES_encrypt3' is not compiled with -fpic/-fPIC
the file containing the function 'DES_decrypt3' is not compiled with -fpic/-fPIC
the file containing the function 'DES_ncbc_encrypt' is not compiled with -fpic/-fPIC
the file containing the function 'DES_ede3_cbc_encrypt' is not compiled with -fpic/-fPIC

This does not happen on 64bit system and eu-findtextrel reports on text relocations. I think this is the default behavior on x86 systems.

Can someone point me to why building static libs on 32 bit system with fPIC is a bad idea?
Also, if I want to build the static lib with fPIC, how do I go about it? All the .o files are built with fPIC

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

Re: Static libraries with fPIC on x86

by Andrew Haley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

john blair wrote:

> I have built openssl-0.9.8k and am trying to link libcrypto.a statically with my project.
> For example, consider the following:
> #include <openssl/des.h>
> void foo(void) {
>             DES_encrypt3(NULL, NULL, NULL, NULL);
>             AES_encrypt(NULL, NULL);
>
> }
>
> $ gcc -fPIC -o libfoo.so -shared foo.c /usr/lib/libcrypto.a
> $ eu-findtextrel libfoo.so
> the file containing the function 'DES_encrypt3' is not compiled with -fpic/-fPIC
> the file containing the function 'DES_decrypt3' is not compiled with -fpic/-fPIC
> the file containing the function 'DES_ncbc_encrypt' is not compiled with -fpic/-fPIC
> the file containing the function 'DES_ede3_cbc_encrypt' is not compiled with -fpic/-fPIC
>
> This does not happen on 64bit system and eu-findtextrel reports on text relocations. I think this is the default behavior on x86 systems.
>
> Can someone point me to why building static libs on 32 bit system with fPIC is a bad idea?

It slows things down a bit because 32 bit x86 doesn't have PC-relative addressing.

> Also, if I want to build the static lib with fPIC, how do I go about it? All the .o files are built with fPIC

Then I don't know why it hasn't worked.  It always works for me.

Andrew.