From: Christopher Dykes Date: Tue, 26 Jul 2016 22:53:34 +0000 (-0700) Subject: Fix the weak linking of JEMalloc under MSVC X-Git-Tag: v2016.07.29.00~10 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cdcb98c4ff11e684368d8fc9e598dc8b872b94e8;p=folly.git Fix the weak linking of JEMalloc under MSVC Summary: While the previous version did compile, it wouldn't actually work at link time. Reviewed By: meyering Differential Revision: D3614424 fbshipit-source-id: 578677b65edca720330319594e1163d214e1400d --- diff --git a/folly/detail/Malloc.h b/folly/detail/Malloc.h index 2b658f2a..46704c79 100644 --- a/folly/detail/Malloc.h +++ b/folly/detail/Malloc.h @@ -47,6 +47,20 @@ extern int (*mallctl)(const char*, void*, size_t*, void*, size_t); extern int (*mallctlnametomib)(const char*, size_t*, size_t*); extern int (*mallctlbymib)(const size_t*, size_t, void*, size_t*, void*, size_t); +#ifdef _MSC_VER +// We emulate weak linkage for MSVC. The symbols we're +// aliasing to are hiding in MallocImpl.cpp +#pragma comment(linker, "/alternatename:mallocx=mallocxWeak") +#pragma comment(linker, "/alternatename:rallocx=rallocxWeak") +#pragma comment(linker, "/alternatename:xallocx=xallocxWeak") +#pragma comment(linker, "/alternatename:sallocx=sallocxWeak") +#pragma comment(linker, "/alternatename:dallocx=dallocxWeak") +#pragma comment(linker, "/alternatename:sdallocx=sdallocxWeak") +#pragma comment(linker, "/alternatename:nallocx=nallocxWeak") +#pragma comment(linker, "/alternatename:mallctl=mallctlWeak") +#pragma comment(linker, "/alternatename:mallctlnametomib=mallctlnametomibWeak") +#pragma comment(linker, "/alternatename:mallctlbymib=mallctlbymibWeak") +#endif #endif } diff --git a/folly/detail/MallocImpl.cpp b/folly/detail/MallocImpl.cpp index 36d70e97..1fbfe530 100644 --- a/folly/detail/MallocImpl.cpp +++ b/folly/detail/MallocImpl.cpp @@ -20,27 +20,17 @@ extern "C" { #ifdef _MSC_VER // MSVC doesn't have weak symbols, so do some linker magic -// to emulate them. +// to emulate them. (the magic is in the header) const char* mallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_mallocx=_mallocxWeak") const char* rallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_rallocx=_rallocxWeak") const char* xallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_xallocx=_xallocxWeak") const char* sallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_sallocx=_sallocxWeak") const char* dallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_dallocx=_dallocxWeak") const char* sdallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_sdallocx=_sdallocxWeak") const char* nallocxWeak = nullptr; -#pragma comment(linker, "/alternatename:_nallocx=_nallocxWeak") const char* mallctlWeak = nullptr; -#pragma comment(linker, "/alternatename:_mallctl=_mallctlWeak") const char* mallctlnametomibWeak = nullptr; -#pragma comment(linker, "/alternatename:_mallctlnametomib=_mallctlnametomibWeak") const char* mallctlbymibWeak = nullptr; -#pragma comment(linker, "/alternatename:_mallctlbymib=_mallctlbymibWeak") #elif !FOLLY_HAVE_WEAK_SYMBOLS void* (*mallocx)(size_t, int) = nullptr; void* (*rallocx)(void*, size_t, int) = nullptr;