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

[devkitPPC] ::aligned_alloc is available, but not std::aligned_alloc #4

Open
dkosmari opened this issue Oct 23, 2023 · 3 comments
Open

Comments

@dkosmari
Copy link

I'm reporting this here, since the gcc repo doesn't allow submitting issues.

In devkitPPC/powerpc-eabi/include/c++/13.2.0/powerpc-eabi/bits/c++config.h, the _GLIBCXX_HAVE_ALIGNED_ALLOC macro is not defined, and that prevents the C function aligned_alloc() to be imported into the std namespace for C++ (in cstdlib).

This code compiles:

#include <stdlib.h>
// ...
buffer = ::aligned_alloc(256, size);

but this doesn't:

#include <cstdlib>
// ...
buffer = std::aligned_alloc(256, size);
@dkosmari dkosmari changed the title ::aligned_alloc is available, but not std::aligned_alloc [devkitPPC] ::aligned_alloc is available, but not std::aligned_alloc Oct 23, 2023
@WinterMute
Copy link
Member

WinterMute commented Apr 28, 2024

The same error occurs for me on linux, mingw64 and macOS with both g++ and clang suggesting this usage isn't portable. Where is this a problem?

@WinterMute WinterMute transferred this issue from devkitPro/newlib Apr 28, 2024
@WinterMute
Copy link
Member

Further investigation shows -std=c++17 is necessary for my linux & macOS compilers to compile this test code

#include <cstdlib>
#include <cstdio>

int main(int argc, char **argv) {

	printf("alloc is %p\n", std::aligned_alloc(256, 1024));
	return 0;
}

Still won't work with mingw64 and, from what I can see here, won't work with other newlib based toolchains without patching. I do have a fix for this though which I'll apply for next release.

@dkosmari
Copy link
Author

dkosmari commented Apr 28, 2024

From inspecting the libstdc++v3 configuration scripts, I think it's simply missing a AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc), or the corresponding AC_DEFINE, in the non-native path. A lot of these function checks are hardcoded in crossconfig.m4 for each target, so it's expected for features to be missing until somebody manually patches them in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants