I'm contributing to one open-source project named AMX Mod X. It uses really simple, custom-made build system (called AMBuild). Project is built using Clang on Linux.
I tried to enable LTO for it, just by passing compile-time and link-time arguments.
As a link time arguments I added
-O2 -flto=thin -fuse-ld=lld -Wl,-z,notext
And as a compile-time arguments.
-O2 -flto=thin -fPIC
I selected this configuration after careful googling. It seems I'm very close to achieving complete LTO. Only one module fails to build, it links against pcre.
Generated (by build system) linking command is like this.
clang-4.0 _public_sdk_amxxmodule.o module.o CRegEx.o utils.o -m32 -O2 -flto=thin -fuse-ld=lld -Wl,-z,notext -ldl -lm -lgcc_eh ../../../support/versionlib/version/libversion.a /home/travis/build/alliedmodders/amxmodx/modules/regex/lib_linux/libpcre.a -shared -o regex_amxx_i386.so
And linking errors are many, but they are very similar. This is one of them.
/usr/lib/llvm-4.0/bin/ld.lld: error: pcre_compile.c
function add_to_class): can't create dynamic relocation R_386_32 against symbol '_pcre_ucd_stage1' defined in /home/travis/build/alliedmodders/amxmodx/modules/regex/lib_linux/libpcre.a(libpcre_la-pcre_ucd.o)
I read that LLD and bfd have different defaults and -Wl,-z,notext should work, but it didn't have any effect.
libpcre.a is just a binary file bundled with repository. AMBuild isn't building pcre from sources. This is my PR, you can find there failed travis build and read logs more carefully. Don't be afraid against custom build system, all executed commands are printed to the terminal in the most verbose form. It shouldn't be problem.
How to enable LTO when linking against pcre? I don't really care about other compilers (gcc, icc, etc..) or other operating systems.
UPD: LTO stands for Link Time Optimization