bind fails to build with jemalloc if jemalloc is using different prefix
Summary
bind build with jemalloc fails (if jemalloc is using non default prefix)
BIND version used
9.18.0
Steps to reproduce
build jemalloc with --with-jemalloc-prefix=je_ and install it build bind --with-jemalloc=yes
What is the current bug behavior?
Build fails with:
/bin/sh ../../libtool --tag=CC --mode=compile x86_64-pld-linux-gcc -DHAVE_CONFIG_H -I. -I../.. -D_FORTIFY_SOURCE=2 -include ../../config.h -I./include -I../../include -I../../lib/isc/include -I../../lib/isc/include -I/usr/include/json-c -I/usr/include/libxml2 -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes -fno-strict-aliasing -fno-delete-null-pointer-checks -fdiagnostics-show-option -D_GNU_SOURCE=1 -O2 -fwrapv -pipe -Wformat -Werror=format-security -gdwarf-4 -fno-debug-types-section -fvar-tracking-assignments -g2 -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -Werror=trampolines -fPIC -march=x86-64 -mtune=generic -gdwarf-4 -fno-debug-types-section -fvar-tracking-assignments -g2 -pthread -MT libisc_la-mem.lo -MD -MP -MF .deps/libisc_la-mem.Tpo -c -o libisc_la-mem.lo `test -f 'mem.c' || echo './'`mem.c
libtool: compile: x86_64-pld-linux-gcc -DHAVE_CONFIG_H -I. -I../.. -D_FORTIFY_SOURCE=2 -include ../../config.h -I./include -I../../include -I../../lib/isc/include -I../../lib/isc/include -I/usr/include/json-c -I/usr/include/libxml2 -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes -fno-strict-aliasing -fno-delete-null-pointer-checks -fdiagnostics-show-option -D_GNU_SOURCE=1 -O2 -fwrapv -pipe -Wformat -Werror=format-security -gdwarf-4 -fno-debug-types-section -fvar-tracking-assignments -g2 -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -Werror=trampolines -fPIC -march=x86-64 -mtune=generic -gdwarf-4 -fno-debug-types-section -fvar-tracking-assignments -g2 -pthread -MT libisc_la-mem.lo -MD -MP -MF .deps/libisc_la-mem.Tpo -c mem.c -fPIC -DPIC -o .libs/libisc_la-mem.o
mem.c: In function ‘mem_get’:
mem.c:345:15: error: implicit declaration of function ‘mallocx’; did you mean ‘malloc’? [-Werror=implicit-function-declaration]
345 | ret = mallocx(size, flags);
| ^~~~~~~
| malloc
mem.c:345:13: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
345 | ret = mallocx(size, flags);
| ^
mem.c: In function ‘mem_put’:
mem.c:366:9: error: implicit declaration of function ‘sdallocx’; did you mean ‘je_sdallocx’? [-Werror=implicit-function-declaration]
366 | sdallocx(mem, size, flags);
| ^~~~~~~~
| je_sdallocx
mem.c: In function ‘mem_realloc’:
mem.c:376:19: error: implicit declaration of function ‘rallocx’; did you mean ‘valloc’? [-Werror=implicit-function-declaration]
376 | new_ptr = rallocx(old_ptr, new_size, flags);
| ^~~~~~~
| valloc
mem.c:376:17: warning: assignment to ‘void *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
376 | new_ptr = rallocx(old_ptr, new_size, flags);
| ^
mem.c: In function ‘mem_create’:
mem.c:462:13: warning: assignment to ‘isc_mem_t *’ {aka ‘struct isc_mem *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
462 | ctx = mallocx(sizeof(*ctx), MALLOCX_ALIGN(ISC_OS_CACHELINE_SIZE));
| ^
mem.c: In function ‘isc__mem_allocate’:
mem.c:897:16: error: implicit declaration of function ‘sallocx’; did you mean ‘valloc’? [-Werror=implicit-function-declaration]
897 | size = sallocx(ptr, 0);
| ^~~~~~~
| valloc
cc1: some warnings being treated as errors
make[4]: *** [Makefile:1391: libisc_la-mem.lo] Error 1
make[4]: Leaving directory '/home/users/arekm/rpm/BUILD/bind-9.18.0/lib/isc'
What is the expected correct behavior?
build without failure
Possible fixes
--- bind-9.18.0/lib/isc/mem.c~ 2022-01-24 09:28:57.000000000 +0100
+++ bind-9.18.0/lib/isc/mem.c 2022-01-27 15:01:27.389870903 +0100
@@ -48,6 +48,7 @@
#if defined(HAVE_MALLOC_NP_H)
#include <malloc_np.h>
#elif defined(HAVE_JEMALLOC)
+#define JEMALLOC_MANGLE 1
#include <jemalloc/jemalloc.h>
#if JEMALLOC_VERSION_MAJOR < 4
as explained in jemalloc/jemalloc.h itself:
/*
* By default application code must explicitly refer to mangled symbol names,
* so that it is possible to use jemalloc in conjunction with another allocator
* in the same application. Define JEMALLOC_MANGLE in order to cause automatic
* name mangling that matches the API prefixing that happened as a result of
* --with-mangling and/or --with-jemalloc-prefix configuration settings.
*/