llvm::Linker::linkModules destroys source module

We have some LLVM 3.4 based code that we are now trying to upgrade. There used to be the following API in LLVM 3.4 which is now gone:

Linker::LinkModules(dst, src, Linker::PreserveSource, &error);

The current function Linker::linkModules wants to take ownership of src and destroys it on return.

In our use case, src is a module containing a predefined set of inline functions. We link src with dst, optimize dst, emit object code for dst, destroy dst and then create a new dst module from our code generator and repeat this process. The src module is a constant throughout. What is the recommended way of doing something like this in current version of LLVM? Is there a way of copying only what is needed from src into dst and then updating all the call instructions in dst that refer to src functions?

Or do I just have to write something like this myself and not use linkModules?


You might want http://llvm.org/doxygen/Cloning_8h.html to copy the Module before you link it in?

Looks like this functionality was removed a few years ago because it had bitrotted/was broken: http://llvm.org/viewvc/llvm-project?view=revision&revision=220741

  • Dave