Kaleidoscope doesn't work properly

Hi

I hope this is a proper place to put my question.

I've compiled Kaleidoscope from "Adding JIT and Optimizer Support" tutorial.
Basically it works just fine but when I try to run extern'ed putchard
function it aborts.
Please, tell me what am I doing wrong?

Here is more information:
My PC runs FreeBSD.
I've copied the toy source code exactly and didn't change it.

Here is the log:
# ./toy

extern putchard(x);
Read extern:

declare double @putchard(double)

def asd (a) putchard(a);
Read function definition:

define double @asd(double %a) {
entry:
        %calltmp = call double @putchard( double %a ) ;
<double> [#uses=1]
        ret double %calltmp
}

asd(120);
ERROR: Program used external function 'putchard' which could

not be resolved!
Abort (core dumped)

Here is the backtrace from the toy.core:
(gdb) backtrace
#0 0x4889cbb7 in kill () from /lib/libc.so.7
#1 0x4868d146 in raise () from /lib/libthr.so.3
#2 0x4889b76a in abort () from /lib/libc.so.7
#3 0x0831f8a0 in llvm::JIT::getPointerToNamedFunction ()
#4 0x0832177a in llvm::JIT::getPointerToFunction ()
#5 0x083275a2 in (anonymous namespace)::JITEmitter::getPointerToGlobal ()
#6 0x083280e4 in (anonymous namespace)::JITEmitter::finishFunction ()
#7 0x0805f8d0 in (anonymous namespace)::Emitter::runOnMachineFunction ()
#8 0x081deee8 in llvm::MachineFunctionPass::runOnFunction ()
#9 0x08561cd7 in llvm::FPPassManager::runOnFunction ()
#10 0x08562185 in llvm::FunctionPassManagerImpl::run ()
#11 0x08562337 in llvm::FunctionPassManager::run ()
#12 0x0831f9ec in llvm::JIT::runJITOnFunction ()
#13 0x08321847 in llvm::JIT::getPointerToFunction ()
#14 0x0804f680 in MainLoop () at toy.cpp:508
#15 0x0804ff12 in main () at toy.cpp:590

Link with -rdynamic or provide a mapping.

/Stein Roger

Andrii Vasyliev wrote:

Thanks, -rdynamic helps! It's a pity that it's not written in the tutorial.

Also I'm interested how can I provide a mapping?

Andrii Vasyliev wrote:

I've compiled Kaleidoscope from "Adding JIT and Optimizer Support" tutorial.
Basically it works just fine but when I try to run extern'ed putchard
function it aborts.
Please, tell me what am I doing wrong?

Have you tried to link with -rdynamic (Linux-specific, not needed on OSX
or Windows)?

I've already filed a bug report but nobody cares :frowning:

Is it possible to fix the documentation? Because I think the tutorial is really important to beginners, which should not be misleading.

-- Haohui

Haohui Mai <haohui.mai@gmail.com> writes:

I've already filed a bug report but nobody cares :frowning:

Is it possible to fix the documentation? Because I think the tutorial
is really important to beginners, which should not be misleading.

Thanks, -rdynamic helps! It's a pity that it's not written in the
tutorial.

Also I'm interested how can I provide a mapping?

Link with -rdynamic or provide a mapping.

Which is the id number of the bug you filed? I don't see any bugs
related to Kaleidoscope on the last two days.

And be reassured that people here care about bugs, but they are not
*that* fast that *always* fixes them on less than 24 hours :slight_smile:

Please suggest a change to apply (either in patch form, or "add these words here in the tutorial") and I'll be happy to do it.

-Chris

Not exactly the same, but I think it is the same problem.

http://llvm.org/bugs/show_bug.cgi?id=2712

-- Haohui