[Android Software/Hacking General [Developers Only]] newbit:
Hi nathanchance,

thanks for your thread, I am struggling a bit to get make running. Maybe you could help me out please?

I would like to build a goldfish kernel 5.4

uname -r && uname -v
5.4.61-android11-2-00064-g4271ad6e8ade-ab6991359
#1 SMP PREEMPT Mon Nov 23 17:45:44 UTC 2020

git clone -b android-goldfish-5.4-dev --single-branch https://android.googlesource.com/kernel/goldfish

Because of your github page, I figured I need the CLANG Toolchain instead of the GCC 4.9.

The GCC 4.9 worked very well with a 4.14. Goldfish kernel. I also git cloned the recommend CLANG Toolchain.

git clone \
-b android-11.0.0_r27 \
--single-branch https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86

After my exports from within goldfish:

export PATH=$PATH:$(pwd)/../linux-x86/clang-r383902b/bin
export PATH=$PATH:$(pwd)/../x86_64-linux-android-4.9/bin

I try to run a make savedefconfig:

make savedefconfig ARCH=x86_64 \
CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=x86_64-linux-android-

But it breaks right away with this message:

scripts/kconfig/conf --savedefconfig=defconfig Kconfig
scripts/Kconfig.include:39: gold linker 'x86_64-linux-android-ld' not supported
make[1]: *** [scripts/kconfig/Makefile:78: savedefconfig] Error 1
make: *** [Makefile:571: savedefconfig] Error 2

(I do have a .config file from an AVD, which I want to create a defconfig of it...)

I am getting a bit confused, because of your statements:

I thought when using a 5.4 Kernel, GCC is obsolete and CLANG replaced it?! What am I missing here? Which 64-bit GCC is needed? The 4.9 pops up the error message above.

Update 09.01.2021

I actually made it work! The Kernel now builds without Errors! And the bootup sequence

from the stock kernel is identical until Run /init as init process

[ 1.383866] Run /init as init process
[ 1.388899] init: init first stage started!
[ 1.390740] init: Loading module /lib/modules/btbcm.ko with args ""
[ 1.392283] btbcm: disagrees about version of symbol module_layout
[ 1.393818] init: Failed to insmod '/lib/modules/btbcm.ko' with args ''
[ 1.395154] init: LoadWithAliases was unable to load btbcm
[ 1.396361] init: [libfs_mgr]ReadFstabFromDt(): failed to read fstab from dt
[ 1.398041] init: Using Android DT directory /proc/device-tree/firmware/android/
[ 1.425461] init: bool android::init::BlockDevInitializer::InitDevices(std::set<std::string>): partition(s) not found in /sys, waiting for their uevent(s): metadata, super, vbmeta
[ 11.438802] init: Wait for partitions returned after 10010ms
[ 11.440723] init: bool android::init::BlockDevInitializer::InitDevices(std::set<std::string>): partition(s) not found after polling timeout: metadata, super, vbmeta
[ 11.445314] init: Failed to mount required partitions early ...
[ 11.447176] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00007f00

I guess the real issu lies in btbcm: disagrees about version of symbol module_layout

The stock kernel at this point, just keeps loading module after module.

I've compared the Module.symvers from the common and goldfish 5.4 Kernel, and they

even differ in the first 2 lines. I guess this the End Of The Line ? Any Idea how I can get

the right kernel source with the proper symbol versions? Or how I can adjust my build configs?

### Kernel try with Android 11 Kernel 5.4
mkdir avdkernel5.4compile && cd avdkernel5.4compile

git clone \
-b android-11.0.0_r28 \
--single-branch https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9

git clone -b android-11.0.0_r28 --single-branch https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/
git clone -b android-goldfish-5.4-dev --single-branch https://android.googlesource.com/kernel/goldfish
git clone https://android.googlesource.com/kernel/prebuilts/build-tools

mkdir clang-r383902 && cd clang-r383902
wget https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/android-11.0.0_r28/clang-r383902.tar.gz
tar -xzf clang-r383902.tar.gz && cd ..

git clone -b android11-5.4 --single-branch https://android.googlesource.com/kernel/common
git clone -b android11-5.4 --single-branch https://android.googlesource.com/kernel/common-modules/ common-modules/virtual-device
####

### export stuff:
cd goldfish
export ARCH=x86_64
export CLANG_TRIPLE=x86_64-linux-gnu-
export CROSS_COMPILE=x86_64-linux-androidkernel-
export LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=$(pwd)/../x86_64-linux-android-4.9/bin
export CLANG_PREBUILT_BIN=$(pwd)/../clang-r383902/bin
export BUILDTOOLS_PREBUILT_BIN=$(pwd)/../build-tools/linux-x86
DEVEXPS="CC=clang LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy DEPMOD=depmod EXTRA_CMDS='' STOP_SHIP_TRACEPRINTK=1 DO_NOT_STRIP_MODULES=1"
export PATH=$PATH:$LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN:$CLANG_PREBUILT_BIN:$BUILDTOOLS_PREBUILT_BIN
###

### merging adb pulled .config with cloned kernel devconfigs
cp ../config .config
make savedefconfig $DEVEXPS
mv defconfig arch/x86/configs/avd_pulled_defconfig && rm .config

./scripts/kconfig/merge_config.sh -m \
./arch/x86/configs/avd_pulled_defconfig \
./arch/x86/configs/gki_defconfig
x86_64_defconfig

make savedefconfig $DEVEXPS
mv defconfig arch/x86/configs/merged_gki_avd_pulled_defconfig && rm .config
### build the kernel
make $DEVEXPS merged_gki_avd_pulled_defconfig
time make $DEVEXPS -j$(nproc)
###

Update 12.01.2021

This time, I really made it working! I "just" had to add the EXTRAVERSION from the original stock Kernel Build to the LOCALVERSION in the .config file.

[ 0.000000] Linux version 5.4.61-android11-2-00064-g4271ad6e8ade-ab6991359 (build-user@build-host) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Mon Nov 23 17:45:44 UTC 2020

-g4271ad6e8ade

And then the build kernel from the common source became to:

[ 0.000000] Linux version 5.4.61-g4271ad6e8ade-00014-g158eae717346 (build-user@build-user) (Android (6443078 based on r383902) clang version 11.0.1 (https://android.googlesource.com/toolchain/llvm-project b397f81060ce6d701042b782172ed13bee898b79), LLD 11.0.1 (/buildbot/tmp/tmp6_m7QH b397f81060ce6d701042b782172ed13bee898b79)) #1 SMP PREEMPT Mon Jan 11 12:58:18 CET 2021

Now it boots the Android 11 (R) AVD with Google Play Store APIs.

Also I've updated my rootAVD script to root it with Magisk-v21.2

More details soon in a seperated [GUIDE]

Thanks for reading

NewBit