Hi Nick:<div><br></div><div>Thanks for pointing me to libffi.</div><div>Recompile LLVM with libffi does solve the problem of printf.</div><div>But it still has other problems:</div><div>1) sinf() returns 0 in the interpreter, but returns correct value in JIT (see hellosin.c)</div>
<div>2) calling pthread_create cause lli to crash in the interpreter mode, but no problem in JIT (see phello.c).</div><div><br></div><div>My questions are:</div><div>i) can I call any arbitrary external function in the interpreter? </div>
<div>ii) how do I specify the dynamic library (where the external function is implemented), when I call the interpreter?</div><div><br></div><div>Thanks</div><div>Xu</div><div><br></div><div>hellosin.c</div><div><div><div>
<div>=======================</div><div>#include <stdio.h></div><div>#include <math.h></div><div><br></div><div><br></div><div>int main(int argc, char** argv){</div><div>  float f = sinf(0.5235988f);</div><div>
  printf("hello sin: %10.2f\n", f);</div><div>  return 0;</div><div>}</div><div>========================</div><div><div>$ llvm-gcc -o hellosin.bc -emit-llvm -c hellosin.c</div><div>$ lli -force-interpreter=true hellosin.bc</div>
<div>hello sin:       0.00</div><div><div>$ lli hellosin.bc</div><div>hello sin:       0.50</div><div><br></div></div></div><div>phello.c</div><div>========================</div><div><div>#include <pthread.h></div><div>
#include <stdio.h></div><div>#define NUM_THREADS     4</div><div><br></div><div>void *PrintHello(void *threadid)</div><div>{</div><div>   long tid;</div><div>   tid = (long)threadid;</div><div>   printf("Hello from %ld.\n", tid);</div>
<div>   pthread_exit(NULL);</div><div>}</div><div><br></div><div>int main (int argc, char *argv[])</div><div>{</div><div>   pthread_t threads[NUM_THREADS];</div><div>   int ret;</div><div>   long t;</div><div>   for(t=0; t<NUM_THREADS; t++){</div>
<div>#ifdef DEBUG</div><div>      printf("creating thread %ld\n", t);</div><div>#endif</div><div>      ret = pthread_create(&threads[t], NULL, PrintHello, (void *)t);</div><div>      if (ret){</div><div>         printf("pthread_create ERROR: %d\n", ret);</div>
<div>         return(-1);</div><div>      }</div><div>   }</div><div>   pthread_exit(NULL);</div><div>}</div><div><div>========================</div><div></div></div></div></div></div></div><div>$ llvm-gcc -o phello.bc -emit-llvm -c phello.c</div>
<div><div>$ lli -force-interpreter=true phello.bc</div><div>0   lli 0x08796bf8</div><div>Segmentation fault</div><div><div>$ lli phello.bc</div><div>Hello from 0.</div><div>Hello from 1.</div><div>Hello from 2.</div><div>
Hello from 3.</div><div><br></div></div></div><div><br></div><div>On Tue, Nov 17, 2009 at 2:52 AM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a>></span> wrote:</div><div><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">Timo Juhani Lindfors wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Nick Lewycky<<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>  writes:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The interpreter uses libffi to make external function calls. However, it<br>
needs to be detected at LLVM's compile time. If you're using the<br>
released packages, we disabled that because we were worried about users<br>
who don't have libffi installed.<br>
</blockquote>
<br>
This seems to be quite a common problem (I too hit it once, thought it<br>
was a bug and reported it at<br>
<a href="http://llvm.org/bugs/show_bug.cgi?id=5466" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=5466</a>) how about making lli inform<br>
the user that LLVM was built without FFI support?<br>
</blockquote>
<br></div></div>
Thanks for the reminder. I recall looking at the patch but I didn't apply it at the time because I couldn't figure out why the code above it used errs() in one case and llvm_report_error in another.<br><font color="#888888">
<br>
Nick<br>
</font></blockquote></div><br></div>