https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104069

--- Comment #34 from Miklos Karacsony <mkaracsony81 at gmail dot com> ---
(In reply to Sergei Trofimovich from comment #32)
> Created attachment 55068 [details]
> gzip.c.c
> 
> > > You should be able to extract preprocessed file using
> > > https://gcc.gnu.org/bugs/#need: you will need to find exact `gcc` 
> > > invocation
> > > that causes build failure, add `-save-temps` parameter to it, grab '*.i'
> > > file and attach it along with exact command you used to produce it.
> > 
> > That gcc page does not say how to extract the command from the makefile that
> > triggers the error, so I've tried to reproduce this bug manually and after
> > like the 8th attempt when all the header files were finally found by the
> > compiler, the linker errored out with some undefined references, so no luck.
> > The good new is that this error is reproducible if the
> > cflags/ldflags/configure...etc switches set up like in c#29
> 
> gcc help can't cover specifics of external build systems. You have to have a
> bit of expertise to extract the actual command build system runs.
> 
> As elfutils is an automake-maked '$ make V=1' will print you every gcc
> command the build system is running. It should be in a form you can copy and
> paste as is (modulo current directory and a few environment variables).
> 
> I think I reproduced it on gcc-12.2.0 and elfutils-0.189. Attached as
> gzip.c.c.
> 
> Trigger on gcc-12.2.0:
> 
> $ gcc  -std=gnu99 -Wall  -Werror -Os -mtune=generic -c gzip.c.c
> In function 'bigger_buffer',
>     inlined from '__libdw_gunzip' at gzip.c.c:7751:13:
> gzip.c.c:7609:13: error: pointer may be used after 'realloc'
> [-Werror=use-after-free]
>  7609 |         b = realloc (state->buffer, more -= 1024);
>       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> gzip.c.c:7605:15: note: call to 'realloc' here
>  7605 |     char *b = realloc (state->buffer, more);
>       |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> gcc-master does not seem to reproduce the failure. I did not test gcc-13.

Thank you for your last comment, it was really helpful.
This bug is still present for me, which makes me think that gcc-master is a
different branch than gcc-12. I grabbed the latest gcc tarball to test it using
the following commands:

git clone --depth 1 git://gcc.gnu.org/git/gcc.git gcc-dir.tmp
git --git-dir=gcc-dir.tmp/.git fetch --depth 1 origin
0bfba6442264af83382c26f60286bd33c901178a
git --git-dir=gcc-dir.tmp/.git archive --prefix=gcc-12.3.1-20230513/
0bfba6442264af83382c26f60286bd33c901178a | xz -3 > gcc-12.3.1-20230513.tar.xz

then built gcc (gcc -v):
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.3.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /sources/gcc-12.3.1-20230513/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --enable-bootstrap --enable-languages=c,c++,lto
--enable-multilib --enable-install-libiberty --enable-checking=release
--enable-default-pie --enable-default-ssp --with-abi=m64 --with-arch=x86-64
--with-arch_32=x86-64 --with-build-config=bootstrap-lto
--with-multilib-list=m64,m32 --with-fpmath=sse --with-linker-hash-style=gnu
--with-system-zlib --with-tune=generic --with-zstd --without-isl
--disable-libitm --disable-libquadmath --disable-libsanitizer --disable-libvtv
--disable-nls --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.3.1 20230513 (Netux R1) (GCC)

and finally ran the elfutils build test, using the same environment, parameters
as before.

See attachment for the preprocessed file.

The invocation of gcc that triggered the bug was:
gcc -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  -std=gnu99 -Wall -Wshadow -Wformat=2
-Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op
-Wduplicated-cond -Wnull-dereference -Wimplicit-fallthrough=5
-Wuse-after-free=3 -Werror -Wunused -Wextra -Wstack-usage=262144  
-D_FORTIFY_SOURCE=3 -Os -mtune=generic -MT gzip.o -MD -MP -MF .deps/gzip.Tpo -c
-o gzip.o gzip.c

Reply via email to