big module for a project

Hi All,

I am using clang to compile Mysql source code. Because I want to do some inter-procedural analysis, hopefully, I want to get a .o(bitcode) file(a module) containing all possible function declarations and definitions. Is it possible to do that ? Or you guys have some suggestions?

To be clear, like Mysql, there is a mysqld routine, which is a major routine. I want to mysqld.o(which is generated by clang) to contain all possible function declarations and definitions. So when I do some analysis, I just need load one module, which is mysqld.o, instead of all .o files.

Best,
Yuxi

Maybe use llvm-link to collect the individual bitcode .o files into one master .o file, then your tool can load just the one big .o file.

–paulr

Take a look at wllvm (https://github.com/travitch/whole-program-llvm)

Dear Yuxi,

There are three general ways to do this (two of which have already been mentioned).

First, you can change the Makefiles to emit bitcode and then use llvm-link to link all the bitcode files together into a big bitcode file. You can then run the opt program on this large bitcode file.

Second, you can use some third-party tools (for lack of a better term) that will get you a single bitcode file with fewer changes to the Makefiles. I'm not very familiar with these, but I think others have commented on them.

Third, you can add your analysis pass to the libLTO library and use LLVM's link-time optimization framework to run your analysis. Documentation libLTO can be found at http://llvm.org/docs/LinkTimeOptimization.html and http://llvm.org/docs/GoldPlugin.html. LLVM's LTO infrastructure is designed to be transparent (i.e., you shouldn't have to modify Makefiles to use it), though some programs' Makefiles are more...complaint than others.

I've used the libLTO approach for large programs with reasonable success. However, some of the other third-party approaches have been reported to work well, so you might try looking at those.

Regards,

John Criswell

Maybe use llvm-link to collect the individual bitcode .o files into one master .o file, then your tool can load just the one big .o file.

–paulr

Awesome.

Thanks,
Yuxi

Hi John,

Really appreciate your detailed information.
The first one works for me.
I will take a look at the third solution.

Thanks again,
Yuxi

Hi John,

One more question, I try to use libLTO, and try example ON http://llvm.org/docs/GoldPlugin.html.
For the example, it directly generates executable, what I want is a .o file(which I can use llvm-dis to see the bitcode). Maybe I misinterpret your solution.

Or you want to say if I follow the instruction like http://llvm.org/docs/GoldPlugin.html. After ./configure&&make&&make ckeck, I can get one module, containing as many functions as possible.

Best,
Yuxi

It depends what you want to do on the bitcode. I think the idea is to generate your own libLTO that includes your pass(es) as part of the LTO pipeline.