Libc++abi linking problem with newlib

Hi All.
I am trying to use LLVM+CLANG for bare metal compilation (cross compilation on x86_64 host for aarch64 target). I have successfully compiled clang, then compiled newlib with clang, then I compiled libc++abi against the newlib build. The libc++abi (and libc++) was successfully built. But when I try to link any c++ program I get:

ld.lld: error: undefined symbol: posix_memalign

referenced by stdlib_new_delete.cpp
stdlib_new_delete.cpp.o:(operator new(unsigned long, std::align_val_t)) in archive /opt/clang/lib/clang-runtimes/aarch64/lib/libc++abi.a

Is there a newlib equivalent (memalign maybe?) that I can use instead of posix_memalign()?
Is there any documentation on how to compile llvm’s c++ libraries for baremetal?

Thank you

Would this link help you:

Not really, this link uses picolibc, which is too ‘thin’ for my needs. With the link you mentioned, you get immediate failures if only include <iostream> (because locales are not supported). This is why I was aiming for the full newlib.

Hi Ben,

As of Make C++ example use iostream by mplatings · Pull Request #151 · ARM-software/LLVM-embedded-toolchain-for-Arm · GitHub the toolchain support for iostream was enabled.

LLVM 14 based version (Release release-14.0.0 · ARM-software/LLVM-embedded-toolchain-for-Arm · GitHub) did use newlib, though locales were not supported in the prebuilt configuration either.

FYI this Fix "undefined symbol: operator new" by mplatings · Pull Request #136 · ARM-software/LLVM-embedded-toolchain-for-Arm · GitHub is the fix for the same, I believe, problem in picolibc, since picolibc is based on newlib, the fix might be similar.

Oh that’s great, I will definitely try that. Even though I would still be interested in having a full newlib along with libc++, and not picolibc, as picolibc is designed for embedded, and my goal is to run it on a simulator so newlib is my preferred choice.
Isn’t it possible to enable posix_memalign in newlib somehow? I saw that newlib is ISO C implementation only, but I will try to find a way to enable it there…