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

--- Comment #29 from Miklos Karacsony <mkaracsony81 at gmail dot com> ---
(In reply to Sergei Trofimovich from comment #28)
> (In reply to Miklos Karacsony from comment #27)
> > (In reply to Sergei Trofimovich from comment #26)
> > > #c12 fixed elfutils case.
> > 
> > That's not accurate. It's only fixed if you use the default "-O2"
> > optimization level, but if you use "-Os" instead, you'll find that the bug
> > is still present. I've managed to hit a similar bug while building glibc
> > with "-Os" as well, but in that case adding "--disable-werror" helped.
> > Sadly, elfutils' configure script does not respect that flag. I could just
> > add "-Wno-error" into my cflags when building, but then doing this on a per
> > package basis is cumbersome.
> 
> I was not able to reproduce -Os build failure on elfutils-0.189. Can you
> extract an example from the case you see?

Sadly, I cannot extract an example as I'm mostly packaging stuff for my LFS
based distro, without any knowledge of C programming language and/or the inner
workings of gcc. That said, I will share as much details as I can here, which
should help you reproduce this bug:

The configure command used was as follows:
   ./configure --prefix=/usr \
               --sysconfdir=/etc \
               --program-prefix="eu-" \
               --enable-deterministic-archives \
               --enable-libdebuginfod=dummy \
               --disable-debuginfod \
               --disable-werror

Then I used the following to build the package and then install the libraries
only:
   make
   make -C debuginfod install
   make -C libasm install
   make -C libdw install
   make -C libdwelf install
   make -C libdwfl install
   make -C libelf install

This is the output of the build when using "-Os":

configure: WARNING: unrecognized options: --disable-werror
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[2]: *** [Makefile:715: gzip.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from bzip2.c:4:
In function 'bigger_buffer',
    inlined from '__libdw_bunzip2' at gzip.c:331:9:
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
In file included from lzma.c:4:
In function 'bigger_buffer',
    inlined from '__libdw_unlzma' at gzip.c:331:9:
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);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:715: bzip2.o] Error 1
In file included from zstd.c:4:
In function 'bigger_buffer',
    inlined from '__libdw_unzstd' at gzip.c:265:9:
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[2]: *** [Makefile:715: lzma.o] Error 1
cc1: all warnings being treated as errors
make[2]: *** [Makefile:715: zstd.o] Error 1
make[1]: *** [Makefile:537: all-recursive] Error 1
make: *** [Makefile:453: all] Error 2

This was with CFLAGS="-Os -mtune=generic" and
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,--hash-style=gnu".

If I build this package with CFLAGS="-O2 -mtune=generic" and the same LDFLAGS
as above, the build succeeds.

I did not use any patches on elfutils.

gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /sources/gcc-12.2.1-20230503/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.2.1 20230503 (Netux R1) (GCC)

Reply via email to