Last active
August 18, 2025 10:55
-
-
Save MUWASEC/edf05dc9676170cd7da89915fb1905de to your computer and use it in GitHub Desktop.
kernel build note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linux kernel "slab virtual" edition | |
https://github.com/thejh/linux/commit/aa0a1fb37ba0c2180da51254dce2268cb7c34813 | |
# kernel source | |
https://www.kernel.org/pub/linux/kernel/ | |
https://cdn.kernel.org/pub/linux/kernel/ | |
# builder gcc | |
https://github.com/a13xp0p0v/kernel-build-containers | |
# compile | |
make menuconfig | |
make -j$(nproc) | |
# enable debug kconfig | |
Kernel hacking -> Generic Kernel Debugging Instruments -> KGDB: kernel debugger | |
Kernel hacking -> Compile-time checks and compiler options -> Compile the kernel with debug info | |
scripts/config --enable DEBUG_INFO | |
scripts/config --enable DEBUG_KERNEL | |
scripts/config --disable CC_OPTIMIZE_FOR_SIZE | |
scripts/config --enable GDB_SCRIPTS | |
# we want below file | |
- vmlinux: uncompressed kernel with full symbols (you want this!) | |
- arch/x86/boot/bzImage: bootable compressed image (x86_64) | |
- arch/arm64/boot/Image (aarch64) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# android kernel | |
> emulator: | |
| specific qemu for running the android vm | |
https://github.com/f-droid/android-sdk-transparency-log/blob/master/signed/checksums.json | |
- https://dl.google.com/android/repository/emulator-windows_x64-<num>.zip | |
- https://dl.google.com/android/repository/emulator-linux_x64-<num>.zip | |
- https://mirrors.cloud.tencent.com/AndroidSDK/ (index file listing) | |
> aosp/sdk | |
| image and stuff | |
| get info from source.properties, https://dl.google.com/android/repository/sys-img/android/$arch-$api_$revision.zip | |
| $arch = SystemImage.Abi | |
| $api = AndroidVersion.ApiLevel | |
| $revision = Pkg.Revision | |
| arm64-v8a-25_r01.zip, x86_64-25_r01.zip | |
> build | |
| yay -S jdk8-openjdk python2 ncurses5-compat-libs repo | |
# case study | |
- emulate Android 7.1.1_r20, Kernel version: Linux 3.10.0 | |
- host linux (arch linux x64) | |
| Android emulator version 30.3.5.0 | |
| Emulator linux_x64-7033400 | |
| target kernel-ranchu aarch64/arm64 | |
> emulator: | |
- https://dl.google.com/android/repository/emulator-linux_x64-7033400.zip | |
> build kernel-ranchu | |
cd /opt/ | |
# --- kernel --- | |
git clone --branch android-goldfish-3.10 https://android.googlesource.com/kernel/goldfish.git android-goldfish-3.10 | |
# --- toolchain --- | |
git clone --branch android-7.1.1_r20 https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9.git aarch64-gcc-4.9-7.1.1_r20 | |
# --- toolchain setup --- | |
export CC_PATH=$PWD/aarch64-gcc-4.9-7.1.1_r20/bin | |
export ARCH=arm64 SUBARCH=arm64 CROSS_COMPILE=$CC_PATH/aarch64-linux-android- | |
# --- build --- | |
make ARCH=arm64 ranchu_defconfig | |
make -j`nproc` | |
# case error | |
================================================ | |
``` | |
emulator: CPU Acceleration: DISABLED | |
emulator: CPU Acceleration status: KVM requires a CPU that supports vmx or svm | |
emulator: ERROR: CPU acceleration is not supported on this machine! | |
emulator: ERROR: Reason: KVM requires a CPU that supports vmx or svm | |
``` | |
> check for kvm support : | |
$ egrep --color '(vmx|svm)' /proc/cpuinfo | |
> fix by run emulator with : | |
-accel off | |
-qemu -accel tcg | |
================================================ | |
================================================ | |
``` | |
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x50): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here | |
collect2: error: ld returned 1 exit status | |
make[2]: *** [scripts/Makefile.host:127: scripts/dtc/dtc] Error 1 | |
make[1]: *** [scripts/Makefile.build:455: scripts/dtc] Error 2 | |
make[1]: *** Waiting for unfinished jobs.... | |
make: *** [Makefile:518: scripts] Error 2 | |
``` | |
> apply https://github.com/BPI-SINOVOIP/BPI-M4-bsp/issues/4#issuecomment-1140414552 | |
================================================ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
================================================ | |
# compile older kernel in modern kernel # | |
================================================ | |
arch/x86/entry/thunk_64.o: warning: objtool: missing symbol table | |
make[2]: *** [scripts/Makefile.build:361: arch/x86/entry/thunk_64.o] Error 1 | |
make[2]: *** Deleting file 'arch/x86/entry/thunk_64.o' | |
make[1]: *** [scripts/Makefile.build:497: arch/x86/entry] Error 2 | |
make: *** [Makefile:1752: arch/x86] Error 2 | |
user@bcaa1fe2e35a:/src$ exit | |
================================================ | |
solution: https://www.reddit.com/r/archlinux/comments/pl9pak/compiling_older_versions_of_the_kernel_using/ | |
`Apply this patch to fix builds with binutils 2.36: https://github.com/torvalds/linux/commit/1d489151e9f9d1647110277ff77282fe4d96d09b.patch` | |
`Or presumably also: https://github.com/torvalds/linux/commit/de979c83574abf6e78f3fa65b716515c91b2613d.patch` | |
================================================ | |
- | |
================================================ | |
Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373. | |
/src/kernel/Makefile:133: recipe for target 'kernel/timeconst.h' failed | |
make[1]: *** [kernel/timeconst.h] Error 255 | |
Makefile:791: recipe for target 'kernel' failed | |
make: *** [kernel] Error 2 | |
================================================ | |
version: 3.7.1 | |
solution: https://lkml.org/lkml/2012/11/18/159 | |
basically remove all "defined()" inside kernel/timeconst.pl | |
================================================ | |
================================================ | |
# enable some non-builtin module like userfaultfd # | |
================================================ | |
In file included from help.c:12: | |
In function 'xrealloc', | |
inlined from 'add_cmdname' at help.c:24:2: | |
subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=use-after-free] | |
56 | ret = realloc(ptr, size); | |
| ^~~~~~~~~~~~~~~~~~ | |
subcmd-util.h:52:21: note: call to 'realloc' here | |
52 | void *ret = realloc(ptr, size); | |
| ^~~~~~~~~~~~~~~~~~ | |
subcmd-util.h:58:31: error: pointer may be used after 'realloc' [-Werror=use-after-free] | |
58 | ret = realloc(ptr, 1); | |
| ^~~~~~~~~~~~~~~ | |
subcmd-util.h:52:21: note: call to 'realloc' here | |
52 | void *ret = realloc(ptr, size); | |
| ^~~~~~~~~~~~~~~~~~ | |
cc1: all warnings being treated as errors | |
make[4]: *** [/src/tools/build/Makefile.build:97: /src/tools/objtool/help.o] Error 1 | |
make[3]: *** [Makefile:59: /src/tools/objtool/libsubcmd-in.o] Error 2 | |
make[2]: *** [Makefile:71: /src/tools/objtool/libsubcmd.a] Error 2 | |
make[1]: *** [Makefile:68: objtool] Error 2 | |
make: *** [Makefile:1854: tools/objtool] Error 2 | |
user@5ec1f7f69896:/src$ exit | |
================================================ | |
solution: https://unix.stackexchange.com/a/767697 | |
`Add -Wno-use-after-free to the makefile tools/lib/subcmd/Makefile Line 22.` | |
specifically at CFLAGS like below | |
`CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC -Wno-use-after-free` | |
================================================ |
Comments are disabled for this gist.