Creating and using "shared library" of LLVM IR

I am trying to use LLVM to get the IR for a whole program. The program’s Makefile is somewhat complicated so I have written wrappers which emit LLVM IR at every step in the process instead of ELF object files and executables. My problem is that during linking, I get “multiple definition” errors. Here is a small example:

file: a.c

I’ve never used .so that are bitcode files before, that seems weird to me, since the point of a .so is to stay a separated entity and not being linked into the main executable.
Any reason you’re not using static archives? It seems to correspond more to what you’re trying to do (i.e. LTO all the code in a single binary).

Any reason you're not using static archives? It seems to correspond more
to what you're trying to do (i.e. LTO all the code in a single binary).

I just want to avoid modifying the application's build system. If there's
no other way, I could go in and change the build scripts, but I'd like to
avoid doing that as much as possible.

Tarun

If you’re doing LTO with shared library, usually you’re still producing shared library that are not bitcode (i.e. the LTO is performed separately within the boundary of each library).

Other people may have different experience, CC Rafael maybe?

I am primarily interested in running an analysis pass on the entire code, and I can’t quite do it separately for each library and then combine the results which is why I need the whole program. For the moment, it isn’t strictly necessary to produce the exact same output at the end of the process as you would produce with a regular compiler.

Tarun

I just want to avoid modifying the application's build system. If there's no
other way, I could go in and change the build scripts, but I'd like to avoid
doing that as much as possible.

If you're doing LTO with shared library, usually you're still producing
shared library that are not bitcode (i.e. the LTO is performed separately
within the boundary of each library).

Correct. If you want code to be linked in the binary (lto or not) you
need to replace the shared library with a static one.

Cheers,
Rafael

> If you're doing LTO with shared library, usually you're still producing
> shared library that are not bitcode (i.e. the LTO is performed separately
> within the boundary of each library).

Correct. If you want code to be linked in the binary (lto or not) you
need to replace the shared library with a static one.

I think I understand now. Thank you all for helping.

Tarun