fPIC in llvm 2.6

Is fPIC broken on x86_64 in LLVM 2.6? I looked through the release notes but did not see anything mentioned. When I try:

Is fPIC broken on x86_64 in LLVM 2.6?

No, it works w/o any problems

-------------------
> llvm-gcc -Iinclude -emit-llvm -fPIC -O3 -c -o file.opt.bc file.c
> llvm-ld -native -Xlinker=-shared -Xlinker=-Wl,-soname,libtest.so -o
file.so file.opt.bc
-------------------

PIC-ness is a backend option. So, passing -fPIC to llvm-gcc does not
make any sense, it is not saved into the bytecode.
Try passing -relocation-model=pic to llvm-ld, or just compile
everything via llvm-gcc which known how to pass necessary options to
backend :slight_smile:

Is fPIC broken on x86_64 in LLVM 2.6?

No, it works w/o any problems

-------------------
> llvm-gcc -Iinclude -emit-llvm -fPIC -O3 -c -o file.opt.bc file.c
> llvm-ld -native -Xlinker=-shared -Xlinker=-Wl,-soname,libtest.so -o
file.so file.opt.bc
-------------------

PIC-ness is a backend option. So, passing -fPIC to llvm-gcc does not
make any sense, it is not saved into the bytecode.
Try passing -relocation-model=pic to llvm-ld, or just compile
everything via llvm-gcc which known how to pass necessary options to
backend :slight_smile:

Alternately, use Clang to compile your bitcode files, which also knows
how to pass the necessary options to the backend in that case! :slight_smile:

- Daniel

The reason I was linking via llvm-ld is because I didn't know how to pass bitcode files to llvm-gcc. How can I do that?

Anton Korobeynikov wrote:

You do it by using the -flto flag. But you will need a linker that's able to handle the bitcode files. The Apple linker can and so can the "gold" linker.

-bw

It appears that llvm-ld can handle bitcode files but llvm-gcc complains that when I pass bitcode files to it. I assume that means that llvm-gcc does not use llvm-ld by default. Is there a way to force it to use llvm-ld?

Bill Wendling wrote:

Hi Ryan,

It appears that llvm-ld can handle bitcode files but llvm-gcc complains
that when I pass bitcode files to it. I assume that means that llvm-gcc
does not use llvm-ld by default. Is there a way to force it to use llvm-ld?

if you are on linux, read this:

http://llvm.org/docs/GoldPlugin.html

Ciao,

Duncan.

It appears that llvm-ld can handle bitcode files but llvm-gcc complains
that when I pass bitcode files to it. I assume that means that llvm-gcc
does not use llvm-ld by default. Is there a way to force it to use llvm-ld?

One possibility is to use the gold linker as Bill was describing. Directions for Linux can be found at http://llvm.org/docs/GoldPlugin.html and http://llvm.org/docs/LinkTimeOptimization.html.

The directions may be incorrect in a few places; email llvmdev if you run into problems.

-- John T.