xref: /netbsd-src/external/bsd/jemalloc.old/dist/include/jemalloc/jemalloc_mangle.sh (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1*8e33eff8Schristos#!/bin/sh -eu
2*8e33eff8Schristos
3*8e33eff8Schristospublic_symbols_txt=$1
4*8e33eff8Schristossymbol_prefix=$2
5*8e33eff8Schristos
6*8e33eff8Schristoscat <<EOF
7*8e33eff8Schristos/*
8*8e33eff8Schristos * By default application code must explicitly refer to mangled symbol names,
9*8e33eff8Schristos * so that it is possible to use jemalloc in conjunction with another allocator
10*8e33eff8Schristos * in the same application.  Define JEMALLOC_MANGLE in order to cause automatic
11*8e33eff8Schristos * name mangling that matches the API prefixing that happened as a result of
12*8e33eff8Schristos * --with-mangling and/or --with-jemalloc-prefix configuration settings.
13*8e33eff8Schristos */
14*8e33eff8Schristos#ifdef JEMALLOC_MANGLE
15*8e33eff8Schristos#  ifndef JEMALLOC_NO_DEMANGLE
16*8e33eff8Schristos#    define JEMALLOC_NO_DEMANGLE
17*8e33eff8Schristos#  endif
18*8e33eff8SchristosEOF
19*8e33eff8Schristos
20*8e33eff8Schristosfor nm in `cat ${public_symbols_txt}` ; do
21*8e33eff8Schristos  n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'`
22*8e33eff8Schristos  echo "#  define ${n} ${symbol_prefix}${n}"
23*8e33eff8Schristosdone
24*8e33eff8Schristos
25*8e33eff8Schristoscat <<EOF
26*8e33eff8Schristos#endif
27*8e33eff8Schristos
28*8e33eff8Schristos/*
29*8e33eff8Schristos * The ${symbol_prefix}* macros can be used as stable alternative names for the
30*8e33eff8Schristos * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined.  This is primarily
31*8e33eff8Schristos * meant for use in jemalloc itself, but it can be used by application code to
32*8e33eff8Schristos * provide isolation from the name mangling specified via --with-mangling
33*8e33eff8Schristos * and/or --with-jemalloc-prefix.
34*8e33eff8Schristos */
35*8e33eff8Schristos#ifndef JEMALLOC_NO_DEMANGLE
36*8e33eff8SchristosEOF
37*8e33eff8Schristos
38*8e33eff8Schristosfor nm in `cat ${public_symbols_txt}` ; do
39*8e33eff8Schristos  n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'`
40*8e33eff8Schristos  echo "#  undef ${symbol_prefix}${n}"
41*8e33eff8Schristosdone
42*8e33eff8Schristos
43*8e33eff8Schristoscat <<EOF
44*8e33eff8Schristos#endif
45*8e33eff8SchristosEOF
46