[LLVMdev] Creating a shared library from a module

Tim Northover t.p.northover at gmail.com
Wed Dec 11 09:19:08 PST 2013


Hi Frank,

> I'd like to create a shared library out of a module in memory. Thus, I have
> a working module and would like to produce a library similar to what

That's not something LLVM can do on its own. You need a linker of some
kind to create a shared library (to create appropriate GOT entries,
resolve relocations, find dependent libraries, ...).

LLVM includes a component called MCJIT which does some of this work,
sort of, but it's in no way designed to output another object file at
the end of the process, which would be needed. It's designed to fixup
an object file in mostly ad-hoc ways so that it can be executed
directly in memory.

Other than that, you might have success linking against lld as a
library in addition to base LLVM. The documentation there is likely to
be even more sparse though (lld is reasonably new and embedding
linkers is less popular than embedding compilers).

> Where in the code (probably clang?!) is a good starting point to look?
> 'Shared' and 'position-independent' would be important.

Certainly you'd have to setup your target to compile PIC.

Cheers.

Tim.



More information about the llvm-dev mailing list