From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8263 invoked by alias); 9 Nov 2006 11:26:06 -0000 Received: (qmail 8229 invoked by uid 22791); 9 Nov 2006 11:26:05 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 09 Nov 2006 11:25:54 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id kA9BPm2r003661; Thu, 9 Nov 2006 12:25:48 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id kA9BPmjD003659; Thu, 9 Nov 2006 12:25:48 +0100 Date: Thu, 09 Nov 2006 11:26:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix _dl_debug_initialize Message-ID: <20061109112547.GK5868@sunsite.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 Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-11/txt/msg00004.txt.bz2 Hi! If ld.so is prelinked and a program is executed through ld.so (/lib*/ld-*.so --library-path whatever /the/program) and kernel mmaps prelink at its base address, then _r_debug.r_map is NULL. _r_debug is initialized by _dl_debug_initialize calls. When invoking /the/program directly, GL(dl_ns)[ns]._ns_loaded is initialized before first call to _dl_debug_initialize, but when invoking program using ld.so, it is non-NULL only on the second and following _dl_debug_initialize calls. But at that point _r_debug.r_brk is already non-zero. If ld.so is not prelinked or kernel mmaps it elsewhere, one of the following _dl_debug_initialize calls will have ldbase != 0 and it will be still reinitialized. But when rtld's l_addr is 0 (i.e. it is mmapped at the prelinked address), _dl_debug_initialize never reinitializes it. We talked about splitting _dl_debug_initialize into _dl_debug_initialize and _dl_debug_query which wouldn't initialize it, just return the struct address, while _dl_debug_initialize would reinitialize always, but I think that just can't work in other namespaces. The following patch is much shorter, we simply keep reinitializing until r_map is non-NULL. If r->r_map is non-NULL, we know r->r_brk is also != 0. 2006-10-09 Jakub Jelinek * elf/dl-debug.c (_dl_debug_initialize): Check r->r_map for 0 rather than r->r_brk. --- libc/elf/dl-debug.c.jj 2006-10-19 17:28:01.000000000 +0200 +++ libc/elf/dl-debug.c 2006-11-09 12:04:37.000000000 +0100 @@ -54,7 +54,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, else r = &GL(dl_ns)[ns]._ns_debug; - if (r->r_brk == 0 || ldbase != 0) + if (r->r_map == NULL || ldbase != 0) { /* Tell the debugger where to find the map of loaded objects. */ r->r_version = 1 /* R_DEBUG_VERSION XXX */; Jakub