From 21f54c53b96c7a70ec2a0b4472578c7c70838ee2 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 28 May 2021 12:45:14 +0200 Subject: [PATCH] Autodetect RTLD_GLOBAL and RTLD_NOW values and use those in __init__.py.in (#35) --- configure.ac | 17 +++++++---------- m4/ax_dlflags.m4 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ pyext/gammalib/__init__.py.in | 9 +++++---- 3 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 m4/ax_dlflags.m4 diff --git a/configure.ac b/configure.ac index db381be..3e0cede 100644 --- a/configure.ac +++ b/configure.ac @@ -289,21 +289,17 @@ AC_MSG_CHECKING([for the shared library paths environment variable]) case $ac_sys_system in BeOS*) SHAREDSUFFIX='.so' - DLFLAGS=258 ;; CYGWIN*) SHAREDSUFFIX='.dll.a' - DLFLAGS=258 ;; SunOS*) SHAREDSUFFIX='.so' RUNSHARED='LD_LIBRARY_PATH' - DLFLAGS=258 ;; Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) SHAREDSUFFIX='.so' RUNSHARED='LD_LIBRARY_PATH' - DLFLAGS=258 ;; hp*|HP*) case `uname -m` in @@ -315,33 +311,34 @@ case $ac_sys_system in ;; esac RUNSHARED='SHLIB_PATH' - DLFLAGS=258 ;; OSF*) SHAREDSUFFIX='.so' RUNSHARED='LD_LIBRARY_PATH' - DLFLAGS=258 ;; atheos*) SHAREDSUFFIX='.so' RUNSHARED='DLL_PATH' - DLFLAGS=258 ;; Darwin*) SHAREDSUFFIX='.dylib' RUNSHARED='DYLD_LIBRARY_PATH' - DLFLAGS=10 ;; AIX*) SHAREDSUFFIX='.so' RUNSHARED='LIBPATH' - DLFLAGS=258 ;; esac AC_MSG_RESULT($RUNSHARED) AC_SUBST(SHAREDSUFFIX) AC_SUBST(RUNSHARED) -AC_SUBST(DLFLAGS) + + +############################################################################# +# Determine values of RTLD_GLOBAL and RTLD_NOW # +############################################################################# +AX_DLFLAGS(RTLD_GLOBAL) +AX_DLFLAGS(RTLD_NOW) ############################################################################# diff --git a/m4/ax_dlflags.m4 b/m4/ax_dlflags.m4 new file mode 100644 index 0000000..2c7df59 --- /dev/null +++ b/m4/ax_dlflags.m4 @@ -0,0 +1,52 @@ +# =========================================================================== +# +# SYNOPSIS +# +# AX_DLFLAGS +# +# DESCRIPTION +# +# This macro determines the value of a DL flags such as RTLD_GLOBAL or +# RTLD_NOW from the dlfcn.h file. +# +# USAGE +# +# AX_DLFLAGS(RTLD_GLOBAL) +# AC_MSG_RESULT($DLFLAGS_RTLD_GLOBAL) +# +# LICENSE +# +# Copyright (c) 2021 Juergen Knodlseder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#serial 8 + +AC_DEFUN([AX_DLFLAGS], [ + DLFLAGS_$1="" + AC_CHECK_HEADERS([dlfcn.h]) + AS_IF([test "x$ac_cv_header_dlfcn_h" = "xyes"],[ + AC_MSG_CHECKING([for value of $1]) + for flags in 1 2 4 8 16 32 64 128 256 512 ; do + AC_EGREP_CPP([test_true],[ + #include + #if defined($1) && $1 == $flags + test_true + #endif + ],[DLFLAGS_$1=$flags],[]) + done + ]) + AC_MSG_RESULT($DLFLAGS_$1) + AC_SUBST([DLFLAGS_$1]) +]) diff --git a/pyext/gammalib/__init__.py.in b/pyext/gammalib/__init__.py.in index efd668a..d63d266 100644 --- a/pyext/gammalib/__init__.py.in +++ b/pyext/gammalib/__init__.py.in @@ -18,11 +18,12 @@ # # ========================================================================== -# Make sur that library symbols are exported by setting the RTLD_GLOBAL flag. -# This is necessary on some systems. +# Make sur that library symbols are exported by setting the dynamic library +# loading flag to RTLD_GLOBAL | RTLD_NOWflag. This is necessary on some +# systems. import sys -flags = sys.getdlopenflags() # Get original flags -sys.setdlopenflags(@DLFLAGS@) # Set RTLD_GLOBAL | RTLD_NOW +flags = sys.getdlopenflags() +sys.setdlopenflags(@DLFLAGS_RTLD_GLOBAL@ | @DLFLAGS_RTLD_NOW@) # Import modules from gammalib.app import * -- libgit2 0.21.4