The best way to generate IRs for a big project (e.g. httpd, mysql, etc...)

Hello, everyone; as the title says, I am looking for the correct way to generate IRs for a big project such as nginx, httpd, etc…

I have done some search on different ways of doing it, and many have recommended tools such as:

Among these approaches, I tried methods such as wllvm/gllvm, could not get their tools to work. Therefore, I figured the LTO method was the way to go, as many people here suggested. I think I almost made it through, but I am having trouble.

Following is the exact command (order is important) to try to generate bitcodes for each source file of the httpd, but failed with an error. I’m wondering if anyone has a different method of getting it to work/tested on Ubuntu 20.04 or got any suggestions on the different method.

// Assuming current dir: /home/$USER/Downloads
git clone https://github.com/apache/httpd.git
cd httpd
wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz  
wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz 
tar -xvf apr-1.7.0.tar.gz && tar -xvf apr-util-1.6.1.tar.gz 
./buildconf --with-apr=/home/$USER/Downloads/httpd/apr-1.7.0 --with-apr-util=/home/$USER/Downloads/httpd/apr-util-1.6.1

This should generate the configure file for the httpd and then I followed the tutorial here: Compiling Autotooled projects to LLVM Bitcode (gbalats.github.io)

export CC=clang
export CXX=clang++
export RANLIB=llvm-ranlib
export CFLAGS=" -flto -std=gnu99 "
export LDFLAGS=" -flto -fuse-ld=gold  -Wl,-plugin-opt=save-temps "
./configure && make

Which actually works to a certain point when it faces an error such as this:

/usr/bin/ld.gold: error: modules/core/.libs/libmod_so.a: no archive symbol table (run ranlib)
/usr/bin/ld.gold: error: modules/http/.libs/libmod_http.a: no archive symbol table (run ranlib)
/usr/bin/ld.gold: error: server/mpm/event/.libs/libevent.a: no archive symbol table (run ranlib)
...
httpd.lto.o:ld-temp.o:ap_prelinked_modules: error: undefined reference to 'core_module'
httpd.lto.o:ld-temp.o:ap_prelinked_modules: error: undefined reference to 'so_module'
httpd.lto.o:ld-temp.o:ap_prelinked_modules: error: undefined reference to 'http_module'
httpd.lto.o:ld-temp.o:ap_prelinked_modules: error: undefined reference to 'mpm_event_module'

Which is fascinating because I double checked that my RANLIB is set properly:

~/Downloads/httpd (trunk*) » echo $RANLIB                                                                                  2 ↵ jay@ssrg-jay
llvm-ranlib
--------------------------------------------------------------------------------------------------------------------------------------------
~/Downloads/httpd (trunk*) » llvm-ranlib --version  
LLVM (http://llvm.org/):
  LLVM version 13.0.0
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: haswell

So, in the end, I am still stuck on trying to figure out how to properly use the LTO to compile a big project.

I provided an above-detailed description using the LTO option as I wanted to provide an easily reproducible example for anyone else who may have had to solve this problem.

I would appreciate any kind of suggestion or feedback on the question of “a good way to generate IR files for a big project.”