From 256eb9784910b708dc3d583bc1c1cb9d24420797 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sun, 23 Jun 2019 23:04:43 +0800 Subject: [PATCH 1/2] Avoid unnecessary symbol exposure with ELF-based systems GCC's default visibility is "public" but can be changed to "hidden" with the argument "-fvisibility=hidden". Tested with x86_64 / Ubuntu Linux 18.04 LTS: [before] $ nm -g -C libmimalloc.so | grep "T " | wc -l 142 [after] $ nm -g -C libmimalloc.so | grep "T " | wc -l 93 This patch does not change the build on macOS. --- CMakeLists.txt | 1 + src/alloc-override.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a35e885e..095fc2c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -ftls-model=initial-exec) if(CMAKE_C_COMPILER_ID MATCHES "GNU") list(APPEND mi_cflags -Wno-invalid-memory-model) + list(APPEND mi_cflags -fvisibility=hidden) endif() endif() diff --git a/src/alloc-override.c b/src/alloc-override.c index 03bb2a00..e06a3e6e 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -25,7 +25,7 @@ terms of the MIT license. A copy of the license can be found in the file #if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) // use aliasing to alias the exported function to one of our `mi_` functions - #define MI_FORWARD(fun) __attribute__((alias(#fun), used)); + #define MI_FORWARD(fun) __attribute__((alias(#fun), used, visibility("default"))); #define MI_FORWARD1(fun,x) MI_FORWARD(fun) #define MI_FORWARD2(fun,x,y) MI_FORWARD(fun) #define MI_FORWARD0(fun,x) MI_FORWARD(fun) @@ -60,6 +60,10 @@ terms of the MIT license. A copy of the license can be found in the file void free(void* p) mi_attr_noexcept MI_FORWARD0(mi_free, p) #endif +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) +#pragma GCC visibility push(default) +#endif + // ------------------------------------------------------ // Override new/delete // This is not really necessary as they usually call @@ -189,4 +193,8 @@ void* reallocarray( void* p, size_t count, size_t size ) { // BSD } #endif +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) +#pragma GCC visibility pop +#endif + #endif // MI_MALLOC_OVERRIDE & !_WIN32 From 9ba53d3e2b59de7f8236196f7df43668a254c8dd Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 25 Jun 2019 19:57:21 -0700 Subject: [PATCH 2/2] fix missing prototype for heap_alloc_small --- include/mimalloc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mimalloc.h b/include/mimalloc.h index e88d9712..b5fd6f96 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -161,6 +161,7 @@ mi_decl_export mi_decl_allocator void* mi_heap_malloc(mi_heap_t* heap, size_t si mi_decl_export mi_decl_allocator void* mi_heap_zalloc(mi_heap_t* heap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2); mi_decl_export mi_decl_allocator void* mi_heap_calloc(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(2, 3); mi_decl_export mi_decl_allocator void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(2, 3); +mi_decl_export mi_decl_allocator void* mi_heap_malloc_small(mi_heap_t* heap, size_t size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(2); mi_decl_export char* mi_heap_strdup(mi_heap_t* heap, const char* s) mi_attr_noexcept; mi_decl_export char* mi_heap_strndup(mi_heap_t* heap, const char* s, size_t n) mi_attr_noexcept;