Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get llvm IR after lto linking

Tags:

llvm

ld

lto

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?

like image 463
alexanius Avatar asked Dec 07 '25 16:12

alexanius


1 Answers

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

like image 75
alexanius Avatar answered Dec 11 '25 09:12

alexanius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!