summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2022-09-20 16:07:14 +0300
committerTor Lillqvist <tml@collabora.com>2023-02-09 13:47:02 +0000
commitd552b4a549d614a03aa9328e017dec27bd3ff41e (patch)
tree8c9e0021b94f37ca6d2add345932751d060c25b5 /external
parent1854f8ae2cf5966db1b51968dafc27785d3b7a11 (diff)
Enable opening of downloaded fonts only in ForKit in Online
We want that only the ForKit process needs to have access to new font files added to a Collabora Online instance dynamically by downloading from a server. There are however many locations in the Kit process, in core and in external libraries like harfbuzz, where the code wants to open a font file. Handle this so that the ForKit process opens such a downloaded font file and doesn't close it. The file descriptor is thus inherited by Kit processes. The font file pathname passed on to other code is a fake on in the format "/:FD:/%d" where the %d is the file descriptor of the opened font file. Add checks in all places where font files are opened, look for this special pathname format, and modify the code to just dup() the already open file descriptor in that case. All this is relevant for Linux only, as Collabora Online runs on Linux. Do the above for harfbuzz, cairo, fontconfig, and freetype. In addition make sure that these libraries (except harfbuzz which needs to be a static library and freetype) when bundled, on Linux, are built as shared libraries, and won't be confused with the corresponding system libraries by making sure their sonames are different. Change-Id: Ib059cb27e1637d07bb709249abd0d984f948caa9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140714 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146341 Tested-by: Jenkins
Diffstat (limited to 'external')
-rw-r--r--external/cairo/ExternalPackage_cairo.mk3
-rw-r--r--external/cairo/UnpackedTarball_cairo.mk2
-rw-r--r--external/cairo/cairo/cairo-fd-hack.patch.015
-rw-r--r--external/cairo/cairo/libcairo-bundled-soname.patch.012
-rw-r--r--external/fontconfig/ExternalPackage_fontconfig.mk16
-rw-r--r--external/fontconfig/ExternalProject_fontconfig.mk15
-rw-r--r--external/fontconfig/Module_fontconfig.mk1
-rw-r--r--external/fontconfig/UnpackedTarball_fontconfig.mk1
-rw-r--r--external/fontconfig/libfontconfig-bundled-soname.patch.011
-rw-r--r--external/freetype/ExternalProject_freetype.mk2
-rw-r--r--external/freetype/UnpackedTarball_freetype.mk1
-rw-r--r--external/freetype/freetype-fd-hack.patch.053
-rw-r--r--external/harfbuzz/UnpackedTarball_harfbuzz.mk3
-rw-r--r--external/harfbuzz/harfbuzz-fd-hack.patch.024
14 files changed, 155 insertions, 4 deletions
diff --git a/external/cairo/ExternalPackage_cairo.mk b/external/cairo/ExternalPackage_cairo.mk
index 116db8a3499d..74a46688406a 100644
--- a/external/cairo/ExternalPackage_cairo.mk
+++ b/external/cairo/ExternalPackage_cairo.mk
@@ -12,7 +12,8 @@ $(eval $(call gb_ExternalPackage_ExternalPackage,cairo,cairo))
$(eval $(call gb_ExternalPackage_use_external_project,cairo,cairo))
ifneq ($(DISABLE_DYNLOADING),TRUE)
-$(eval $(call gb_ExternalPackage_add_file,cairo,$(LIBO_LIB_FOLDER)/libcairo.so.2,src/.libs/libcairo.so.2.1170$(CAIRO_VERSION_MICRO).0))
+$(eval $(call gb_ExternalPackage_add_file,cairo,$(LIBO_LIB_FOLDER)/libcairo-lo.so.2.1170$(CAIRO_VERSION_MICRO).0,src/.libs/libcairo-lo.so.2.1170$(CAIRO_VERSION_MICRO).0))
+$(eval $(call gb_ExternalPackage_add_file,cairo,$(LIBO_LIB_FOLDER)/libcairo-lo.so.2,src/.libs/libcairo-lo.so.2))
endif
# vim: set noet sw=4 ts=4:
diff --git a/external/cairo/UnpackedTarball_cairo.mk b/external/cairo/UnpackedTarball_cairo.mk
index 8353adb32035..de1d9296434d 100644
--- a/external/cairo/UnpackedTarball_cairo.mk
+++ b/external/cairo/UnpackedTarball_cairo.mk
@@ -28,6 +28,8 @@ $(eval $(call gb_UnpackedTarball_add_patches,cairo,\
external/cairo/cairo/cairo.ofz46165.patch.1 \
external/cairo/cairo/cairo.ofz50805.patch.1 \
external/cairo/cairo/0025-libtool-pass-use-ld.patch \
+ external/cairo/cairo/libcairo-bundled-soname.patch.0 \
+ external/cairo/cairo/cairo-fd-hack.patch.0 \
))
ifeq ($(OS),iOS)
diff --git a/external/cairo/cairo/cairo-fd-hack.patch.0 b/external/cairo/cairo/cairo-fd-hack.patch.0
new file mode 100644
index 000000000000..e5d980e94dfb
--- /dev/null
+++ b/external/cairo/cairo/cairo-fd-hack.patch.0
@@ -0,0 +1,15 @@
+# -*- Mode: Diff -*-
+--- src/cairo-ft-font.c
++++ src/cairo-ft-font.c
+@@ -737,7 +737,10 @@
+ if (ret == FcResultOutOfMemory)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ if (ret == FcResultMatch) {
+- if (access (filename, R_OK) == 0) {
++ int nFD = -1;
++ int n;
++ if ((sscanf (filename, "/:FD:/%d%n", &nFD, &n) == 1 && filename[n] == '\0') ||
++ access (filename, R_OK) == 0) {
+ /* If FC_INDEX is not set, we just use 0 */
+ ret = FcPatternGetInteger (pattern, FC_INDEX, 0, &id);
+ if (ret == FcResultOutOfMemory)
diff --git a/external/cairo/cairo/libcairo-bundled-soname.patch.0 b/external/cairo/cairo/libcairo-bundled-soname.patch.0
new file mode 100644
index 000000000000..92aac5f753df
--- /dev/null
+++ b/external/cairo/cairo/libcairo-bundled-soname.patch.0
@@ -0,0 +1,12 @@
+# -*- Mode: Diff -*-
+--- src/Makefile.in
++++ src/Makefile.in
+@@ -2075,7 +2075,7 @@
+ $(enabled_cairo_sources) \
+ $(NULL)
+
+-libcairo_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols)
++libcairo_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols) -release lo -Wl,-soname -Wl,libcairo-lo.so.2
+ libcairo_la_LIBADD = $(CAIRO_LIBS)
+ libcairo_la_DEPENDENCIES = $(cairo_def_dependency)
+
diff --git a/external/fontconfig/ExternalPackage_fontconfig.mk b/external/fontconfig/ExternalPackage_fontconfig.mk
new file mode 100644
index 000000000000..7114f80d9507
--- /dev/null
+++ b/external/fontconfig/ExternalPackage_fontconfig.mk
@@ -0,0 +1,16 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_ExternalPackage_ExternalPackage,fontconfig,fontconfig))
+
+$(eval $(call gb_ExternalPackage_use_external_project,fontconfig,fontconfig))
+
+$(eval $(call gb_ExternalPackage_add_file,fontconfig,$(LIBO_LIB_FOLDER)/libfontconfig-lo.so.1.12.0,src/.libs/libfontconfig-lo.so.1.12.0))
+
+# vim: set noet sw=4 ts=4:
diff --git a/external/fontconfig/ExternalProject_fontconfig.mk b/external/fontconfig/ExternalProject_fontconfig.mk
index 88db225f88fc..3bbecf1d672a 100644
--- a/external/fontconfig/ExternalProject_fontconfig.mk
+++ b/external/fontconfig/ExternalProject_fontconfig.mk
@@ -18,6 +18,9 @@ $(eval $(call gb_ExternalProject_register_targets,fontconfig,\
build \
))
+# Can't have this inside the $(call gb_ExternalProject_run as it contains commas
+fontconfig_add_fonts=/usr/share/X11/fonts/Type1,/usr/share/X11/fonts/TTF,/usr/local/share/fonts
+
$(call gb_ExternalProject_get_state_target,fontconfig,build) :
$(call gb_Trace_StartRange,fontconfig,EXTERNAL)
$(call gb_ExternalProject_run,build,\
@@ -26,23 +29,31 @@ $(call gb_ExternalProject_get_state_target,fontconfig,build) :
$(gb_VISIBILITY_FLAGS) \
$(if $(filter EMSCRIPTEN,$(OS)),-pthread)" \
$(if $(filter ANDROID,$(OS)),LIBS="-lm") \
- LDFLAGS="$(call gb_ExternalProject_get_link_flags,fontconfig)" \
$(if $(filter EMSCRIPTEN,$(OS)),LIBXML2_CFLAGS="$(LIBXML_CFLAGS)" LIBXML2_LIBS="$(LIBXML_LIBS)") \
$(gb_RUN_CONFIGURE) ./configure \
- --disable-shared \
--disable-silent-rules \
--with-pic \
$(if $(filter ANDROID,$(OS)),--with-arch=arm) \
--with-expat-includes=$(call gb_UnpackedTarball_get_dir,expat)/lib \
--with-expat-lib=$(gb_StaticLibrary_WORKDIR) \
$(gb_CONFIGURE_PLATFORMS) \
+ $(if $(filter ANDROID,$(OS)), \
+ --disable-shared \
+ ) \
$(if $(filter EMSCRIPTEN,$(OS)), \
+ --disable-shared \
--with-baseconfigdir=/instdir/share/fontconfig \
--with-cache-dir=/instdir/share/fontconfig/cache \
--with-add-fonts=/instdir/share/fonts \
--enable-libxml2 \
ac_cv_func_fstatfs=no ac_cv_func_fstatvfs=no \
) \
+ $(if $(filter LINUX,$(OS)), \
+ --disable-static \
+ --prefix=/ \
+ --with-add-fonts=$(fontconfig_add_fonts) \
+ --with-cache-dir=/usr/lib/fontconfig/cache \
+ ) \
&& $(MAKE) -C src && $(MAKE) fonts.conf \
)
$(call gb_Trace_EndRange,fontconfig,EXTERNAL)
diff --git a/external/fontconfig/Module_fontconfig.mk b/external/fontconfig/Module_fontconfig.mk
index 2f8f9c8f54d6..61f201d415b6 100644
--- a/external/fontconfig/Module_fontconfig.mk
+++ b/external/fontconfig/Module_fontconfig.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_Module_Module,fontconfig))
$(eval $(call gb_Module_add_targets,fontconfig,\
ExternalProject_fontconfig \
$(if $(filter EMSCRIPTEN,$(OS)),ExternalPackage_fontconfig_data) \
+ $(if $(filter LINUX,$(OS)),ExternalPackage_fontconfig) \
UnpackedTarball_fontconfig \
))
diff --git a/external/fontconfig/UnpackedTarball_fontconfig.mk b/external/fontconfig/UnpackedTarball_fontconfig.mk
index f41b21cdf552..ceb87ea062ad 100644
--- a/external/fontconfig/UnpackedTarball_fontconfig.mk
+++ b/external/fontconfig/UnpackedTarball_fontconfig.mk
@@ -16,6 +16,7 @@ $(eval $(call gb_UnpackedTarball_set_patchlevel,fontconfig,0))
$(eval $(call gb_UnpackedTarball_add_patches,fontconfig,\
external/fontconfig/fontconfig-2.12.1.patch.1 \
external/fontconfig/ubsan.patch \
+ external/fontconfig/libfontconfig-bundled-soname.patch.0 \
))
# vim: set noet sw=4 ts=4:
diff --git a/external/fontconfig/libfontconfig-bundled-soname.patch.0 b/external/fontconfig/libfontconfig-bundled-soname.patch.0
new file mode 100644
index 000000000000..390338e957e8
--- /dev/null
+++ b/external/fontconfig/libfontconfig-bundled-soname.patch.0
@@ -0,0 +1,11 @@
+# -*- Mode: Diff -*-
+--- src/Makefile.in
++++ src/Makefile.in
+@@ -525,6 +525,6 @@
+ lib_LTLIBRARIES = libfontconfig.la
+ libfontconfig_la_LDFLAGS = \
+- -version-info @LIBT_VERSION_INFO@ -no-undefined $(export_symbols)
++ -version-info @LIBT_VERSION_INFO@ -no-undefined $(export_symbols) -release lo -Wl,-soname -Wl,libfontconfig-lo.so.1.12.0
+
+ libfontconfig_la_LIBADD = $(ICONV_LIBS) $(FREETYPE_LIBS) $(LIBXML2_LIBS) $(EXPAT_LIBS) $(LTLIBINTL)
+ libfontconfig_la_DEPENDENCIES = $(fontconfig_def_dependency)
diff --git a/external/freetype/ExternalProject_freetype.mk b/external/freetype/ExternalProject_freetype.mk
index 04c11cf794b8..e9720065490c 100644
--- a/external/freetype/ExternalProject_freetype.mk
+++ b/external/freetype/ExternalProject_freetype.mk
@@ -28,9 +28,9 @@ $(call gb_ExternalProject_get_state_target,freetype,build) :
$(gb_CONFIGURE_PLATFORMS) \
CFLAGS="$(CFLAGS) \
$(call gb_ExternalProject_get_build_flags,freetype) \
+ $(call gb_ExternalProject_get_link_flags,freetype) \
$(gb_VISIBILITY_FLAGS) \
$(gb_EMSCRIPTEN_CPPFLAGS)" \
- LDFLAGS="$(call gb_ExternalProject_get_link_flags,freetype)" \
&& $(MAKE) install \
&& touch $@ )
$(call gb_Trace_EndRange,freetype,EXTERNAL)
diff --git a/external/freetype/UnpackedTarball_freetype.mk b/external/freetype/UnpackedTarball_freetype.mk
index 076edb9e3d97..5ea678f80280 100644
--- a/external/freetype/UnpackedTarball_freetype.mk
+++ b/external/freetype/UnpackedTarball_freetype.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_UnpackedTarball_set_tarball,freetype,$(FREETYPE_TARBALL),,freet
$(eval $(call gb_UnpackedTarball_add_patches,freetype,\
external/freetype/freetype-2.6.5.patch.1 \
external/freetype/ubsan.patch \
+ external/freetype/freetype-fd-hack.patch.0 \
))
$(eval $(call gb_UnpackedTarball_set_patchlevel,freetype,0))
diff --git a/external/freetype/freetype-fd-hack.patch.0 b/external/freetype/freetype-fd-hack.patch.0
new file mode 100644
index 000000000000..db2bdc9e92f6
--- /dev/null
+++ b/external/freetype/freetype-fd-hack.patch.0
@@ -0,0 +1,53 @@
+# -*- Mode: Diff -*-
+--- src/base/ftsystem.c
++++ src/base/ftsystem.c
+@@ -237,6 +237,8 @@
+ const char* filepathname )
+ {
+ FT_FILE* file;
++ int nFD;
++ int n;
+
+
+ if ( !stream )
+@@ -257,7 +257,13 @@
+ stream->read = NULL;
+ stream->close = NULL;
+
+- file = ft_fopen( filepathname, "rb" );
++ if ( sscanf( filepathname, "/:FD:/%d%n", &nFD, &n ) == 1 && filepathname[n] == '\0')
++ {
++ lseek( nFD, 0, SEEK_SET );
++ file = fdopen( dup( nFD ), "rb" );
++ }
++ else
++ file = ft_fopen( filepathname, "rb" );
+ if ( !file )
+ {
+ FT_ERROR(( "FT_Stream_Open:"
+--- builds/unix/ftsystem.c
++++ builds/unix/ftsystem.c
+@@ -249,6 +249,8 @@
+ {
+ int file;
+ struct stat stat_buf;
++ int nFD;
++ int n;
+
+
+ if ( !stream )
+@@ -255,7 +255,13 @@
+ return FT_THROW( Invalid_Stream_Handle );
+
+ /* open the file */
+- file = open( filepathname, O_RDONLY );
++ if ( sscanf( filepathname, "/:FD:/%d%n", &nFD, &n ) == 1 && filepathname[n] == '\0')
++ {
++ lseek( nFD, 0, SEEK_SET );
++ file = dup( nFD );
++ }
++ else
++ file = open( filepathname, O_RDONLY );
+ if ( file < 0 )
+ {
+ FT_ERROR(( "FT_Stream_Open:" ));
diff --git a/external/harfbuzz/UnpackedTarball_harfbuzz.mk b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
index 9bc9e326b426..37c5946a5ce4 100644
--- a/external/harfbuzz/UnpackedTarball_harfbuzz.mk
+++ b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
@@ -16,6 +16,9 @@ $(eval $(call gb_UnpackedTarball_update_autoconf_configs,harfbuzz))
$(eval $(call gb_UnpackedTarball_set_patchlevel,harfbuzz,0))
$(eval $(call gb_UnpackedTarball_add_patches,harfbuzz, \
+ $(if $(filter LINUX,$(OS)), \
+ external/harfbuzz/harfbuzz-fd-hack.patch.0 \
+ ) \
))
# vim: set noet sw=4 ts=4:
diff --git a/external/harfbuzz/harfbuzz-fd-hack.patch.0 b/external/harfbuzz/harfbuzz-fd-hack.patch.0
new file mode 100644
index 000000000000..1cc5820fd49c
--- /dev/null
+++ b/external/harfbuzz/harfbuzz-fd-hack.patch.0
@@ -0,0 +1,24 @@
+# -*- Mode: Diff -*-
+--- src/hb-blob.cc
++++ src/hb-blob.cc
+@@ -737,7 +737,19 @@
+ char *data = (char *) hb_malloc (allocated);
+ if (unlikely (!data)) return nullptr;
+
+- FILE *fp = fopen (file_name, "rb");
++ FILE *fp;
++ int nFD;
++ int n;
++ if (sscanf (file_name, "/:FD:/%d%n", &nFD, &n) == 1 && file_name[n] == '\0')
++ {
++ lseek (nFD, 0, SEEK_SET);
++ fp = fdopen (dup (nFD), "rb");
++ }
++ else
++ {
++ fp = fopen (file_name, "rb");
++ }
++
+ if (unlikely (!fp)) goto fread_fail_without_close;
+
+ while (!feof (fp))