From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18304 invoked by alias); 13 Nov 2004 18:01:01 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 18280 invoked from network); 13 Nov 2004 18:01:01 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 13 Nov 2004 18:01:01 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id iADHwKTN029629; Sat, 13 Nov 2004 18:58:20 +0100 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id iADHwKdn029625; Sat, 13 Nov 2004 18:58:20 +0100 Date: Sat, 13 Nov 2004 18:01:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix LD_DEBUG=statistics Message-ID: <20041113175819.GF3536@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-SW-Source: 2004-11/txt/msg00038.txt.bz2 Hi! LD_DEBUG=statistics someprog leads to segfaults with current glibc. The problem is that print_statistics doesn't check for NULL _ns_loaded namespaces and happily dereferences it. While looking into it, I have noticed the num_relative_relocations computation doesn't match what do-rel.h is actually doing, particularly on !ELF_MACHINE_REL_RELATIVE RELA architectures it is processing relative relocations even if l_addr == 0, but the library is not prelinked. 2004-11-13 Jakub Jelinek * elf/rtld.c (print_statistics): Avoid segfaults if not all namespaces are used. Fix computation of num_relative_relocations on RELA architectures other than IA-64 and Alpha. --- libc/elf/rtld.c.jj 2004-11-09 12:26:41.000000000 +0100 +++ libc/elf/rtld.c 2004-11-13 18:56:32.574028935 +0100 @@ -2336,19 +2336,29 @@ print_statistics (hp_timing_t *rtld_tota unsigned long int num_relative_relocations = 0; for (Lmid_t ns = 0; ns < DL_NNS; ++ns) { + if (GL(dl_ns)[ns]._ns_loaded == NULL) + continue; + struct r_scope_elem *scope = &GL(dl_ns)[ns]._ns_loaded->l_searchlist; for (unsigned int i = 0; i < scope->r_nlist; i++) { struct link_map *l = scope->r_list [i]; - if (!l->l_addr) - continue; - - if (l->l_info[VERSYMIDX (DT_RELCOUNT)]) + if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELCOUNT)]) num_relative_relocations += l->l_info[VERSYMIDX (DT_RELCOUNT)]->d_un.d_val; - if (l->l_info[VERSYMIDX (DT_RELACOUNT)]) +#ifndef ELF_MACHINE_REL_RELATIVE + /* Relative relocations are processed on these architectures if + library is loaded to different address than p_vaddr or + if not prelinked. */ + if ((l->l_addr != 0 || !map->l_info[VALIDX(DT_GNU_PRELINKED)]) + && l->l_info[VERSYMIDX (DT_RELACOUNT)]) +#else + /* On e.g. IA-64 or Alpha, relative relocations are processed + only if library is loaded to different address than p_vaddr. */ + if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELACOUNT)]) +#endif num_relative_relocations += l->l_info[VERSYMIDX (DT_RELACOUNT)]->d_un.d_val; } Jakub