Continuing compilation from output of -flto -Wl, -plugin-opt=also-emit-llvm

Hello all,

I have a program that compiles correctly with clang with link-time optimization enabled. What I would like to do is save the llvm bitcode of the program, and then later compile that bitcode into a (hopefully equivalent) executable. Some helpful folks on IRC pointed out the option

-Wl,-plugin-opt=also-emit-llvm

which causes clang to output an llvm file when linking. For some cases, if I take that file (say, program.bc) and run

clang $CFLAGS $LDFLAGS program.bc -o program

it will generate an executable, and the executable will do the same thing as if I compiled the program normally. However, in some cases it will give an error about invalid linkage type for global variable, or it will compile, but then segfault when I try to run it. Is there something I’m missing? what would be the proper way to compile this bitcode file?

Thanks,

Jeremy