[LLVMdev] -fPIC troubles on Linux x86 (32 bit)

Gary Benson gbenson at redhat.com
Tue May 19 05:40:19 PDT 2009

Albert Graef wrote:
> Hi all,
> I noticed that now that --enable-pic is the default in svn, there's
> also some logic in Makefiles.rules to eliminate -fPIC for the case
> of mingw and cygwin:
>   ifeq ($(ENABLE_PIC),1)
>     ifeq ($(OS), $(filter $(OS), Cygwin MingW))
>       # Nothing. Win32 defaults to PIC and warns when given -fPIC
>     else
>   ...
> I would suggest that it should be done this way (i.e., eliminating
> -fPIC) not only for win32, but for all 32 bit x86 systems. Or has
> anyone seen any kind of x86 system where the -fPIC is indeed
> required?
> The problem with using -fPIC on x86 is not only the speed of the
> generated code, I also get JIT-related segfaults in the Pure
> interpreter (on Linux). See, e.g.:
> http://code.google.com/p/pure-lang/issues/detail?id=9
> (That specific bug report relates to the Ubuntu Jaunty LLVM 2.5
> package, which is (mis)configured with --enable-pic on all
> architectures including x86. But the issue is exactly the same with
> current svn, as has been reported for various different x86 Linux
> systems by other Pure users. The segfaults go away if LLVM is
> compiled with --disable-pic on x86. I don't have a minimal test
> example, but I'm pretty sure that the bug is in LLVM, not in the
> Pure interpreter, as the interpreter passes its test suite just fine
> if LLVM is compiled with --disable-pic.)
> Note that -fPIC is *not* required to build shared libraries on 32
> bit x86, in fact AFAICT it's recommended to *not* use -fPIC
> there. The workaround is obvious: we just tell users to build LLVM
> with --disable-pic on x86 systems (and to avoid broken binary x86
> packages like the one in Jaunty). But of course it would make things
> easier for packagers and end users if this worked out of the box.

I'm not sure if it's specifically required on 32-bit x86 (and I don't
have a machine lying around to test it on) but certainly on PowerPC
you cannot link other shared libraries with LLVM unless you build LLVM
with --enable-pic because parts of LLVM end up statically linked into
the library that's linked with LLVM (there are ordinary object files
listed in `llvm_config --libs`).  

If something is crashing in Pure/LLVM when LLVM is built with
--enable-pic then surely the correct solution is to find and fix the
crash, not to silently remove compiler options on certain platforms.
If someone builds LLVM with --enable-pic then presumably they wanted



More information about the llvm-dev mailing list