<div dir="ltr">Hi Stanislav,<div><br></div><div>I actually looked into this recently. It is possible, but takes some non-trivial effort right now: You have to hook into the JIT memory allocator, parse the objective C metadata sections in the object file, then call the objective C runtime to register any newly added classes, protocols and selectors.</div><div><br></div><div>I can't release my code as-is: I built it against a hacked up copy of the runtime. The right way to do this would be to write parsers for the objective C metadata, and an Objective-C registration call that uses the parsers and calls the runtime. These should be made available conditionally if the objective C runtime headers are available. This is something that I'd like to get to eventually, but I have a long to-do list. If you or anyone you know is interested in working on it I'd be happy to provide pointers and code review.</div><div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 18, 2016 at 1:33 PM, Stanislav Pankevich via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div>Is it possible to execute Objective-C code using LLVM JIT?</div><div><br></div><div>The original point for my research is this topic on StackOverflow: </div><div><br></div><div>All selectors unrecognised when invoking Objective-C methods using the LLVM ExecutionEngine <a href="http://stackoverflow.com/questions/10375324/all-selectors-unrecognised-when-invoking-objective-c-methods-using-the-llvm-exec" target="_blank">http://<wbr>stackoverflow.com/questions/<wbr>10375324/all-selectors-<wbr>unrecognised-when-invoking-<wbr>objective-c-methods-using-the-<wbr>llvm-exec</a></div><div><br></div><div>Running that example with lli produces the following output:</div><div><br></div><div><div>2016-10-18 21:25:58.332 lli[12970:169282] *** NSForwarding: warning: selector (0x10356a38f) for message 'alloc' does not match selector known to Objective C runtime (0x7fff8e93afb5)-- abort</div><div>2016-10-18 21:25:58.334 lli[12970:169282] +[NSAutoreleasePool alloc]: unrecognized selector sent to class 0x7fff7a562130</div><div>2016-10-18 21:25:58.338 lli[12970:169282] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSAutoreleasePool alloc]: unrecognized selector sent to class 0x7fff7a562130'</div></div><div><br></div><div>See also additional discussion here: <a href="https://twitter.com/sbpankevich/status/783363161537798144" target="_blank">https://twitter.com/<wbr>sbpankevich/status/<wbr>783363161537798144</a>.</div><div><br></div><div>Thanks.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Stanislav Pankevich</div><div><br></div></font></span></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>