Quantcast

How to create shared library using llvm-ld

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to create shared library using llvm-ld

gauss
Hi, all. I am using llvm-gcc to compile some softwares, and compile them with CFLAGS="-emit-llvm" to gernerate bitcode IR. Then I have to replace normal ld with llvm-ld. Unfortunately, llvm-ld doesn't support -shared option which is used to create a shared library. I've also noticed that llvm-ld supports an option '-link-as-library' which is used to generate static library file. It is helpless. Any ideas? Thanks a lot. Gauss, 2009-09-23
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to create shared library using llvm-ld

Nick Lewycky
gauss wrote:
> Hi, all. I am using llvm-gcc to compile some softwares, and compile them
> with CFLAGS="-emit-llvm" to gernerate bitcode IR. Then I have to replace
> normal */ld/* with */llvm-ld/*. Unfortunately, */llvm-ld/* doesn't
> support */-shared/* option which is used to create a shared library.
> I've also noticed that llvm-ld supports an option '-link-as-library'
> which is used to generate static library file. It is helpless. Any
> ideas? Thanks a lot. Gauss, 2009-09-23

Use the gold plugin: http://llvm.org/docs/GoldPlugin.html . Then 'ld
-shared foo.bc' will work just as if foo.bc were a .o file.

If you don't want to (or can't) use gold for some reason, you'll need to
a) run llvm-ld -link-as-library to produce a merged .bc
b) run llc -relocation-model=pic to produce a .s file
c) assemble and link it into a .so file (gcc -shared foo.s will work
fine, or you can run 'as' and 'ld' yourself, though figuring out the
options is a pain.)

but this route may give you slightly less optimization than using gold
directly, for the reasons explained in
llvm.org/docs/LinkTimeOptimization.html .

Alternately, you can implement the -shared flag for llvm-ld yourself,
which does the same operations as the above list but without the need to
run the individual commands.

Nick
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Loading...