Simplify JEMALLOC_ATTR_* macros to become JEMALLOC_ATTR().

Use JEMALLOC_ATTR(tls_model("initial-exec)) instead of -ftls-model=initial-exec
so that libjemalloc_pic.a can be directly linked into another library without
needing linker options changes.

Add attributes to malloc, calloc, and posix_memalign, for compatibility with
glibc's declarations.

Add function prototypes for the standard malloc(3) API.
This commit is contained in:
Jason Evans 2010-01-03 11:59:20 -08:00
parent bf10ae64a7
commit 9ad48230ed
6 changed files with 42 additions and 29 deletions

View File

@ -94,7 +94,6 @@ if test "x$CFLAGS" = "x" ; then
JE_CFLAGS_APPEND([-pipe])
JE_CFLAGS_APPEND([-g3])
JE_CFLAGS_APPEND([-march=native])
JE_CFLAGS_APPEND([-ftls-model=initial-exec])
fi
dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
if test "x$EXTRA_CFLAGS" != "x" ; then
@ -152,9 +151,7 @@ JE_COMPILABLE([__attribute__ syntax],
[],
[attribute])
if test "x${attribute}" = "xyes" ; then
AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [__attribute__((unused))])
else
AC_DEFINE_UNQUOTED([JEMALLOC_UNUSED], [])
AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
fi
dnl Platform-specific settings. abi and RPATH can probably be determined

View File

@ -739,7 +739,8 @@ static unsigned ncpus;
static malloc_mutex_t trace_mtx;
static unsigned trace_next_tid = 1;
static unsigned __thread trace_tid;
static unsigned __thread trace_tid
JEMALLOC_ATTR(tls_model("initial-exec"));
/* Used to cause trace_cleanup() to be called. */
static pthread_key_t trace_tsd;
#endif
@ -1008,12 +1009,14 @@ static malloc_mutex_t arenas_lock; /* Protects arenas initialization. */
* Map of pthread_self() --> arenas[???], used for selecting an arena to use
* for allocations.
*/
static __thread arena_t *arenas_map;
static __thread arena_t *arenas_map
JEMALLOC_ATTR(tls_model("initial-exec"));
#endif
#ifdef JEMALLOC_TCACHE
/* Map of thread-specific caches. */
static __thread tcache_t *tcache_tls;
static __thread tcache_t *tcache_tls
JEMALLOC_ATTR(tls_model("initial-exec"));
/*
* Same contents as tcache, but initialized such that the TSD destructor is
@ -1041,8 +1044,11 @@ static
#ifndef NO_TLS
__thread
#endif
bool mmap_unaligned;
bool mmap_unaligned
#ifndef NO_TLS
JEMALLOC_ATTR(tls_model("initial-exec"))
#endif
;
#ifdef JEMALLOC_STATS
/* Chunk statistics. */
static chunk_stats_t stats_chunks;
@ -1749,8 +1755,8 @@ extent_szad_comp(extent_node_t *a, extent_node_t *b)
}
/* Wrap red-black tree macros in functions. */
rb_wrap(static JEMALLOC_UNUSED, extent_tree_szad_, extent_tree_t, extent_node_t,
link_szad, extent_szad_comp)
rb_wrap(static JEMALLOC_ATTR(unused), extent_tree_szad_, extent_tree_t,
extent_node_t, link_szad, extent_szad_comp)
#endif
static inline int
@ -1763,8 +1769,8 @@ extent_ad_comp(extent_node_t *a, extent_node_t *b)
}
/* Wrap red-black tree macros in functions. */
rb_wrap(static JEMALLOC_UNUSED, extent_tree_ad_, extent_tree_t, extent_node_t,
link_ad, extent_ad_comp)
rb_wrap(static JEMALLOC_ATTR(unused), extent_tree_ad_, extent_tree_t,
extent_node_t, link_ad, extent_ad_comp)
/*
* End extent tree code.
@ -2322,8 +2328,8 @@ arena_chunk_comp(arena_chunk_t *a, arena_chunk_t *b)
}
/* Wrap red-black tree macros in functions. */
rb_wrap(static JEMALLOC_UNUSED, arena_chunk_tree_dirty_, arena_chunk_tree_t,
arena_chunk_t, link_dirty, arena_chunk_comp)
rb_wrap(static JEMALLOC_ATTR(unused), arena_chunk_tree_dirty_,
arena_chunk_tree_t, arena_chunk_t, link_dirty, arena_chunk_comp)
static inline int
arena_run_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
@ -2338,7 +2344,7 @@ arena_run_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
}
/* Wrap red-black tree macros in functions. */
rb_wrap(static JEMALLOC_UNUSED, arena_run_tree_, arena_run_tree_t,
rb_wrap(static JEMALLOC_ATTR(unused), arena_run_tree_, arena_run_tree_t,
arena_chunk_map_t, link, arena_run_comp)
static inline int
@ -2370,7 +2376,7 @@ arena_avail_comp(arena_chunk_map_t *a, arena_chunk_map_t *b)
}
/* Wrap red-black tree macros in functions. */
rb_wrap(static JEMALLOC_UNUSED, arena_avail_tree_, arena_avail_tree_t,
rb_wrap(static JEMALLOC_ATTR(unused), arena_avail_tree_, arena_avail_tree_t,
arena_chunk_map_t, link, arena_avail_comp)
static inline void
@ -6086,6 +6092,7 @@ MALLOC_OUT:
* Begin malloc(3)-compatible functions.
*/
JEMALLOC_ATTR(malloc)
void *
malloc(size_t size)
{
@ -6142,6 +6149,7 @@ RETURN:
return (ret);
}
JEMALLOC_ATTR(nonnull(1))
int
posix_memalign(void **memptr, size_t alignment, size_t size)
{
@ -6217,6 +6225,7 @@ RETURN:
return (ret);
}
JEMALLOC_ATTR(malloc)
void *
calloc(size_t num, size_t size)
{

View File

@ -6,8 +6,14 @@ extern "C" {
#include "jemalloc_defs.h"
size_t malloc_usable_size(const void *ptr);
void *malloc(size_t size) JEMALLOC_ATTR(malloc);
void *calloc(size_t num, size_t size) JEMALLOC_ATTR(malloc);
int posix_memalign(void **memptr, size_t alignment, size_t size)
JEMALLOC_ATTR(nonnull(1));
void *realloc(void *ptr, size_t size);
void free(void *ptr);
size_t malloc_usable_size(const void *ptr);
#ifdef JEMALLOC_TCACHE
void malloc_tcache_flush(void);
#endif

View File

@ -36,12 +36,13 @@
*/
#undef CPU_SPINWAIT
/*
* Attribute with which to mark potentially unused functions. For gcc this is:
*
* __attribute__((unused))
*/
#undef JEMALLOC_UNUSED
/* Defined if __attribute__((...)) syntax is supported. */
#undef JEMALLOC_HAVE_ATTR
#ifdef JEMALLOC_HAVE_ATTR
# define JEMALLOC_ATTR(s) __attribute__((s))
#else
# define JEMALLOC_ATTR(s)
#endif
/*
* JEMALLOC_DEBUG enables assertions and other sanity checks, and disables

View File

@ -65,7 +65,7 @@ cacheComp(AllocationCacheRecord *a, AllocationCacheRecord *b)
}
}
rb_wrap(static JEMALLOC_UNUSED, cache_tree_, AllocationCache,
rb_wrap(static JEMALLOC_ATTR(unused), cache_tree_, AllocationCache,
AllocationCacheRecord, link, cacheComp)
// Parse utrace records. Following are prototypical examples of each type of
@ -324,7 +324,7 @@ genOutput(FILE *outfile, const char *fileType, bool legend,
fprintf(stderr,
"mtrgraph: Trace record %"PRIu64
" realloc()s unknown object 0x%"PRIx64"\n",
i, trace->trace[i].oldAddr);
i, (uint64_t)trace->trace[i].oldAddr);
rVal = true;
goto RETURN;
}
@ -429,7 +429,7 @@ genOutput(FILE *outfile, const char *fileType, bool legend,
fprintf(stderr,
"mtrgraph: Trace record %"PRIu64
" free()s unknown object 0x%"PRIx64"\n",
i, trace->trace[i].oldAddr);
i, (uint64_t)trace->trace[i].oldAddr);
rVal = true;
goto RETURN;
}

View File

@ -43,8 +43,8 @@ record_comp(record_t *a, record_t *b)
return (1);
}
rb_wrap(static JEMALLOC_UNUSED, record_tree_, record_tree_t, record_t, link,
record_comp)
rb_wrap(static JEMALLOC_ATTR(unused), record_tree_, record_tree_t, record_t,
link, record_comp)
static record_t *rec_stack = NULL;