Skip to content

libstdc++: Use of non-standard memalign instead of C11 aligned_alloc #675

Open
@stephanosio

Description

@stephanosio

libstdc++ seems to internally make use of the GNU memalign function instead of the ISO C aligned_alloc function.

Looking at the libstdc++ internals, it should be using the aligned_alloc instead of memalign when aligned_alloc is detected as available:

namespace __gnu_cxx {
#if _GLIBCXX_HAVE_ALIGNED_ALLOC
using ::aligned_alloc;
[...]
#elif _GLIBCXX_HAVE_MEMALIGN
static inline void*
aligned_alloc (std::size_t al, std::size_t sz)
{
  // Solaris requires al >= sizeof a word and QNX requires >= sizeof(void*)
  // but they both provide posix_memalign, so will use the definition above.
  return memalign (al, sz);
}
[...]
  while ((p = __gnu_cxx::aligned_alloc (align, sz)) == nullptr)

Find out why _GLIBCXX_HAVE_ALIGNED_ALLOC is not being defined and make sure it is defined and the non-standard memalign function is not used by libstdc++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: GCCIssues related to GCC (GNU Compiler Collection)area: libstdc++Issues related to libstdc++ (GNU C++ Library)priority: mediumMedium impact/importance issue

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions