effect of -fPIC on code speed

Andrew Haley aph@redhat.com
Mon Sep 20 14:49:00 GMT 2010


On 20/09/10 02:17, Miles Bader wrote:
> Ian Lance Taylor <iant@google.com> writes:
>> What happens here is that when using -fPIC symbol interposition is
>> permitted for any globally visible symbol.  That is, the -fPIC code is
>> presumed to wind up in a shared library.  An executable may override any
>> function in a shared library.  The code in the shared library which
>> calls that function is then expected to call the definition in the
>> executable instead.  It follows that when using -fPIC the compiler may
>> not inline any call to a globally visible function, because that would
>> prevent symbol interposition.
> 
> Hmm, I guess this makes sense.
> 
> It would definitely be nice to have a more precise description in a
> document somewhere though.
> 
> I'd think it would also be good to have a way of disabling this
> particular side-effect -- e.g., for non-shared-library uses of shared
> objects, like loadable modules/plugins etc, which presumably don't aim
> to provide the same guarantees that shared libraries do.

It's actually part of the C standard: there may only be one definition
of any symbol, whether that symbol refers to a function or to data.  So,
for every visible symbol X in a program, &X must be the same, no matter
who is asking.  All manner of things break without this.

Andrew.



More information about the Gcc-help mailing list