Hi,
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 works:
extern sin(a);
Read extern:
declare double @sin(double)
sin(1);
Evaluated to 0.841471
Unfortunatly as soon as the external function is used in another def-d function body, the REPL crashes:
def test(b) sin(b);
Read function definition:
define double @test(double %b) {
entry:
%calltmp = call double @sin(double %b)
ret double %calltmp
}
test(1);
Failure value returned from cantFail wrapped call
UNREACHABLE executed at /Users/lui/Work/llvm/include/llvm/Support/Error.h:716!
Process 46951 stopped
- thread #1, queue = ‘com.apple.main-thread’, stop reason = signal SIGABRT
frame #0: 0x00007fff5d3bab6e libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
→ 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 ErrorHandling.cpp:222
frame #4: 0x0000000100031967 Kaleidoscope-Ch4`unsigned long long llvm::cantFail(ValOrErr=, 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
(lldb)
Is it something related to OS X? Or is there something known in git master that temporary disabled the dynamic loading of extern functions?