On Tue, Aug 23, 2005 at 03:49:46PM -0500, Quentin Spencer wrote: > While we're on this topic, I have a related question. I've been looking > at the Debian version of a package I'm working on, and in their > buildscripts they build a static library without -fPIC and then rebuild > with -fPIC for the shared library. It seems like unnecessary extra > compilation. Is there any possible performance loss (or any other side > effect) that can come from using -fPIC? Of course there is, at least on most architectures. There are 2 differences: 1) -fpic/-fPIC code can't must avoid text relocations, so where they would be needed, an indirection is needed instead. On many architectures (e.g. i386, ppc32, s390, s390x) a PIC register needs to be loaded on entry to most of the -fpic/-fPIC compiled routines, which means additional overhead. 2) with -fpic/-fPIC code, the compiler can't assume globally visible functions/variables defined in the same source as code referring to them will be defined in the same binary or shared library at runtime as well, which again can mean an indirection or a hop through PLT And -fPIC is on some architectures noticably slower than -fpic as well. Either it means more instructions to load the addresses (e.g. on sparc -fpic means one instruction that loads address, while -fPIC needs 3 instructions to do the same), or on some architectures -fPIC means double indirection. Jakub