[llvm-dev] Kaleidoscope Tutorial Chapter #4: externs crash REPL

Lajos V├ętek via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 10 00:01:40 PDT 2018


I am working myself through the LLVM Kaleidoscope tutorials, with a current
(git master) llvm build on a Mac OS X 10.13.5. I must say the tutorial is
realy a good read, and it is great fun to work through the examples...
Up until Chapter 4 everything was working as expected, but  in Chapter 4 I
ran into some issues. I cannot get the extern (dlsym-d) function to work in
another function.
Declaring the external prototype and using it as a top level expression

ready> extern sin(a);

ready> Read extern:

declare double @sin(double)

ready> sin(1);

ready> Evaluated to 0.841471

Unfortunatly as soon as the external function is used in another def-d
function body, the REPL crashes:

ready> def test(b) sin(b);

ready> Read function definition:

define double @test(double %b) {


  %calltmp = call double @sin(double %b)

  ret double %calltmp


ready> test(1);

ready> Failure value returned from cantFail wrapped call

UNREACHABLE executed at

Process 46951 stopped

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT

    frame #0: 0x00007fff5d3bab6e libsystem_kernel.dylib`__pthread_kill + 10


->  0x7fff5d3bab6e <+10>: jae    0x7fff5d3bab78            ; <+20>

    0x7fff5d3bab70 <+12>: movq   %rax, %rdi

    0x7fff5d3bab73 <+15>: jmp    0x7fff5d3b1b00            ; cerror_nocancel

    0x7fff5d3bab78 <+20>: retq

Target 0: (Kaleidoscope-Ch4) stopped.

(lldb) bt

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT

  * frame #0: 0x00007fff5d3bab6e libsystem_kernel.dylib`__pthread_kill + 10

    frame #1: 0x00007fff5d585080 libsystem_pthread.dylib`pthread_kill + 333

    frame #2: 0x00007fff5d3161ae libsystem_c.dylib`abort + 127

    frame #3: 0x0000000100c28ee0
Kaleidoscope-Ch4`llvm::llvm_unreachable_internal(msg="Failure value
returned from cantFail wrapped call",
file="/Users/lui/Work/llvm/include/llvm/Support/Error.h", line=716) at

    frame #4: 0x0000000100031967 Kaleidoscope-Ch4`unsigned long long
llvm::cantFail<unsigned long long>(ValOrErr=<unavailable>, Msg="Failure
value returned from cantFail wrapped call") at Error.h:716

    frame #5: 0x0000000100008e5d
Kaleidoscope-Ch4`HandleTopLevelExpression() at toy.cpp:615

    frame #6: 0x0000000100003b73 Kaleidoscope-Ch4`MainLoop() at toy.cpp:644

    frame #7: 0x0000000100002ee5 Kaleidoscope-Ch4`main at toy.cpp:697

    frame #8: 0x00007fff5d26a015 libdyld.dylib`start + 1

    frame #9: 0x00007fff5d26a015 libdyld.dylib`start + 1


Is it something related to OS X? Or is there something known in git master
that temporary disabled the dynamic loading of extern functions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180610/5f61b798/attachment.html>

More information about the llvm-dev mailing list