From abf230a9ac4750f4cacfb1d4c8610732c15b417c Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 8 Apr 2015 12:26:30 +0200 Subject: [PATCH] malloc_debug: Set default alignment to max_align_t if available. For it to be available we build malloc_debug in C++11 mode when not using GCC2. Note that max_align_t is not in the std namespace in GCC4 versions prior to GCC 4.9. The extra "using namespace std" is there to be forward compatible once we update. --- src/system/libroot/posix/malloc_debug/Jamfile | 4 ++++ .../libroot/posix/malloc_debug/guarded_heap.cpp | 9 ++++++++- src/system/libroot/posix/malloc_debug/heap.cpp | 11 +++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/system/libroot/posix/malloc_debug/Jamfile b/src/system/libroot/posix/malloc_debug/Jamfile index ce2d68a298..903167d934 100644 --- a/src/system/libroot/posix/malloc_debug/Jamfile +++ b/src/system/libroot/posix/malloc_debug/Jamfile @@ -7,6 +7,10 @@ for architectureObject in [ MultiArchSubDirSetup ] { on $(architectureObject) { local architecture = $(TARGET_PACKAGING_ARCH) ; + if $(architecture) != x86_gcc2 { + SubDirC++Flags -std=gnu++11 ; + } + UsePrivateSystemHeaders ; MergeObject <$(architecture)>posix_malloc_debug.o : diff --git a/src/system/libroot/posix/malloc_debug/guarded_heap.cpp b/src/system/libroot/posix/malloc_debug/guarded_heap.cpp index 1e0bd70d48..5084e2c7bc 100644 --- a/src/system/libroot/posix/malloc_debug/guarded_heap.cpp +++ b/src/system/libroot/posix/malloc_debug/guarded_heap.cpp @@ -19,7 +19,14 @@ static bool sDebuggerCalls = true; + +#if __cplusplus >= 201103L +#include +using namespace std; +static size_t sDefaultAlignment = alignof(max_align_t); +#else static size_t sDefaultAlignment = 0; +#endif static void @@ -950,7 +957,7 @@ __init_heap_post_env(void) const char *argument = strchr(mode, 'a'); if (argument != NULL && sscanf(argument, "a%" B_SCNuSIZE, &defaultAlignment) == 1 - && defaultAlignment > 0) { + && defaultAlignment >= 0) { heap_debug_set_default_alignment(defaultAlignment); } } diff --git a/src/system/libroot/posix/malloc_debug/heap.cpp b/src/system/libroot/posix/malloc_debug/heap.cpp index 1b735b59ac..533a42b268 100644 --- a/src/system/libroot/posix/malloc_debug/heap.cpp +++ b/src/system/libroot/posix/malloc_debug/heap.cpp @@ -44,7 +44,14 @@ static bool sParanoidValidation = false; static thread_id sWallCheckThread = -1; static bool sStopWallChecking = false; static bool sUseGuardPage = false; -static bool sDefaultAlignment = 0; + +#if __cplusplus >= 201103L +#include +using namespace std; +static size_t sDefaultAlignment = alignof(max_align_t); +#else +static size_t sDefaultAlignment = 0; +#endif void @@ -1852,7 +1859,7 @@ __init_heap_post_env(void) const char *argument = strchr(mode, 'a'); if (argument != NULL && sscanf(argument, "a%" B_SCNuSIZE, &defaultAlignment) == 1 - && defaultAlignment > 0) { + && defaultAlignment >= 0) { heap_debug_set_default_alignment(defaultAlignment); } }