Building FP4 Kernel - some errors

Hiya,
trying to build the FP4 kernel on PopOS 21.10, following the instructions at Fairphone 4 Kernel Source Code — FAIRPHONE open source documentation

I keep running into this some errors pointing to four header files:
…/arch/arm64/include/asm/stack_pointer.h
…/arch/arm64/include/asm/kgdb.h
…/arch/arm64/include/asm/brk-imm.h
…/arch/arm64/include/asm/vdso/gettimeofday.h

full make output
$ make CC=clang LLVM=1 -j$(nproc)
make[1]: Entering directory '/home/user/ARM_tink/FP4/fp4-kernel/kernel/msm-4.19/build'
arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
arch/arm64/Makefile:48: Detected assembler with broken .inst; disassembly will be unreliable
  GEN     ./Makefile
  Using .. as source for kernel
  CC      arch/arm64/kernel/asm-offsets.s
In file included from ../arch/arm64/kernel/asm-offsets.c:21:
In file included from ../include/linux/arm_sdei.h:14:
In file included from ../arch/arm64/include/asm/sdei.h:15:
In file included from ../include/linux/preempt.h:81:
In file included from ./arch/arm64/include/generated/asm/preempt.h:1:
In file included from ../include/asm-generic/preempt.h:5:
In file included from ../include/linux/thread_info.h:38:
In file included from ../arch/arm64/include/asm/thread_info.h:31:
../arch/arm64/include/asm/stack_pointer.h:8:51: error: register 'sp' unsuitable for global register variables on this target
register unsigned long current_stack_pointer asm ("sp");
                                                  ^
In file included from ../arch/arm64/kernel/asm-offsets.c:27:
In file included from ../include/linux/suspend.h:5:
In file included from ../include/linux/swap.h:9:
In file included from ../include/linux/memcontrol.h:31:
In file included from ../include/linux/writeback.h:184:
In file included from ../include/linux/bio.h:21:
In file included from ../include/linux/highmem.h:12:
In file included from ../arch/arm64/include/asm/cacheflush.h:22:
In file included from ../include/linux/kgdb.h:20:
../arch/arm64/include/asm/kgdb.h:32:25: error: value '1025' out of range for constraint 'I'
        asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM));
                               ^~~~~~~~~~~~~~~~~~~~~~~~~
../arch/arm64/include/asm/brk-imm.h:23:35: note: expanded from macro 'KGDB_COMPILED_DBG_BRK_IMM'
#define KGDB_COMPILED_DBG_BRK_IMM       0x401
                                        ^~~~~
In file included from ../arch/arm64/kernel/asm-offsets.c:28:
In file included from ../include/vdso/datapage.h:114:
../arch/arm64/include/asm/vdso/gettimeofday.h:22:35: error: unknown register name 'x1' in asm
        register struct timezone *tz asm("x1") = _tz;
                                         ^
../arch/arm64/include/asm/vdso/gettimeofday.h:23:47: error: unknown register name 'x0' in asm
        register struct __kernel_old_timeval *tv asm("x0") = _tv;
                                                     ^
../arch/arm64/include/asm/vdso/gettimeofday.h:24:25: error: unknown register name 'x0' in asm
        register long ret asm ("x0");
                               ^
../arch/arm64/include/asm/vdso/gettimeofday.h:25:23: error: unknown register name 'x8' in asm
        register long nr asm("x8") = __NR_gettimeofday;
                             ^
../arch/arm64/include/asm/vdso/gettimeofday.h:39:44: error: unknown register name 'x1' in asm
        register struct __kernel_timespec *ts asm("x1") = _ts;
                                                  ^
../arch/arm64/include/asm/vdso/gettimeofday.h:40:31: error: unknown register name 'x0' in asm
        register clockid_t clkid asm("x0") = _clkid;
                                     ^
../arch/arm64/include/asm/vdso/gettimeofday.h:41:25: error: unknown register name 'x0' in asm
        register long ret asm ("x0");
                               ^
../arch/arm64/include/asm/vdso/gettimeofday.h:42:23: error: unknown register name 'x8' in asm
        register long nr asm("x8") = __NR_clock_gettime;
                             ^
