summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-06-11 12:44:10 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-06-11 19:38:09 +0200
commit58a7e4f0bc5e9290cc205762d51adc5806b034fd (patch)
treef61d3bceeefe2b0ed5f714d32de0518bb7b03ec3 /cmake
parentb3e0732740d8fdace82d91973dac87261402604f (diff)
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>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuild.cmake23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index 029468732c..42a3c05f1c 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -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()