Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc++ fails to compile on systems without posix_memalign #30796

Closed
jeremyhu mannequin opened this issue Dec 21, 2016 · 12 comments
Closed

libc++ fails to compile on systems without posix_memalign #30796

jeremyhu mannequin opened this issue Dec 21, 2016 · 12 comments
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@jeremyhu
Copy link
Mannequin

jeremyhu mannequin commented Dec 21, 2016

Bugzilla Link 31448
Resolution FIXED
Resolved on Nov 07, 2018 00:17
Version unspecified
OS All
CC @compnerd,@mclow

Extended Description

On older systems without posix_memalign, libcxx now fails to compile with:

new.cpp:73:14: error: no member named 'posix_memalign' in the global namespace
while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0)
~~^
1 error generated.

This regressed in 9acbffa370bd03e4e0ed742110e4c780b99c28ac with:

commit 9acbffa370bd03e4e0ed742110e4c780b99c28ac
Author: Eric Fiselier eric@efcs.ca
Date: Fri Oct 14 06:46:30 2016 +0000

Implement P0035R4 -- Add C++17 aligned allocation functions

Summary:
This patch implements the library side of P0035R4. The implementation is thanks to @&#8203;rsmith.

In addition to the C++17 implementation, the library implementation can be explicitly turned on using `-faligned-allocation` in all dialects.


Reviewers: mclow.lists, rsmith

Subscribers: rsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D25591

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@284206 91177308-0d34-0410-b5e6-96231b3b80d8

Can we test for the existence of posix_memalign

@jeremyhu
Copy link
Mannequin Author

jeremyhu mannequin commented Dec 21, 2016

Can we test for the existence of posix_memalign and disable support for C++17 aligned allocation functions if it doesn't exist? I'm not suggesting we implement that internally to libcxx, but that would obviously be an option as well.

@compnerd
Copy link
Member

On Windows, posix_memalign wouldn't be available, but _aligned_malloc would.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 23, 2016

@​Jeremy Can you be more specific about the platform causing issues? Is it just an older OS X version? If so do you know how to detect the availability of posix_memalign or Apple's libc version on that platform?

On Windows, posix_memalign wouldn't be available, but _aligned_malloc would.

Ack. I'll make that change right away.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 23, 2016

Windows fix made in r290448.

@jeremyhu
Copy link
Mannequin Author

jeremyhu mannequin commented Dec 24, 2016

posix_memalign was added in Snow Leopard, and we've (MacPorts) got some users still on Leopard that we try to support. Yes, that's a bit far back.

Something like this should do it in CMakeLists.txt:

CHECK_SYMBOL_EXISTS(posix_memalign "stdlib.h" HAVE_POSIX_MEMALIGN)
CHECK_SYMBOL_EXISTS(_aligned_malloc "malloc.h" HAVE_ALIGNED_MALLOC)

Then something like this in new.cpp:

#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_MALLOC)
#define SUPPORT_ALIGNED_ALLOCATION 1
#else
#define SUPPORT_ALIGNED_ALLOCATION 0
#endif

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 24, 2016

Using CMake to detect it doesn't work.

We need to be able to detect it inside so we know if we can offer the aligned new/delete overloads.

@jeremyhu
Copy link
Mannequin Author

jeremyhu mannequin commented Dec 24, 2016

Oh, well you could do something like this in :

#if defined(APPLE)

include <Availability.h>

if __MAC_OS_X_VERSION_MIN_REQUIRED < 1060

define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION

endif

#endif

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 24, 2016

Awesome thanks!

Can you point to the OS X documentation that specifies the min required version for posix_memalign? I can't seem to find it anywhere.

@jeremyhu
Copy link
Mannequin Author

jeremyhu mannequin commented Dec 24, 2016

It's declared in stdlib.h as:

int posix_memalign(void **, size_t, size_t) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0);

And I've also verified as such through nm.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 20, 2017

Fix up for review in D28931. I'll backport it to Clang 4.0 as well.

https://reviews.llvm.org/D28931

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 20, 2017

Fixed in r292564 and merged into the 4.0 release branch.

@jeremyhu
Copy link
Mannequin Author

jeremyhu mannequin commented Jan 20, 2017

Patch LGTM. Thanks.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants