I'm trying to recompile the kernel (following the official Arch Linux guide: https://wiki.archlinux.org/title/Kernel/Traditional_compilation) but every time I get compilation errors:

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]: *** [/home/jenusi/Downloads/linux-5.15/tools/build/Makefile.build:97: /home/jenusi/Downloads/linux-5.15/tools/objtool/help.o] Error 1
make[3]: *** [Makefile:59: /home/jenusi/Downloads/linux-5.15/tools/objtool/libsubcmd-in.o] Error 2
make[2]: *** [Makefile:63: /home/jenusi/Downloads/linux-5.15/tools/objtool/libsubcmd.a] Error 2
make[1]: *** [Makefile:69: objtool] Error 2
make: *** [Makefile:1371: tools/objtool] Error 2

Kernel: 5.15.54, GCC: 12.1.0

2 Answers 2


First of all, your make is not "crashing", it's exiting due to GCC errors.

GCC 12.1 is ill-advised to compile certain kernels because it enables new stricter checks in terms of code [quality] which means that various -Werror options ("treat warnings as errors") could result in errors which were not present in earlier versions of the compiler.

You have several options:

  • Use an older GCC version, e.g. GCC 11.4
  • With GCC 12.1: edit Makefile(s) and remove -Werror=use-after-free
  • Wait for kernel patches (which may or may not come) to fix these errors
  • In my Makefile there is nothing like -Werror=use-after-free. I also tried downgrading (downloading the older package from archive.archlinux.org) with pacman -U package but It just gives me an error that It would break dependencies, do you know another way?
    – jenusipr
    Jul 13, 2022 at 9:47
  • -Werror= is not necessarily in the Makefile, it could be in any other files as well. grep -r Werror /path/to/sources will show where it's present and then you can remove it. If you are not a friend with console and console utilities I'm not sure you want to compile your own kernel. BTW vanilla kernel 5.15 seemingly doesn't contain this flag anywhere, maybe you're applying patches which specify this option needlessly. Or this option is specified by your build. Anyways you could look for it and remove it. Jul 13, 2022 at 10:35
  • Downgrading gcc also requires the corresponding old gcc-libs. Anyhow, this error is caused by the introduction of -Wuse-after-free to begin with. This ended up inside all the pre-existing -Wall flags (in this case the one inside tools/lib/subcmd/Makefile).
    – mirh
    Aug 4, 2023 at 11:58

Add -Wno-use-after-free to the makefile tools/lib/subcmd/Makefile Line 22.

It looks like below.

CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC -Wno-use-after-free

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .