Kaleidoscope-tutorial: Fails to create the JIT

Hello All

I 'm studing LLVM/Clang and trying to follow the Kaleidoscope tutorial (Release 2.6 version).
I found some minir docu-bugs and added them to Bugzilla.

However, Now I found a show-stopper for me, the toy (v4) demo does build, but does crash, on any input. Even a simpe ';'!
Looking into the (demo-code) found the that the JIT can't be build/created,/loaded/...
Which result's in a null-pointer for "TheExecutionEngine"; which explains the bus-errror ..

The main code is
  >> ... //GAM some setting of vars
  >> fprintf(stderr, "ready> ");
  >> getNextToken();
  >>
  >> // Make the module, which holds all the code.
  >> TheModule = new Module("my cool jit", getGlobalContext());
  >> //GAM: check TheModule: it's a valid pointer
  >>
  >> // create the JIT.
  >> TheExecutionEngine = EngineBuilder(TheModule).create();
  >> //GAM: check TheExecutionEngine: IT IS A NULL POINTER
[My addition are annotated by 'GAM']

This code, seams right to me; so probably it is an installation problem. Or such.
But the code is to big to solve this now. I' following the tutorial, to get familiair with it. :slight_smile:

So I need some help. Please give respond with a fix, workaround,. or when needed details

Some details: Version is 2.6, PreBuild Apple OS-X download (from llvm-website). But the same happens with build form 2.6 sources.
Apple (Laptop) , intel; Leopard OS (No Snow), with all updates
Placed the bin/libs in a custom dir: $HOME/NoTimeMachine/LLCM/PreBuild/ is LLVM home [or: .../<OwnBuidl>/Release/]
Build the Kaleidoscope tool, as mentioned in the docs:
  g++ -g -O3 $< -o $@ `${LLVM}/bin/llvm-config --cppflags --ldflags --libs core jit native`
Also tried with -rdynamic option; same result

Please send me instruction for a patch/workarond, so I can continue this tutorial, make bug-reports and/or -fixes. Thanks!

Notice: I'n not part of the -dev list, so please responds to my directly: albert AT mietus DOT nl, or the email in header.

Thanks

ALbert Mietus
    GSM: +316 16 531 258
    Send prive mail to: ALbert at ons-huis dot net
                                                 Don't send spam mail!
Mijn missie: http://SoftwareBeterMaken.nl product, proces & imago.
Mijn leven in het kort: http://albert.mietus.nl/Doc/CV_ALbert.html

Try changing the above line to:
  std::string str;
  TheExecutionEngine =
EngineBuilder(OurModuleProvider).setErrorStr(str).create();
  cout << str << '\n';

This interface should set str to an appropriate error message if it
returns NULL.

Reid

I suspect the code is wrong as of LLVM 2.6 which introduced a new requirement:
the initialize_native_target function must be called before the JIT is
created, in order to initialize the available target architectures.
Otherwise, the JIT will not initialize.

This breaking change was described in the OCaml Journal article "LLVM 2.6
support and a new HLVM garbage collector" (23rd October 2009).

I ask for advice, for TheExecutionEngine === NULL,

Which result's in a null-pointer for "TheExecutionEngine"; which
explains the bus-errror ..

Reid Kleckner wrote:

Try changing the above line to:
std::string str;
TheExecutionEngine = EngineBuilder(OurModuleProvider).setErrorStr(str).create();
cout << str << '\n';

This interface should set str to an appropriate error message if it
returns NULL.

I tried this, assuming that line should be

TheExecutionEngine =

EngineBuilder(TheModule).setErrorStr(&str).create();

Look at what is in <llvm source root>/examples/Kaleidoscope/toy.cpp.
This is the final version of the tutorial and worked the last time I played with 2.6.

Garrison

--Groetjes, Albert

ALbert Mietus
    GSM: +316 16 531 258
    Send prive mail to: ALbert at ons-huis dot net
                                                 Don't send spam mail!
Mijn missie: http://SoftwareBeterMaken.nl product, proces & imago.
Mijn leven in het kort: http://albert.mietus.nl/Doc/CV_ALbert.html

