Introduce qmake feature use_gold_linker

This patch adds the feature use_gold_linker to use the gold linker that
has been part of of GNU binutils since 2008. Gold links C++ libraries
much faster and use less memory.

The feature is autodetected when building Qt on Linux, but can be disabled
in configure. On MingW builds it is default off but can be enabled for
cross builds.

Change-Id: Icdd6ba2e706b2c791bcf44b6e718c2b7a5eb2218
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Allan Sandfeld Jensen 2014-07-01 11:46:50 +02:00
parent ea34893b8f
commit 01c82b945d
5 changed files with 42 additions and 0 deletions

26
configure vendored
View File

@ -698,6 +698,7 @@ CFG_INOTIFY=auto
CFG_EVENTFD=auto CFG_EVENTFD=auto
CFG_RPATH=yes CFG_RPATH=yes
CFG_FRAMEWORK=auto CFG_FRAMEWORK=auto
CFG_USE_GOLD_LINKER=auto
DEFINES= DEFINES=
INCLUDES= INCLUDES=
D_FLAGS= D_FLAGS=
@ -1592,6 +1593,13 @@ while [ "$#" -gt 0 ]; do
UNKNOWN_OPT=yes UNKNOWN_OPT=yes
fi fi
;; ;;
use-gold-linker)
if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
CFG_USE_GOLD_LINKER="$VAL"
else
UNKNOWN_OPT=yes
fi
;;
zlib) zlib)
[ "$VAL" = "qt" ] && VAL=yes [ "$VAL" = "qt" ] && VAL=yes
if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ] || [ "$VAL" = "system" ]; then
@ -2465,6 +2473,9 @@ Additional options:
linker optimizations (Qt/X11 and Qt for Embedded Linux only; linker optimizations (Qt/X11 and Qt for Embedded Linux only;
experimental; needs GNU ld >= 2.18). experimental; needs GNU ld >= 2.18).
-no-use-gold-linker ..... Do not link using the GNU gold linker.
+ -use-gold-linker ........ Link using the GNU gold linker if available.
-force-asserts ........ Force Q_ASSERT to be enabled even in release builds. -force-asserts ........ Force Q_ASSERT to be enabled even in release builds.
-device <name> ............... Cross-compile for device <name> (experimental) -device <name> ............... Cross-compile for device <name> (experimental)
@ -3230,6 +3241,19 @@ if [ "$CFG_REDUCE_EXPORTS" != "no" ]; then
fi fi
fi fi
# auto-detect -fuse-ld=gold support
if [ "$CFG_USE_GOLD_LINKER" != "no" ]; then
if linkerSupportsFlag $TEST_COMPILER -fuse-ld=gold; then
CFG_USE_GOLD_LINKER=yes
else
if [ "$CFG_USE_GOLD_LINKER" = "yes" ]; then
echo "-use-gold-linker was requested but this compiler does not support it"
exit 1
fi
CFG_USE_GOLD_LINKER=no
fi
fi
# auto-detect -fstack-protector-strong support (for QNX only currently) # auto-detect -fstack-protector-strong support (for QNX only currently)
if [ "$XPLATFORM_QNX" = "yes" ]; then if [ "$XPLATFORM_QNX" = "yes" ]; then
if compilerSupportsFlag $TEST_COMPILER -fstack-protector-strong; then if compilerSupportsFlag $TEST_COMPILER -fstack-protector-strong; then
@ -5598,6 +5622,7 @@ fi
[ "$CFG_REDUCE_RELOCATIONS" = "yes" ] && QT_CONFIG="$QT_CONFIG reduce_relocations" [ "$CFG_REDUCE_RELOCATIONS" = "yes" ] && QT_CONFIG="$QT_CONFIG reduce_relocations"
[ "$CFG_STRIP" = "no" ] && QMAKE_CONFIG="$QMAKE_CONFIG nostrip" [ "$CFG_STRIP" = "no" ] && QMAKE_CONFIG="$QMAKE_CONFIG nostrip"
[ "$CFG_PRECOMPILE" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG precompile_header" [ "$CFG_PRECOMPILE" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG precompile_header"
[ "$CFG_USE_GOLD_LINKER" = "yes" ] && QMAKE_CONFIG="$QMAKE_CONFIG use_gold_linker"
if [ "$CFG_SEPARATE_DEBUG_INFO" = "yes" ]; then if [ "$CFG_SEPARATE_DEBUG_INFO" = "yes" ]; then
QT_CONFIG="$QT_CONFIG separate_debug_info" QT_CONFIG="$QT_CONFIG separate_debug_info"
fi fi
@ -6472,6 +6497,7 @@ else
fi fi
unset build_mode release unset build_mode release
echo " Using C++11 ............ $CFG_CXX11" echo " Using C++11 ............ $CFG_CXX11"
echo " Using gold linker....... $CFG_USE_GOLD_LINKER"
echo " Using PCH .............. $CFG_PRECOMPILE" echo " Using PCH .............. $CFG_PRECOMPILE"
echo " Target compiler supports:" echo " Target compiler supports:"
if [ "$CFG_ARCH" = "i386" -o "$CFG_ARCH" = "x86_64" ]; then if [ "$CFG_ARCH" = "i386" -o "$CFG_ARCH" = "x86_64" ]; then

View File

@ -16,6 +16,7 @@ QMAKE_LFLAGS_SONAME += -Wl,-soname,
QMAKE_LFLAGS_THREAD += QMAKE_LFLAGS_THREAD +=
QMAKE_LFLAGS_RPATH = -Wl,-rpath, QMAKE_LFLAGS_RPATH = -Wl,-rpath,
QMAKE_LFLAGS_RPATHLINK = -Wl,-rpath-link, QMAKE_LFLAGS_RPATHLINK = -Wl,-rpath-link,
QMAKE_LFLAGS_USE_GOLD = -fuse-ld=gold
# -Bsymbolic-functions (ld) support # -Bsymbolic-functions (ld) support
QMAKE_LFLAGS_BSYMBOLIC_FUNC = -Wl,-Bsymbolic-functions QMAKE_LFLAGS_BSYMBOLIC_FUNC = -Wl,-Bsymbolic-functions

View File

@ -61,6 +61,8 @@ debug {
QMAKE_LIBFLAGS += $$QMAKE_LIBFLAGS_RELEASE QMAKE_LIBFLAGS += $$QMAKE_LIBFLAGS_RELEASE
} }
use_gold_linker: QMAKE_LFLAGS += $$QMAKE_LFLAGS_USE_GOLD
dll:win32: QMAKE_LFLAGS += $$QMAKE_LFLAGS_DLL dll:win32: QMAKE_LFLAGS += $$QMAKE_LFLAGS_DLL
static:mac: QMAKE_LFLAGS += $$QMAKE_LFLAGS_STATIC_LIB static:mac: QMAKE_LFLAGS += $$QMAKE_LFLAGS_STATIC_LIB
staticlib:unix { staticlib:unix {

View File

@ -78,6 +78,7 @@ QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows
QMAKE_LFLAGS_DLL = -shared QMAKE_LFLAGS_DLL = -shared
QMAKE_LFLAGS_CXX11 = QMAKE_LFLAGS_CXX11 =
QMAKE_LFLAGS_GCSECTIONS = -Wl,--gc-sections QMAKE_LFLAGS_GCSECTIONS = -Wl,--gc-sections
QMAKE_LFLAGS_USE_GOLD = -fuse-ld=gold
QMAKE_LINK_OBJECT_MAX = 10 QMAKE_LINK_OBJECT_MAX = 10
QMAKE_LINK_OBJECT_SCRIPT = object_script QMAKE_LINK_OBJECT_SCRIPT = object_script
QMAKE_PREFIX_STATICLIB = lib QMAKE_PREFIX_STATICLIB = lib

View File

@ -250,6 +250,8 @@ Configure::Configure(int& argc, char** argv)
dictionary[ "C++11" ] = "auto"; dictionary[ "C++11" ] = "auto";
dictionary[ "USE_GOLD_LINKER" ] = "no";
dictionary[ "SHARED" ] = "yes"; dictionary[ "SHARED" ] = "yes";
dictionary[ "ZLIB" ] = "auto"; dictionary[ "ZLIB" ] = "auto";
@ -461,6 +463,10 @@ void Configure::parseCmdLine()
dictionary[ "C++11" ] = "yes"; dictionary[ "C++11" ] = "yes";
else if (configCmdLine.at(i) == "-no-c++11") else if (configCmdLine.at(i) == "-no-c++11")
dictionary[ "C++11" ] = "no"; dictionary[ "C++11" ] = "no";
else if (configCmdLine.at(i) == "-use-gold-linker")
dictionary[ "USE_GOLD_LINKER" ] = "yes";
else if (configCmdLine.at(i) == "-no-use-gold-linker")
dictionary[ "USE_GOLD_LINKER" ] = "no";
else if (configCmdLine.at(i) == "-shared") else if (configCmdLine.at(i) == "-shared")
dictionary[ "SHARED" ] = "yes"; dictionary[ "SHARED" ] = "yes";
else if (configCmdLine.at(i) == "-static") else if (configCmdLine.at(i) == "-static")
@ -1762,6 +1768,9 @@ bool Configure::displayHelp()
desc("C++11", "yes", "-c++11", "Compile Qt with C++11 support enabled."); desc("C++11", "yes", "-c++11", "Compile Qt with C++11 support enabled.");
desc("C++11", "no", "-no-c++11", "Do not compile Qt with C++11 support enabled.\n"); desc("C++11", "no", "-no-c++11", "Do not compile Qt with C++11 support enabled.\n");
desc("USE_GOLD_LINKER", "yes", "-use-gold-linker", "Link using the GNU gold linker (gcc only).");
desc("USE_GOLD_LINKER", "no", "-no-use-gold-linker", "Do not link using the GNU gold linker.\n");
desc("SHARED", "yes", "-shared", "Create and use shared Qt libraries."); desc("SHARED", "yes", "-shared", "Create and use shared Qt libraries.");
desc("SHARED", "no", "-static", "Create and use static Qt libraries.\n"); desc("SHARED", "no", "-static", "Create and use static Qt libraries.\n");
@ -2609,6 +2618,9 @@ void Configure::generateOutputVars()
if (dictionary[ "C++11" ] == "yes") if (dictionary[ "C++11" ] == "yes")
qtConfig += "c++11"; qtConfig += "c++11";
if (dictionary[ "USE_GOLD_LINKER" ] == "yes")
qmakeConfig += "use_gold_linker";
if (dictionary[ "SHARED" ] == "no") if (dictionary[ "SHARED" ] == "no")
qtConfig += "static"; qtConfig += "static";
else else