Fix a weird problem with lib6 versioned symbols.

This commit is contained in:
Sam Hocevar 2012-04-16 23:02:42 +00:00 committed by sam
parent 2384fa2601
commit 177d421111
6 changed files with 32 additions and 4 deletions

View File

@ -178,6 +178,9 @@ AC_TRY_COMPILE([],
[AC_MSG_RESULT(no)])
AC_DEFINE_UNQUOTED(ATTRIBUTE_PRINTF(x,y), $ac_v_attribute_printf, [Define to the __printf__ attribute if present])
AC_CHECK_LIB(dl, dladdr,
[AC_DEFINE(HAVE_DLADDR, 1, Define to 1 if you have the `dladdr' function.)])
AC_CHECK_LIB(m, log, [MATH_LIBS="-lm"])
AC_SUBST(MATH_LIBS)
AC_CHECK_LIB(dl, dlopen, [DL_LIBS="-ldl"])

View File

@ -28,6 +28,7 @@
#define HAVE_CONNECT 1
#define HAVE_CREATEFILEA 1
#define HAVE_CREATEFILEW 1
/* #undef HAVE_DLADDR */
/* #undef HAVE_DLFCN_H */
#define HAVE_DUP 1
#define HAVE_DUP2 1

View File

@ -20,8 +20,6 @@
#include "config.h"
/* Need this for RTLD_NEXT */
#define _GNU_SOURCE
/* Use this to get lseek64() on glibc systems */
#define _LARGEFILE64_SOURCE
/* Use this to get off64_t() on Solaris systems */

View File

@ -29,7 +29,8 @@
* otherwise we may miss a lot of stuff if we wait for \
* the linker to load us fully. */ \
_zz_init(); \
ORIG(x) = dlsym(RTLD_NEXT, STR(x)); \
extern void *_zz_dl_lib; \
ORIG(x) = dlsym(_zz_dl_lib, STR(x)); \
} \
if(!ORIG(x)) \
abort(); \

View File

@ -16,7 +16,7 @@
#include "config.h"
/* Need this for RTLD_NEXT */
/* Need this for off64_t */
#define _GNU_SOURCE
/* Need this for MAP_ANON and valloc() on FreeBSD (together with cdefs.h) */
#define _BSD_SOURCE

View File

@ -16,12 +16,19 @@
#include "config.h"
/* Need this for RTLD_NEXT */
#define _GNU_SOURCE
#if defined HAVE_STDINT_H
# include <stdint.h>
#elif defined HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#if defined HAVE_WINDOWS_H
# include <windows.h>
# include <imagehlp.h>
@ -35,6 +42,10 @@
#include "sys.h"
#include "lib-load.h"
#if defined HAVE_DLFCN_H
void *_zz_dl_lib = RTLD_NEXT;
#endif
#if defined HAVE_WINDOWS_H
static void insert_funcs(void *);
@ -77,6 +88,20 @@ void _zz_sys_init(void)
insert_funcs(entry.hModule);
}
CloseHandle(list);
#elif defined HAVE_DLFCN_H
/* If glibc is recent enough, we use dladdr() to get its address. This
* way we are sure that the symbols we load are the most recent version,
* or we may get weird problems. We choose fileno as a random symbol to
* get, because we know we don't divert it. */
# if HAVE_DLADDR
Dl_info di;
if (dladdr(&fileno, &di) != 0)
{
void *lib = dlopen(di.dli_fname, RTLD_NOW);
if (lib)
_zz_dl_lib = lib;
}
# endif
#else
/* Nothing to do on our platform */
#endif