Skip to content

Instantly share code, notes, and snippets.

@MUWASEC
Last active April 14, 2025 20:16
Show Gist options
  • Save MUWASEC/edf05dc9676170cd7da89915fb1905de to your computer and use it in GitHub Desktop.
Save MUWASEC/edf05dc9676170cd7da89915fb1905de to your computer and use it in GitHub Desktop.
kernel build note
# builder gcc
https://github.com/a13xp0p0v/kernel-build-containers
# 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
================================================
# 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`
================================================
================================================
# 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`
================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment