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

NDK r15 missing c++17 aligned allocation operators #421

Closed
DoDoENT opened this issue Jun 12, 2017 · 10 comments
Closed

NDK r15 missing c++17 aligned allocation operators #421

DoDoENT opened this issue Jun 12, 2017 · 10 comments
Assignees
Milestone

Comments

@DoDoENT
Copy link

DoDoENT commented Jun 12, 2017

.../ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:2540: error: undefined reference to 'operator delete(void*, std::align_val_t)'
.../ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:3149: error: undefined reference to 'operator new(unsigned int, std::align_val_t)'
.../ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:2540: error: undefined reference to 'operator delete(void*, std::align_val_t)'
.../ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:3149: error: undefined reference to 'operator delete(void*, std::align_val_t)'

This happens to our program after updating to NDK r15 - only on armeabi-v7a. On arm64-v8a it works correctly.

My current workaround is to add this file to our codebase when using ARM7 slice:

#include <boost/align/aligned_alloc.hpp>

#include <cstddef>

namespace std
{
enum class align_val_t : size_t {};
}

void* operator new( std::size_t count, std::align_val_t alignment )
{
    return boost::alignment::aligned_alloc( static_cast< std::size_t >( alignment ), count );
}

void operator delete( void* ptr, std::align_val_t ) noexcept
{
    boost::alignment::aligned_free( ptr );
}
@DanAlbert
Copy link
Member

That's surprising. There are some known failures in the libc++ tests right now, but none of them like that. Clang or GCC?

@DoDoENT
Copy link
Author

DoDoENT commented Jun 12, 2017

Clang

@DanAlbert DanAlbert self-assigned this Jun 12, 2017
@DanAlbert
Copy link
Member

We'll be shipping an r15b to cover a misdefined API (libsync doesn't match its header). I'm going to investigate this today and see if there's a fix we can make at the same time.

@DanAlbert DanAlbert added this to the r15b milestone Jun 12, 2017
@DanAlbert
Copy link
Member

Looks like this just has to do with whether or not the compiler decides to use it or not. This test case:

struct alignas(16) vec4 {
  float x, y, z, w;
};

int main(int argc, char** argv) {
  auto vectors = new vec4[16];
  return 0;
}

Only works on LP64 ABIs (when built with -std=c++1z, of course). If I change the alignment to 64, it fails on LP64 too.

So, the reason this is happening is because we updated to a Clang that can take advantage of these, but we don't have a new enough libc++ to provide them. I got us up to matching the platform again last week, and was already planning to do a full update to HEAD for r16. Once that's done, this should be good to go.

This isn't anything we can do something about for r15b though. Updating libc++ is much too high risk for a hotfix.

You can maybe work around this by targeting C++14 instead. A lot of new stuff in libc++ gets backported to earlier standard versions, so other stuff you're trying to use might be available anyway. Unfortunately C++1z is still all experimental, so these sorts of things are somewhat expected.

@DanAlbert DanAlbert modified the milestones: r16, r15b Jun 12, 2017
@DoDoENT
Copy link
Author

DoDoENT commented Jun 13, 2017

The workaround from my first post works OK for us. Thanks for letting us know the issue is also present on ARM64.

Since we use boost as a fallback option for missing c++17 features on all platforms, this workaround is OK for us, i.e. it is not a showstopper, unlike issues #318 and #313.

@DanAlbert
Copy link
Member

Good to know.

FWIW, the former should be unblocked the next time we update the compiler (was https://reviews.llvm.org/D33287), and the latter is something on my list for r16 (though thanks for the reminder, I'd forgotten to actually assign it to the milestone).

@DanAlbert
Copy link
Member

The libc++ update is in r16 now. It looks like we need a newer Clang to actually get all the libc++ tests working in C++1z mode (which we planned to have anyway, just noting that we don't have it yet).

miodragdinic pushed a commit to MIPS/external-libcxx that referenced this issue Apr 17, 2018
Test: ndk/run_tests.py
Bug: android/ndk#421
Change-Id: I23b07ba8a064035bbc7dc4f2e1ec0e1ec85eb5c9
miodragdinic pushed a commit to MIPS/external-libcxx that referenced this issue Apr 17, 2018
Test: ndk/run_tests.py
Bug: android/ndk#421
Change-Id: I0765f5dffc6622f9b06a557b5a95d4900751c693
miodragdinic pushed a commit to MIPS/external-libcxxabi that referenced this issue Apr 17, 2018
Test: ndk/run_tests.py
Bug: android/ndk#421
@tcamargo
Copy link

tcamargo commented Aug 18, 2020

Hi All,

This issue seems to be back. Using NDK21d.

../../../../libretro/bin/mame_mame/liboptional.a(netlist.o):netlist.cpp:function netlist_mame_analog_output_device::pre_parse_action(netlist::nlparse_t&): error: undefined reference to 'aligned_alloc'

Compiling using std=c++14. Do I have to pass some extra lib when linking?

@DanAlbert
Copy link
Member

Not enough information for me to know. The test case above works fine for me. File a bug with a repro case.

@tcamargo
Copy link

Not enough information for me to know. The test case above works fine for me. File a bug with a repro case.

Thanks! Mame test cases are always a pain to reproduce. I will try to create a small tc.

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

3 participants