From 18958c6298bf5cc5495375e2940b640b04ec9ccb Mon Sep 17 00:00:00 2001 From: Jiangli Zhou Date: Thu, 13 Feb 2025 15:44:46 +0000 Subject: [PATCH] 8349925: [REDO] Support static JDK in libfontmanager/freetypeScaler.c Reviewed-by: prr --- .../java.desktop/lib/ClientLibraries.gmk | 1 + .../native/libfontmanager/freetypeScaler.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/make/modules/java.desktop/lib/ClientLibraries.gmk b/make/modules/java.desktop/lib/ClientLibraries.gmk index 80845899ec4..6599f655c10 100644 --- a/make/modules/java.desktop/lib/ClientLibraries.gmk +++ b/make/modules/java.desktop/lib/ClientLibraries.gmk @@ -407,6 +407,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBFONTMANAGER, \ LDFLAGS_aix := -Wl$(COMMA)-berok, \ JDK_LIBS := libawt java.base:libjava $(LIBFONTMANAGER_JDK_LIBS), \ JDK_LIBS_macosx := libawt_lwawt, \ + JDK_LIBS_unix := java.base:libjvm, \ LIBS := $(LIBFONTMANAGER_LIBS), \ LIBS_unix := $(LIBM), \ LIBS_macosx := \ diff --git a/src/java.desktop/share/native/libfontmanager/freetypeScaler.c b/src/java.desktop/share/native/libfontmanager/freetypeScaler.c index 37c6dba2a78..8b7e147c72c 100644 --- a/src/java.desktop/share/native/libfontmanager/freetypeScaler.c +++ b/src/java.desktop/share/native/libfontmanager/freetypeScaler.c @@ -32,6 +32,7 @@ #include #if !defined(_WIN32) && !defined(__APPLE_) #include +#include "jvm.h" #endif #include #include "ft2build.h" @@ -298,6 +299,21 @@ static void setInterpreterVersion(FT_Library library) { #if defined(_WIN32) || defined(__APPLE__) FT_Property_Set(library, module, property, (void*)(&version)); #else + + FT_Prop_Set_Func func = NULL; + if (JVM_IsStaticallyLinked()) { + // The bundled libfreetype may be statically linked with + // the launcher. + func = (FT_Prop_Set_Func)dlsym(RTLD_DEFAULT, "FT_Property_Set"); + if (func != NULL) { + func(library, module, property, (void*)(&version)); + return; + } + + // libfreetype is not statically linked with the executable, + // fall through to find the system provided library dynamically. + } + void *lib = dlopen("libfreetype.so", RTLD_LOCAL|RTLD_LAZY); if (lib == NULL) { lib = dlopen("libfreetype.so.6", RTLD_LOCAL|RTLD_LAZY); @@ -305,7 +321,7 @@ static void setInterpreterVersion(FT_Library library) { return; } } - FT_Prop_Set_Func func = (FT_Prop_Set_Func)dlsym(lib, "FT_Property_Set"); + func = (FT_Prop_Set_Func)dlsym(lib, "FT_Property_Set"); if (func != NULL) { func(library, module, property, (void*)(&version)); }