[LLVMdev] Primer with LLVM

Reid Spencer reid at x10sys.com
Thu Dec 30 12:46:36 PST 2004

On Thu, 2004-12-30 at 11:14, Francisco Puentes wrote:
> Hi, everybody:
Hi Francisco

> I am a beginner with LLVM, in fact today was the first day that I use it.


> I have several questions about LLVM:

If you haven't already, a good place to start is the Getting Started
Guide, at http://llvm.cs.uiuc.edu/docs/GettingStarted.html 

> Can I use LLVM to compile several files (bytecode), scripts (char*) and link
> them with external libraries generating *only* one executable (all in
> memory)?

I'm not exactly sure what you're trying to do, but I believe you can do
what you want. The llvm-link tool will link together multiple bytecode
files. lli will generate code in memory (JIT compilation) and execute
it. Since the bulk of the implementation of these tools is in the LLVM
libraries, you can create your own process to do the same sorts of

I'm not quite sure what you mean by "scripts (char*)" but if you mean
LLVM assembly then this is possible to. The ParseAssemblyFile function
(include/llvm/Assembly/Parser.h) can be used to turn an LLVM assembly
into a Module* which is then suitable for linking via the linker
interface (include/llvm/Linker.h).

> Can I invoke externals functions from a guest (LLVM generated) code which
> exist in the host code (the code that execute the first one)?

Yes. The lli interpreter/JIT compiler will resolve symbols within its
own executable or dynamically via a loadable plug-in (-load option).
Some platforms don't support this currently (Cygwin for example).

> And a problem:
> I made a little aplication with use the functions llvm::LinkModules and
> llvm::LinkLibraries that, I suppouse, exist in libLLVMLinker.a archive,

that is correct.

>  but
> gcc linker reports 'undefined' errors for this functions.

The only thing I can think of is dependencies that libLLVMLinker has.
You will probably want a linke line that looks something like: 

gcc -o myapp myapp.o -lLLVMLinker -lLLVMArchive -lLLVMBCReader \
      -lLLVMBCWriter -lLLVMCore -lLLVMSupport -lLLVMbzip2 -lLLVMSystem

To get examples of these library specifications, look at the llvm-ld and
gccld tools' Makefiles.

>  I don't use the
> makefile system from LLVM because is so complex to incorporate in this point
> of my work that it isn't usefull at the moment.

That's unfortunate to hear. We've tried to make it as dead simple as
possible. The typical end-user Makefile for LLVM is about 3 or 4 lines
long.  What do you find confusing? Have you read the Makefile Guide?

>  I use the libraries directly
> in my own Makefile. I tried to explicitly insert **all** LLVM libraries and
> it doesn't work :-(

Order of specification of the libraries on the link command is
important. There are numerous inter-dependencies amongst the libraries
and you need to understand them before this kind of approach will work.
Its unlikely that you would want *all* LLVM libraries in any tool. 

> Does anybody have got a example of an aplication which uses these functions
> to compile and execute in memory a multi-file application? (lli isn't useful
> for me)

The closest thing we have is the HowToUseJIT example program. I believe
Duraid Madina is working on something similar. You might want to check
with him (duraid at octopus dot com dot au)

> Thanks in advance and apologize so basic questions.

Glad to help. I hope you find LLVM useful.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20041230/b8008b16/attachment.sig>

More information about the llvm-dev mailing list