Q:

How can I use llvm-ar generated archive file?

llvm-ar archives several LLVM bitcode files into a single archive library that can be linked into a program. The archive operation works as expected. Aslo, it is possible to use llvm-nm to show all the symbols in the generated archive.
However, I noticed the generated archive can not be used by the other standard llvm tools, for example, llc, lli and llvm-link directly.
In order to use the generated archived file, I have to extract all the bitcode files from the archived file and then use them directly by llc. 
Questions:

Is there some more elegant or efficient way to use the generated archived file by llvm-ar?
Could clang use bitcode archived file directly as below:

// assumes hello.bc is valid bitcode file and it is built successfully
clang-3.8  -o main main.c hello.bc

// ar hello.bc into lib libhello.bca
llvm-ar-3.8 rcs libhello.bca hello.bc

llvm-nm libhello.bca // has below output

   hello.bc:
   ---------------- T outupt
                    U puts

clang-3.8 -o main main.c libhello.bca // has below error

  libhello.bca: error adding symbols: File format not recognized
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

A:

LLVM tools like llc, lli, opt and others can't operate on bitcode archives directly. You have to unpack it before running them. Alternatively, you can link archive items into one single bitcode file, but that's not the same as having the archive, so it depends if that suits you.
As for clang, you can pass bitcode archives along with source files and libraries, and it will do the correct thing - unpack it, run passes, compile to object file and link into the final binary.

