且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用llvm生成机器代码

更新时间:2023-11-10 18:02:34

使用llc -filetype=obj从IR发出可链接的目标文件.您可以查看llc的代码,以查看它发出的LLVM API调用以发出此类代码.至少对于Mac OS X和Linux,以这种方式发出的对象应该是相当不错的(即,到目前为止,这还不是"alpha quality"选项).

Use llc -filetype=obj to emit a linkable object file from your IR. You can look at the code of llc to see the LLVM API calls it makes to emit such code. At least for Mac OS X and Linux, the objects emitted in such a manner should be pretty good (i.e. this is not a "alpha quality" option by now).

LLVM不包含链接器(尚未!).因此,要将这个目标文件实际链接到某些可执行文件或共享库中,您将需要使用系统链接器.请注意,即使您有一个包含单个目标文件的可执行文件,也无论如何都必须链接后者. LLVM社区中的开发人员正在开发一个名为lld的LLVM真实链接器.您可以访问其页面或搜索邮件列表档案以跟踪其进度.

LLVM does not contain a linker (yet!), however. So to actually link this object file into some executable or shared library, you will need to use the system linker. Note that even if you have an executable consisting of a single object file, the latter has to be linked anyway. Developers in the LLVM community are working on a real linker for LLVM, called lld. You can visit its page or search the mailing list archives to follow its progress.