1As of Android S, this deprecation is fully complete (except for ARCH=arm on
2android-4.19-stable) and step 9 which is being cleaned up for Android T.
3
4The relevant kernel commits are:
5v5.7-rc1:
6commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default tools to Clang/LLVM")
7v5.15-rc1:
8commit f12b034afeb3 ("scripts/Makefile.clang: default to LLVM_IAS=1")
9
10The original version of this document is retained below:
11
12---
13
14In the effort to improve test coverage of the LLVM substitutes when building
15Linux kernels for Android distributions, as well as minimize build
16dependencies, we plan to phase kernel builds over to use the LLVM substitutes
17distributed through AOSP for Android S. This will remove the kernels from being
18dependent on binutils in Android. The NDK is currently the other largest
19dependency.
20
21Invoking a kernel build with all of the substitutes is tedious; see
22https://www.kernel.org/doc/html/latest/kbuild/llvm.html#llvm-utilities, so
23`make LLVM=1` was introduced in:
24commit a0d1c951ef08 ("kbuild: support LLVM=1 to switch the default tools to Clang/LLVM")
25which first landed in v5.7-rc1 and will need to be backported to at least 5.4.
26
27Support for using Clang's "integrated assembler" is a risk; we have gotten it
28working upstream, but then small changes to assembly quickly uncover missing
29support. Thus `LLVM_IAS=1` is a separate flag from `LLVM=1`.
30
31The plan for S is:
32
331. Ensure a0d1c951ef08 is backported to all supported kernel version branches
34   for S.
352. Wire up support in Android common kernel's build/build.sh to forward
36   `LLVM=1` to `make` from a supplied config. `LLVM=1` needs to be specified
37   for all invocations of `make`.
383. Update kernel configs to use `LLVM=1` and remove the individual flags like
39   `CC=clang`, `NM=llvm-nm`, and such.
404. Create a branch of
41   https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/
42   that only contains the GNU as (assembler) binary.
43   (https://android.googlesource.com/platform/prebuilts/gas/linux-x86/)
445. Update repo manifests for kernels to use the branch from 4, and ensure
45   kernels build cleanly.
466. Remove GNU binutils from Android kernel manifests.
47
485 is potentially a lot of work, depending on whether we have a lot of fixes to
49backport or certain configs are broken that haven't been tested upstream.
50
51A stretch goal, assuming we get LLVM_IAS=1 in shape:
52
537. Wire up support in Android common kernel's build/build.sh to forward
54   `LLVM_IAS=1` to `make` from a supplied config. `LLVM_IAS=1` needs to be
55   specified for all invocations of `make`. Alternatively, we can just modify
56   the top level Makefile to do what LLVM_IAS=1 would do anyways, though having
57   flexibility of turning it off quickly should it regress in mainline is
58   probably a safer bet.
598. Update kernel configs to use `LLVM_IAS=1`, unless we simply modified the top
60   level Makefile in 6.  At this point we will be using Clang's integrated
61   assembler.
629. Remove prebuilts/gas/linux-x86 (from step 4) from Android kernel manifests.
63
64I think we can get all 9 done for S, but 7,8,9 are a risk, and aren't critical
65to solve for S. Luckily, our comrades over at CrOS LLVM are helping whip
66Clang's integrated assembler into shape. In fact, they may end up beating us to
67the punch.
68
69See this public hotlist for some of the outstanding issues to be resolved.
70https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aissue+is%3Aopen+label%3A%22%5BTOOL%5D+integrated-as%22
71(Not all of those are blockers).
72
73The version of GNU binutils distributed by AOSP is version 2.27.0.20170315 (ToT
74GNU binutils is 2.35) plus cherry picks. The 5.9-rc1 linux kernel currently
75requires binutils 2.23 or newer.
76
77## Contingency Plans
78
79Let's say a kernel change doesn't work with Clang's integrated assembler. The
80immediate question is "does this change need to land now, or can we bear a
81revert until Clang's integrated assembler is fixed?"
82
83With the answer to the above question being "Yes, revert now please" then the
84contingency plan is:
851. file a bug, or at least email [email protected] and
86   [email protected].
872. revert step 9 above.
883. revert step 8 above.
894. Wait for toolchain feature or bug to be fixed in upstream LLVM.
905. Wait for AOSP LLVM release containing fix.
916. Move kernel builds to newer toolchains.
927. Reapply step 8 above.
938. Reapply step 9 above.
94
95With the answer to the above question being "No, we can wait for assembler
96support" then the contingency plan is:
971. file a bug, or at least email [email protected] and
98   [email protected].
992. Wait for toolchain feature or bug to be fixed in upstream LLVM.
1003. Wait for AOSP LLVM release containing fix.
1014. Move kernel builds to newer toolchains.
102