[LLVMdev] Can llvm write shared objects?
t.p.northover at gmail.com
Fri Jan 31 03:09:34 PST 2014
On 31 January 2014 10:36, Yuri <yuri at rawbw.com> wrote:
> Currently ELFObjectWriter only writes ET_REL, making relocable ELF.
> Why isn't it able to write ET_DYN object, that would make shared object ELF?
> Shared objects are of course achievable through calling 'ld' on object
> modules, but I am curious why llvm can't write them directly.
> The difference is probably cosmetic from the standpoint of llvm.
Quite a lot of work actually goes into producing a functional shared
object, at least in non-trivial cases.
Completely different relocations are used (far fewer types of them, to
be more efficiently handled by ld-linux or whatever loader you're
using). To handle that, GOT and PLT entries need to be created.
Dynamic dependencies need to be searched and recorded in the file (so
that ld-linux knows *where* it might find "printf", say).
There's probably others I'm forgetting, but all in all creating a
correct .so file is one of the harder jobs a system linker has to do.
The "lld" project is a system linker associated with LLVM though, and
probably usable as a library if you're interested in producing .so
files without involving an external process.
More information about the llvm-dev