From 6dbe24da2e4acb5015abd9bb0f28001e5923ed1e Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Tue, 13 Aug 2019 14:03:37 +0100 Subject: [PATCH] [NFC] Replace HEADER_GLOBAL with inline (C++17). HEADER_GLOBAL was using non-standard attributes to achieve what C++17 now permits with a keyword. Use the standard formulation. Update the README to note that gcc is still not recommended, but because of its poor codegen for 128-bit atomic compare and exchange, rather than because it doesn't support the attribute used for HEADER_GLOBAL. --- README.md | 5 ++--- src/ds/defines.h | 8 -------- src/mem/largealloc.h | 2 +- src/mem/threadalloc.h | 2 +- src/pal/pal_windows.h | 6 +++--- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 574d95b..11ec8fd 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,8 @@ To use snmalloc on NetBSD, you must either acquire a `libatomic` implementation snmalloc has very few dependencies, CMake, Ninja, Clang 6.0 or later and a C++17 standard library. -Building with GCC is currently not recommended because GCC lacks support for the -`selectany` attribute to specify variables in a COMDAT. -It will build with GCC-7, but some of global variables will be preemptible. +Building with GCC is currently not recommended because GCC emits calls to +libatomic for 128-bit atomic operations. To build a debug configuration: ``` diff --git a/src/ds/defines.h b/src/ds/defines.h index 1e80a5f..19668de 100644 --- a/src/ds/defines.h +++ b/src/ds/defines.h @@ -3,7 +3,6 @@ #ifdef _MSC_VER # define ALWAYSINLINE __forceinline # define NOINLINE __declspec(noinline) -# define HEADER_GLOBAL __declspec(selectany) # define likely(x) !!(x) # define unlikely(x) !!(x) # define SNMALLOC_SLOW_PATH NOINLINE @@ -17,13 +16,6 @@ # define SNMALLOC_SLOW_PATH NOINLINE # define SNMALLOC_FAST_PATH inline ALWAYSINLINE # define SNMALLOC_PURE __attribute__((const)) -# ifdef __clang__ -# define HEADER_GLOBAL __attribute__((selectany)) -# else -// GCC does not support selectany, weak is almost the correct -// attribute, but leaves the global variable preemptible. -# define HEADER_GLOBAL __attribute__((weak)) -# endif #endif #ifndef __has_builtin diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index f36c1b5..08048b9 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -405,5 +405,5 @@ namespace snmalloc * The memory provider that will be used if no other provider is explicitly * passed as an argument. */ - HEADER_GLOBAL GlobalVirtual default_memory_provider; + inline GlobalVirtual default_memory_provider; } // namespace snmalloc diff --git a/src/mem/threadalloc.h b/src/mem/threadalloc.h index fb92032..b5b24d3 100644 --- a/src/mem/threadalloc.h +++ b/src/mem/threadalloc.h @@ -18,7 +18,7 @@ namespace snmalloc * replace itself with the thread-local allocator, allocating one if * required. This avoids a branch on the fast path. */ - HEADER_GLOBAL Alloc GlobalPlaceHolder( + inline Alloc GlobalPlaceHolder( default_memory_provider, SNMALLOC_DEFAULT_PAGEMAP(), nullptr, true); #ifdef SNMALLOC_EXTERNAL_THREAD_ALLOC diff --git a/src/pal/pal_windows.h b/src/pal/pal_windows.h index 65b9320..3b12b62 100644 --- a/src/pal/pal_windows.h +++ b/src/pal/pal_windows.h @@ -231,8 +231,8 @@ namespace snmalloc } # endif }; - HEADER_GLOBAL std::atomic PALWindows::pressure_epoch; - HEADER_GLOBAL std::atomic PALWindows::registered_for_notifications; - HEADER_GLOBAL HANDLE PALWindows::lowMemoryObject; + inline std::atomic PALWindows::pressure_epoch; + inline std::atomic PALWindows::registered_for_notifications; + inline HANDLE PALWindows::lowMemoryObject; } #endif