a modified python script to build ndk for aarch64-linux-gnu with system library
This project is still in develop, building steps may occur unexpected errors.
export llvm-toolchain=path/to/empty_a
export aarch64ndk=path/to/empty_b
- Download ndk source code.
cd ${llvm-toolchain}
repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain
repo sync -c
- Clone this repository.
cd ${aarch64ndk}
git clone https://github.com/SnowNF/ndk-aarch64-linux
cd ${llvm-toolchain}/toolchain/llvm_android
mv patches ../patches #backup patches.
rm -rf *
cp -rf ${aarch64ndk}/ndk-aarch64-linux/* . #replace this repository's code
mv ../patchss patches #restore patches
To build the core clang binary, you need to install essential packages and try several times.
for Debian based
sudo apt install clang bison llvm llvm-dev python3 lld ninja-build cmake crossbuild-essential-arm64
try to build
cd ${llvm-toolchain}
python3 toolchain/llvm_android/build.py --no-build windows --skip-tests --single-stage --no-musl
To not always copy llvm source,you can try
cd ${llvm-toolchain} python3 toolchain/llvm_android/build.py --no-build windows --skip-tests --single-stage --no-musl --skip-source-setup
if building end with
/usr/include/limits.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
#include <bits/libc-header-start.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
This is mean that the clang core binary are built.
export NDK=/path/to/amd64/linux/ndk
cp -fr ${llvm-toolchain}/out/stage2/bin/clang* ${NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/
cp -fr ${llvm-toolchain}/out/stage2/lib/llvm-* ${NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/
cp -fr ${llvm-toolchain}/out/stage2/lib/lld* ${NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/
cp -fr ${llvm-toolchain}/out/stage2/lib/clang ${NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib/
cp -fr /usr/bin/make ${NDK}/prebuilt/linux-x86_64/bin/
cp -fr /usr/bin/yasm ${NDK}/prebuilt/linux-x86_64/bin/
cp -fr /usr/bin/ytasm ${NDK}/prebuilt/linux-x86_64/bin/
$ ./aarch64-linux-android33-clang test.c
$ file ./a.out
./a.out: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, not stripped
For the latest version of this doc, please make sure to visit: Android Clang/LLVM Toolchain Readme Doc
You can also visit the Android Clang/LLVM Prebuilts Readme Doc for more information about our prebuilt toolchains (and what versions they are based upon).
$ mkdir llvm-toolchain && cd llvm-toolchain
$ repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain
$ repo sync -c
$ python toolchain/llvm_android/build.py
The built toolchain will be installed to out/install/$HOST/clang-dev
.
If building on Linux, pass --no-build windows
to build.py
to skip
building Clang for Windows.
Pass the --lto
option to build.py
to build the toolchain with LTO. LTO is
enabled in official Android Clang/LLVM prebuilts but the flag is off by default.
This option only affects the second stage Clang toolchain and not the on-device
targets (compiler-rt, lldb-server etc).
If you have an additional llvm tree built and present in your $PATH
, then
build.py
might fail during the Windows build of libcxxabi with the error
'libstdc++ version must be at least 4.8.'
. The solution is to remove that
path from your $PATH
before invoking build.py
.
To rebuild a particular toolchain, find the manifest file for that release:
$ $TOOLCHAIN_DIR/bin/clang -v
Android (6317467 based on r365631c1) clang version 9.0.8...
The build number for that toolchain is 6317467
and the manifest is found in
$TOOLCHAIN_DIR/manifest_6317467.xml
Rebuild the toolchain with that manifest:
$ mkdir llvm-toolchain && cd llvm-toolchain
$ repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain
$ cp $TOOLCHAIN_DIR/manifest_6317467.xml .repo/manifests
$ repo init -m manifest_6317467.xml
$ repo sync -c
# Optional: Apply any LLVM/Clang modifications to toolchain/llvm-project
$ python toolchain/llvm_android/build.py
- Download source code.
We can use either llvm-toolchain or master-plus-llvm branch. master-plus-llvm branch is a combination of llvm-toolchain and aosp-master, which can test building platform and create the build switch CL in the same tree. llvm-toolchain is more suitable when trying to reproduce a toolchain from a different release.
$ mkdir master-plus-llvm && cd master-plus-llvm
$ repo init -u https://android.googlesource.com/platform/manifest -b master-plus-llvm
$ repo sync -c
- Update toolchain/llvm-project.
# replace r407598 with the update version
$ export NEW_REVISION=r407598
$ cd toolchain/llvm_android
$ ./merge_from_upstream.py --rev $NEW_REVISION
- Update build version.
In android_version.py: _patch_level = '1' _svn_revision = $NEW_REVISION
- Test build.
$ ./build.py
- Submit CLs in toolchain/llvm_android and toolchain/llvm-project together.
Examples are in aosp/1515350 and aosp/1515697.
It is to speed up compile time for the new compiler. The profdata is generated in go/ab/aosp-master-plus-llvm, target Clang-PGO.
An example is in aosp/1513058.
Use cherrypick_cl.py to cherry pick upstream patches:
$ ./cherrypick_cl.py --sha <upstream_patch1_sha> <upstream_patch2_sha> ... --verify-merge --create-cl
We want to find all patches before $NEW_REVISION but reverted after $NEW_REVISION in upstream. Search "revert-checker/android" emails to find candidates, and cherry pick them.
We may revert upstream patches locally or add local patches. Put patch files in patches/, and add patch info at the end of patches/PATCHES.json.
An example is in aosp/1556717.
Clang prebuilts are generated in go/ab/aosp-llvm-toolchain. Use update-prebuilts.py to download them.
$ ./update-prebuilts.py <build_number from aosp-llvm-toolchain>
Then upload clang prebuilts in prebuilts/clang/host/linux-x86, prebuilts/clang/host/darwin-x86, and prebuilts/clang/host/windows-x86 for testing.
An example is in aosp/1532505.
- Upload switch CL in build/soong.
In build/soong/cc/config/global.go: ClangDefaultVersion = "clang-$NEW_VERSION" ClangDefaultShortVersion = "<NEW_CLANG_MAJOR_VERSION>.0.1"
If ther are new compiler warnings we need to suppress, add them at the end of ClangExtraNoOverrideCflags in build/soong/cc/config/clang.go.
If there are new sanitizer flags we need to suppress, add them in build/soong/cc/sanitize.go.
An example is in aosp/1541244.
-
Put clang linux-x86 prebuilt CL and soong CL in the same topic. Run presubmit check.
-
Cherry pick the prebuilt and soong CLs to internal main, and run presubmit check. Some tests (like bionic fortify tests) only run there.
-
Use toolchain/llvm_android/test/scripts/test_prebuilts.py.
$ test/scripts/test_prebuilts.py --prebuilt_cl <linux-x86 cl no> --soong_cl <soong cl no> \
--tag "test_clang_${NEW_VERSION}_v1" --test_kind platform --build <build_number of prebuilts> \
--verbose
The test results are shown in go/forrest.
After all tests complete. Run test/scripts/update_results.py
to upload results to
go/android-llvm-testing-dashboard.
Some device_boot_health_check tests are flaky. So it is unlikely to get fully green results.
- Manually test on linux.
Below tests have been affected by compiler updates. It's better to test them manually on all architectures (arm, arm64, x86, x86_64). bionic_unit_tests or CtsBionicTestCases CtsNNAPITestCases CtsMediaV2TestCases
- Manually test on windows.
Run on wine using test/platform/run_windows_tests.sh.
- Manually test on darwin.
We used to build platform on darwin. But probably we will change to only build and run selected tests.
Currently we submit prebuilts before the soong CL. This usually needs the soong CL to wait for at least six hours to pass presubmit check. Maybe we can submit them together if that is supported by RBE.
All places need to switch to the new compiler are listed in https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/README.md.
The updates in the kernel and NDK are done separately.
After switching, we also need to update the doc.
We have a public mailing list that you can subscribe to: [email protected]