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>
This commit is contained in:
parent
bbf46e38b1
commit
119ffd4781
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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!
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user