how to generate both IR and object file

Hi,

I use the -emit-llvm flag to generate IR files and use LTO to link them together to produce the final executable. Sometimes LTO gives me link-time errors, so I want to avoid using it, yet I need IR files.

Question: Is there a way to instruct clang to generate *both* an IR file and a regular object file at compile-time, and during the link time, use the object files only, while leaving out the IR files?

Thanks,
JS

Surely you can just change the way the Makefile behaves to do what you want.
At the moment you have:
compile dependencies:
.c/.cpp -> .bc (clang)
link dependencies for LTO:
Many .bc -> big .so or .a or exe

Change this to:
compile dependencies
.c/.cpp -> .bc (with clang)
.bc -> .o (with llc)
link dependencies:
many .o -> big .so or .a or exe

A normal compiler would do this:
compile dependencies
.c/.cpp -> .o (with clang)
link dependencies:
many .o -> big .so or .a or exe

So, you are breaking the compile dependencies into two.

Hi,

I use the -emit-llvm flag to generate IR files and use LTO to link them together to produce the final executable. Sometimes LTO gives me link-time errors, so I want to avoid using it, yet I need IR files.

Question: Is there a way to instruct clang to generate *both* an IR file and a regular object file at compile-time, and during the link time, use the object files only, while leaving out the IR files?

That isn't supported by the standard driver and frontend but it's a perfectly reasonable feature to request.

It's missing mostly for historical reasons -- the frontend action pipeline wasn't designed to be composable, meaning you can only do one thing per invocation.

The limitation doesn't apply if you use the clang C++ API to build a custom tool.

Alp.

Thanks guys. Yes, it would be awesome to have this feature in the future
release.

Modifying the build environment as James suggested isn¹t an option for me
for political reasons with other teams I¹m working with.

This reminds me of another recent question where someone wanted to run both compile and analyze actions. Is there anything that actually prevents us from running multiple actions?