Add HAVE_(UNIX_)DLAPI config header define

..., add the configure test flags and rename DLOPEN_LIBS to
UNIX_DLAPI_LIBS.

Initinally convert two dlsym callers to use HAVE_DLAPI and
osl_getAsciiFunctionSymbol.

There are a lot of places, which still use -ldl and even more
direct dlsym calls; good opportunity for many simple EasyHacks.

Change-Id: I4f2d2f7cb079a075af8f9d01eb5ee45de40c7f03
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128523
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
This commit is contained in:
Jan-Marek Glogowski
2022-01-18 13:44:53 +01:00
parent 31700036e5
commit b5b1eae538
15 changed files with 75 additions and 44 deletions
+1 -1
View File
@@ -126,7 +126,6 @@ export DICT_SYSTEM_DIR=@DICT_SYSTEM_DIR@
export DISABLE_CVE_TESTS=@DISABLE_CVE_TESTS@
export DISABLE_DYNLOADING=@DISABLE_DYNLOADING@
export DISABLE_PYTHON=@DISABLE_PYTHON@
export DLOPEN_LIBS=@DLOPEN_LIBS@
export DOCDIR=@DOCDIR@
export DOXYGEN=@DOXYGEN@
export DO_FETCH_TARBALLS=@DO_FETCH_TARBALLS@
@@ -668,6 +667,7 @@ export TOUCH=@TOUCH@
export UCRTSDKDIR=@UCRTSDKDIR@
export UCRTVERSION=@UCRTVERSION@
export UCRT_REDISTDIR=@UCRT_REDISTDIR@
export UNIX_DLAPI_LIBS=@UNIX_DLAPI_LIBS@
export USE_HEADLESS_CODE=@USE_HEADLESS_CODE@
export USE_LD=@USE_LD@
export USE_LIBRARY_BIN_TAR=@USE_LIBRARY_BIN_TAR@
+7
View File
@@ -43,4 +43,11 @@ Any change in this header will cause a rebuild of almost everything.
bogus -Werror=redundant-move (GCC 9)". */
#define HAVE_P1155R3 0
// Whether the OS provides a usable dynamcic loading API
#define HAVE_DLAPI 0
// Whether the OS uses the common UNIX dynamcic loading API calls, like dlopen, dlsym, dladdr etc.
// Use HAVE_DLAPI instead. Should not be used outside of sal/osl/unx/module.cxx!
#define HAVE_UNIX_DLAPI 0
#endif
+18 -7
View File
@@ -823,6 +823,7 @@ test_gdb_index=no
test_openldap=yes
test_split_debug=no
test_webdav=yes
usable_dlapi=yes
# There is currently just iOS not using salplug, so this explicitly enables it.
# must: using_freetype_fontconfig
@@ -909,6 +910,7 @@ cygwin*|wsl*)
using_freetype_fontconfig=no
using_x11=no
test_unix_dlapi=no
test_openldap=no
test_eot=no
enable_pagein=no
@@ -1069,6 +1071,8 @@ dragonfly*)
;;
linux-android*)
# API exists, but seems not really usable since Android 7 AFAIK
usable_dlapi=no
using_freetype_fontconfig=yes
using_headless_plugin=no
using_x11=no
@@ -1104,6 +1108,8 @@ haiku*)
;;
emscripten)
# API currently just exists in headers, not code
usable_dlapi=no
using_freetype_fontconfig=yes
using_x11=no
test_openldap=no
@@ -1190,6 +1196,7 @@ fi
AC_SUBST(ENABLE_HEADLESS)
AC_SUBST(USE_HEADLESS_CODE)
AC_MSG_NOTICE([VCL platform has a usable dynamic loading API: $usable_dlapi])
AC_MSG_NOTICE([VCL platform uses freetype+fontconfig: $using_freetype_fontconfig])
AC_MSG_NOTICE([VCL platform uses headless plugin: $using_headless_plugin])
AC_MSG_NOTICE([VCL platform uses X11: $using_x11])
@@ -1334,14 +1341,18 @@ else
fi
AC_SUBST(ENDIANNESS)
if test $_os != "WINNT"; then
save_LIBS="$LIBS"
AC_SEARCH_LIBS([dlsym], [dl],
[case "$ac_cv_search_dlsym" in -l*) DLOPEN_LIBS="$ac_cv_search_dlsym";; esac],
[AC_MSG_ERROR([dlsym not found in either libc nor libdl])])
LIBS="$save_LIBS"
if test "$usable_dlapi" != no; then
AC_DEFINE([HAVE_DLAPI])
if test "$test_unix_dlapi" != no; then
save_LIBS="$LIBS"
AC_SEARCH_LIBS([dlsym], [dl],
[case "$ac_cv_search_dlsym" in -l*) UNIX_DLAPI_LIBS="$ac_cv_search_dlsym";; esac],
[AC_MSG_ERROR([dlsym not found in either libc nor libdl])])
LIBS="$save_LIBS"
AC_DEFINE([HAVE_UNIX_DLAPI])
fi
fi
AC_SUBST(DLOPEN_LIBS)
AC_SUBST(UNIX_DLAPI_LIBS)
# Check for a (GNU) backtrace implementation
AC_ARG_VAR([BACKTRACE_CFLAGS], [Compiler flags needed to use backtrace(3)])
+1 -1
View File
@@ -25,7 +25,7 @@ $(eval $(call gb_Library_add_defs,crashreport,\
$(eval $(call gb_Library_add_libs,crashreport,\
$(if $(filter LINUX %BSD SOLARIS, $(OS)), \
$(DLOPEN_LIBS) \
$(UNIX_DLAPI_LIBS) \
) \
))
+2
View File
@@ -25,6 +25,8 @@
#define INCLUDED_OSL_MODULE_H
#include "sal/config.h"
// convenience include for HAVE_DLAPI define
#include "config_global.h"
#include "rtl/ustring.h"
#include "sal/saldllapi.h"
+1 -1
View File
@@ -42,7 +42,7 @@ $(eval $(call gb_Executable_use_libraries,gtktiledviewer,\
ifeq ($(OS), $(filter LINUX %BSD SOLARIS, $(OS)))
$(eval $(call gb_Executable_add_libs,gtktiledviewer,\
-lm $(DLOPEN_LIBS) \
-lm $(UNIX_DLAPI_LIBS) \
))
endif
+1 -1
View File
@@ -23,7 +23,7 @@ $(eval $(call gb_Executable_use_libraries,tilebench,\
))
$(eval $(call gb_Executable_add_libs,tilebench,\
-lm $(DLOPEN_LIBS) \
-lm $(UNIX_DLAPI_LIBS) \
))
$(eval $(call gb_Executable_add_exception_objects,tilebench,\
+1 -1
View File
@@ -35,7 +35,7 @@ $(eval $(call gb_Library_add_defs,libreofficekitgtk,\
ifeq ($(OS),$(filter LINUX %BSD SOLARIS, $(OS)))
$(eval $(call gb_Library_add_libs,libreofficekitgtk,\
$(DLOPEN_LIBS) -lm \
$(UNIX_DLAPI_LIBS) -lm \
))
endif
+27 -23
View File
@@ -35,14 +35,9 @@
#include <sys/ldr.h>
#endif
#ifdef ANDROID
#include <osl/detail/android-bootstrap.h>
#endif
static bool getModulePathFromAddress(void * address, rtl_String ** path) {
static bool getModulePathFromAddress(void * address, rtl_String ** path)
{
bool result = false;
// We do want to have this functionality also in the
// DISABLE_DYNLOADING case, I think?
#if defined(AIX)
int size = 4 * 1024;
char *buf, *filename=NULL;
@@ -87,6 +82,7 @@ static bool getModulePathFromAddress(void * address, rtl_String ** path) {
free(buf);
#else
#if HAVE_UNIX_DLAPI
Dl_info dl_info;
result = dladdr(address, &dl_info) != 0;
@@ -95,6 +91,10 @@ static bool getModulePathFromAddress(void * address, rtl_String ** path) {
{
rtl_string_newFromStr(path, dl_info.dli_fname);
}
#else
(void) address;
(void) path;
#endif
#endif
return result;
}
@@ -134,16 +134,13 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *ustrModuleName, sal_Int32 nRtldMo
oslModule SAL_CALL osl_loadModuleAscii(const char *pModuleName, sal_Int32 nRtldMode)
{
#if HAVE_UNIX_DLAPI
SAL_WARN_IF(
((nRtldMode & SAL_LOADMODULE_LAZY) != 0
&& (nRtldMode & SAL_LOADMODULE_NOW) != 0),
"sal.osl", "only either LAZY or NOW");
if (pModuleName)
{
#ifdef ANDROID
(void) nRtldMode;
void *pLib = lo_dlopen(pModuleName);
#else
int rtld_mode =
((nRtldMode & SAL_LOADMODULE_NOW) ? RTLD_NOW : RTLD_LAZY) |
((nRtldMode & SAL_LOADMODULE_GLOBAL) ? RTLD_GLOBAL : RTLD_LOCAL);
@@ -153,9 +150,12 @@ oslModule SAL_CALL osl_loadModuleAscii(const char *pModuleName, sal_Int32 nRtldM
pLib == nullptr, "sal.osl",
"dlopen(" << pModuleName << ", " << rtld_mode << "): "
<< dlerror());
#endif
return pLib;
}
#else
(void) pModuleName;
(void) nRtldMode;
#endif
return nullptr;
}
@@ -197,45 +197,49 @@ oslModule osl_loadModuleRelativeAscii(
sal_Bool SAL_CALL
osl_getModuleHandle(rtl_uString *, oslModule *pResult)
{
#if !defined(DISABLE_DYNLOADING) || defined(IOS)
#if HAVE_UNIX_DLAPI
*pResult = static_cast<oslModule>(RTLD_DEFAULT);
return true;
#else
*pResult = nullptr;
return false;
#endif
return true;
}
#ifndef DISABLE_DYNLOADING
/*****************************************************************************/
/* osl_unloadModule */
/*****************************************************************************/
void SAL_CALL osl_unloadModule(oslModule hModule)
{
#if !defined(DISABLE_DYNLOADING) && HAVE_UNIX_DLAPI
if (hModule)
{
#ifdef ANDROID
int nRet = lo_dlclose(hModule);
#else
int nRet = dlclose(hModule);
#endif
SAL_INFO_IF(
nRet != 0, "sal.osl", "dlclose(" << hModule << "): " << dlerror());
}
#else
(void) hModule;
#endif
}
#endif // !DISABLE_DYNLOADING
namespace {
void * getSymbol(oslModule module, char const * symbol) {
void * getSymbol(oslModule module, char const * symbol)
{
assert(symbol != nullptr);
#if HAVE_UNIX_DLAPI
// We do want to use dlsym() also in the DISABLE_DYNLOADING case
// just to look up symbols in the static executable, I think:
void * p = dlsym(module, symbol);
SAL_INFO_IF(
p == nullptr, "sal.osl",
"dlsym(" << module << ", " << symbol << "): " << dlerror());
#else
(void) module;
(void) symbol;
void *p = nullptr;
#endif
return p;
}
+1 -1
View File
@@ -2204,7 +2204,7 @@ define gb_LinkTarget_use_glxtest
$(call gb_LinkTarget_use_libraries,$(1),vcl,,$(4))
ifeq (,$(DISABLE_DYNLOADING))
$(call gb_LinkTarget_add_libs,$(1),$(DLOPEN_LIBS))
$(call gb_LinkTarget_add_libs,$(1),$(UNIX_DLAPI_LIBS))
endif
ifeq (,$(DISABLE_GUI))
+1 -1
View File
@@ -66,7 +66,7 @@ $(eval $(call gb_Library_add_exception_objects,desktop_detector,\
ifeq ($(OS), $(filter LINUX %BSD SOLARIS, $(OS)))
$(eval $(call gb_Library_add_libs,desktop_detector,\
-lm $(DLOPEN_LIBS) \
-lm $(UNIX_DLAPI_LIBS) \
))
endif
+1 -1
View File
@@ -648,7 +648,7 @@ $(eval $(call gb_Library_use_externals,vcl,\
$(eval $(call gb_Library_add_libs,vcl,\
$(if $(filter LINUX %BSD SOLARIS,$(OS)), \
-lm \
$(if $(DISABLE_DYNLOADING),,$(DLOPEN_LIBS)) \
$(if $(DISABLE_DYNLOADING),,$(UNIX_DLAPI_LIBS)) \
) \
))
+1 -1
View File
@@ -30,7 +30,7 @@ $(eval $(call gb_StaticLibrary_use_api,glxtest,\
))
$(eval $(call gb_StaticLibrary_add_libs,glxtest,\
-lm $(DLOPEN_LIBS) \
-lm $(UNIX_DLAPI_LIBS) \
-lX11 \
))
+5 -4
View File
@@ -27,14 +27,15 @@
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <sal/log.hxx>
#include <osl/module.h>
void dl_cairo_surface_set_device_scale(cairo_surface_t* surface, double x_scale, double y_scale)
{
#ifdef ANDROID
#if !HAVE_DLAPI
cairo_surface_set_device_scale(surface, x_scale, y_scale);
#else
static auto func = reinterpret_cast<void (*)(cairo_surface_t*, double, double)>(
dlsym(nullptr, "cairo_surface_set_device_scale"));
osl_getAsciiFunctionSymbol(nullptr, "cairo_surface_set_device_scale"));
if (func)
func(surface, x_scale, y_scale);
#endif
@@ -42,11 +43,11 @@ void dl_cairo_surface_set_device_scale(cairo_surface_t* surface, double x_scale,
void dl_cairo_surface_get_device_scale(cairo_surface_t* surface, double* x_scale, double* y_scale)
{
#ifdef ANDROID
#if !HAVE_DLAPI
cairo_surface_get_device_scale(surface, x_scale, y_scale);
#else
static auto func = reinterpret_cast<void (*)(cairo_surface_t*, double*, double*)>(
dlsym(nullptr, "cairo_surface_get_device_scale"));
osl_getAsciiFunctionSymbol(nullptr, "cairo_surface_get_device_scale"));
if (func)
func(surface, x_scale, y_scale);
else
@@ -34,6 +34,7 @@
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <sal/log.hxx>
#include <osl/module.h>
#include <langboost.hxx>
#include <font/PhysicalFontCollection.hxx>
@@ -161,11 +162,16 @@ namespace
{
void dlFT_Done_MM_Var(FT_Library library, FT_MM_Var *amaster)
{
static auto func = reinterpret_cast<void(*)(FT_Library, FT_MM_Var*)>(dlsym(nullptr, "FT_Done_MM_Var"));
#if !HAVE_DLAPI
FT_Done_MM_Var(library, amaster);
#else
static auto func = reinterpret_cast<void(*)(FT_Library, FT_MM_Var*)>(
osl_getAsciiFunctionSymbol(nullptr, "FT_Done_MM_Var"));
if (func)
func(library, amaster);
else
free(amaster);
#endif
}
}