Building libc++ for sysroots in llvm-toolchain

227 views
Skip to first unread message

Bryan Chan

unread,
Sep 26, 2020, 10:13:11 PM9/26/20
to android-llvm
I was trying to build the latest code in llvm-toolchain to get a relatively standalone toolchain, but ran into a problem with libc++. While libc++.so.1 is built correctly for the host (i.e. out/install/linux-x86/clang-dev/lib64/libc++.so.1), only stubs are generated under the sysroot directories, which cannot actually be used for linking C++ programs that use the STL. Judging by the comment inside toolchain/llvm_android/do_build.py, it seems that libc++ is not built since NDK r15 because strtod_l is missing (http://b/64037266).

What is the correct way to build libc++ for arm and aarch64 sysroots?

Bryan

Pirama Arumuga Nainar

unread,
Sep 26, 2020, 10:49:19 PM9/26/20
to Bryan Chan, android-llvm, Dan Albert
libc++ for the device is built as part of the NDK.  See https://android.googlesource.com/platform/ndk/+/master/docs/Building.md for instructions to build the NDK.

(+danalbert, in case I'm wrong :)

--
You received this message because you are subscribed to the Google Groups "android-llvm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-llvm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-llvm/46a7c0f3-c344-45e9-8b19-6011548a1060n%40googlegroups.com.

Bryan Chan

unread,
Sep 26, 2020, 11:38:44 PM9/26/20
to android-llvm
Thanks, that's what I figured as well. I started syncing the ndk-release-r21 branch a few hours ago... it's still cloning!

Bryan Chan

unread,
Sep 27, 2020, 3:58:59 PM9/27/20
to android-llvm
I have synced the ndk-release-r21 branch and ran checkbuild.py to get a usable NDK toolchain with sysroot, under out/linux/android-ndk-r21d/. How do I go about modifying Clang and LLVM now? The ndk-release-r21 branch only contains prebuilt binaries and no obvious way to edit or rebuild Clang/LLVM. If I try to use the sysroot and lib directories from the NDK with the compiler I built from the llvm-toolchain branch, C++ programs fail to link with errors like this:

ld.lld: error: undefined symbol: std::__1::__basic_string_common<true>::__throw_length_error() const

Bryan

Bryan Chan

unread,
Sep 27, 2020, 4:01:26 PM9/27/20
to android-llvm
I found the relevant documentation: 


Sorry for the noise. Let me try again.

Bryan Chan

unread,
Sep 27, 2020, 7:43:42 PM9/27/20
to android-llvm
I built llvm-r353983 after my modification, and then unpacked the clang-dev tarball in the NDK prebuilts directory as per the instructions in Toolchains.md. checkbuild.py ran successfully. But the resulting toolchain is unusable; it seems that clang cannot find the sysroot automatically when invoked with -target aarch64-linux-android21, and ends up using the host system's headers. What did I do wrong? How do people hack Clang/LLVM inside the NDK, especially when we need to work with an older version than tip of trunk?

Dan Albert

unread,
Sep 28, 2020, 1:47:14 PM9/28/20
to Bryan Chan, android-llvm
If it's older enough it's probably missing several of the patches that make it work without manually configuring sysroots and whatnot. That's a pretty old compiler, so that's probably what happened.

Bryan Chan

unread,
Sep 29, 2020, 9:39:33 AM9/29/20
to android-llvm
Thanks Dan. That's exactly what happened. I was trying to use the AOSP 10 compiler as my baseline, not realizing that NDK r21 had moved on to a newer version of Clang/LLVM 9. Checking out llvm-r365631 allowed me to make more progress.
Reply all
Reply to author
Forward
0 new messages