[PATCH] PR libstdc++/84773 use aligned alloc functions for FreeBSD and MinGW cross-compilers
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Mar 12 22:52:00 GMT 2018
Cross-compilers for FreeBSD and MinGW do not currently check for
aligned_alloc, posix_memalign, _aligned_malloc etc which are used by
native compilers when available. This omission caused bootstrap failures
for FreeBSD cross-compilers, and caused ABI differences for MinGW due
to a different implementation of operator new(size_t, align_val_t).
Also add a using-declaration for aligned_alloc in namespace std for
C++17 support.
PR libstdc++/84773
PR libstdc++/83662
* crossconfig.m4: Check for aligned_alloc etc. on freebsd and mingw32.
* configure: Regenerate.
* include/c_global/cstdlib [_GLIBCXX_HAVE_ALIGNED_ALLOC]
(aligned_alloc): Add using-declaration.
* testsuite/18_support/aligned_alloc/aligned_alloc.cc: New test.
Tested powerpc64le-linux, and by building cross-compilers for
x86_64-unknown-freebsd11.0 and x86_64-w64-mingw32. Committed to trunk,
backport to gcc-7-branch to follow.
-------------- next part --------------
commit e06031f334cfffe11c5249f96e685d309c554306
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Mar 9 01:19:51 2018 +0000
PR libstdc++/84773 use aligned alloc functions for FreeBSD and MinGW cross-compilers
PR libstdc++/84773
PR libstdc++/83662
* crossconfig.m4: Check for aligned_alloc etc. on freebsd and mingw32.
* configure: Regenerate.
* include/c_global/cstdlib [_GLIBCXX_HAVE_ALIGNED_ALLOC]
(aligned_alloc): Add using-declaration.
* testsuite/18_support/aligned_alloc/aligned_alloc.cc: New test.
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index a8b1da9a607..fa56795b25e 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -133,6 +133,7 @@ case "${host}" in
AC_DEFINE(HAVE_ISNANL)
fi
AC_CHECK_FUNCS(__cxa_thread_atexit)
+ AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
;;
*-fuchsia*)
@@ -197,6 +198,7 @@ case "${host}" in
GLIBCXX_CHECK_LINKER_FEATURES
GLIBCXX_CHECK_MATH_SUPPORT
GLIBCXX_CHECK_STDLIB_SUPPORT
+ AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
;;
*-netbsd*)
SECTION_FLAGS='-ffunction-sections -fdata-sections'
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index a3b19f30b33..10335017f0c 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -78,6 +78,9 @@ namespace std
// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
#undef abort
+#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
+# undef aligned_alloc
+#endif
#undef atexit
#if __cplusplus >= 201103L
# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
@@ -125,6 +128,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using ::ldiv_t;
using ::abort;
+#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
+ using ::aligned_alloc;
+#endif
using ::atexit;
#if __cplusplus >= 201103L
# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
diff --git a/libstdc++-v3/testsuite/18_support/aligned_alloc/aligned_alloc.cc b/libstdc++-v3/testsuite/18_support/aligned_alloc/aligned_alloc.cc
new file mode 100644
index 00000000000..8af9c723ad1
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/aligned_alloc/aligned_alloc.cc
@@ -0,0 +1,42 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+#include <cstdlib>
+#include <cstdint>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+#ifdef _GLIBCXX_HAVE_ALIGNED_ALLOC
+ void* p = std::aligned_alloc(256, 1);
+ if (p)
+ {
+ VERIFY( (reinterpret_cast<std::uintptr_t>(p) % 256) == 0 );
+ std::free(p);
+ }
+#endif
+}
+
+int
+main()
+{
+ test01();
+}
More information about the Gcc-patches
mailing list