Skip to content

Commit

Permalink
MSVC: Optimize global data to reduce binary size
Browse files Browse the repository at this point in the history
Package global data in COMDAT sections for optimization.
According to the docs, this can significantly reduce the
size of the resulting binary executable.

I've tested build Qt with /Gw locally with and without
LTCG, the result shows /Gw can reduce the binary size
indeed, but not "significantly". The result also reveals
that exes can benefit much more from /Gw than dlls.
The result can be seen from the QTBUG-98894 bug report.

Microsoft Docs:
https://docs.microsoft.com/en-us/cpp/build/reference/gw-optimize-global-data?view=msvc-170

Task-number: QTBUG-98894
Change-Id: Ibce34c98e791e519d669a5fe39c0027d1459c382
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Kai Koehne <[email protected]>
  • Loading branch information
wangwenx190 committed Dec 15, 2021
1 parent 877d6cf commit d2a0202
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cmake/QtInternalTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ if (MSVC)
target_compile_options(PlatformCommonInternal INTERFACE -Zc:wchar_t)

target_compile_options(PlatformCommonInternal INTERFACE
$<$<NOT:$<CONFIG:Debug>>:-guard:cf>
$<$<NOT:$<CONFIG:Debug>>:-guard:cf -Gw>
)

target_link_options(PlatformCommonInternal INTERFACE
Expand Down

0 comments on commit d2a0202

Please sign in to comment.