I have a C++ project that uses a C++ library that I also wrote. I'm using clang++ 3.3 to build everything. Each file in the library is compiled as
clang++ -c -O -emit-llvm somefile.cpp -o somefile.bc
I'm then using llvm-link to combine all the library *.bc files into a single bit code file like so
llvm-link -o MyLibrary.bc somefile.bc someotherfile.bc etc.bc
I'm conceptualizing this to be similar to creating an archive of object files, but I don't think that's true based on how things are acting.
I then compile the source files of my project using a similar command to the one above. I then use llvm-link (again) to combine these, along with the library bit code file into a single bit code file like this
llvm-link -o app.bc1 main.bc x.bc y.bc path/to/MyLibrary.bc
Next I compile app.bc1 into a native object file
llc -filetype=obj app.bc1 -o app.o
Finally I use clang++ again to link this native object file (and against the other native libraries I need, such as the C++ standard library, etc)
clang++ app.o -o app
However, what appears to be happening is that when I llvm-link the application's bit code the entire contents of MyLibrary.bc seems to be included in the result. Thus the final linking needs to resolve references made by library components that I'm not actually using.
What I would like to do is extract from MyLibrary.bc only the bit code files that my application needs. I see there is an llvm-ar program but in reading about it I don't get the impression that it would help here. I guessed I could combine the library with llvm-ar instead of llvm-link, but I can't figure it out. I'm hoping all I need is a little push :)