Look at what is in <llvm source root>/examples/Kaleidoscope/toy.cpp.
This is the final version of the tutorial and worked the last time I played with 2.6.

Tried, that code ... And got a error (which I not really understand, yet)

> g++ -g -O0 toy-example26.cpp -o toy-example26 \
  `/Users/albert/NoTimeMachine/LLCM_Clang/llvm-trunk/BUILD/Debug/bin/

llvm-config --cppflags --ldflags --libs core jit native`

Undefined symbols:
"_LLVMLinkInInterpreter", referenced from:
     (anonymous

namespace)::ForceInterpreterLinking::ForceInterpreterLinking() in ccXf1BAH.o

ld: symbol(s) not found
collect2: ld returned 1 exit status

Note, `/Users/albert/NoTimeMachine/LLCM_Clang/llvm-trunk/BUILD/Debug/bin/llvm-config --cppflags --ldflags --libs core jit native` gives
(formating by me)
  -I/Users/albert/NoTimeMachine/LLCM_Clang/BUILD-llvm-2.6+clang/../llvm-2.6/include \
  -I/Users/albert/NoTimeMachine/LLCM_Clang/BUILD-llvm-2.6+clang/include
  -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS \
  \
  -L/Users/albert/NoTimeMachine/LLCM_Clang/llvm-trunk/BUILD/Debug/lib -lpthread -lffi -lm \
  -lLLVMX86Disassembler \
  -lLLVMX86AsmParser \
  -lLLVMMCParser \
  -lLLVMX86AsmPrinter \
  -lLLVMX86CodeGen \
  -lLLVMSelectionDAG \
  -lLLVMAsmPrinter \
  -lLLVMX86Info \
  -lLLVMJIT \
  -lLLVMExecutionEngine \
  -lLLVMCodeGen \
  -lLLVMScalarOpts \
  -lLLVMInstCombine \
  -lLLVMTransformUtils \
  -lLLVMipa \
  -lLLVMAnalysis \
  -lLLVMTarget \
  -lLLVMMC \
  -lLLVMCore \
  -lLLVMSupport \
  -lLLVMSystem \
  #eol

Trying to build with other version/Build (PreBuild one, Debug-version, or trunk) give same error and simular values for llvm-config output (same, but for the path)

Any Idea? --THANKS

Change your g++ build to:

g++ -g -O0 toy-example26.cpp -o toy-example26 `/Users/albert/NoTimeMachine/LLCM_Clang/llvm-trunk/BUILD/Debug/bin/llvm-config --cppflags --ldflags --libs core jit interpreter native`

After you get this working, try it with the source interpreter include removed, and minus the above interpreter llvm-config addition.

Garrison

First, THANKS for all the help!

Change your g++ build to:

g++ -g -O0 toy-example26.cpp -o toy-example26 `/Users/albert/NoTimeMachine/LLCM_Clang/llvm-trunk/BUILD/Debug/bin/llvm-config --cppflags --ldflags --libs core jit interpreter native`

This help! But, see below ...

After you get this working, try it with the source interpreter include removed, and minus the above interpreter llvm-config addition.

Now, I removed the interpreter lib and the line: '#include "llvm/ExecutionEngine/Interpreter.h"', which again results in a "working" executable.

Great! This enables me to study llvm again.

As I wrote above, both build work more-or-less. I found a "new" bug; which I have feed to Bugzilla, see bug 6136.

As A summary:
When entering end-of-line, both build start dumping/showing the module content AND fail at it, with a abort-trap!
See bugzilla for details

For now, I will "backport" this working build to in-between (chapter) version of the tutorial and study it a bit more. Whenever I found doc-bugs or other items, I will enter them in in bugzilla (as I did before).
Whenever I got a "good" explanation why I didn't/doesn't work (yet) on my system I will bugzilla and/or email it, with patches if possible

THANKS

--Groetjes, Albert

ALbert Mietus
    GSM: +316 16 531 258
    Send prive mail to: ALbert at ons-huis dot net
                                                 Don't send spam mail!
Mijn missie: http://SoftwareBeterMaken.nl product, proces & imago.
Mijn leven in het kort: http://albert.mietus.nl/Doc/CV_ALbert.html