https://sourceware.org/bugzilla/show_bug.cgi?id=33433

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
                 CC|                            |mark at klomp dot org

--- Comment #1 from Mark Wielaard <mark at klomp dot org> ---
(In reply to Andreas Schwab from comment #0)
> When building with current gcc trunk libelf.so fails to build with LTO:
> 
> gcc -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    -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
> -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -Werror=return-type -flto=auto -ffat-lto-objects -g
> -g -Werror=date-time  -flto=auto -ffat-lto-objects -o libelf.so -shared
> -Wl,-z,defs -Wl,-z,relro -o libelf.so \
>         -Wl,--soname,libelf.so.1 \
>         -Wl,--version-script,libelf.map \
>         -Wl,--no-undefined \
>         -Wl,--whole-archive libelf_pic.a -Wl,--no-whole-archive \
>         ../lib/libeu.a -lz -lzstd -llzma  -lbz2  
> In function ‘default_ehdr64’,
>     inlined from ‘__elf64_updatenull_wrlock’ at elf32_updatenull.c:138:7,
>     inlined from ‘elf_update’ at elf_update.c:211:6:
> elf32_updatenull.c:57:7: error: potential null pointer dereference
> [-Werror=null-dereference]
>    57 |   if (memcmp (&ehdr->e_ident[EI_MAG0], ELFMAG, SELFMAG) != 0)
>       |       ^
> lto1: all warnings being treated as errors
> make[3]: *** [/tmp/ccENG5L0.mk:2: /tmp/ccMoFZZ9.ltrans0.ltrans.o] Error 1
> lto-wrapper: fatal error: make returned 2 exit status
> compilation terminated.
> /usr/lib64/gcc/x86_64-suse-linux/16/../../../../x86_64-suse-linux/bin/ld:
> error: lto-wrapper failed
> collect2: error: ld returned 1 exit status
> make[2]: *** [Makefile:1395: libelf.so] Error 1
> make[1]: *** [Makefile:626: all-recursive] Error 1
> make: *** [Makefile:541: all] Error 2

I can replicate with GCC git trunk.

> Since getehdr_wrlock can return NULL, this seems to be a valid complaint.

Yes, and easy to fix. Committed:

commit 13153e98ee4f4b4ad2c73c2a747b6c2db984e029
Author: Mark Wielaard <[email protected]>
Date:   Mon Sep 15 23:58:08 2025 +0200

    libelf: check ehdr isn't NULL before calling default_ehdr

    default_ehdr assumes the passed ehdr pointer is not NULL and can be
    directly dereferenced. But getehdr can return NULL. So explicitly
    check.

            * libelf/elf32_updatenull.c (updatenull_wrlock): Check ehdr is
            not NULL.

    https://sourceware.org/bugzilla/show_bug.cgi?id=33433

    Signed-off-by: Mark Wielaard <[email protected]>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to