Commit 119f3e0c authored by Michał Kępień's avatar Michał Kępień

Make lib/dns/tests/tkey_test.c more portable

Weak symbols are handled differently by different dynamic linkers.  With
glibc, lib/dns/tests/tkey_test works as expected no matter whether
--with-libtool is used or not: __attribute__((weak)) prevents a static
build from failing and it just so happens that the desired symbols are
picked at runtime for dynamic builds.  However, with BSD libc, the
libdns functions called from lib/dns/tests/tkey_test.c use the "real"
memory allocation functions from libisc, thus breaking that unit test.
(Note: similar behavior can be reproduced with glibc by setting the
LD_DYNAMIC_WEAK environment variable.)

The simplest way to make lib/dns/tests/tkey_test work reliably is to
drop all uses of __attribute__((weak)) in it - this way, the memory
functions inside lib/dns/tests/tkey_test.c will always be used instead
of the "real" libisc ones for dynamic builds.  However, this would not
work with static builds as it would result in multiple strong symbols
with the same name being present in a single binary.

Work around the problem by only compiling in the overriding definitions
of memory functions when building using --with-libtool.  For static
builds, keep relying on the --wrap linker option for replacing calls to
the functions we are interested in.
parent 1bffa602
......@@ -544,6 +544,9 @@
non-blocking. */
#undef USE_FIONBIO_IOCTL
/* Define if libtool is used for compilation */
#undef USE_LIBTOOL
/* define if OpenSSL is used for Public-Key Cryptography */
#undef USE_OPENSSL
......
......@@ -15827,6 +15827,9 @@ $as_echo "yes" >&6; }
LIBTOOL_MODE_LINK='--mode=link'
LIBTOOL_MODE_UNINSTALL='--mode=uninstall'
INSTALL_LIBRARY='${INSTALL_PROGRAM}'
$as_echo "#define USE_LIBTOOL 1" >>confdefs.h
;;
*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
......
......@@ -669,6 +669,7 @@ case $use_libtool in
LIBTOOL_MODE_LINK='--mode=link'
LIBTOOL_MODE_UNINSTALL='--mode=uninstall'
INSTALL_LIBRARY='${INSTALL_PROGRAM}'
AC_DEFINE([USE_LIBTOOL],[1],[Define if libtool is used for compilation])
;;
*)
AC_MSG_RESULT(no)
......
......@@ -84,14 +84,14 @@ __wrap_isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size) {
__wrap_isc_mem_detach(ctxp);
}
#ifdef USE_LIBTOOL
#if ISC_MEM_TRACKLINES
#define FLARG , const char *file, unsigned int line
#else
#define FLARG
#endif
__attribute__((weak)) void *
void *
isc__mem_get(isc_mem_t *mctx, size_t size FLARG)
{
UNUSED(file);
......@@ -99,7 +99,7 @@ isc__mem_get(isc_mem_t *mctx, size_t size FLARG)
return (__wrap_isc__mem_get(mctx, size));
}
__attribute__((weak)) void
void
isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG)
{
UNUSED(file);
......@@ -107,22 +107,23 @@ isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG)
__wrap_isc__mem_put(ctx0, ptr, size);
}
__attribute__((weak)) void
void
isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
__wrap_isc_mem_attach(source0, targetp);
}
__attribute__((weak)) void
void
isc_mem_detach(isc_mem_t **ctxp) {
__wrap_isc_mem_detach(ctxp);
}
__attribute__((weak)) void
void
isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG){
UNUSED(file);
UNUSED(line);
__wrap_isc__mem_putanddetach(ctxp, ptr, size);
}
#endif /* USE_LIBTOOL */
static int
_setup(void **state) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment