Bug 26485 - UBSAN error: bfd/elf64-ppc.c:16582:18:
Summary: UBSAN error: bfd/elf64-ppc.c:16582:18:
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.36
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-20 12:37 UTC by Martin Liska
Modified: 2020-08-26 14:38 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-08-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2020-08-20 12:37:29 UTC
The following fails when I build binutils with:
configure --build=x86_64-linux --disable-nls --disable-gdb --disable-gdbserver --disable-sim --disable-readline --disable-libdecnumber --enable-obsolete --target=powerpc-eabisim CFLAGS="-g -O2 -fsanitize=address,undefined -Wno-error" CXXLAGS="-g -O2 -fsanitize=address,undefined -Wno-error" LDFLAGS="-ldl"
Target: powerpc-eabisim
FAIL: TLS dynamic exec (--no-tls-optimize)
Executing on host: sh -c {./ld-new   -o tmpdir/tls.so -z norelro -L/home/mliska/Programming/binutils/ld/testsuite/ld-powerpc -shared -melf64ppc --no-plt-align --no-ld-generated-unwind-info --hash-style=sysv tmpdir/tls.o   2>&1}  /dev/null ld.tmp (timeout = 300)
/home/mliska/Programming/binutils/bfd/elf64-ppc.c:16582:18: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
Comment 1 Alan Modra 2020-08-26 00:31:07 UTC
I don't see this fail.  Code at line 16582 on master is
	      : (h != NULL
		 ? h->elf.dyn_relocs != NULL
		 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
Compiler bug?  I'm assuming all these ubsan bug reports were actually against master not the 2.34 branch as marked..
Comment 2 Martin Liska 2020-08-26 08:53:07 UTC
The mentioned line is gone with current master, but I still see the following errors related to 'struct ppc_link_hash_entry':

./ld-new   -o tmpdir/tls -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -melf64ppc --no-plt-align tmpdir/tls.o tmpdir/tlslib.o 
Executing on host: sh -c {./ld-new   -o tmpdir/tls -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -melf64ppc --no-plt-align tmpdir/tls.o tmpdir/tlslib.o  2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
../../bfd/elf64-ppc.c:5653:52: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:5654:45: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:7912:36: runtime error: member access within null pointer of type 'const struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:5653:52: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:5654:45: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:7912:36: runtime error: member access within null pointer of type 'const struct ppc_link_hash_entry'
FAIL: TLS static exec
/home/marxin/Programming/binutils/objdir/ld/../gas/as-new   -I/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc   -o tmpdir/tls.o -a64 --defsym TLSMARK=1 /home/marxin/Programming/binutils/ld/testsuite/ld-powerpc/tls.s
Executing on host: sh -c {/home/marxin/Programming/binutils/objdir/ld/../gas/as-new   -I/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc   -o tmpdir/tls.o -a64 --defsym TLSMARK=1 /home/marxin/Programming/binutils/ld/testsuite/ld-powerpc/tls.s 2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
/home/marxin/Programming/binutils/objdir/ld/../gas/as-new   -I/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc   -o tmpdir/tlslib.o -a64 --defsym TLSMARK=1 /home/marxin/Programming/binutils/ld/testsuite/ld-powerpc/tlslib.s
Executing on host: sh -c {/home/marxin/Programming/binutils/objdir/ld/../gas/as-new   -I/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc   -o tmpdir/tlslib.o -a64 --defsym TLSMARK=1 /home/marxin/Programming/binutils/ld/testsuite/ld-powerpc/tlslib.s 2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
./ld-new   -o tmpdir/tlsno -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -melf64ppc --no-tls-optimize --no-plt-align tmpdir/tls.o tmpdir/tlslib.o 
Executing on host: sh -c {./ld-new   -o tmpdir/tlsno -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -melf64ppc --no-tls-optimize --no-plt-align tmpdir/tls.o tmpdir/tlslib.o  2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
../../bfd/elf64-ppc.c:16147:6: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:16147:6: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
FAIL: TLS static exec (--no-tls-optimize)
./ld-new   -o tmpdir/libtlslib.so -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -shared -melf64ppc tmpdir/tlslib.o  
Executing on host: sh -c {./ld-new   -o tmpdir/libtlslib.so -z norelro -L/home/marxin/Programming/binutils/ld/testsuite/ld-powerpc -shared -melf64ppc tmpdir/tlslib.o   2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
../../bfd/elf64-ppc.c:16622:18: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
../../bfd/elf64-ppc.c:16622:18: runtime error: member access within null pointer of type 'struct ppc_link_hash_entry'
Comment 3 Alan Modra 2020-08-26 10:19:49 UTC
Got it.
Comment 4 cvs-commit@gcc.gnu.org 2020-08-26 13:55:13 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9e51d549d7901be8b999f8dac86c5efd6a7edef2

commit 9e51d549d7901be8b999f8dac86c5efd6a7edef2
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Aug 26 19:43:18 2020 +0930

    PR 26484-26488, 26490 UBSAN &h->elf null pointer
    
            PR 26484
            PR 26485
            PR 26486
            PR 26487
            PR 26488
            PR 26490
            * elf64-ppc.c (is_tls_get_addr): Avoid UB &h->elf when h is NULL.
            (ppc64_elf_tls_setup): Likewise.
            (branch_reloc_hash_match): Likewise.
            (build_plt_stub): Likewise.
            (ppc64_elf_relocate_section): Likewise.
Comment 5 Alan Modra 2020-08-26 14:38:58 UTC
Fixed