【问题标题】:Building android kernel构建安卓内核
【发布时间】:2021-03-29 09:20:29
【问题描述】:

两周以来,我尝试为我的 htc 设备构建内核。获得正确的资源不是问题,但由于 gcc 已从工具链中删除,这真是一场噩梦。遵循使用 clang 的建议总是以大量错误消息结束。

到目前为止我做了什么?

  1. 正确安装最新的android-ndk (21.3.6528147)
  2. 通过命令行成功测试交叉编译(只是一个简单的程序)
  3. 为内核构建设置 ENV 变量:(仅在尚未设置时导出命令)
$ cd <kernel-source-root>
($ make mrproper) // just after failed attempt to build
$ export ARCH=arm64
$ export SUBARCH=arm64
$ export CROSS_COMPILE=<path-to-toolchain-llvm-bin-folder>
  1. 修改 Makefile 和 AndroidKernel.mk
// replace all occurences of 'gcc' with 'clang'
-gcc 
+clang
  1. 生成.config
$ make msm-perf_defconfig
  1. 执行构建
$ make V=1
  1. 收到错误消息:
// ...
../kernel/bounds.c:18:2: error: unexpected token at start of statement
        DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);
        ^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
                        ^
<inline asm>:2:1: note: instantiated into assembly here
->NR_PAGEFLAGS 21 __NR_PAGEFLAGS
^
../kernel/bounds.c:19:2: error: unexpected token at start of statement
        DEFINE(MAX_NR_ZONES, __MAX_NR_ZONES);
        ^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
                        ^
<inline asm>:2:1: note: instantiated into assembly here
->MAX_NR_ZONES 3 __MAX_NR_ZONES
^
../kernel/bounds.c:21:2: error: unexpected token at start of statement
        DEFINE(NR_CPUS_BITS, ilog2(CONFIG_NR_CPUS));
        ^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
                        ^
<inline asm>:2:1: note: instantiated into assembly here
->NR_CPUS_BITS 3 ilog2(CONFIG_NR_CPUS)
^
../kernel/bounds.c:23:2: error: unexpected token at start of statement
        DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
        ^
../include/linux/kbuild.h:5:25: note: expanded from macro 'DEFINE'
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
                        ^
<inline asm>:2:1: note: instantiated into assembly here
->SPINLOCK_SIZE 4 sizeof(spinlock_t)
^
4 errors generated.
make[2]: *** [kernel/bounds.s] Error 1
make[1]: *** [prepare0] Error 2
make: *** [sub-make] Error 2

有人知道出了什么问题吗?

【问题讨论】:

  • 同样的错误,你发现@Sergio 有什么问题了吗?

标签: android macos toolchain android-kernel


【解决方案1】:

-no-integrated-as 添加到构建命令修复它。

根据 clang 开发者的说法:

添加-no-integrated-as。这是已知的编译器滥用编译器来输出汇编以外的东西。

reference

make ARCH=arm64 -j64 -no-integrated-as

【讨论】:

    猜你喜欢
    • 2015-08-06
    • 1970-01-01
    • 2012-05-08
    • 2020-05-13
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    相关资源
    最近更新 更多