[Interest] building Qt 4.8.7 with gcc 5 and link-time optimisation on Linux

Thiago Macieira thiago.macieira at intel.com
Wed Jul 22 21:07:26 CEST 2015


On Wednesday 22 July 2015 19:50:27 René J.V. Bertin wrote:
> Hi,
> 
> I'm experimenting with gcc-5.1 and link-time optimisation on Linux. I
> configure with
> 
> CC = gcc-5
> CXX = g++-5
> CFLAGS += -O3 -ftracer -ftree-vectorize -flto -fuse-linker-plugin
> CXXFLAGS += -O3 -ftracer -ftree-vectorize -flto -fuse-linker-plugin
> LDFLAGS += -O3 -ftracer -ftree-vectorize -flto -fuse-linker-plugin
> 
> and get as far as libQtScript which fails to link:

No need to look further. Neither QtScript nor QtWebKit will link with LTO. 
Turn it off for those two.

The problem is the same: it's the SquirrelFishExtreme JIT code and their use 
of inline assembly. The symbols created by the inline assembly aren't visible 
to the LTO code generator.

> Some quick googling only leads to the impression that building with LTO is
> supported (even suggested as a means to reduce start-up times), but I
> haven't yet found any explicit instructions on how to activate the feature.

Yes, for all the other modules, but not those two.

Also, for QtGui (in both Qt 4 and 5), you need to be careful with the code for 
SSE2 and SSSE3. Until I applied certain fixes to Qt 5, those would cause the 
*entire* *build* to suddenly require SSSE3. Or fail to compile, depending on 
the order of the files.

Note that this was GCC 4.8 and it has since got better at LTO. Maybe those 
problems won't affect you, but I'd verify that QtGui isn't using unprotected 
SSSE3 instructions.

> Am I doing something wrong (missing an option to prevent the discarding of
> .text sections maybe)?
> 
> If this were a local build I'd just skip the LTO for QtScript, but the build
> is to be handled by a LauncPad PPA ....

Add to script.pro:
QMAKE_CXXFLAGS -= -flto

As for Qt 5, don't change CXXFLAGS. Instead, just rerun qmake and ask it to do 
it the right way:

qtbase:
	./configure [...]
	qmake -config ltcg
	make
other modules (besides qtscript and qtwebkit):
	qmake -config ltcg
	make

qmake propagates the flag to sub instances when it creates their Makefiles.

ltcg.prf will properly pass the compiler optimisation flags to the linker, will 
pass -fno-fat-lto to GCC for dynamic library builds, will use the proper ar 
wrapper to create static libraries, it will activate link_ltcg.prf so linking 
to LTO static libraries works, etc.

ltcg.prf also supports Clang LTO, ICC's IPO and MSVC LTCG. You don't want to 
use ICC IPO unless you have at least 32 GB of RAM, though.

Does it work? Yes, my GCC release build of Qt has been done with LTCG for two 
years.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list