Success: Bring-up of LLVM/clang-built Linux ARM(32-bit) kernel for Android - Nexus 5

Hello,

I would like to share my successful bring-up of LLVM/clang-built Linux ARM(32-bit) hammerhead kernel for Android running on my Nexus 5 smartphone. After having successfully brought up LLVM/clang-built Linux kernel(since v4.15.7 to the most recent v4.17) on x86_64, I was interested in accomplishing the same on the ARM platform of my Nexus 5 - Android smartphone. So, here is the complete report of the same for the interested people.

The main advantage of the clang-built Android ARM(32-bit) hammerhead kernel for my Nexus 5 has been the better battery usage when compared to that of gcc-built kernel, with the same kernel config and hardware(my Nexus 5 Android Smartphone). Details of the same can be found below.

NOTE : By the way, I came across some reports of ARM64 clang-kernel for some Android Smartphones - but, the information over there did not help for my ARM32 clang-kernel case of Nexus 5(hammerhead). So, I started off this project from scratch and it has been lot of *entirely my own original work* to first successfully build the ARM32 clang-kernel for Nexus 5(hammerhead) and second to make it actually work on the real hardware - Nexus 5.

For easy reading with formatting, etc : https://ubuntuforums.org/showthread.php?t=2394035

Cheers.

The main advantage of the clang-built Android ARM(32-bit) hammerhead kernel for my Nexus 5 has been the better battery usage when compared to that of gcc-built kernel, with the same kernel config and hardware(my Nexus 5 Android Smartphone). Details of the same can be found below.

To be fair, the GCC version which comes with the android ndk has not been updated for four years, while the clang version is kept up-to-date. It would be interesting to compare clang and GCC latest releases instead… that’s where the future lies :stuck_out_tongue:

Looks like you didn't read the whole article. Well, for more complete
comparison between GCC and LLVM/clang, I have used four different LLVM/clang
versions(old to to the new), from within the Google's Android NDK and from
outside of the NDK i.e., from other sources, in my project as under :

   1.

*NDK r13b LLVM/clang : Android clang version 3.8.256229 (based on LLVM
   3.8.256229) *
   2.

*Qualcomm Snapdragon LLVM/clang for Android : Snapdragon LLVM ARM Compiler
   4.0.2 for Android NDK (based on llvm.org <http://llvm.org> 4.0+) - clang
   version 4.0.2 for Android NDK *
   3.

*NDK r17 LLVM/clang : Android (4691093 based on r316199) clang version
   6.0.2 (https://android.googlesource.com/toolchain/clang
   <https://android.googlesource.com/toolchain/clang>
   183abd29fc496f55536e7d904e0abae47888fc7f)
   (https://android.googlesource.com/toolchain/llvm
   <https://android.googlesource.com/toolchain/llvm>
   34361f192e41ed6e4e8f9aca80a4ea7e9856f327) (based on LLVM 6.0.2svn) *
   4. *Main LLVM/clang : Flash clang version 7.0.332826
   (https://git.llvm.org/git/clang
   4029c7ddda99ecbfa144f0afec44a192c442b6e5) (https://git.llvm.org/git/llvm
   <https://git.llvm.org/git/llvm> 1181c40e0e24e0cca32e2609686db1f14151fc1a)
   (based on LLVM 7.0.332826)*

And I saw improved battery usage in all these cases as published over there
in my article. So, read the entire article before making assumptions... :stuck_out_tongue:

To be fair, the GCC version which comes with the android ndk has not been

updated for four years, while the clang version is kept up-to-date. It
would be interesting to compare clang and GCC latest releases instead...
that's where the future lies :stuck_out_tongue:

Looks like you didn't read the whole article. Well, for more complete
comparison between GCC and LLVM/clang, I have used four different LLVM/clang
versions(old to to the new), from within the Google's Android NDK and from
outside of the NDK i.e., from other sources, in my project as under :

   1.

*NDK r13b LLVM/clang : Android clang version 3.8.256229 (based on LLVM
   3.8.256229) *
   2.

*Qualcomm Snapdragon LLVM/clang for Android : Snapdragon LLVM ARM Compiler
   4.0.2 for Android NDK (based on llvm.org <http://llvm.org/> 4.0+) - clang
   version 4.0.2 for Android NDK *
   3.

*NDK r17 LLVM/clang : Android (4691093 based on r316199) clang version
   6.0.2 (https://android.googlesource.com/toolchain/clang
   <https://android.googlesource.com/toolchain/clang>183abd29fc496f55536e7d904e0abae47888fc7f)
   (https://android.googlesource.com/toolchain/llvm
   <https://android.googlesource.com/toolchain/llvm>
34361f192e41ed6e4e8f9aca80a4ea7e9856f327)
   (based on LLVM 6.0.2svn) *
   4. *Main LLVM/clang : Flash clang version 7.0.332826
   (https://git.llvm.org/git/clang
   <https://git.llvm.org/git/clang> 4029c7ddda99ecbfa144f0afec44a192c442b6e5)
   (https://git.llvm.org/git/llvm
   <https://git.llvm.org/git/llvm> 1181c40e0e24e0cca32e2609686db1f14151fc1a)
   (based on LLVM 7.0.332826)*

And I saw improved battery usage in all these cases as published over there
in my article. So, read the entire article before making assumptions... :stuck_out_tongue:

To be fair, the GCC version which comes with the android ndk has not been updated for four years, while the clang version is kept up-to-date. It would be interesting to compare clang and GCC latest releases instead… that’s where the future lies :stuck_out_tongue:

To account for the easy reading with formatting instead of plain-text format of mailing list, I also mentioned the URL to the thread where I have posted the same content.

All the Android versions I have used prior to my Android clang-kernel have been gcc-built from different ROMs(custom and AOSP) - none of them have given good experience
in terms of battery usage. AFAIK, for obvious reasons, Google has announced they have switched over from GCC to LLVM/clang for userspace and for kernel, they have done it to
some extent - not yet for ARM(32-bit) as I got to know and that’s why I was interested in it to accomplish it.

Having said that, I tried to use GCC-8-cross toolchain for gnueabi to build the Android kernel, there were some assembler error messages, so researched upon building the androideabi
version from gcc-8.1 source - the Android NDK toolchain source has some build scripts which need to be worked upon to pick out-of-tree gcc-source - so, not a straightforward process.
I saw some Linaro GCC toolchain but of the older 7.* version and not the latest 8.* one - I have seen some people using Linaro GCC as well to build the kernel but I didn’t see any
positive notes with respect to battery usage with that.

Anyway, I am satisfied with my Android clang-built kernel as it has been battery efficient as opposed to earlier gcc-built kernels and that’s with rest of the
Android(ramdisk, system image, etc) being the same including the hardware(Nexus 5).