CFLAGS+= -fPIC per default?

Peter Wemm peter at
Sat Feb 21 12:23:50 PST 2004

On Saturday 21 February 2004 11:47 am, Hendrik Scholz wrote:

> Adding CFLAGS= -fPIC to /etc/make.conf may be a local solution but
> are there any drawbacks by adding something like
> .if ${ARCH} == "amd64"
> .endif
> to ports/Mk/

No.. please don't.  Although the AMD64 platform supports PIC addressing 
modes directly, it is still a penalty.  (Although thankfully, its 
nowhere near as expensive as it is on i386!)

For example, in libc when built in PIC mode:
#ifdef PIC
        movq    PIC_GOT(HIDENAME(curbrk)),%rdx
        movq    (%rdx),%rax
        movq    HIDENAME(curbrk)(%rip),%rax

The problem is that we can't be sure that everything will be in +/- 31 
bit offsets of each other.  This means that PIC objects have to do 
indirect memory references that aren't required in no-pic mode.

I386 also loses a general purpose register (%ebx) which is why -fpic is 
more expensive there.  But even though we don't lose a register, its 
still a cost because of the extra global-offset-table memory 

Footnote: you just made me wonder about some of these ifdefs..  We 
shouldn't need them for intra-object references like this.  I'll have 
to go and look again.
Peter Wemm - peter at; peter at; peter at
"All of this is for nothing if we don't go to the stars" - JMS/B5

More information about the freebsd-amd64 mailing list