From patchwork Fri Oct 31 21:33:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 3514 Received: (qmail 12919 invoked by alias); 31 Oct 2014 21:34:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12910 invoked by uid 89); 31 Oct 2014 21:34:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: filtteri2.pp.htv.fi From: Aaro Koskinen To: Carlos O'Donell , GNU C Library , John David Anglin Subject: [PATCH] hppa: avoid NULL dereference of sym_map in elf_machine_rela() Date: Fri, 31 Oct 2014 23:33:51 +0200 Message-Id: <1414791231-30990-1-git-send-email-aaro.koskinen@iki.fi> If sym_map in elf_machine_rela() is NULL, some switch cases in theory could try to dereference it. Avoid those. This fixes the following build failure with GCC 4.9.2: hppa-linux-gnu-gcc -nostdlib -nostartfiles -r -o /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/librtld.map.o '-Wl,-(' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/aaro/los/work/parisc/glibc-2.20-build/default/elf/librtld.mapT /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(dl-addr.os): In function `_dl_addr_inside_object': /home/aaro/git/glibc/elf/dl-addr.c:152: multiple definition of `_dl_addr_inside_object' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.text+0x8b8): first defined here /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(init-first.os):(.data+0x0): multiple definition of `__libc_multiple_libcs' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.bss+0x7c): first defined here /home/aaro/los/work/parisc/glibc-2.20-build/default/libc_pic.a(_itoa.os): In function `_itoa': /home/aaro/git/glibc/stdio-common/_itoa.c:199: multiple definition of `_itoa' /home/aaro/los/work/parisc/glibc-2.20-build/default/elf/dl-allobjs.os:(.text+0x5b8): first defined here The build failure is triggered in GCC 4.9 due to "Isolate erroneous paths optimization". References: https://sourceware.org/ml/libc-alpha/2013-11/msg00291.html https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63691 2014-10-31 Aaro Koskinen * sysdeps/hppa/dl-machine.h: Avoid NULL dereference of sym_map in elf_machine_rela(). --- sysdeps/hppa/dl-machine.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h index 9c7471e..6043753 100644 --- a/sysdeps/hppa/dl-machine.h +++ b/sysdeps/hppa/dl-machine.h @@ -587,6 +587,8 @@ elf_machine_rela (struct link_map *map, break; case R_PARISC_DIR21L: + if (sym_map == NULL) + break; { unsigned int insn = *(unsigned int *)reloc_addr; value = sym_map->l_addr + sym->st_value @@ -598,6 +600,8 @@ elf_machine_rela (struct link_map *map, return; case R_PARISC_DIR14R: + if (sym_map == NULL) + break; { unsigned int insn = *(unsigned int *)reloc_addr; value = ((sym_map->l_addr + sym->st_value) & 0x7ff) @@ -686,7 +690,8 @@ elf_machine_rela (struct link_map *map, #if defined USE_TLS && (!defined RTLD_BOOTSTRAP) case R_PARISC_TLS_DTPMOD32: - value = sym_map->l_tls_modid; + if (sym_map != NULL) + value = sym_map->l_tls_modid; break; case R_PARISC_TLS_DTPOFF32: @@ -698,7 +703,7 @@ elf_machine_rela (struct link_map *map, case R_PARISC_TLS_TPREL32: /* The offset is negative, forward from the thread pointer */ - if (sym != NULL) + if (sym != NULL && sym_map != NULL) { CHECK_STATIC_TLS (map, sym_map); value = sym_map->l_tls_offset + sym->st_value + reloc->r_addend;