<div dir="ltr">Hi,<div><br></div><div>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...</div><div>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. </div><div>Declaring the external prototype and using it as a top level expression works:</div><div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> extern sin(a);</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> Read extern: </span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">declare double @sin(double)</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> sin(1);</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> Evaluated to 0.841471</span></p></div><div><br></div><div>Unfortunatly as soon as the external function is used in another def-d function body, the REPL crashes:</div><div><br></div><div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> def test(b) sin(b);</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> Read function definition:</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">define double @test(double %b) {</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">entry:</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  %calltmp = call double @sin(double %b)</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  ret double %calltmp</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> test(1);</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ready> Failure value returned from cantFail wrapped call</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">UNREACHABLE executed at /Users/lui/Work/llvm/include/llvm/Support/Error.h:716!</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">Process 46951 stopped</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #0: 0x00007fff5d3bab6e libsystem_kernel.dylib`__pthread_kill + 10</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">libsystem_kernel.dylib`__pthread_kill:</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">->  0x7fff5d3bab6e <+10>: jae    0x7fff5d3bab78            ; <+20></span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    0x7fff5d3bab70 <+12>: movq   %rax, %rdi</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    0x7fff5d3bab73 <+15>: jmp    0x7fff5d3b1b00            ; cerror_nocancel</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    0x7fff5d3bab78 <+20>: retq   </span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">Target 0: (Kaleidoscope-Ch4) stopped.</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(113,113,113);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">(lldb) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(238,238,238)">bt</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  * frame #0: 0x00007fff5d3bab6e libsystem_kernel.dylib`__pthread_kill + 10</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #1: 0x00007fff5d585080 libsystem_pthread.dylib`pthread_kill + 333</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #2: 0x00007fff5d3161ae libsystem_c.dylib`abort + 127</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    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</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    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</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #5: 0x0000000100008e5d Kaleidoscope-Ch4`HandleTopLevelExpression() at toy.cpp:615</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #6: 0x0000000100003b73 Kaleidoscope-Ch4`MainLoop() at toy.cpp:644</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #7: 0x0000000100002ee5 Kaleidoscope-Ch4`main at toy.cpp:697</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #8: 0x00007fff5d26a015 libdyld.dylib`start + 1</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(238,238,238);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    frame #9: 0x00007fff5d26a015 libdyld.dylib`start + 1</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(113,113,113);background-color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">(lldb) </span></p></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div>Is it something related to OS X? Or is there something known in git master that temporary disabled the dynamic loading of extern functions?</div></div>