diff options
author | Mikhail Svetkin <mikhail.svetkin@qt.io> | 2018-04-10 15:03:11 +0200 |
---|---|---|
committer | Mikhail Svetkin <mikhail.svetkin@qt.io> | 2018-04-27 06:47:35 +0000 |
commit | 194a40449039a1e1dad2f370255698172bf5e7f7 (patch) | |
tree | f5d33472cea9afbc500ef5a34f3f724704dd2bfe | |
parent | 18d26192242873625a3132d0ad6b9342226d14bb (diff) |
Make the use of -fdata-sections and --gc-sections more generic in Qt
Add qmake feature and configure option, which optimze the size of static
exectuable. Use for static build.
Enabled via configure --gc-binaries, or CONFIG += gc-binaries in 3rd party
projects.
Change-Id: I3c25b02caaef6a4afc6019afc9c67122dd11696d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
-rw-r--r-- | config_help.txt | 3 | ||||
-rw-r--r-- | configure.json | 16 | ||||
-rw-r--r-- | mkspecs/common/gcc-base.conf | 2 | ||||
-rw-r--r-- | mkspecs/features/gc_binaries.prf | 3 | ||||
-rw-r--r-- | mkspecs/features/qt_app.prf | 3 | ||||
-rw-r--r-- | mkspecs/features/qt_module.prf | 2 | ||||
-rw-r--r-- | mkspecs/features/uikit/gc_binaries.prf | 2 | ||||
-rw-r--r-- | mkspecs/linux-icc/qmake.conf | 2 | ||||
-rw-r--r-- | mkspecs/macx-icc/qmake.conf | 2 | ||||
-rw-r--r-- | src/corelib/corelib.pro | 1 | ||||
-rw-r--r-- | src/tools/bootstrap/bootstrap.pro | 3 |
11 files changed, 30 insertions, 9 deletions
diff --git a/config_help.txt b/config_help.txt index c606ffb579..5b32eb183f 100644 --- a/config_help.txt +++ b/config_help.txt @@ -98,6 +98,9 @@ Build options: -gdb-index ........... Index the debug info to speed up GDB [no; auto if -developer-build with debug info] -strip ............... Strip release binaries of unneeded symbols [yes] + -gc-binaries ......... Place each function or data item into its own section + and enable linker garbage collection of unused + sections. [auto for static builds, otherwise no] -force-asserts ....... Enable Q_ASSERT even in release builds [no] -developer-build ..... Compile and link Qt for developing Qt itself (exports for auto-tests, extra checks, etc.) [no] diff --git a/configure.json b/configure.json index 595bb619ce..6e48f5da61 100644 --- a/configure.json +++ b/configure.json @@ -80,6 +80,7 @@ "force-debug-info": { "type": "boolean", "name": "force_debug_info" }, "force-pkg-config": { "type": "void", "name": "pkg-config" }, "framework": "boolean", + "gc-binaries": { "type": "boolean", "name": "gc_binaries" }, "gdb-index": { "type": "boolean", "name": "gdb_index" }, "gcc-sysroot": "boolean", "gcov": "boolean", @@ -397,6 +398,17 @@ ] } }, + "gc_binaries": { + "label": "support for split sections and linker garbage collection", + "type": "compile", + "test": { + "qmake": [ + "isEmpty(QMAKE_CFLAGS_SPLIT_SECTIONS): error(\"Nope\")", + "isEmpty(QMAKE_CXXFLAGS_SPLIT_SECTIONS): error(\"Nope\")", + "isEmpty(QMAKE_LFLAGS_GCSECTIONS): error(\"Nope\")" + ] + } + }, "sse2": { "label": "SSE2 instructions", "type": "x86Simd" @@ -592,6 +604,10 @@ "compiler-flags": { "output": [ "compilerFlags" ] }, + "gc_binaries": { + "condition": "!features.shared && tests.gc_binaries", + "output": [ "privateFeature" ] + }, "gcc-sysroot": { "output": [ "gccSysroot" ], "condition": "input.sysroot != ''" diff --git a/mkspecs/common/gcc-base.conf b/mkspecs/common/gcc-base.conf index 0407ba9724..e51b173276 100644 --- a/mkspecs/common/gcc-base.conf +++ b/mkspecs/common/gcc-base.conf @@ -50,7 +50,7 @@ QMAKE_CFLAGS_ISYSTEM = -isystem QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden QMAKE_CFLAGS_EXCEPTIONS_OFF += -fno-exceptions -QMAKE_CFLAGS_SPLIT_SECTIONS += -ffunction-sections +QMAKE_CFLAGS_SPLIT_SECTIONS += -ffunction-sections -fdata-sections QMAKE_CFLAGS_LTCG = -flto -fno-fat-lto-objects QMAKE_CFLAGS_LTCG_FATOBJECTS = -ffat-lto-objects QMAKE_CFLAGS_DISABLE_LTCG = -fno-lto diff --git a/mkspecs/features/gc_binaries.prf b/mkspecs/features/gc_binaries.prf new file mode 100644 index 0000000000..111d5d95ef --- /dev/null +++ b/mkspecs/features/gc_binaries.prf @@ -0,0 +1,3 @@ +QMAKE_CFLAGS += $$QMAKE_CFLAGS_SPLIT_SECTIONS +QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_SPLIT_SECTIONS +QMAKE_LFLAGS += $$QMAKE_LFLAGS_GCSECTIONS diff --git a/mkspecs/features/qt_app.prf b/mkspecs/features/qt_app.prf index 883f8ca215..8354f30eea 100644 --- a/mkspecs/features/qt_app.prf +++ b/mkspecs/features/qt_app.prf @@ -20,9 +20,6 @@ isEmpty(QMAKE_TARGET_DESCRIPTION): \ isEmpty(QMAKE_INFO_PLIST): CONFIG -= app_bundle -# This decreases the binary size for tools if statically linked -QMAKE_LFLAGS += $$QMAKE_LFLAGS_GCSECTIONS - host_build: QT -= gui # no host tool will ever use gui host_build:force_bootstrap { !build_pass:qtConfig(release_tools): CONFIG += release diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf index f8729de947..cd8b41d36d 100644 --- a/mkspecs/features/qt_module.prf +++ b/mkspecs/features/qt_module.prf @@ -28,8 +28,6 @@ host_build|staticlib: CONFIG += static host_build { QT -= gui # no host module will ever use gui - QMAKE_CFLAGS += $$QMAKE_CFLAGS_SPLIT_SECTIONS - QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_SPLIT_SECTIONS force_bootstrap { !build_pass:qtConfig(release_tools): CONFIG += release contains(QT, core(-private)?|xml) { diff --git a/mkspecs/features/uikit/gc_binaries.prf b/mkspecs/features/uikit/gc_binaries.prf new file mode 100644 index 0000000000..c4f7445951 --- /dev/null +++ b/mkspecs/features/uikit/gc_binaries.prf @@ -0,0 +1,2 @@ +# bitcode (release mode) is incompatible with splitting sections. +!bitcode|!release: load(gc_binaries) diff --git a/mkspecs/linux-icc/qmake.conf b/mkspecs/linux-icc/qmake.conf index ec09afe381..57638326a0 100644 --- a/mkspecs/linux-icc/qmake.conf +++ b/mkspecs/linux-icc/qmake.conf @@ -26,7 +26,7 @@ QMAKE_CFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_SHLIB QMAKE_CFLAGS_YACC = QMAKE_CFLAGS_ISYSTEM = -isystem QMAKE_CFLAGS_THREAD = -D_REENTRANT -QMAKE_CFLAGS_SPLIT_SECTIONS = -ffunction-sections +QMAKE_CFLAGS_SPLIT_SECTIONS = -ffunction-sections -fdata-sections QMAKE_CFLAGS_LTCG = -ipo -fno-fat-lto-objects QMAKE_CFLAGS_LTCG_FATOBJECTS = -ffat-lto-objects QMAKE_CFLAGS_DISABLE_LTCG = -no-ipo diff --git a/mkspecs/macx-icc/qmake.conf b/mkspecs/macx-icc/qmake.conf index fa3944f843..e11782e885 100644 --- a/mkspecs/macx-icc/qmake.conf +++ b/mkspecs/macx-icc/qmake.conf @@ -25,7 +25,7 @@ QMAKE_CFLAGS_SHLIB = -fPIC QMAKE_CFLAGS_STATIC_LIB = $$QMAKE_CFLAGS_SHLIB QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses QMAKE_CFLAGS_THREAD = -QMAKE_CFLAGS_SPLIT_SECTIONS = -ffunction-sections +QMAKE_CFLAGS_SPLIT_SECTIONS = -ffunction-sections -fdata-sections QMAKE_CFLAGS_LTCG = -ipo QMAKE_CFLAGS_DISABLE_LTCG = -no-ipo diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 7f62a6f1b0..2244020795 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -4,6 +4,7 @@ CONFIG += exceptions MODULE = core # not corelib, as per project file MODULE_CONFIG = moc resources +qtConfig(gc_binaries): MODULE_CONFIG += gc_binaries !isEmpty(QT_NAMESPACE): MODULE_DEFINES = QT_NAMESPACE=$$QT_NAMESPACE TRACEPOINT_PROVIDER = $$PWD/qtcore.tracepoints diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index a45382106a..d340df8cbb 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -2,7 +2,7 @@ option(host_build) TARGET = QtBootstrap QT = -CONFIG += minimal_syncqt internal_module force_bootstrap +CONFIG += minimal_syncqt internal_module force_bootstrap gc_binaries MODULE_INCNAME = QtCore QtXml MODULE_DEFINES = \ @@ -12,6 +12,7 @@ MODULE_DEFINES = \ QT_VERSION_PATCH=$$QT_PATCH_VERSION \ QT_BOOTSTRAPPED \ QT_NO_CAST_TO_ASCII +MODULE_CONFIG = gc_binaries DEFINES += \ $$MODULE_DEFINES \ |