../arch/arm64/include/asm/vdso/gettimeofday.h:56:44: error: unknown register name 'x1' in asm
        register struct __kernel_timespec *ts asm("x1") = _ts;
                                                  ^
../arch/arm64/include/asm/vdso/gettimeofday.h:57:31: error: unknown register name 'x0' in asm
        register clockid_t clkid asm("x0") = _clkid;
                                     ^
../arch/arm64/include/asm/vdso/gettimeofday.h:58:25: error: unknown register name 'x0' in asm
        register long ret asm ("x0");
                               ^
../arch/arm64/include/asm/vdso/gettimeofday.h:59:23: error: unknown register name 'x8' in asm
        register long nr asm("x8") = __NR_clock_getres;
                             ^
14 errors generated.
make[2]: *** [.././Kbuild:56: arch/arm64/kernel/asm-offsets.s] Error 1
make[1]: *** [/home/user/ARM_tink/FP4/fp4-kernel/kernel/msm-4.19/Makefile:1259: prepare0] Error 2
make[1]: Leaving directory '/home/user/ARM_tink/FP4/fp4-kernel/kernel/msm-4.19/build'
make: *** [Makefile:151: sub-make] Error 2

I haven’t compiled android kernels from source before and duckduckgoing leads me nowhere useful regarding these headers.

The instructions mention the CLANG/LLVM toolchain, not sure if I have everything relevant but I grabbed

these
$ sudo apt search llvm | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

clang/impish,now 1:13.0-53~exp1 amd64 [installed]
clang-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libclang-13-dev/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libclang-common-13-dev/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libclang-cpp13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libclang1-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
liblldb-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libllvm12/impish,now 1:12.0.1-8build1 amd64 [installed,automatic]
libllvm13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
libomp5-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm/impish,now 1:13.0-53~exp1 amd64 [installed]
llvm-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm-13-dev/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm-13-linker-tools/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm-13-runtime/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm-13-tools/impish,now 1:13.0.0-2 amd64 [installed,automatic]
llvm-dev/impish,now 1:13.0-53~exp1 amd64 [installed]
llvm-runtime/impish,now 1:13.0-53~exp1 amd64 [installed,automatic]
python3-clang/impish,now 1:13.0-53~exp1 amd64 [installed]
python3-clang-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]
python3-lldb/impish,now 1:13.0-53~exp1 amd64 [installed]
python3-lldb-13/impish,now 1:13.0.0-2 amd64 [installed,automatic]

Different env vars:

I did notice that the CROSS_COMPILE= environment variable used at AOSP differs from the one at FP4

AOSP:

CROSS_COMPILE=aarch64-linux-android-

FP4

CROSS_COMPILE=aarch64-linux-gnu-

don’t think this is relevant as I get the same errors with either variable.


My goal is to modify the kernel to run docker in the background as laid out in this gist

2 Likes

Hi,
with these following packages installed the kernel builds fine for me in a Ubuntu 21.10 container:

$ apt-get install bc binutils-aarch64-linux-gnu bison clang cpio flex libssl-dev lld llvm make xz-utils

You can also try removing the build/ directory, if you started a build with some build packages missing there might be some weird issues.

3 Likes

I’m almost certain that, while the kernel you are compiling is for aarch64, the compiler you are using is the x86 one (no other LLVM target can emit the message “register … unsuitable for global register variables on this target”). You need to use a cross-compiler too. This suggests that the value of CROSS_COMPILE you set is not getting picked up.

Note that CROSS_COMPILE is prepended to the filename of the toolchain components (compiler, linker, etc) when they’re executed, so you should use whichever is appropriate for whatever toolchain you have installed. If you get it wrong, kbuild will usually error out, but it’s rather easy for this to break and for it to fall back to just using the native compiler, with the results you see.

The FP4 versus AOSP CROSS_COMPILE values have the same ultimate meaning (“android” versus “gnu” relates to the C library, which the kernel doesn’t use), but if you pick the wrong one, you’ll still get misbehaviour. A simple ls /usr/bin/aarch64* should tell you which is right for your build system.

1 Like