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

Thiago Macieira thiago.macieira at intel.com
Thu Jul 23 20:05:26 CEST 2015


On Thursday 23 July 2015 11:01:58 René J.V. Bertin wrote:
> Thiago Macieira wrote:
> > That's qhash.cpp (the only place where we use _mm_crc32_xxx()).
> > 
> > This sounds like qhash.cpp was compiled with -march=native but *linked*
> > without. Can you confirm that you see the compiler options passed on the
> > linker command-line (-O2 -march=native, etc.)?
> 
> Well, even if you were right, something else appears to be going on.
> Wouldn't it be simply the same issue that makes it impossible to build
> QtScript and QtWebkit with LTO, the use of inline assembly? 

No, because that's a different solution. There's no inline assembly in 
qhash.cpp, only a call to the _mm_crc32_xxx intrinsics. And even if there were 
assembly, it would differ in nature to what ctiVMTrampoline does.

> That's very likely what the _mm_ intrinsics macros contain. 

a) they're not macros, they're functions
b) they're intrinsics, not assembly.

GCC's:
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
_mm_crc32_u32 (unsigned int __C, unsigned int __V)
{
  return __builtin_ia32_crc32si (__C, __V);
}

The function __builtin_ia32_crc32si is not defined anywhere. The compiler 
interprets it and replaces it with the proper assembly.

> OTOH, if you use them for
> SSE <4 too that cannot be the whole explanation.

The use is runtime-checked:

   if (hasFastCrc32())
        return crc32(p, size_t(len), h);

Note that runtime detection is only supported with MSVC, ICC and GCC 4.9. 
Older versions of GCC or other compilers will make a decision at compile time: 
always use CRC32 or never use CRC32.

I have a patch to enable the runtime detection for Clang 3.7, but I haven't 
done enough testing yet.

> /usr/bin/clang++ -c -O3 -march=native -g -ffunction-sections
> :-fPIC -isysroot
> :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Devel
> :oper/SDKs/MacOSX10.10.sdk -std=c++11 -stdlib=libc++
> :-mmacosx-version-min=10.7 -fno-exceptions -Wall -W -DQT_NO_MTDEV

This is Clang, so the decision is compile-time. That -march=native tells Clang 
to enable it if your computer supports it. Assuming you have a non-ancient 
Mac, it should get enabled.

> :/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolc
> :hain/usr/bin/ar cq libQt5Bootstrap.a .obj/qstring_mac.o

Creation of a static library. That means the binary linking against this 
library needs to get the -march=native option from above.

> :/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolc
> :hain/usr/bin/clang++ -L/opt/local/lib -Wl,-headerpad_max_install_names -O3
> :-march=native -g
> :-Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOS
> :X.platform/Developer/SDKs/MacOSX10.9.sdk -stdlib=libc++
> :-mmacosx-version-min=10.7 -D_REENTRANT -I/opt/local/include/glib-2.0
> :-I/opt/local/lib/glib-2.0/include -I/opt/local/include -isysroot
> :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Devel
> :oper/SDKs/MacOSX10.9.sdk -std=c++11 -fvisibility=hidden
> :-fvisibility-inlines-hidden -flto -single_module -dynamiclib -fPIC
> :-compatibility_version	5.4 -current_version	5.4.2
> :-install_name	/opt/local/libexec/qt5/Library/Frameworks/QtCore.framework/V
> :ersions/5/QtCore -o QtCore .obj/qlocale_mac.o .obj/qtimezoneprivate_mac.o

This is the linking of QtCore, not of moc or rcc. But either way, note how -
march=native is present here.

So this is a compiler bug.

Sorry, please try GCC.

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




More information about the Interest mailing list