Using lex in a shared library

Kostik Belousov kostikbel at gmail.com
Sat Jul 3 11:22:39 UTC 2010


On Sat, Jul 03, 2010 at 12:08:11PM +0200, Joerg Sonnenberger wrote:
> On Fri, Jul 02, 2010 at 04:52:45PM -0700, Xin LI wrote:
> > I think that amd64 requires a static library be compiled with -fPIC if
> > it's being linked into shared object.  This should not be done for
> > normal static libraries, though, as this could give some performance
> > penalty when it's not needed (i.e. a static binary).
> 
> More precisely, AMD64 disallows absolute references in the text segment.
> The performance penalty for PIC on AMD64 is minimal as it can do
> RIP-relative addressing.
Even more precisely, amd64 does not disallow such references, it only
disallows the 32bit signed relocations. The reasoning is that shared
object may be loaded at arbitrary location at the process address space,
and correct relocation might be larger then can be fi in 32 signed bit.

The solution is either use PIC, thus going through PLT, or use big
(or whatever is called) memory model when compiling, that makes
all relocations 64 bit, with obvious performance penalty.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100703/14705f73/attachment.pgp


More information about the freebsd-hackers mailing list