I’m trying to build iwlwifi module manually and for my needs.

https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes.git/tree/net/wireless/

When I run Makefile as make, I get:

subcmd-util.h: In function ‘xrealloc’:
subcmd-util.h:58:31: error: pointer ‘ptr’ 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);
      |                     ^~~~~~~~~~~~~~~~~~
subcmd-util.h:56:23: error: pointer ‘ptr’ 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);
      |                     ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[4]: *** [/data/iwlwifi-fixes/tools/build/Makefile.build:97: /data/iwlwifi-fixes/tools/objtool/help.o] Error 1
make[3]: *** [Makefile:59: /data/iwlwifi-fixes/tools/objtool/libsubcmd-in.o] Error 2
make[2]: *** [Makefile:63: /data/iwlwifi-fixes/tools/objtool/libsubcmd.a] Error 2
make[1]: *** [Makefile:69: objtool] Error 2
make: *** [Makefile:1349: tools/objtool] Error 2

Why is it? How to fix it?

  • AlmightySnoo 🐢🇮🇱🇺🇦@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    What revision are you using? Because I don’t see the ret = realloc(ptr, 1); line in https://github.com/torvalds/linux/blob/master/tools/lib/subcmd/subcmd-util.h . (EDIT: my bad, it’s in the subcmd-util.h file linked in the other comment)

    Also, make sure you have the latest version of GCC, because I remember it yielding many false-positives when I was implementing some reference counting (which obviously is prone to false positives in static analysis) and those warnings disappeared after updating the compiler.

    EDIT: from the looks of it GCC’s “static analysis” basically assumed the worst case (ie that the first realloc is freeing memory and the second one is allocating new memory elsewhere and is copying from the old pointer, thus accessing it and hence the use-after-free warning). You can probably just remove the warning as the others have suggested, or you could try to downgrade GCC to version 11 as many of the search results regarding those use-after-free warnings involve later versions.