<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=""><div class="">Hi Kevin</div><div class=""><br class=""></div><div class="">I am just pointing out that is a good place to look at how metadata is parsed and it supports parsing metadata from pre-linked object file which is important to JIT.</div><div class=""><br class=""></div><div class="">My code pretty much replicate most of the functions in MachODump in C++ and hope it can much more reusable than the c parser. The biggest missing part is the resilience to bad metadata due to the fact we currently don't have good way to recover from error but I know Chris B is working on something like that. I will definitely ask more feedback from you when I feel like my code is ready.</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Steven</div><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 11, 2016, at 1:38 PM, Kevin Enderby <<a href="mailto:enderby@apple.com" class="">enderby@apple.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="">Just a comment here. The code in tools/llvm-objdump/MachODump.cpp has requirements beyond being able to parse the Objective-C for the machine it is running on. It must work cross byte sex, with differing alignment, dealing with both Objc1 & Objc2, pointers of the non-native size and not the native addresses and be robust enough to not crash with bad meta data. So while it parses the Objective-C meta data it likely is not a good model for execution.<div class=""><br class=""></div><div class="">Kev</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 11, 2016, at 1:26 PM, Steven Wu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</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="">Hi Stanislav<div class=""><br class=""></div><div class="">Thanks for checking on this. If you want a quick hack, you can try to read the code in tools/llvm-objdump/MachODump.cpp. There are some c code in there to parse metadata.</div><div class=""><br class=""></div><div class="">My code is something I put up for my own purpose for debugging/parsing objc metadata. The interface is a bit rough to use but the biggest problem is testing. I have my own binary living out of tree to test the parser but it doesn't make sense to have another parser in tree to do the same thing. I really hope I can replace the code in MachODump, but unfortunately the current error handling model in libObject prevents me from replicate all the functions in MachODump. We are working towards that direction but we are not there yet. In the meantime, I won't mind posting some patches when I have time.</div><div class=""><br class=""></div><div class="">Steven</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 10, 2016, at 2:03 PM, Stanislav Pankevich <<a href="mailto:s.pankevich@gmail.com" class="">s.pankevich@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="">Hi Lang, Steven,<div class=""><br class=""></div><div class="">Any updates on this? Steven, is there a progress with metadata parser for Objective-C?</div><div class=""><br class=""></div><div class="">Let us know if we can help somehow.</div><div class=""><br class=""></div><div class="">Thanks.</div><div class=""><br class=""></div><div class="">Stanislav</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22 Oct 2016, at 03:21, Lang Hames <<a href="mailto:lhames@gmail.com" class="">lhames@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">> <span style="font-size:12.800000190734863px" class="">So no JIT for i386?</span><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">I didn't realise i386 still used ObjC 1 - all my experiments were on arm64.</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">i386 support for ObjC would be nice to have, but it's not a blocker for adding ObjC 2 support.</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">- Lang.</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Oct 20, 2016 at 11:57 AM, Steven Wu <span dir="ltr" class=""><<a href="mailto:stevenwu@apple.com" target="_blank" class="">stevenwu@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><br class=""></div> <br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Oct 19, 2016, at 11:28 AM, Stanislav Pankevich <<a href="mailto:s.pankevich@gmail.com" target="_blank" class="">s.pankevich@gmail.com</a>> wrote:</div><br class="m_1482315521426938988Apple-interchange-newline"><div class=""><div style="word-wrap:break-word" class="">Hi Lang, Steven,<div class=""><br class=""></div><div class=""><span class="">At this point it seems that the best next step is for Steven to share his code, right? Or is there some other work that can be done in parallel?</span></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">It will take some time to create patch from my existing implementation. After that, we still need to correctly register the implementation to objc runtime. I dont expect this to be a quick task.</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Lang? Steven?</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class=""><span id="m_1482315521426938988result_box" class="m_1482315521426938988short_text" lang="en">Here’s small note about my interest here: Alex Denisov and I are working on a tool for mutation testing <a href="https://github.com/AlexDenisov/mutang" target="_blank" class="">https://github.com/<wbr class="">AlexDenisov/mutang</a>. Alex has made fascinating progress towards mutation testing of C++ code and we would also like to bring mutation testing to iOS where we are by profession. Currently inability to run Objective-C code via JIT is a critical dependency for our progress on iOS part so </span>I'll be happy to help with this in any way even though my experience with LLVM is very limited.</span></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">This sounds like an interesting project. Maybe you can generate the object file and statically linked the mutated code for now? </div><div class=""><br class=""></div><div class="">Steven</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Thanks.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Stanislav</span></div><div class=""><br class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On 19 Oct 2016, at 01:49, Lang Hames <<a href="mailto:lhames@gmail.com" target="_blank" class="">lhames@gmail.com</a>> wrote:</div><br class="m_1482315521426938988Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Steven,<div class=""><br class=""></div><div class="">That sounds great. The object file parser would definitely be of interest to JIT clients. Having ObjC 1 support would be nice, but I don't see it as a blocker to committing what you've got: all code produced by the JIT is going to be ObjC-2.</div></div></div></blockquote></div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">So no JIT for i386? </div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Steven</div></font></span><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Lang.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Oct 18, 2016 at 2:22 PM, Steven Wu <span dir="ltr" class=""><<a href="mailto:stevenwu@apple.com" target="_blank" class="">stevenwu@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hi Stanislav, Lang<div class=""><br class=""></div><div class="">I have a version of objc metadata parser based on LLVM which can handle objc2 metadata from MachO object and bitcode (bitcode version is even swift compatible). I don't know if there is enough interest for me to upstream it. It probably requires some work to clean up the interface and complete it by adding objc1 support and other object format support.</div><span class="m_1482315521426938988HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Steven</div></font></span><div class=""><div class="m_1482315521426938988h5"><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 18, 2016, at 2:10 PM, Lang Hames via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_1482315521426938988m_3774682329238735481Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Stanislav,<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Cheers,</div><div class="">Lang.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Oct 18, 2016 at 1:33 PM, Stanislav Pankevich 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"><div style="word-wrap:break-word" class="">Hello,<div class=""><br class=""></div><div class="">Is it possible to execute Objective-C code using LLVM JIT?</div><div class=""><br class=""></div><div class="">The original point for my research is this topic on StackOverflow: </div><div class=""><br class=""></div><div class="">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" class="">http://stackov<wbr class="">erflow.com/questions/10375324/<wbr class="">all-selectors-unrecognised-whe<wbr class="">n-invoking-objective-c-methods<wbr class="">-using-the-llvm-exec</a></div><div class=""><br class=""></div><div class="">Running that example with lli produces the following output:</div><div class=""><br class=""></div><div class=""><div class="">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 class="">2016-10-18 21:25:58.334 lli[12970:169282] +[NSAutoreleasePool alloc]: unrecognized selector sent to class 0x7fff7a562130</div><div class="">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 class=""><br class=""></div><div class="">See also additional discussion here: <a href="https://twitter.com/sbpankevich/status/783363161537798144" target="_blank" class="">https://twitter.com/sbpa<wbr class="">nkevich/status/783363161537798<wbr class="">144</a>.</div><div class=""><br class=""></div><div class="">Thanks.</div><span class="m_1482315521426938988m_3774682329238735481HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Stanislav Pankevich</div><div class=""><br class=""></div></font></span></div><br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" 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/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
______________________________<wbr class="">_________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div>_______________________________________________<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" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>