Broken PIC support in OS X

Manuel M T Chakravarty chak at
Sat Aug 6 08:40:15 CEST 2011

Thank you for the explanation.  I did indeed not realise that the library archive is not PIC on purpose.

The problem that I see with this policy for OS X 10.7 is that a non PIC library prevents the creation of a PIE executable, which in turn prevents address space layout randomisation.  AFAIK this is the reason why Apple discourages non PIC code on this platform and made PIC the default.

As a consequence, it is my understanding that whether a library is static (.a) or dynamic (.dynlib) shouldn't make a difference wrt to whether the code is PIC or not on this particular platform.

The --disable-shared configure option doesn't seem to make a difference:

> withinreason chak 92 (.../gmp-5.0.2/bin-install): gcc -o gmp-chudnovsky gmp-chudnovsky.c -Iinclude -L`pwd`/lib -lgmp
> ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in ___gmpn_divexact_1 from /Users/chak/Code/gmp-5.0.2/bin-install/lib/libgmp.a(dive_1.o). To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

I configured GMP with '--disable-shared'.  It omits generating the dynamic library (.dylib), but the library archive (.a) appears to be still the same.  Is that the intention?


Torbjorn Granlund:
> If I understand it correctly, you're using libgmp.a and notice that it
> is not PIC.  It is not, indeed.
> Then you copy-paste a internal GMP build command that is part of
> building libgmp.a, and again correctly notice that it is not PIC.
> Please use the shared lib, created by default, called something.dylib on
> darwin.  If that is not PIC, we have a bug.
> If you don't want a static (non-PIC) lib, please use the
> --disable-shared configure option.
> -- 
> Torbjörn

More information about the gmp-bugs mailing list