From 43ec023e1a730f7f5bce89d0e16508a213894098 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 3 Jun 2025 07:56:13 +0200 Subject: [PATCH] * src/autofit/ft-hb.c: Fix usage of `RTLD_DEFAULT`. Using `RTLD_DEFAULT` we see whether the process already has HarfBuzz linked in, and reuse it. If this symbol is not defined it is tempting to use `RTLD_GLOBAL` instead, which would make the library available to the whole process. However, without `RTLD_DEFAULT`, we would risk loading a second HarfBuzz library, and if the linker mixes them up, probably giving symbols from the new library to other clients, we might get into trouble. For this reason, we do not pass `RTLD_GLOBAL` to `dlopen`; the default is `RTLD_LOCAL`, and the rest of the process won't see the loaded HarfBuzz and hopefully all be happy. --- src/autofit/ft-hb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/autofit/ft-hb.c b/src/autofit/ft-hb.c index 105d14924..8ea7192d6 100644 --- a/src/autofit/ft-hb.c +++ b/src/autofit/ft-hb.c @@ -45,6 +45,7 @@ #else /* !_WIN32 */ +# define _GNU_SOURCE 1 /* for RTLD_DEFAULT */ # include /* The GCC pragma suppresses the warning "ISO C forbids */ @@ -96,8 +97,11 @@ #else /* !_WIN32 */ - lib = RTLD_DEFAULT; +# ifdef RTLD_DEFAULT + lib = RTLD_DEFAULT; version_atleast = DLSYM( lib, hb_version_atleast ); +# endif + if ( !version_atleast ) { /* Load the HarfBuzz library.