« 基因地理工程:我们自身的历史 | Main | 俺爹俺娘 »

gcc -fPIC/-fpic

CN wrote:
> Hi,
>
>   what are the implications of using/dropping -fPIC ?
>
> The direct one which comes to my mind is -fPIC reduces the memory
> footprint of the process. Does this _always_ come at the expense
> of CPU cycles?

PIC code results in more instructions to execute.  However, since the
code is shareable by all proc's that are using it, there's a greater
likelihood of keeping the code in-cache closer to the processor
which means fewer cycles lost on cache misses.

So the extremes are 5-15% performance loss if only one process is
using the code, to huge performance gains if you had a large number
of processes executing the same code and the working set for any
given process completely fit in L1 cache.

The actual effect on any given system will, of course, lie somewhere
in the middle.  Any benchmark must be live code running actual
production workload to have any validity since the cache effects
are what govern the outcome and that is extremely difficult to
simulate.

> What other consequences am I looking at if I drop
> PIC totally from one of my shared libraries ?

The only condition where it's worth considering building a non-PIC
shared library is if the library is used solely by a single application
which loads the library before forking working procs.  Since PHP
meets that condition, it's compiled that way.

Rr

RelatedEntries:
ubuntu8.10[Intrepid Ibex]mac风格美化 - 11 18, 2008
ubuntu 下vpn - 09 05, 2008
accept Serialization - multiple sockets - 04 29, 2008
gcc浮点运算的一个编译选项 - 06 06, 2007
关于hash_map的一个例子 - 04 26, 2007



TrackBack

TrackBack URL for this entry:
http://www.trucy.org/cgi-bin/blog/mt-tb.cgi/1975

Post a comment