CMake: Implement workaround for failing linux static builds

In static builds, due to our CMake design for auto-linking plugins
being incorrect we sometimes cause link failures on Linux in leaf
modules, because the link line order is incorrect.

So far such failures were fixed by explicitly modifying the order of
libraries on the link line in each failing CMake project.

This proves to be problematic because the failures appear in seemingly
random integrations that don't even touch the build system parts.

Until we fix the design, another less performant but more
general / safe way is to increase the link interface multiplicity,
which causes a cycle of libraries to be repeated more than 2 times
on the link line, thus giving the ld linker more chances to figure out
which symbols are needed for linking.

Implement this for Linux static builds to avoid random integration
failures for people that know nothing about this issue.

The link multiplicity for all qt modules is increased to 3, thus
QtGui would be repeated 3 times on the link line of each dependent
library. The value is also configurable via the
QT_LINK_CYCLE_MULTIPLICITY cache variable.

Task-number: QTBUG-83498
Change-Id: I2fd2bb2b5e7fec4e3ef5d1194668b524d20f7067
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2020-06-11 12:44:10 +02:00
parent b3e0732740
commit 58a7e4f0bc

View File

@ -2357,6 +2357,29 @@ function(qt_add_module target)
qt_set_target_info_properties(${target} ${ARGN})
qt_handle_multi_config_output_dirs("${target}")
if(NOT BUILD_SHARED_LIBS AND LINUX)
# Horrible workaround for static build failures due to incorrect static library link
# order. By increasing the multiplicity to 3, each library cycle will be repeated
# 3 times on the link line, reducing the probability of undefined symbols at
# link time.
# These failures are only observed on Linux with the ld linker (not sure about
# ld.gold).
# Allow opting out and modifying the value via cache value, in case if we urgently
# need to increase it without waiting for the qtbase change to propagate to
# other dependent repos.
# The proper fix will be to get rid of the cycles in the future.
# See QTBUG-83498 for details.
set(default_link_cycle_multiplicity "3")
if(DEFINED QT_LINK_CYCLE_MULTIPLICITY)
set(default_link_cycle_multiplicity "${QT_LINK_CYCLE_MULTIPLICITY}")
endif()
if(default_link_cycle_multiplicity)
set_property(TARGET "${target}"
PROPERTY
LINK_INTERFACE_MULTIPLICITY "${default_link_cycle_multiplicity}")
endif()
endif()
if (arg_SKIP_DEPENDS_INCLUDE)
set_target_properties(${target} PROPERTIES QT_MODULE_SKIP_DEPENDS_INCLUDE TRUE)
endif()