https://sourceware.org/bugzilla/show_bug.cgi?id=32311
Bug ID: 32311 Summary: elf_compress_gnu.c: gcc warns null-dereference with lto Product: elfutils Version: unspecified Status: UNCONFIRMED Severity: minor Priority: P2 Component: libelf Assignee: unassigned at sourceware dot org Reporter: the.ra2.ifv at gmail dot com CC: elfutils-devel at sourceware dot org Target Milestone: --- Created attachment 15764 --> https://sourceware.org/bugzilla/attachment.cgi?id=15764&action=edit full log when building elfutils in openwrt elfutils: 0.191 When compiling elfutils in OpenWRT, gcc warn potential null pointer dereference with lto enabled. If I disable it or use `-Wno-null-dereference` then the build would pass with no problems. ``` ccache aarch64-openwrt-linux-musl-gcc -std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes -Wtrampolines -Wlogical-op -Wduplicated-co nd -Wnull-dereference -Wimplicit-fallthrough=5 -Wuse-after-free=3 -Werror -Wunused -Wextra -Wstack-usage=262144 -fno-caller-saves -fno-plt -pipe -Ofast -fhon our-copts -fmacro-prefix-map=/openwrt/build_dir/target-aarch64_generic_musl/elfutils-0.191=elfutils-0.191 -ffunction-sections -fdata-sections -flto=auto -fno-fa t-lto-objects -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -D_GNU_SOURCE -Wno-unused-result -Wno-format-nonl iteral -Wno-error=use-after-free -L/openwrt/staging_dir/toolchain-aarch64_generic_gcc-14.2.0_musl/usr/lib -L/openwrt/staging_dir/toolchain-aarch64_generic_gcc -14.2.0_musl/lib -fuse-ld=mold -Wl,--gc-sections -flto=auto -fuse-linker-plugin -znow -zrelro -Wl,--build-id -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 elf_compress.c: In function 'elf_compress': elf_compress.c:675:26: error: potential null pointer dereference [-Werror=null-dereference] 675 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:675:15: error: potential null pointer dereference [-Werror=null-dereference] 675 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:674:30: error: potential null pointer dereference [-Werror=null-dereference] 674 | shdr->sh_addralign = __libelf_type_align (ELFCLASS32, ELF_T_CHDR); | ^ elf_compress.c:673:25: error: potential null pointer dereference [-Werror=null-dereference] 673 | shdr->sh_size = new_size; | ^ elf_compress.c:675:26: error: potential null pointer dereference [-Werror=null-dereference] 675 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:675:15: error: potential null pointer dereference [-Werror=null-dereference] 675 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:674:30: error: potential null pointer dereference [-Werror=null-dereference] 674 | shdr->sh_addralign = __libelf_type_align (ELFCLASS32, ELF_T_CHDR); | ^ elf_compress.c:673:25: error: potential null pointer dereference [-Werror=null-dereference] 673 | shdr->sh_size = new_size; | ^ elf_compress.c:682:26: error: potential null pointer dereference [-Werror=null-dereference] 682 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:682:15: error: potential null pointer dereference [-Werror=null-dereference] 682 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:681:30: error: potential null pointer dereference [-Werror=null-dereference] 681 | shdr->sh_addralign = __libelf_type_align (ELFCLASS64, ELF_T_CHDR); | ^ elf_compress.c:680:25: error: potential null pointer dereference [-Werror=null-dereference] 680 | shdr->sh_size = new_size; | ^ elf_compress.c:682:26: error: potential null pointer dereference [-Werror=null-dereference] 682 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:682:15: error: potential null pointer dereference [-Werror=null-dereference] 682 | shdr->sh_flags |= SHF_COMPRESSED; | ^ elf_compress.c:681:30: error: potential null pointer dereference [-Werror=null-dereference] 681 | shdr->sh_addralign = __libelf_type_align (ELFCLASS64, ELF_T_CHDR); | ^ elf_compress.c:680:25: error: potential null pointer dereference [-Werror=null-dereference] 680 | shdr->sh_size = new_size; | ^ elf_compress.c:727:26: error: potential null pointer dereference [-Werror=null-dereference] 727 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:727:15: error: potential null pointer dereference [-Werror=null-dereference] 727 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:726:30: error: potential null pointer dereference [-Werror=null-dereference] 726 | shdr->sh_addralign = scn->zdata_align; | ^ elf_compress.c:725:25: error: potential null pointer dereference [-Werror=null-dereference] 725 | shdr->sh_size = scn->zdata_size; | ^ elf_compress.c:727:26: error: potential null pointer dereference [-Werror=null-dereference] 727 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:727:15: error: potential null pointer dereference [-Werror=null-dereference] 727 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:726:30: error: potential null pointer dereference [-Werror=null-dereference] 726 | shdr->sh_addralign = scn->zdata_align; | ^ elf_compress.c:725:25: error: potential null pointer dereference [-Werror=null-dereference] 725 | shdr->sh_size = scn->zdata_size; | ^ elf_compress.c:734:26: error: potential null pointer dereference [-Werror=null-dereference] 734 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:734:15: error: potential null pointer dereference [-Werror=null-dereference] 734 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:733:30: error: potential null pointer dereference [-Werror=null-dereference] 733 | shdr->sh_addralign = scn->zdata_align; | ^ elf_compress.c:732:25: error: potential null pointer dereference [-Werror=null-dereference] 732 | shdr->sh_size = scn->zdata_size; | ^ elf_compress.c:734:26: error: potential null pointer dereference [-Werror=null-dereference] 734 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:734:15: error: potential null pointer dereference [-Werror=null-dereference] 734 | shdr->sh_flags &= ~SHF_COMPRESSED; | ^ elf_compress.c:733:30: error: potential null pointer dereference [-Werror=null-dereference] 733 | shdr->sh_addralign = scn->zdata_align; | ^ elf_compress.c:732:25: error: potential null pointer dereference [-Werror=null-dereference] 732 | shdr->sh_size = scn->zdata_size; | ^ elf_compress_gnu.c: In function 'elf_compress_gnu': elf_compress_gnu.c:127:25: error: potential null pointer dereference [-Werror=null-dereference] 127 | shdr->sh_size = new_size; | ^ elf_compress_gnu.c:127:25: error: potential null pointer dereference [-Werror=null-dereference] elf_compress_gnu.c:132:25: error: potential null pointer dereference [-Werror=null-dereference] 132 | shdr->sh_size = new_size; | ^ elf_compress_gnu.c:132:25: error: potential null pointer dereference [-Werror=null-dereference] elf_compress_gnu.c:192:25: error: potential null pointer dereference [-Werror=null-dereference] 192 | shdr->sh_size = size; | ^ elf_compress_gnu.c:192:25: error: potential null pointer dereference [-Werror=null-dereference] elf_compress_gnu.c:197:25: error: potential null pointer dereference [-Werror=null-dereference] 197 | shdr->sh_size = size; | ^ elf_compress_gnu.c:197:25: error: potential null pointer dereference [-Werror=null-dereference] lto1: all warnings being treated as errors ``` Check the attachment for build log. -- You are receiving this mail because: You are on the CC list for the bug.