diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-02-17 14:58:16 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-02-25 15:47:50 +0100 |
commit | 119ffd478134d793fb4414a65549acd19e919e0b (patch) | |
tree | 91f81998f26ec91771230b7def53d2e0ce5e4011 | |
parent | bbf46e38b1d0f70b5c830b3ae2fccf66cf7edb8d (diff) |
CMake: Port the reduce-relocations feature
As reduce-relocations implies bsymbolic_functions, we also add the
-Bsymbolic-functions linker flag.
Also, handle the .dynlist files that are passed to the linker by
bsymbolic_functions.prf in the qmake build.
Change-Id: I535c33fba888596d2f8975b16864bbe9f0a7caa4
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | cmake/QtBuild.cmake | 15 | ||||
-rw-r--r-- | configure.cmake | 6 | ||||
-rw-r--r-- | src/corelib/.prev_CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/corelib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/corelib/Qt6CoreConfigExtras.cmake.in | 12 | ||||
-rw-r--r-- | src/gui/.prev_CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/gui/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/widgets/.prev_CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/widgets/CMakeLists.txt | 5 | ||||
-rwxr-xr-x | util/cmake/configurejson2cmake.py | 1 | ||||
-rwxr-xr-x | util/cmake/pro2cmake.py | 15 |
11 files changed, 61 insertions, 18 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 4c5a7a6019..8deb9b8cbd 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1573,6 +1573,7 @@ function(qt_add_module target) ### Define Targets: set(is_interface_lib 0) + set(is_shared_lib 0) if(${arg_HEADER_MODULE}) add_library("${target}" INTERFACE) set(is_interface_lib 1) @@ -1580,6 +1581,7 @@ function(qt_add_module target) add_library("${target}" STATIC) elseif(${QT_BUILD_SHARED_LIBS}) add_library("${target}" SHARED) + set(is_shared_lib 1) else() add_library("${target}" STATIC) endif() @@ -1596,6 +1598,19 @@ function(qt_add_module target) ) endif() + if(QT_FEATURE_reduce_relocations AND UNIX AND NOT is_interface_lib) + # On x86 and x86-64 systems with ELF binaries (especially Linux), due to + # a new optimization in GCC 5.x in combination with a recent version of + # GNU binutils, compiling Qt applications with -fPIE is no longer + # enough. + # Applications now need to be compiled with the -fPIC option if the Qt option + # \"reduce relocations\" is active. + target_compile_options(${target} INTERFACE -fPIC) + if(GCC AND is_shared_lib) + target_link_options(${target} PRIVATE LINKER:-Bsymbolic-functions) + endif() + endif() + if (ANDROID) qt_android_apply_arch_suffix("${target}") endif() diff --git a/configure.cmake b/configure.cmake index 9f620a8973..075c8df7a8 100644 --- a/configure.cmake +++ b/configure.cmake @@ -447,6 +447,12 @@ qt_feature("reduce_exports" PRIVATE ) qt_feature_definition("reduce_exports" "QT_VISIBILITY_AVAILABLE") qt_feature_config("reduce_exports" QMAKE_PUBLIC_QT_CONFIG) +qt_feature("reduce_relocations" PRIVATE + LABEL "Reduce amount of relocations" + CONDITION NOT WIN32 AND TEST_reduce_relocations +) +qt_feature_definition("reduce_relocations" "QT_REDUCE_RELOCATIONS") +qt_feature_config("reduce_relocations" QMAKE_PUBLIC_QT_CONFIG) qt_feature("signaling_nan" PUBLIC LABEL "Signaling NaN" CONDITION TEST_signaling_nan diff --git a/src/corelib/.prev_CMakeLists.txt b/src/corelib/.prev_CMakeLists.txt index a0b11a7329..51885497bf 100644 --- a/src/corelib/.prev_CMakeLists.txt +++ b/src/corelib/.prev_CMakeLists.txt @@ -250,6 +250,10 @@ qt_add_simd_part(Core SIMD mips_dsp text/qstring_mips_dsp_asm.S ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Core PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtCore.dynlist") +endif() if(ANDROID) set_property(TARGET Core APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES @@ -272,7 +276,6 @@ endif() # MODULE = "core" # MODULE_CONFIG = "moc" "resources" # QMAKE_DSYM_DEBUG_SCRIPT = "$$PWD/debug_script.py" -# QMAKE_DYNAMIC_LIST_FILE = "$$PWD/QtCore.dynlist" # QMAKE_PKGCONFIG_VARIABLES = "host_bins" "qt_conf" # QMAKE_SUBSTITUTES = "ctest_macros_file" "cmake_umbrella_config_file" "cmake_umbrella_config_module_location" "cmake_umbrella_config_module_location_for_install" "cmake_umbrella_config_version_file" "cmake_extras_mkspec_dir" "cmake_extras_mkspec_dir_for_install" # cmake_extras_mkspec_dir.input = "$$PWD/Qt5CoreConfigExtrasMkspecDir.cmake.in" diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 8e236ec3f5..b62ce89f4d 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -358,6 +358,10 @@ qt_add_simd_part(Core SIMD mips_dsp text/qstring_mips_dsp_asm.S ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Core PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtCore.dynlist") +endif() if(ANDROID) set_property(TARGET Core APPEND PROPERTY QT_ANDROID_BUNDLED_JAR_DEPENDENCIES @@ -380,7 +384,6 @@ endif() # MODULE = "core" # MODULE_CONFIG = "moc" "resources" # QMAKE_DSYM_DEBUG_SCRIPT = "$$PWD/debug_script.py" -# QMAKE_DYNAMIC_LIST_FILE = "$$PWD/QtCore.dynlist" # QMAKE_PKGCONFIG_VARIABLES = "host_bins" "qt_conf" # QMAKE_SUBSTITUTES = "ctest_macros_file" "cmake_umbrella_config_file" "cmake_umbrella_config_module_location" "cmake_umbrella_config_module_location_for_install" "cmake_umbrella_config_version_file" "cmake_extras_mkspec_dir" "cmake_extras_mkspec_dir_for_install" # cmake_extras_mkspec_dir.input = "$$PWD/Qt5CoreConfigExtrasMkspecDir.cmake.in" diff --git a/src/corelib/Qt6CoreConfigExtras.cmake.in b/src/corelib/Qt6CoreConfigExtras.cmake.in index cb1dc9689c..984980b5dc 100644 --- a/src/corelib/Qt6CoreConfigExtras.cmake.in +++ b/src/corelib/Qt6CoreConfigExtras.cmake.in @@ -18,18 +18,6 @@ if (NOT QT_NO_CREATE_TARGETS) set_property(TARGET @QT_CMAKE_EXPORT_NAMESPACE@::Core APPEND PROPERTY COMPATIBLE_INTERFACE_STRING QT_MAJOR_VERSION QT_COORD_TYPE ) - - # On x86 and x86-64 systems with ELF binaries (especially Linux), due to - # a new optimization in GCC 5.x in combination with a recent version of - # GNU binutils, compiling Qt applications with -fPIE is no longer - # enough. - # Applications now need to be compiled with the -fPIC option if the Qt option - # \"reduce relocations\" is active. For backward compatibility only, Qt accepts - # the use of -fPIE for GCC 4.x versions. - if (CMAKE_CXX_COMPILER MATCHES "icc.*$" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set_property(TARGET @QT_CMAKE_EXPORT_NAMESPACE@::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-fPIC") - endif() - if (NOT "@QT_NAMESPACE@" STREQUAL "") set_property(TARGET @QT_CMAKE_EXPORT_NAMESPACE@::Core APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS QT_NAMESPACE=@QT_NAMESPACE@) endif() diff --git a/src/gui/.prev_CMakeLists.txt b/src/gui/.prev_CMakeLists.txt index 8d1ea159f0..953dc8b2da 100644 --- a/src/gui/.prev_CMakeLists.txt +++ b/src/gui/.prev_CMakeLists.txt @@ -241,9 +241,12 @@ qt_add_resource(Gui "qpdf" ${qpdf_resource_files} ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Gui PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtGui.dynlist") +endif() #### Keys ignored in scope 1:.:.:gui.pro:<TRUE>: -# QMAKE_DYNAMIC_LIST_FILE = "$$PWD/QtGui.dynlist" # QMAKE_LIBS = "$$QMAKE_LIBS_GUI" ## Scopes: diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 1383381c85..14859069a5 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -290,6 +290,11 @@ qt_add_resource(Gui "qpdf" ${qpdf_resource_files} ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Gui PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtGui.dynlist") +endif() + # special case begin # Replace arch_haswell with avx2 feature. That is what is used in the code requireing # this file, too! diff --git a/src/widgets/.prev_CMakeLists.txt b/src/widgets/.prev_CMakeLists.txt index db39f84104..51e8f8064d 100644 --- a/src/widgets/.prev_CMakeLists.txt +++ b/src/widgets/.prev_CMakeLists.txt @@ -279,10 +279,13 @@ qt_add_resource(Widgets "qstyle1" ${qstyle1_resource_files} ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Widgets PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtWidgets.dynlist") +endif() #### Keys ignored in scope 1:.:.:widgets.pro:<TRUE>: # MODULE_CONFIG = "uic" -# QMAKE_DYNAMIC_LIST_FILE = "$$PWD/QtWidgets.dynlist" # QMAKE_LIBS = "$$QMAKE_LIBS_GUI" ## Scopes: diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index e756b27bee..b3c015f3db 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -281,10 +281,13 @@ qt_add_resource(Widgets "qstyle1" ${qstyle1_resource_files} ) +if(QT_FEATURE_reduce_relocations AND UNIX AND GCC) + target_link_options(Widgets PRIVATE + "LINKER:--dynamic-list=${CMAKE_CURRENT_LIST_DIR}/QtWidgets.dynlist") +endif() #### Keys ignored in scope 1:.:.:widgets.pro:<TRUE>: # MODULE_CONFIG = "uic" -# QMAKE_DYNAMIC_LIST_FILE = "$$PWD/QtWidgets.dynlist" # QMAKE_LIBS = "$$QMAKE_LIBS_GUI" ## Scopes: diff --git a/util/cmake/configurejson2cmake.py b/util/cmake/configurejson2cmake.py index 29753bf641..f479732406 100755 --- a/util/cmake/configurejson2cmake.py +++ b/util/cmake/configurejson2cmake.py @@ -742,7 +742,6 @@ def parseFeature(ctx, feature, data, cm_fh): "profile": None, "qmakeargs": None, "qpa_default_platform": None, # Not a bool! - "reduce_relocations": None, "release": None, "release_tools": None, "rpath_dir": None, # rpath related diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index fca5d4fceb..43d608e219 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -2519,6 +2519,19 @@ def write_simd_part(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0): cm_fh.write(extend_scope) +def write_reduce_relocations_part(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0): + ind = spaces(indent) + dynlist_file = scope.get_files("QMAKE_DYNAMIC_LIST_FILE") + if dynlist_file: + dynlist_path = "${CMAKE_CURRENT_LIST_DIR}/" + dynlist_file[0] + cm_fh.write(f'{ind}if(QT_FEATURE_reduce_relocations AND UNIX AND GCC)\n') + ind = spaces(indent + 1) + cm_fh.write(f'{ind}target_link_options({target} PRIVATE\n') + cm_fh.write(f'{ind} "LINKER:--dynamic-list={dynlist_path}")\n') + ind = spaces(indent) + cm_fh.write(f'{ind}endif()\n') + + def write_android_part(cm_fh: IO[str], target: str, scope: Scope, indent: int = 0): keys = [ "ANDROID_BUNDLED_JAR_DEPENDENCIES", @@ -2825,6 +2838,8 @@ def write_main_part( write_simd_part(cm_fh, name, scope, indent) + write_reduce_relocations_part(cm_fh, name, scope, indent) + write_android_part(cm_fh, name, scopes[0], indent) write_wayland_part(cm_fh, name, scopes[0], indent) |