Fix linking of sources without LTCG to a static lib with LTCG
Whenever a binary is created and linked against a static lib that was compiled with LTCG, the final linking step requires the compiler flags so that the pre-compiled data in the shared library can get properly compiled. This could happen for a static build of Qt with LTCG, but also happens frequently for Qt's own build when linking regular libraries and applications against QtBootstrap or QtPlatformSupport. The linking fails when the target is a shared library (example: QtWaylandClient linking against QtPlatformSupport). The .prl file actually contains the "ltcg" flag, so the best solution would actually be to process that flag there and add link_ltcg if any dependent .prl has "ltcg", but I couldn't find out how to do that. Change-Id: I4a75a14d1dcb8c2089a427285e25d5555df7d7d3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
parent
2b258dc80b
commit
fe6f4b9ad7
18
mkspecs/features/link_ltcg.prf
Normal file
18
mkspecs/features/link_ltcg.prf
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
gcc {
|
||||||
|
# When doing link-time code generation, we need to pass the compiler
|
||||||
|
# flags during linking the stage too. This file is processed after
|
||||||
|
# default_post.prf, so the QMAKE_CXXFLAGS already contains
|
||||||
|
# QMAKE_CXXFLAGS_DEBUG or _RELEASE.
|
||||||
|
use_c_linker {
|
||||||
|
# use_c_linker.prf is in effect, use the C flags
|
||||||
|
QMAKE_LFLAGS_LTCG += $$QMAKE_CFLAGS $$QMAKE_CFLAGS_LTCG
|
||||||
|
QMAKE_LFLAGS_APP += $$QMAKE_CFLAGS_APP
|
||||||
|
QMAKE_LFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
|
||||||
|
QMAKE_LFLAGS_PLUGIN += $$QMAKE_CFLAGS_SHLIB
|
||||||
|
} else {
|
||||||
|
QMAKE_LFLAGS_LTCG = $$QMAKE_CXXFLAGS $$QMAKE_LFLAGS_LTCG
|
||||||
|
QMAKE_LFLAGS_APP += $$QMAKE_CXXFLAGS_APP
|
||||||
|
QMAKE_LFLAGS_SHLIB += $$QMAKE_CXXFLAGS_SHLIB
|
||||||
|
QMAKE_LFLAGS_PLUGIN += $$QMAKE_CFLAGS_SHLIB
|
||||||
|
}
|
||||||
|
}
|
@ -31,25 +31,9 @@ CONFIG(release, debug|release) {
|
|||||||
QMAKE_CXXFLAGS_LTCG =
|
QMAKE_CXXFLAGS_LTCG =
|
||||||
QMAKE_LFLAGS_LTCG =
|
QMAKE_LFLAGS_LTCG =
|
||||||
}
|
}
|
||||||
|
|
||||||
# When doing link-time code generation, we need to pass the compiler
|
|
||||||
# flags during linking stage too. This file is processed after
|
|
||||||
# default_post.prf, so the QMAKE_CXXFLAGS already contains
|
|
||||||
# QMAKE_CXXFLAGS_DEBUG or _RELEASE.
|
|
||||||
use_c_linker {
|
|
||||||
# use_c_linker.prf is in effect, use the C flags
|
|
||||||
QMAKE_LFLAGS_LTCG += $$QMAKE_CFLAGS $$QMAKE_CFLAGS_LTCG
|
|
||||||
QMAKE_LFLAGS_APP += $$QMAKE_CFLAGS_APP
|
|
||||||
QMAKE_LFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB
|
|
||||||
QMAKE_LFLAGS_PLUGIN += $$QMAKE_CFLAGS_SHLIB
|
|
||||||
} else {
|
|
||||||
QMAKE_LFLAGS_LTCG = $$QMAKE_CXXFLAGS $$QMAKE_LFLAGS_LTCG
|
|
||||||
QMAKE_LFLAGS_APP += $$QMAKE_CXXFLAGS_APP
|
|
||||||
QMAKE_LFLAGS_SHLIB += $$QMAKE_CXXFLAGS_SHLIB
|
|
||||||
QMAKE_LFLAGS_PLUGIN += $$QMAKE_CFLAGS_SHLIB
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load(link_ltcg)
|
||||||
QMAKE_CFLAGS *= $$QMAKE_CFLAGS_LTCG
|
QMAKE_CFLAGS *= $$QMAKE_CFLAGS_LTCG
|
||||||
QMAKE_CXXFLAGS *= $$QMAKE_CXXFLAGS_LTCG
|
QMAKE_CXXFLAGS *= $$QMAKE_CXXFLAGS_LTCG
|
||||||
QMAKE_LFLAGS *= $$QMAKE_LFLAGS_LTCG
|
QMAKE_LFLAGS *= $$QMAKE_LFLAGS_LTCG
|
||||||
|
@ -68,6 +68,7 @@ defineTest(qtAddModule) {
|
|||||||
using_privates = true
|
using_privates = true
|
||||||
export(using_privates)
|
export(using_privates)
|
||||||
}
|
}
|
||||||
|
contains(MODULE_CONFIG, ltcg): CONFIG += link_ltcg
|
||||||
|
|
||||||
qtProcessModuleFlags(CONFIG, QT.$${1}.CONFIG)
|
qtProcessModuleFlags(CONFIG, QT.$${1}.CONFIG)
|
||||||
qtProcessModuleFlags(DEFINES, QT.$${1}.DEFINES)
|
qtProcessModuleFlags(DEFINES, QT.$${1}.DEFINES)
|
||||||
|
@ -66,6 +66,8 @@ MODULE_FWD_PRI = $$mod_work_pfx/qt_lib_$${MODULE_ID}.pri
|
|||||||
module_build_type =
|
module_build_type =
|
||||||
internal_module: \
|
internal_module: \
|
||||||
module_build_type += internal_module
|
module_build_type += internal_module
|
||||||
|
ltcg: \
|
||||||
|
module_build_type += ltcg
|
||||||
!isEmpty(MODULE_CONFIG): \
|
!isEmpty(MODULE_CONFIG): \
|
||||||
module_config = "QT.$${MODULE_ID}.CONFIG = $$MODULE_CONFIG"
|
module_config = "QT.$${MODULE_ID}.CONFIG = $$MODULE_CONFIG"
|
||||||
else: \
|
else: \
|
||||||
|
Loading…
Reference in New Issue
Block a user