From 47a8a65022e3fd7624c95d0341b4809aad11fddb Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Mon, 20 Sep 2021 01:44:17 +0200 Subject: use MSVC's /Zc:inline option to reduce binary size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If I'm getting it right, MSVC has a non-conforming feature that allows to declare a function as inline without defining its body in the header, and it'll work if the function is actually emitted elsewhere, and the linker will sort it out. This seems to be implemented by forcing emitting of out-of-line copies of all inline functions, which is wasteful. /Zc:inline disables this useless feature, which seems to save quite some space (optimized build, starmath's .o files 350k->220k, smlo.dll 2.5M->2.2M). The docs don't say anything about binary compatibility, but treat it the same way as -Zc:dllexportInlines, just in case. This change also may help avoid the tdf#144598 problem for our AVX/etc. code, such as in Calc. Change-Id: I73cc5d46ba1e4245e8d3b6688804c2b9684d2f9a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122334 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- solenv/gbuild/LinkTarget.mk | 1 + solenv/gbuild/platform/com_MSC_class.mk | 3 ++- solenv/gbuild/platform/com_MSC_defs.mk | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'solenv') diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk index 29924c9897e0..91dc20adc72f 100644 --- a/solenv/gbuild/LinkTarget.mk +++ b/solenv/gbuild/LinkTarget.mk @@ -2015,6 +2015,7 @@ endef # gb_LinkTarget_use_vclmain # break public ABI. # call gb_LinkTarget_set_is_ure_library,linktarget,,linktargetmakefilename define gb_LinkTarget_set_is_ure_library +$(call gb_LinkTarget_add_cxxflags,$(1),$(gb_CXXFLAGS_ZCINLINE_OFF)) ifeq ($(HAVE_DLLEXPORTINLINES),TRUE) $(call gb_LinkTarget_add_cxxflags,$(1),-Zc:dllexportInlines) endif diff --git a/solenv/gbuild/platform/com_MSC_class.mk b/solenv/gbuild/platform/com_MSC_class.mk index 80944fe70ba4..3ea82e6c4936 100644 --- a/solenv/gbuild/platform/com_MSC_class.mk +++ b/solenv/gbuild/platform/com_MSC_class.mk @@ -48,9 +48,10 @@ endef # Avoid annoying warning D9025 about overriding command-line arguments. gb_Helper_remove_overridden_flags = \ $(lastword $(filter -W4 -w,$(1))) \ - $(filter-out -W4 -w -arch:SSE -arch:SSE2 -arch:AVX -arch:AVX2 -Od -O2 -Zc:dllexportInlines -Zc:dllexportInlines-,$(1)) \ + $(filter-out -W4 -w -arch:SSE -arch:SSE2 -arch:AVX -arch:AVX2 -Od -O2 -Zc:inline -Zc:inline- -Zc:dllexportInlines -Zc:dllexportInlines-,$(1)) \ $(lastword $(filter -Od -O2,$(1))) \ $(lastword $(filter -arch:SSE -arch:SSE2 -arch:AVX -arch:AVX2,$(1))) \ + $(lastword $(filter -Zc:inline -Zc:inline-,$(1))) \ $(lastword $(filter -Zc:dllexportInlines -Zc:dllexportInlines-,$(1))) # $(call gb_CObject__command_pattern,object,flags,source,dep-file,compiler-plugins,symbols,compiler) diff --git a/solenv/gbuild/platform/com_MSC_defs.mk b/solenv/gbuild/platform/com_MSC_defs.mk index 273e17ea71f0..8dccadd1f743 100644 --- a/solenv/gbuild/platform/com_MSC_defs.mk +++ b/solenv/gbuild/platform/com_MSC_defs.mk @@ -133,6 +133,7 @@ gb_CXXFLAGS := \ -Gs \ -GS \ -Gy \ + -Zc:inline \ $(if $(MSVC_USE_DEBUG_RUNTIME),-MDd,-MD) \ -nologo \ -W4 \ @@ -148,6 +149,8 @@ gb_CXXFLAGS := \ -wd4706 \ -bigobj \ +gb_CXXFLAGS_ZCINLINE_OFF := -Zc:inline- + ifeq ($(CPUNAME),INTEL) gb_CXXFLAGS += \ -- cgit