Search code examples
llvmldlto

Get llvm IR after lto linking


Is there any way to get llvm IR after linking for lto? For example I have the following line:

$ clang -flto -O2 a.c main.c -fuse-ld=gold -v -save-temps

So I want to get llvm IR where file a.c and file main.c are linked in one monlithic.bc (or monlithic.o with IR). I tried to add option -Wl,-plugin-opt=save-temps but it occurs an error:

libLLVMLTO: Unknown command line argument 'save-temps'. Try: 'libLLVMLTO -help' clang: error: linker command failed with exit code 1 (use -v to see invocation)

And also is there any way to dump lto transformations of IR?


Solution

  • The problem was solved with newer linker and llvm (llvm-3.8 and binutils-2.25) in the following way:

    $ ls

    t1.c t2.c t2.h

    $ clang -flto -O2 t1.c t2.c -v -fuse-ld=gold -save-temps -Wl,-plugin-opt=save-temps -Wl,--verbose

    ...

    $ ls

    a.out a.out.bc a.out.o a.out.opt.bc t1.bc t1.c t1.i t1.o t2.bc t2.c t2.h t2.i t2.o

    $ llvm-dis a.out.bc

    $ vim a.out.ll