Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to build goldfish kernel #11

Open
ysun opened this issue Apr 28, 2020 · 12 comments
Open

Failed to build goldfish kernel #11

ysun opened this issue Apr 28, 2020 · 12 comments

Comments

@ysun
Copy link

ysun commented Apr 28, 2020

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[1]: Entering directory '/data/kernel-android-emulator/goldfish/out'
  GEN     Makefile
#
# No change to .config
#
make[1]: Leaving directory '/data/kernel-android-emulator/goldfish/out'

make -j64 O=out ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu- CROSS_COMPILE=x86_64-linux-android-

root@chrome-server:/data/kernel-android-emulator/goldfish# make -j64 O=out  ARCH=x86_64 CC=clang CLANG_TRIPLE=x86_64-linux-gnu- CROSS_COMPILE=x86_64-linux-android-
make[1]: Entering directory '/data/kernel-android-emulator/goldfish/out'
  GEN     Makefile
scripts/kconfig/conf  --syncconfig Kconfig
scripts/Kconfig.include:39:  gold linker 'x86_64-linux-android-ld' not supported
make[3]: *** [../scripts/kconfig/Makefile:73: syncconfig] Error 1
make[2]: *** [../Makefile:571: syncconfig] Error 2
make[1]: *** [/data/kernel-android-emulator/goldfish/Makefile:691: include/config/auto.conf.cmd] Error 2
make[1]: Leaving directory '/data/kernel-android-emulator/goldfish/out'
make: *** [Makefile:179: sub-make] Error 2
root@chrome-server:/data/kernel-android-emulator/goldfish#

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

@ysun ysun changed the title Failed to build kernel Failed to build goldfish kernel Apr 28, 2020
@nathanchance
Copy link
Owner

You will need to use CROSS_COMPILE=x86_64-linux-androidkernel-

@ysun
Copy link
Author

ysun commented May 6, 2020

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.

@nathanchance
Copy link
Owner

You should not be getting that exact same error? x86_64-linux-androidkernel-ld explicitly points to ld.bfd.

@ysun
Copy link
Author

ysun commented May 6, 2020

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

@nathanchance
Copy link
Owner

What version of clang are you using? asm goto support was added to clang-9 so it must be rather old.

@ysun
Copy link
Author

ysun commented May 6, 2020

$ 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

@nathanchance
Copy link
Owner

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

@ysun
Copy link
Author

ysun commented May 6, 2020

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

@nathanchance
Copy link
Owner

You should probably add LD=ld.lld to your make command.

@ysun
Copy link
Author

ysun commented May 11, 2020

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?

@nathanchance
Copy link
Owner

No. Honestly, if you care about hacking up the kernel on a virtual Android platform, you should take a look at Cuttlefish.

https://source.android.com/setup/create/cuttlefish

https://nathanchance.dev/posts/building-using-cuttlefish/

@hongwen000
Copy link

hongwen000 commented Jul 29, 2022

@nathanchance Cuttlefish sucks, never worked normally like any Google "new" things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants