[LLVMdev] Question about usage of LLVMLinkModules()

Lefteris Karapetsas lefteris at refu.co
Mon Jun 8 07:11:12 PDT 2015


Hello all,

I am using llvm as a backend to a hobby language I am making.  I have
experimented with the C bindings since the project is written in C. I had
no problems building a single lllvm module so far. I am not using a JIT
compiler but at least at the moment am simply generating executables. The
workflow I am using is to build a module with LLVMModuleCreateWithName()
and populate it with the LLVMBuilder.

After everything is in the module I simply output it into a file with
LLVMPrintModuleToFile(). Then I am calling llc to convert the IR  to native
machine code and finally gcc to create an executable out of it. All these
from inside my program. It may not be the best way to generate an
executable and I would really welcome as much advice as you can give me on
that but it works.

The issue comes when I actually create 2 different modules. One being a
"standard" library of sorts and the other the main module which should use
it. I create both modules, with no errors appearing if I use
LLVMVerifyModule() on them.

The problem is how do I link them? I tried to do it like this:

            // if an error occurs LLVMLinkModules() returns true
            if (true == LLVMLinkModules(main_module, stdlib_module,
LLVMLinkerDestroySource, &error)) {
                bllvm_error("Could not link LLVM modules", error);
                goto end;
            }


But this fails (returns true), with no error. Even though both modules are
valid. I understand that the above may be a really naive mistake, and that
my whole approach may be wrong. This is why I would appreciate any links to
tutorials/documents which would show the proper way to link 2 modules or
some good old simple advice tips from any of you guys.

Thank you for your time.
Best Regards,

Lefteris(Eleftherios) Karapetsas  Click here <http://lefteris.refu.co> for
my CV/portfolio website
<http://lefteris.refu.co>   Also maintain a blog <http://blog.refu.co>on
various topics, mostly engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150608/ebed9edd/attachment.html>


More information about the llvm-dev mailing list