<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi David<div class=""><br class=""></div><div class="">There is an abstraction layer to allow runtime-specific implementations but it is possible that you need to tweak some interfaces to make it working for all your use cases. I design the abstraction to accommodate both macho object file and llvm bitcode, which are two completely different underlying implementations.</div><div class=""><br class=""></div><div class="">I just post the code review: <a href="https://reviews.llvm.org/D59945" class="">https://reviews.llvm.org/D59945</a> and I also added you as code reviewer. Let me know if you have any comments and suggestions.</div><div class=""><br class=""></div><div class="">Steven<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Mar 26, 2019, at 1:39 AM, David Chisnall 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=""><div class="">Hi Steven,<br class=""><br class="">This sounds like a very useful tool. In Clang, we've been very careful to maintain an abstraction layer over different Objective-C runtime implementations. Your email talked only about the Apple runtime - do you already have an abstraction layer for the runtime-specific details, or is this something that will need to be added prior to upstreaming?<br class=""><br class="">David<br class=""><br class="">On 22/03/2019 18:34, Steven Wu via llvm-dev wrote:<br class=""><blockquote type="cite" class="">Overview<br class="">=======<br class="">We are planning to open source our internal implementation of Objective-C metadata reader library to LLVM. Unlike the C style objective-c metadata reader in llvm-objdump, it is designed to be a reusable C++ library to parse objective-c metadata from binaries with LLVM style error handling. The current implementation has an interface that resembles libObject in and it supports parsing objective-c metadata from MachO object file or LLVM bitcode that is generated by clang/swift compiler. It has the flexibility to be extended to support other objective-c metadata format if needed.<br class="">You can find an old open-source version of implementation here[1]. The version we planned to open source has the same design but it will come with some bug fixes and improvements, and it will be rebased to the trunk.<br class="">Background<br class="">=========<br class="">We think it is very beneficial to have an objective-c metadata library in LLVM. We use the library in many tools, including tapi which we are currently in the process of open sourcing. Some have been asking for this libraries on the list or off the list to use it in the contexts like JIT[2] or macports.<br class="">Originally, the open source of this library is delayed because we thought it would be good if we can achieve following two goals before upstreaming:<br class=""> * An improved libObject interface: we are expecting libObject<br class=""> interfaces to be changed which ObjCMetadata library should be<br class=""> updated to match.<br class=""> * Replace the parser inside llvm-objdump.<br class="">The first one has been talked for years but never put into action. The second one requires a strict output match because llvm-objdump is a replacement for otool-classic on darwin platform, and doing so will require LLVM infrastructure improvements on how to handle errors. With some discussion, we believe both tasks can be done in trunk when it is time, rather than waiting for all the requirements are met.<br class="">Design<br class="">=====<br class="">ObjCMetadata library comes with headers (in llvm/include/llvm/ObjCMetadata)[3], implementations (in llvm/lib/ObjCMetadata)[4] and we will also implement a tool similar to a stripped down version of [5] for testing.<br class="">Here is an example how to use the library by extracting and printing the objc class names:<br class="">```<br class=""> MachOMetadata ObjCInfo(InputObject);<br class="">*if* (*auto* ObjCClasses = ObjCInfo.classes()) {<br class="">*for* (*auto* c : *ObjCClasses) {<br class="">*auto* ObjCClass = *c;<br class="">*if* (!ObjCClass) {<br class=""> handleError(ObjCClass.takeError());<br class="">*continue*;<br class=""> }<br class="">*auto* name = ObjCClass->getName();<br class="">*if* (!name) {<br class=""> handleError(name.takeError());<br class="">*continue*;<br class=""> }<br class=""> outs() << *name << "\n";<br class=""> }<br class="">```<br class="">I am preparing a patch and will send out when it is ready. Let me know if you have any questions or feedbacks.<br class="">Thanks<br class="">Steven<br class="">[1] <a href="https://opensource.apple.com/source/clang/clang-800.0.38" class="">https://opensource.apple.com/source/clang/clang-800.0.38</a><br class="">[2] <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-November/106995.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2016-November/106995.html</a><br class="">[3] <a href="https://opensource.apple.com/source/clang/clang-800.0.38/src/lib/ObjCMetadata/" class="">https://opensource.apple.com/source/clang/clang-800.0.38/src/lib/ObjCMetadata/</a><br class="">[4] <a href="https://opensource.apple.com/source/clang/clang-800.0.38/src/include/llvm/ObjCMetadata/" class="">https://opensource.apple.com/source/clang/clang-800.0.38/src/include/llvm/ObjCMetadata/</a><br class="">[5] <a href="https://opensource.apple.com/source/clang/clang-800.0.38/src/tools/api-analyzer/" class="">https://opensource.apple.com/source/clang/clang-800.0.38/src/tools/api-analyzer/</a><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="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></blockquote>_______________________________________________<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="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></div></blockquote></div><br class=""></div></body></html>