<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 10:20 AM, AllenShow <<a href="mailto:xiulunlin@gmail.com" class="">xiulunlin@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for you answer.<div class="">Actually I have tried like this, however, I want to know how could I implement this Just-in-time with ExecutionEngineer.</div><div class="">I have no idea how to make EE recognise libgcc.dylib.<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 5:25 AM, Bruce Hoult <<a href="mailto:bruce@hoult.org" class="">bruce@hoult.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The answer to such questions is usually best obtained by looking at what clang does. See below.<div class=""><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span style="font-size:9px" class="">$ cat foo.c</span></font></div><div class=""><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">#include <stdlib.h></div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class="">void* foo(int i){return malloc(i);}<br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">$ clang -emit-llvm -S foo.c</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">$ cat foo.ll</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">; ModuleID = 'foo.c'</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">target triple = "x86_64-apple-macosx10.10.0"</div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">; Function Attrs: nounwind ssp uwtable</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">define i8* @foo(i32 %i) #0 {</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> %1 = alloca i32, align 4</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> store i32 %i, i32* %1, align 4</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> %2 = load i32* %1, align 4</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> %3 = sext i32 %2 to i64</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> %4 = call i8* @malloc(i64 %3)</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""> ret i8* %4</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">}</div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">declare i8* @malloc(i64) #1</div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">!llvm.ident = !{!0}</div><div style="margin: 0px; font-size: 9px; font-family: Monaco; min-height: 12px;" class=""><br class=""></div><p style="margin:0px;font-size:9px;font-family:Monaco" class="">
</p><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class="">!0 = metadata !{metadata !"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}</div><div class=""><br class=""></div><div style="margin: 0px; font-size: 9px; font-family: Monaco;" class=""><br class=""></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Dec 3, 2015 at 4:03 PM, AllenShow via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, everyone.<br class="">
I am new to llvm and I want to use C function “malloc" and “free" to do heap allocation, but It seems it is not a built-in function like ‘’printf” so I got an error “Unknown extern function”.<br class="">
I use ExecutionEngineer to run my main function and how should I do to make EE link the C library I want.<br class="">
Thanks.<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>