effect of -fPIC on code speed
Thu Sep 16 10:12:00 GMT 2010
I recently wanted to produce both a standalone executable and a shared
library using the same set of object files, and so compiled them all
using -fPIC (as "gcc -shared" demeands it). I made my shared lib, and
also made a normal executable using these object files -- and I
noticed that the resulting executable size was a fair bit smaller
(according to the "size" command) than the previous non-fPIC
executable I had compiled (using non-fPIC object files).
I haven't done any significant amount of benchmarking on it, but it
didn't seem obviously slower.
[This is on an x86-64 system, using a g++-snapshot from debian:
gcc (Debian 20100828-1) 4.6.0 20100828 (experimental) [trunk revision 163616] ]
Is there any general wisdom about the effects of using -fPIC,
especially on code speed? Would it be stupid for me to set up my
configure script to _always_ use -fPIC (even when not needed for a
shared library), when it detects that gcc accepts that option?
If you can't beat them, arrange to have them beaten. [George Carlin]
More information about the Gcc-help