From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25859 invoked by alias); 16 Dec 2008 09:12:22 -0000 Received: (qmail 25851 invoked by uid 22791); 16 Dec 2008 09:12:21 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,FUZZY_VLIUM,KAM_MX,SPF_HELO_PASS,SPF_PASS X-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,FUZZY_VLIUM,KAM_MX,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Dec 2008 09:11:42 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id mBG9BeMj019627 for ; Tue, 16 Dec 2008 04:11:40 -0500 Received: from gateway.sf.frob.com (vpn-12-140.rdu.redhat.com [10.11.12.140]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mBG9Bdl6006171; Tue, 16 Dec 2008 04:11:39 -0500 Received: from magilla.sf.frob.com (magilla.sf.frob.com [198.49.250.228]) by gateway.sf.frob.com (Postfix) with ESMTP id A2C79357B; Tue, 16 Dec 2008 01:11:38 -0800 (PST) Received: by magilla.sf.frob.com (Postfix, from userid 5281) id 68D1FFC351; Tue, 16 Dec 2008 01:11:38 -0800 (PST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Roland McGrath To: Mark Wielaard Cc: systemtap Subject: Re: dwfl_module_relocate_address() versus base address In-Reply-To: Mark Wielaard's message of Monday, 15 December 2008 13:06:01 +0100 <1229342761.3457.13.camel@dijkstra.wildebeest.org> References: <1229103422.3397.98.camel@dijkstra.wildebeest.org> <20081212200639.23B51FC3AB@magilla.sf.frob.com> <1229342761.3457.13.camel@dijkstra.wildebeest.org> X-Antipastobozoticataclysm: When George Bush projectile vomits antipasto on the Japanese. Message-Id: <20081216091138.68D1FFC351@magilla.sf.frob.com> Date: Tue, 16 Dec 2008 09:12:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2008-q4/txt/msg00569.txt.bz2 > Aha! Doh. Yes, things make a lot more sense now. Since older/current > versions of dwfl_module_relocate_address() will have this bug I am using > dwfl_module_address_section() now, which does seem to do the right > thing. Note that for ET_REL that call also incurs a big cost you don't otherwise need (applying relocs to the section data). > Although I am still confused how this ever worked before. The buggy code only affects ET_DYN(-like) with separate debuginfo, not ET_REL. It probably wasn't noticed before because usually vmlinux is not separate debuginfo, it's a whole unstripped copy, and .ko are ET_REL. > Also for the kernel we still do things slightly differently (making > things relative to _stext) . The kernel is treated as ET_DYN by libdwfl (hence the -like). Though the file says ET_EXEC, it really behaves like ET_DYN on CONFIG_RELOCATABLE=y kernels. This is just FYI, I guess. > This is not completely true. I was confused since we also rely on the > secname produced by dwfl_module_relocation_info() (being empty for > ET_DYN). So that is now also replicated by hand in the new patch. It is > getting slightly messy now :{ Since this code does getelf anyway (which, incidentally, imposes all the costs of dwfl_module_address_section on every section), you can just do a different workaround. You can even skip the bad overhead, because you don't need to do any workaround for ET_REL files anyway: if (ki == 0 && secname != NULL && secname[0] == '\0') { check for bug } So, you can do getelf + getdwarf, to get mainbias and dwbias, respectively. If mainbias == dwbias, you are already correct. To check for the bug, you'd see if the original sym_addr and the sym_addr adjusted by dwfl_module_relocate_address mainbias or by dwbias. But, if you just want to work right rather than test for the bug, you can just do: Dwarf_Addr save_addr = sym_addr; int ki = dwfl_module_relocate_address (m, &sym_addr); dwfl_assert ("dwfl_module_relocate_address", ki >= 0); secname = dwfl_module_relocation_info (m, ki, NULL); if (ki == 0 && secname != NULL && secname[0] == '\0') { Dwarf_Addr bias; dwfl_assert ("dwfl_getelf", dwfl_module_getelf (m, &bias) != NULL); sym_addr = save_addr - bias; } Thanks, Roland