From be0ae4f5dc027cc2ebe274d34aed94fe6d7b207f Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 1 Dec 2014 14:49:04 +0200 Subject: [PATCH] memory: Un-hide standard allocator functions With -fvisibility=hidden, all executable symbols are hidden from shared objects, allowing more optimizations (especially with -flto). However, hiding the allocator symbols mean that memory allocated in the executable cannot be freed in a library, since they will use different allocators. Fix by exposing these symbols with default visibility. Fixes crash loading some dpdk libraries. --- core/memory.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/memory.cc b/core/memory.cc index 3904c9c83d..7407d1e201 100644 --- a/core/memory.cc +++ b/core/memory.cc @@ -721,6 +721,7 @@ statistics stats() { using namespace memory; extern "C" +[[gnu::visibility("default")]] void* malloc(size_t n) throw () { if (n == 0) { return nullptr; @@ -734,6 +735,7 @@ void* malloc(size_t n) throw () { extern "C" [[gnu::alias("malloc")]] +[[gnu::visibility("default")]] void* __libc_malloc(size_t n) throw (); extern "C" @@ -745,9 +747,11 @@ void free(void* ptr) { extern "C" [[gnu::alias("free")]] +[[gnu::visibility("default")]] void* __libc_free(void* obj) throw (); extern "C" +[[gnu::visibility("default")]] void* calloc(size_t nmemb, size_t size) { auto s1 = __int128(nmemb) * __int128(size); assert(s1 == size_t(s1)); @@ -761,9 +765,11 @@ void* calloc(size_t nmemb, size_t size) { extern "C" [[gnu::alias("calloc")]] +[[gnu::visibility("default")]] void* __libc_calloc(size_t n, size_t m) throw (); extern "C" +[[gnu::visibility("default")]] void* realloc(void* ptr, size_t size) { auto old_size = ptr ? object_size(ptr) : 0; auto nptr = malloc(size); @@ -779,9 +785,11 @@ void* realloc(void* ptr, size_t size) { extern "C" [[gnu::alias("realloc")]] +[[gnu::visibility("default")]] void* __libc_realloc(void* obj, size_t size) throw (); extern "C" +[[gnu::visibility("default")]] int posix_memalign(void** ptr, size_t align, size_t size) { try { *ptr = allocate_aligned(align, size); @@ -793,9 +801,11 @@ int posix_memalign(void** ptr, size_t align, size_t size) { extern "C" [[gnu::alias("posix_memalign")]] +[[gnu::visibility("default")]] int __libc_posix_memalign(void** ptr, size_t align, size_t size) throw (); extern "C" +[[gnu::visibility("default")]] void* memalign(size_t align, size_t size) { try { return allocate_aligned(align, size); @@ -806,27 +816,33 @@ void* memalign(size_t align, size_t size) { extern "C" [[gnu::alias("memalign")]] +[[gnu::visibility("default")]] void* __libc_memalign(size_t align, size_t size); extern "C" +[[gnu::visibility("default")]] void cfree(void* obj) { return ::free(obj); } extern "C" [[gnu::alias("cfree")]] +[[gnu::visibility("default")]] void __libc_cfree(void* obj); extern "C" +[[gnu::visibility("default")]] size_t malloc_usable_size(void* obj) { return object_size(obj); } extern "C" +[[gnu::visibility("default")]] int malloc_trim(size_t pad) { return 0; } +[[gnu::visibility("default")]] void* operator new(size_t size) { if (size == 0) { size = 1; @@ -834,6 +850,7 @@ void* operator new(size_t size) { return allocate(size); } +[[gnu::visibility("default")]] void* operator new[](size_t size) { if (size == 0) { size = 1; @@ -841,30 +858,35 @@ void* operator new[](size_t size) { return allocate(size); } +[[gnu::visibility("default")]] void operator delete(void* ptr) throw () { if (ptr) { memory::free(ptr); } } +[[gnu::visibility("default")]] void operator delete[](void* ptr) throw () { if (ptr) { memory::free(ptr); } } +[[gnu::visibility("default")]] void operator delete(void* ptr, size_t size) throw () { if (ptr) { memory::free(ptr, size); } } +[[gnu::visibility("default")]] void operator delete[](void* ptr, size_t size) throw () { if (ptr) { memory::free(ptr, size); } } +[[gnu::visibility("default")]] void* operator new(size_t size, std::nothrow_t) throw () { if (size == 0) { size = 1; @@ -876,6 +898,7 @@ void* operator new(size_t size, std::nothrow_t) throw () { } } +[[gnu::visibility("default")]] void* operator new[](size_t size, std::nothrow_t) throw () { if (size == 0) { size = 1; @@ -887,24 +910,28 @@ void* operator new[](size_t size, std::nothrow_t) throw () { } } +[[gnu::visibility("default")]] void operator delete(void* ptr, std::nothrow_t) throw () { if (ptr) { memory::free(ptr); } } +[[gnu::visibility("default")]] void operator delete[](void* ptr, std::nothrow_t) throw () { if (ptr) { memory::free(ptr); } } +[[gnu::visibility("default")]] void operator delete(void* ptr, size_t size, std::nothrow_t) throw () { if (ptr) { memory::free(ptr, size); } } +[[gnu::visibility("default")]] void operator delete[](void* ptr, size_t size, std::nothrow_t) throw () { if (ptr) { memory::free(ptr, size);