Kaleidoscope toy4 failure seg fault on llvm::ExecutionEngine::getTargetData (this=0x0)

I am new to llvm so I might be missing a critical step. My system is
Fedora 12 but this also happens in Mac OS X 10.6.2. Here are the
steps I used to compile llvm:
export TARGETS=x86,x86_64,cpp
export INSTALLDIR=/home/rovitotv/llvm
../llvm-2.6/configure --prefix=$INSTALLDIR --enable-bindings=none
--enable-targets=$TARGETS --enable-optimized
--with-llvmgccdir=$INSTALLDIR --with-llvm-externals=/home/rovitotv/
make ENABLE_OPTIMIZED=1
make install

To compile the llvm-gcc4.2-2.6 front end:
../llvm-gcc4.2-2.6/configure --target=i686-pc-linux-gnu
--with-tune=generic --with-arch=pentium4 --prefix=/home/rovitotv/llvm/
--enable-llvm=/home/rovitotv/llvm/ --enable-languages=c,c++
make
make install

Then I make sure that /home/rovitotv/llvm/bin is in my path. At this
point I copy/paste the example in the tutorial chapter 4, please see
code below. I have tried a few different commands to compile, here
are the variations:
g++ -g toy4_new_copy.cpp `llvm-config --cppflags --ldflags --libs core
jit native` -O3 -o toy4

g++ -g toy4.cpp `llvm-config --cppflags --ldflags --libs core jit
interpreter native` -O2 -o toy4

The compile completes with no errors or warnings. When I execute the
program then enter the expression 4+5; I get a seg fault :frowning: Here is
sample gdb output from a recent run:

(gdb) run
Starting program: /home/rovitotv/prog/llvm-tutorial/toy4
[Thread debugging using libthread_db enabled]

4+5;

Program received signal SIGSEGV, Segmentation fault.
0x080524f0 in llvm::ExecutionEngine::getTargetData (this=0x0)
    at /home/rovitotv/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:167
167 const TargetData *getTargetData() const { return TD; }
Missing separate debuginfos, use: debuginfo-install glibc-2.11-2.i686
libgcc-4.4.2-7.fc12.i686 libstdc++-4.4.2-7.fc12.i686
(gdb) bt
#0 0x080524f0 in llvm::ExecutionEngine::getTargetData (this=0x0)
    at /home/rovitotv/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h:167
#1 0x0805201a in main () at toy4_new_copy.cpp:577
(gdb)

Any help you can provide would be much appreciated. Thanks!

First, you have to call llvm-g++ to use the llvm-gcc front end, but it doesn’t matter here.

I’d like to suggest that you use pastebin to put your code and the send us the link, so that we can download it. The problem is that TheExecutionEngine is set to NULL (maybe because of a previous error), but it will be really better if you use pastebin.

First, you have to call llvm-g++ to use the llvm-gcc front end, but it
doesn't matter here.

I got the compile command from the Kaleidoscope documentation.

I'd like to suggest that you use pastebin to put your code and the send us
the link, so that we can download it. The problem is that TheExecutionEngine
is set to NULL (maybe because of a previous error), but it will be really
better if you use pastebin.

Here is the pastbin:
http://pastebin.com/m167c96c2

Thanks for the help after some further investigation I realized that
there is a difference between the documentation for example 4 on the
web here:
      Kaleidoscope: Adding JIT and Optimizer Support
And the same example that comes with the llvm distribution that is
installed during the build process here:
     file:///Users/rovitotv/llvm/docs/llvm/html/tutorial/LangImpl4.html
(Of course you have to change your path for your installation).

Thanks for the help.

Hum... looks like an outdated documentation. Kaleidoscope docs is
famous for being out-of-date and lots of people asking in the list why
is it not compiling.

I suggest you get the svn trunk and compile Kaleidoscope in site (you
probably did already if you got the llvm source and ran make) and see
what the makefile do to compile it. Also, the source in the site could
be quite outdated, I would start from the source tree.

cheers,
--renato

Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm