Hello, I am trying to emit bitcode files using clang.
I am trying to compile EFI drivers, which are PE32 executables. wllvm1 and gllvm2 do not support PE32; hence they cannot attach the bitcode in the final object files.
For this reason, I am trying to pass flags to clang used by the project’s build system. I cannot modify the build system but play with the compiler flags.
Passing -c -emit-llvm produces .bc files as I wanted, but it does not create object files, making the build system fail the building process. Passing -S requires -o, and I do not have a way to specify the output filename manually.
What are my options here to produce .bc files without modifying the build system? Is there a clang flag that emits both the compiled object and its bitcode separately?
Not that I know of. The .bc files would have to be run through clang again, either explicitly to create object files, or treated as inputs to the linker (which can then use LTO to compile them and link into the final executable).
There isn’t a flag to emit them into two different files (that I know of), but you should be able to pass -fembed-bitcode=all on the command line to embed the bitcode within the object file and then pull it out with llvm-objcopy. May be more or less elegant depending upon what you’re trying to do.
The -fembed-bitcode=all flag creates a .llvmbc and a .llvmcmd section. The command to get the bitcode should be llvm-objcopy --dump-section=.llvmbc=<path to output bitcode file> <path to object file>.