Elfutils build error GCC 12.2 (ramips targets)

When using GCC 12.2.0 instead of the default 11.3 I get the following error:

In function 'bigger_buffer',
    inlined from '__libdw_gunzip' at gzip.c:376:12:
gzip.c:98:9: error: pointer may be used after 'realloc' [-Werror=use-after-free]
   98 |     b = realloc (state->buffer, more -= 1024);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gzip.c:96:13: note: call to 'realloc' here
   96 |   char *b = realloc (state->buffer, more);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

a quick google shows that this is a known problem with GCC 12.2.0 and it should be fixed with version 12.2.1 as stated here:gnu gcc bug report

So I recompiled the toolchain with GCC 12.2.1 and unfortunately the same error exists.

ccache_cc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/usr/share/locale"' -I. -I..  -I. -I. -I../lib -I.. -I. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../debuginfod -I/home/drbrains/new-wrt/staging_dir/toolchain-mipsel_24kc_gcc-12.2.1_musl/usr/include -I/home/drbrains/new-wrt/staging_dir/toolchain-mipsel_24kc_gcc-12.2.1_musl/include/fortify -I/home/drbrains/new-wrt/staging_dir/toolchain-mipsel_24kc_gcc-12.2.1_musl/include    -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -mips16 -minterlink-mips16 -fmacro-prefix-map=/home/drbrains/new-wrt/build_dir/target-mipsel_24kc_musl/elfutils-0.188=elfutils-0.188 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro   -D_GNU_SOURCE -Wno-unused-result -Wno-format-nonliteral  -MT gzip.o -MD -MP -MF .deps/gzip.Tpo -c -o gzip.o gzip.c
In function 'bigger_buffer',
    inlined from '__libdw_gunzip' at gzip.c:374:12:
gzip.c:96:9: error: pointer may be used after 'realloc' [-Werror=use-after-free]
   96 |     b = realloc (state->buffer, more -= 1024);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gzip.c:94:13: note: call to 'realloc' here
   94 |   char *b = realloc (state->buffer, more);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [Makefile:653: gzip.o] Error 1
make[4]: *** [Makefile:531: all-recursive]

Does this have something to do with it:drop linux/musl support even in that case I would expect it to also fail with an older GCC version

Update: Changing from musl to glibc results in the same error:

ccache_cc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/usr/share/locale"' -I. -I..  -I. -I. -I../lib -I.. -I. -I./../libelf -I./../libebl -I./../libdw -I./../libdwelf -I./../debuginfod -I/home/drbrains/new-wrt/staging_dir/toolchain-mipsel_24kc_gcc-12.2.1_glibc/usr/include -I/home/drbrains/new-wrt/staging_dir/toolchain-mipsel_24kc_gcc-12.2.1_glibc/include    -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5 -Werror -Wunused -Wextra -Wstack-usage=262144   -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -mips16 -minterlink-mips16 -fmacro-prefix-map=/home/drbrains/new-wrt/build_dir/target-mipsel_24kc_glibc/elfutils-0.188=elfutils-0.188 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro   -D_GNU_SOURCE -Wno-unused-result -Wno-format-nonliteral  -MT gzip.o -MD -MP -MF .deps/gzip.Tpo -c -o gzip.o gzip.c
In function 'bigger_buffer',
    inlined from '__libdw_gunzip' at gzip.c:374:12:
gzip.c:96:9: error: pointer may be used after 'realloc' [-Werror=use-after-free]
   96 |     b = realloc (state->buffer, more -= 1024);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gzip.c:94:13: note: call to 'realloc' here
   94 |   char *b = realloc (state->buffer, more);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[6]: *** [Makefile:653: gzip.o] Error 1
make[5]: *** [Makefile:531: all-recursive] Error 1
make[4]: *** [Makefile:447: all] Error 2
make[4]: Leaving directory '/home/drbrains/new-wrt/build_dir/target-mipsel_24kc_glibc/elfutils-0.188'