<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">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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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>