<div dir="ltr">I think I understand what you're trying to say. I have to figure out how to generate that. I've tried a few thigns but failing at different places.<div><br></div><div>I tried creating a load int32, and then trying to call through it, and it fails saying it's not a function type. Then I tried different globlmapping things, and they fail with segfaults.</div><div><br></div><div>I also tried creating an constant int, and trying to make pointer to it, but I don't think I quite succeeded here either.</div><div><br></div><div>I'd appreciate any pointers on how to go from a function pointer address to being able to emit call indirect.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 17, 2015 at 10:17 PM, Bruce Hoult <span dir="ltr"><<a href="mailto:bruce@hoult.org" target="_blank">bruce@hoult.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">That's what you get if you don't have the * in '<span style="font-size:13px">extern fn *f;' and therefore in '</span>@f = external global i32 (i32)*'<div><br></div><div>Without the * llvm expects to link to a known and provided function. With the * it's a global variable that contains the address of the function.</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Feb 18, 2015 at 6:34 PM, Hayden Livingston <span dir="ltr"><<a href="mailto:halivingston@gmail.com" target="_blank">halivingston@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>This is my module's dump, which is different than yours. I wonder how I can get the external thing for my function.</div><div><br></div><div>define double @sum(double, double) {</div><div>entry:</div><div>  call void @FooBar()</div><div>  %tmp = fadd double %0, %1</div><div>  ret double %tmp</div><div>}</div><div><br></div><div>; ModuleID = 'My_Module'</div><div><br></div><div>define double @sum(double, double) {</div><div>entry:</div><div>  call void @FooBar()</div><div>  %tmp = fadd double %0, %1</div><div>  ret double %tmp</div><div>}</div><div><br></div><div>declare void @FooBar()</div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 17, 2015 at 9:07 PM, Bruce Hoult <span dir="ltr"><<a href="mailto:bruce@hoult.org" target="_blank">bruce@hoult.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Naturally you can, since C can. As usual, it's instructive to see what Clang generates e.g.<div><br></div><div><div>typedef int fn(int);</div><div><br></div><div>int test(fn f, int val){</div><div>  return f(val);</div><div>}</div></div><div><br></div><div>-----------</div><div><br></div><div>Compiled with: <span style="font-family:Monaco;font-size:9px">clang callfuncptr.c -O -S -emit-llvm -o callfuncptr.ll</span></div><div><span style="font-family:Monaco;font-size:9px"><br></span></div><div><p style="margin:0px;font-size:9px;font-family:Monaco">; ModuleID = 'callfuncptr.c'</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">target triple = "x86_64-apple-macosx10.10.0"</p>
<p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p>
<p style="margin:0px;font-size:9px;font-family:Monaco">; Function Attrs: nounwind ssp uwtable</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">define i32 @test(i32 (i32)* nocapture %f, i32 %val) #0 {</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">  %1 = tail call i32 %f(i32 %val) #1</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">  ret i32 %1</p>
<p style="margin:0px;font-size:9px;font-family:Monaco">}</p></div><div><br></div><div>-------------</div><div><br></div><div>Or...</div><div><br></div><div><br></div><div><div><div>typedef int fn(int);</div><div><br></div><div>extern fn *f;</div><div><br></div><div>int test(int val){</div><div>  return f(val);</div><div>}</div></div></div><div><br></div><div>-----------------------</div><div><br></div><div><p style="margin:0px;font-size:9px;font-family:Monaco">; ModuleID = 'callfuncptr.c'</p><p style="margin:0px;font-size:9px;font-family:Monaco">target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</p><p style="margin:0px;font-size:9px;font-family:Monaco">target triple = "x86_64-apple-macosx10.10.0"</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">@f = external global i32 (i32)*</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">; Function Attrs: nounwind ssp uwtable</p><p style="margin:0px;font-size:9px;font-family:Monaco">define i32 @test(i32 %val) #0 {</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %1 = load i32 (i32)** @f, align 8, !tbaa !1</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %2 = tail call i32 %1(i32 %val) #1</p><p style="margin:0px;font-size:9px;font-family:Monaco">  ret i32 %2</p><p style="margin:0px;font-size:9px;font-family:Monaco">










</p><p style="margin:0px;font-size:9px;font-family:Monaco">}</p></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Wed, Feb 18, 2015 at 5:52 PM, Hayden Livingston <span dir="ltr"><<a href="mailto:halivingston@gmail.com" target="_blank">halivingston@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>I'm having a problem of being unable to call into an arbitrary function that is loaded into memory whose pointer address is known to me but was not linked into LLVM.</div><div><br></div><div>I have added the function and called LLVMAddGlobalMapping with the pointer, and the program segfaults.</div><div><br></div><div>I was wondering if it is a supported scenario that LLVM can generate a call into an arbitrary function that is not linked.</div><div><br></div><div><br></div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
<br></div></div></div></div><span class="HOEnZb"><font color="#888888"><span><font color="#888888">-- 
<br>This message has been scanned for viruses and
<br>dangerous content by
<a href="http://www.mailscanner.info/" target="_blank"><b>MailScanner</b></a>, and is
<br>believed to be clean.

</font></span></font></span></blockquote></div><br></div>
</blockquote></div><br></div>