{"id":388,"date":"2023-02-26T23:39:06","date_gmt":"2023-02-26T15:39:06","guid":{"rendered":"https:\/\/shangwendada.co\/?p=388"},"modified":"2025-05-26T16:48:47","modified_gmt":"2025-05-26T08:48:47","slug":"llvm-ir-bitcode%e6%96%87%e4%bb%b6%e5%8f%8d%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/blog.shangwendada.top\/index.php\/2023\/02\/26\/llvm-ir-bitcode%e6%96%87%e4%bb%b6%e5%8f%8d%e7%bc%96%e8%af%91\/","title":{"rendered":"LLVM IR bitcode\u6587\u4ef6\u53cd\u7f16\u8bd1"},"content":{"rendered":"<h1>LLVM IR bitcode\u6587\u4ef6\u53cd\u7f16\u8bd1<\/h1>\n<h2>\u811a\u672c\u5b89\u88c5<\/h2>\n<h3>\u4f7f\u7528\u5b98\u65b9\u5b89\u88c5\u811a\u672c\u5b89\u88c5<\/h3>\n<blockquote>\n<p>\u4ec5\u9002\u7528\u4e8eDebian\/Ubuntu<\/p>\n<\/blockquote>\n<pre><code class=\"language-bash\">wget https:\/\/apt.llvm.org\/llvm.sh\nchmod +x llvm.sh\nsudo .\/llvm.sh 13<\/code><\/pre>\n<h3>\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5<\/h3>\n<p><strong>Ubuntu<\/strong><\/p>\n<p>\u5148\u5728<code>\/etc\/apt\/source.list<\/code>\u52a0\u5165\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<pre><code class=\"language-text\">deb http:\/\/apt.llvm.org\/focal\/ llvm-toolchain-focal-13 main\ndeb-src http:\/\/apt.llvm.org\/focal\/ llvm-toolchain-focal-13 main<\/code><\/pre>\n<p>\u7136\u540e\u6267\u884c\u4ee5\u4e0bshell\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">sudo apt update\n\nsudo apt install clang-13<\/code><\/pre>\n<blockquote>\n<p>\u5b89\u88c5clang\u7f16\u8bd1\u5668\u65f6\u4f1a\u81ea\u52a8\u5b89\u88c5\u6240\u4f9d\u8d56\u7684LLVM\u5e93\uff0clldb\u7b49\u5176\u4ed6\u7ec4\u4ef6\u9700\u8981\u5355\u72ec\u5b89\u88c5<\/p>\n<\/blockquote>\n<p><strong>macOS<\/strong><\/p>\n<pre><code class=\"language-bash\">brew install llvm<\/code><\/pre>\n<h3>\u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5<\/h3>\n<blockquote>\n<p>\u4ee5LLVM 13.0.1\u4e3a\u4f8b<\/p>\n<\/blockquote>\n<p>\u7f16\u8bd1LLVM\u9700\u8981\u4e8b\u5148\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u7b26\u5408\u4ee5\u4e0b\u6761\u4ef6\u7684\u8f6f\u4ef6<\/p>\n<ul>\n<li>CMake &gt;= 3.4.3<\/li>\n<li>GCC &gt;= 5.1.0<\/li>\n<li>Python &gt;= 2.7<\/li>\n<li>zlib &gt;= 1.2.3.4<\/li>\n<li>GNU Make &gt;= 3.79<\/li>\n<\/ul>\n<p>\u6309\u7167\u4ee5\u4e0b\u547d\u4ee4\u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5LLVM<\/p>\n<pre><code class=\"language-bash\"># \u4e0b\u8f7d\u6e90\u7801\nwget https:\/\/github.com\/llvm\/llvm-project\/releases\/download\/llvmorg-13.0.1\/llvm-project-13.0.1.src.tar.xz\n# \u89e3\u538b\u6e90\u7801\ntar xvf llvm-project-13.0.1.src.tar.xz\n# \u65b0\u5efa\u5b89\u88c5\u76ee\u5f55\nsudo mkdir -p \/usr\/local\/llvm\n# \u65b0\u5efa\u7f16\u8bd1\u76ee\u5f55\nsudo mkdir -p llvm-project-13.0.1.src\/build\n# \u8fdb\u5165\u7f16\u8bd1\u76ee\u5f55\ncd llvm-project-13.0.1.src\/build\n# cmake\u751f\u6210\u7f16\u8bd1\u4fe1\u606f\ncmake -G &quot;Unix Makefiles&quot; -DLLVM_ENABLE_PROJECTS=&quot;clang&quot; -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=&quot;Release&quot; -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_INSTALL_PREFIX=&quot;\/usr\/local\/llvm&quot; ..\/llvm\n# \u7f16\u8bd1\ncmake --build .\n# \u5b89\u88c5\u5230\u5b89\u88c5\u76ee\u5f55\ncmake --build . --target install<\/code><\/pre>\n<p><code>\/usr\/local\/llvm<\/code>\u662f\u5b89\u88c5\u76ee\u5f55\uff08\u53ef\u81ea\u5b9a\u4e49\uff09, <code>llvm-project-13.0.1.src<\/code>\u662f\u6e90\u7801\u76ee\u5f55, <code>llvm-project-13.0.1.src\/build<\/code>\u662f\u7f16\u8bd1\u4ea7\u7269\u76ee\u5f55<\/p>\n<p>\u8fd9\u91cc\u7528\u7684\u6784\u5efa\u5de5\u5177\u662fmake\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u7528\u901f\u5ea6\u66f4\u5feb\u7684ninja<\/p>\n<h2>\u4f7f\u7528<\/h2>\n<p>\u5982\u679c\u4f60\u60f3\u5f97\u5230.s\uff0c\u53ef\u4ee5\u6267\u884c\u547d\u4ee4\uff1a.\/llc baby.bc -o baby.s<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u5f97\u5230.ll\uff0c\u53ef\u4ee5\u6267\u884c\u547d\u4ee4\uff1allvm-dis baby.bc -o baby.ll<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u5f97\u5230\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u6267\u884c\u547d\u4ee4\uff1aas baby.s<\/p>\n<p>\u5f88\u591a\u7f16\u8bd1\u5668\u53ef\u4ee5\u4ece\u4e2d\u95f4\u8868\u793a\u76f4\u63a5\u751f\u6210\u9ad8\u7ea7\u8bed\u8a00\u7684c\u6216fortran\uff0c\u5982open64\u7684whirl2c\u548cwhirl2f\uff0c\u4f46llvm\u662f\u5426\u652f\u6301\u4ece.ll\u6587\u4ef6\u6216.bc\u6587\u4ef6\u5230\u9ad8\u7ea7\u7684.c\u5462\uff1f\u4e0d\u591a\u8bf4\uff0c\u7ee7\u7eed\u4e0a\u56fe\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/shangwendada.top\/wp-content\/uploads\/2023\/02\/image-1677425942050.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/shangwendada.top\/wp-content\/uploads\/2023\/02\/image-1677425942050.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<p>\u4e3a\u4e86\u5927\u5bb6\u66f4\u6e05\u695a\u7684\u770b\u56fe\uff0c\u518d\u5f52\u7eb3\u4e00\u4e0b\uff1a<\/p>\n<ul>\n<li>a.c\uff0c\u6e90\u4ee3\u7801\u3002<\/li>\n<li>a.bc\uff0cllvm\u7684\u5b57\u8282\u7801\u7684\u4e8c\u8fdb\u5236\u5f62\u5f0f\u3002<\/li>\n<li>a.ll\uff0cllvm\u5b57\u8282\u7801\u7684\u6587\u672c\u5f62\u5f0f\u3002<\/li>\n<li>a.s\uff0c\u673a\u5668\u6c47\u7f16\u7801\u8868\u793a\u7684\u6c47\u7f16\u6587\u4ef6\u3002<\/li>\n<li>a.out\uff0c\u53ef\u6267\u884c\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>LLVM IR bitcode\u6587\u4ef6\u53cd\u7f16\u8bd1 \u811a\u672c\u5b89\u88c5 \u4f7f\u7528\u5b98\u65b9\u5b89\u88c5\u811a\u672c\u5b89\u88c5 \u4ec5\u9002\u7528\u4e8eDebian\/Ubuntu  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/posts\/388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":3,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"predecessor-version":[{"id":1447,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/posts\/388\/revisions\/1447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/media\/157"}],"wp:attachment":[{"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.shangwendada.top\/index.php\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}