Open ysun opened 4 years ago
You will need to use CROSS_COMPILE=x86_64-linux-androidkernel-
The same. It seems we need lots of environment setting for CLang. I's now using the whole Android compiling environment to build a kernel.
You should not be getting that exact same error? x86_64-linux-androidkernel-ld
explicitly points to ld.bfd
.
Thanks nathanchance for your quick response. I re-ran the building as following: Indeed, I got a different failure. my repo: https://android.googlesource.com/kernel/goldfish/ branch: "android-5.4"
$ make O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu x86_64_defconfig
make[1]: Entering directory '/data/kernel-android-emulator/goldfish/out'
GEN Makefile
#
# configuration written to .config
#
make[1]: Leaving directory '/data/kernel-android-emulator/goldfish/out'
$ make O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu- CROSS_COMPILE=x86_64-linux-androidkernel-
make[1]: Entering directory '/data/kernel-android-emulator/goldfish/out'
GEN Makefile
HOSTCC arch/x86/tools/relocs_32.o
HOSTCC arch/x86/tools/relocs_64.o
HOSTCC arch/x86/tools/relocs_common.o
HOSTLD arch/x86/tools/relocs
HOSTCC scripts/selinux/genheaders/genheaders
HOSTCC scripts/selinux/mdp/mdp
HOSTCC scripts/kallsyms
HOSTCC scripts/pnmtologo
HOSTCC scripts/conmakehash
HOSTCC scripts/sortextable
HOSTCC scripts/asn1_compiler
HOSTCC scripts/extract-cert
WRAP arch/x86/include/generated/asm/dma-contiguous.h
WRAP arch/x86/include/generated/asm/early_ioremap.h
WRAP arch/x86/include/generated/asm/export.h
WRAP arch/x86/include/generated/asm/mcs_spinlock.h
WRAP arch/x86/include/generated/asm/mm-arch-hooks.h
WRAP arch/x86/include/generated/asm/mmiowb.h
Compiler lacks asm-goto support.
make[1]: *** [arch/x86/Makefile:308: checkbin] Error 1
make[1]: Leaving directory '/data/kernel-android-emulator/goldfish/out'
make: *** [Makefile:179: sub-make] Error 2
What version of clang are you using? asm goto support was added to clang-9 so it must be rather old.
$ clang --version
Android (5484270 based on r353983c) clang version 9.0.3 (https://android.googlesource.com/toolchain/clang 745b335211bb9eadfa6aa6301f84715cee4b37c5) (https://android.googlesource.com/toolchain/llvm 60cf23e54e46c807513f7a36d0a7b777920b5881) (based on LLVM 9.0.3svn)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/goldfish-kernel-54/prebuilts-master/clang/host/linux-x86/clang-r353983c/bin
I would use clang-r377782c
, that appears to be what upstream goldfish uses: https://android.googlesource.com/kernel/goldfish/+/refs/heads/android-5.4/build.config.common#8
Cool, clang-r377782c works~! But there is still some issue.
$ make O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu- CROSS_COMPILE=x86_64-linux-androidkernel-
AR arch/x86/lib/built-in.a
GEN .version
CHK include/generated/compile.h
UPD include/generated/compile.h
CC init/version.o
AR init/built-in.a
LD vmlinux.o
MODPOST vmlinux.o
MODINFO modules.builtin.modinfo
LD .tmp_vmlinux1
KSYM .tmp_kallsyms1.o
LD .tmp_vmlinux2
KSYM .tmp_kallsyms2.o
LD vmlinux
SORTEX vmlinux
SYSMAP System.map
LDS arch/x86/boot/compressed/vmlinux.lds
AS arch/x86/boot/compressed/head_64.o
VOFFSET arch/x86/boot/compressed/../voffset.h
CC arch/x86/boot/compressed/misc.o
CC arch/x86/boot/compressed/cmdline.o
CC arch/x86/boot/compressed/error.o
OBJCOPY arch/x86/boot/compressed/vmlinux.bin
RELOCS arch/x86/boot/compressed/vmlinux.relocs
Invalid absolute R_X86_64_32S relocation: _etext
make[3]: *** [../arch/x86/boot/compressed/Makefile:130: arch/x86/boot/compressed/vmlinux.relocs] Error 1
make[3]: *** Deleting file 'arch/x86/boot/compressed/vmlinux.relocs'
make[2]: *** [../arch/x86/boot/Makefile:112: arch/x86/boot/compressed/vmlinux] Error 2
make[1]: *** [arch/x86/Makefile:289: bzImage] Error 2
make[1]: Leaving directory '/data/kernel-android-emulator/goldfish/out'
make: *** [Makefile:179: sub-make] Error 2
You should probably add LD=ld.lld
to your make
command.
Yes, awesome! By add LD=ld.ldd, I can compile Android kernel now. BTW, do you know how to replace 5.4 kernel in Android emulator? Must I repackage system image?
No. Honestly, if you care about hacking up the kernel on a virtual Android platform, you should take a look at Cuttlefish.
@nathanchance Cuttlefish sucks, never worked normally like any Google "new" things.
Hi the guide is pretty cool. But I met a failure when I make kernel:
make O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu x86_64_defconfig
make -j64 O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu- CROSS_COMPILE=x86_64-linux-android-
I have not much experience on compiling Android or cross build kernel, so could you please guide me more ? Great thank.
Before the code change, I can cross build kernel 4.19 with gcc, but i have no idea how to do that with CLang.
Thanks --Yi