3

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?

2
  • Are you sure this is not working for you? I didn't try this myself, but this article promises it should work: gbalats.github.io/2015/12/10/…. Commented Oct 26, 2017 at 15:27
  • Yes the GOLD Linker can emit a single LLVM IR file. But I would like to have the ability to generate a single LLVM IR bitcode file OR a native executable. The project should link to a static LLVM IR Library and the GOLD Linker can't link to it while generating a native executable. So the LLD Linker can do this, but I don't know how to generate a LLVM IR file with the LLD. Commented Oct 27, 2017 at 7:04

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.