use clang-cl's -Zc:dllexportInlines- for Skia (tdf#144598)
This is clang-cl's equivalent of -fvisibility-inlines-hidden,
and it seems to be also sort of the equivalent of MSVC's
-Zc:inline. So it saves build time and disk space.
As an additional effect, this disables emitting copies
of inlines functions in every .o file where the function
is called (even if inlined), which means that it hopefully
avoids the problem of SkOpts_avx.cpp generating a copy
of SkRect::round() which would include AVX code, and
the linker might select this as the instance of SkRect::round()
to keep, thus making SSE2 code call AVX code without checking
for AVX availability first.
Change-Id: I97541ae11d05f489894bc9233271eb21fd520f43
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122335
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
diff --git a/config_host.mk.in b/config_host.mk.in
index 87d5fed..3aa51a3 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -266,6 +266,7 @@
export HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED=@HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED@
export HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW=@HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW@
export HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR=@HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR@
export HAVE_LO_CLANG_DLLEXPORTINLINES=@HAVE_LO_CLANG_DLLEXPORTINLINES@
export HAVE_GCC_AVX=@HAVE_GCC_AVX@
export HAVE_GCC_BUILTIN_ATOMIC=@HAVE_GCC_BUILTIN_ATOMIC@
export HAVE_GCC_FNO_ENFORCE_EH_SPECS=@HAVE_GCC_FNO_ENFORCE_EH_SPECS@
diff --git a/configure.ac b/configure.ac
index 0a2d098..fde9600 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12035,6 +12035,7 @@
LO_CLANG_CXXFLAGS_INTRINSICS_AVX512F=
LO_CLANG_CXXFLAGS_INTRINSICS_F16C=
LO_CLANG_CXXFLAGS_INTRINSICS_FMA=
HAVE_LO_CLANG_DLLEXPORTINLINES=
if test "$ENABLE_SKIA" = TRUE -a "$COM_IS_CLANG" != TRUE -a ! \( "$_os" = "WINNT" -a "$CPUNAME" = "AARCH64" \); then
if test -n "$LO_CLANG_CC" -a -n "$LO_CLANG_CXX"; then
@@ -12066,6 +12067,24 @@
LO_CLANG_CXX=
fi
fi
if test -n "$LO_CLANG_CC" -a -n "$LO_CLANG_CXX" -a "$_os" = "WINNT"; then
save_CXX="$CXX"
CXX="$LO_CLANG_CXX"
AC_MSG_CHECKING([whether $CXX supports -Zc:dllexportInlines-])
AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS -Werror -Zc:dllexportInlines-"
AC_COMPILE_IFELSE([AC_LANG_SOURCE()], [
HAVE_LO_CLANG_DLLEXPORTINLINES=TRUE
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])])
CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++])
CXX="$save_CXX"
if test -z "$HAVE_LO_CLANG_DLLEXPORTINLINES"; then
AC_MSG_ERROR([Clang compiler does not support -Zc:dllexportInlines-. The Skia library needs to be built using a newer Clang version, or use --disable-skia.])
fi
fi
if test -z "$LO_CLANG_CC" -o -z "$LO_CLANG_CXX"; then
# Skia is the default on Windows, so hard-require Clang.
# Elsewhere it's used just by the 'gen' VCL backend which is rarely used.
@@ -12345,6 +12364,7 @@
AC_SUBST(LO_CLANG_CXXFLAGS_INTRINSICS_F16C)
AC_SUBST(LO_CLANG_CXXFLAGS_INTRINSICS_FMA)
AC_SUBST(CLANG_USE_LD)
AC_SUBST([HAVE_LO_CLANG_DLLEXPORTINLINES])
SYSTEM_GPGMEPP=
diff --git a/external/skia/Library_skia.mk b/external/skia/Library_skia.mk
index 60b8a3c..b1b4f87 100644
--- a/external/skia/Library_skia.mk
+++ b/external/skia/Library_skia.mk
@@ -59,6 +59,17 @@
usp10 \
gdi32 \
))
# cl.exe (and thus clang-cl) likes to emit copies of inline functions even when not needed,
# which means that for e.g. AVX-compiled sources the .o may contain a copy of an inline
# function built using AVX, and the linker may select that copy as the one to keep, thus
# introducing AVX code into generic code. Avoid generating such inlines. The flag currently
# cannot be used for the whole Skia, because code built without the flag cannot use
# libraries built with the flag, so cl.exe-built VCL would have undefined references.
ifeq ($(HAVE_LO_CLANG_DLLEXPORTINLINES),TRUE)
LO_SKIA_AVOID_INLINE_COPIES := -Zc:dllexportInlines-
endif
else ifeq ($(OS),MACOSX)
$(eval $(call gb_Library_use_system_darwin_frameworks,skia,\
@@ -830,20 +841,25 @@
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_avx, $(CXXFLAGS_INTRINSICS_AVX) $(LO_CLANG_CXXFLAGS_INTRINSICS_AVX) \
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_hsw, \
$(CXXFLAGS_INTRINSICS_AVX2) $(CXXFLAGS_INTRINSICS_F16C) $(CXXFLAGS_INTRINSICS_FMA) \
$(LO_CLANG_CXXFLAGS_INTRINSICS_AVX2) $(LO_CLANG_CXXFLAGS_INTRINSICS_F16C) $(LO_CLANG_CXXFLAGS_INTRINSICS_FMA) \
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_sse41, $(CXXFLAGS_INTRINSICS_SSE41) $(LO_CLANG_CXXFLAGS_INTRINSICS_SSE41) \
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_sse42, $(CXXFLAGS_INTRINSICS_SSE42) $(LO_CLANG_CXXFLAGS_INTRINSICS_SSE42) \
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_ssse3, $(CXXFLAGS_INTRINSICS_SSSE3) $(LO_CLANG_CXXFLAGS_INTRINSICS_SSSE3) \
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_crc32 \
@@ -851,6 +867,7 @@
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
UnpackedTarball/skia/src/opts/SkOpts_skx, $(CXXFLAGS_INTRINSICS_AVX512) $(LO_CLANG_CXXFLAGS_INTRINSICS_AVX512)\
$(LO_SKIA_AVOID_INLINE_COPIES) \
))
$(eval $(call gb_Library_add_generated_exception_objects,skia,\
diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk
index 1daf321..9c7e9e3 100644
--- a/solenv/gbuild/LinkTarget.mk
+++ b/solenv/gbuild/LinkTarget.mk
@@ -1824,7 +1824,6 @@
# call gb_LinkTarget_set_clang_precompiled_header,linktarget,pchcxxfile,,linktargetmakefilename
define gb_LinkTarget_set_clang_precompiled_header
$(call gb_LinkTarget_set_precompiled_header,$(1),$(2),$(3),$(4),$(LO_CLANG_CXX))
endef
# call gb_LinkTarget__reuse_precompiled_header_impl,linktarget,pchcxxfile,pchtarget,linktargetmakefilename
@@ -1985,7 +1984,6 @@
$(call gb_LinkTarget_get_target,$(1)) : T_CC := $(LO_CLANG_CC)
$(call gb_LinkTarget_get_target,$(1)) : T_CXX := $(LO_CLANG_CXX)
$(call gb_LinkTarget_get_target,$(1)) : T_USE_LD := $(or $(CLANG_USE_LD),$(USE_LD))
endef
# call gb_LinkTarget_use_glxtest,linktarget,add_libs