Emitting a single IR bitcode File with LLVM LLD using CMake

强颜欢笑 提交于 2021-02-08 05:14:44

问题


I'm using Ubuntu 16.04 x86_64 and LLVM 5.0 and would like to compile a project to a single LLVM IR bitcode file using CMake. I know there is a way to do this using the GOLD Linker with the LLVM Plugin and add the CMake linker flags "-fuse-ld=gold -Wl,-plugin-opt=emit-llvm" and the CXX flag "-flto".

But when I try to compile the project with the LLVM LLD linker and the "-fuse-ld=lld -Wl,-plugin-opt=emit-llvm" respectively "-flto" Flag, the linker is generating a native executable and no LLVM IR file. I was searching for other LLD options to emit a LLVM IR file but found nothing.

Is there a way (or option) to generate a single LLVM IR file using LLD?


回答1:


You can use the -save-temps option.

clang -flto -fuse-ld=lld -Wl,-save-temps a.o b.o -o myprogram

This will generate myprogramXYZ.precodegen.bc among other files. You can then use llvm-dis to get it in readable IR format.



来源:https://stackoverflow.com/questions/46957981/emitting-a-single-ir-bitcode-file-with-llvm-lld-using-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!