From owner-svn-src-all@FreeBSD.ORG Mon Nov 11 16:57:57 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A5494313; Mon, 11 Nov 2013 16:57:57 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8360B2646; Mon, 11 Nov 2013 16:57:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rABGvvYw034386; Mon, 11 Nov 2013 16:57:57 GMT (envelope-from markj@svn.freebsd.org) Received: (from markj@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rABGvvX9034385; Mon, 11 Nov 2013 16:57:57 GMT (envelope-from markj@svn.freebsd.org) Message-Id: <201311111657.rABGvvX9034385@svn.freebsd.org> From: Mark Johnston Date: Mon, 11 Nov 2013 16:57:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258000 - head/lib/libproc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Nov 2013 16:57:57 -0000 Author: markj Date: Mon Nov 11 16:57:57 2013 New Revision: 258000 URL: http://svnweb.freebsd.org/changeset/base/258000 Log: Consistently add the relocation offset only when the ELF type is not ET_EXEC. This fixes several problems with the DTrace pid provider not being able to match probes. Reviewed by: rpaulo MFC after: 2 weeks Modified: head/lib/libproc/proc_sym.c Modified: head/lib/libproc/proc_sym.c ============================================================================== --- head/lib/libproc/proc_sym.c Mon Nov 11 16:52:02 2013 (r257999) +++ head/lib/libproc/proc_sym.c Mon Nov 11 16:57:57 2013 (r258000) @@ -284,7 +284,10 @@ proc_addr2sym(struct proc_handle *p, uin * Calculate the address mapped to the virtual memory * by rtld. */ - rsym = map->pr_vaddr + sym.st_value; + if (ehdr.e_type != ET_EXEC) + rsym = map->pr_vaddr + sym.st_value; + else + rsym = sym.st_value; if (addr >= rsym && addr < rsym + sym.st_size) { s = elf_strptr(e, dynsymstridx, sym.st_name); if (s) { @@ -309,8 +312,6 @@ symtab: * Iterate over the Symbols Table to find the symbol. * Then look up the string name in STRTAB (.dynstr) */ - if (symtabscn == NULL) - goto err2; if ((data = elf_getdata(symtabscn, NULL)) == NULL) { DPRINTFX("ERROR: elf_getdata() failed: %s", elf_errmsg(-1)); goto err2; @@ -465,7 +466,8 @@ proc_name2sym(struct proc_handle *p, con s = elf_strptr(e, dynsymstridx, sym.st_name); if (s && strcmp(s, symbol) == 0) { memcpy(symcopy, &sym, sizeof(sym)); - symcopy->st_value = map->pr_vaddr + sym.st_value; + if (ehdr.e_type != ET_EXEC) + symcopy->st_value += map->pr_vaddr; error = 0; goto out; } @@ -475,20 +477,21 @@ proc_name2sym(struct proc_handle *p, con * Iterate over the Symbols Table to find the symbol. * Then look up the string name in STRTAB (.dynstr) */ - if (symtabscn == NULL) - goto err2; if ((data = elf_getdata(symtabscn, NULL))) { i = 0; while (gelf_getsym(data, i++, &sym) != NULL) { s = elf_strptr(e, symtabstridx, sym.st_name); if (s && strcmp(s, symbol) == 0) { memcpy(symcopy, &sym, sizeof(sym)); + if (ehdr.e_type != ET_EXEC) + symcopy->st_value += map->pr_vaddr; error = 0; goto out; } } } out: + DPRINTFX("found addr 0x%lx for %s", symcopy->st_value, symbol); err2: elf_end(e); err1: @@ -509,6 +512,7 @@ proc_iter_symbyaddr(struct proc_handle * prmap_t *map; Elf_Scn *scn, *foundscn = NULL; Elf_Data *data; + GElf_Ehdr ehdr; GElf_Shdr shdr; GElf_Sym sym; unsigned long stridx = -1; @@ -525,6 +529,10 @@ proc_iter_symbyaddr(struct proc_handle * DPRINTFX("ERROR: elf_begin() failed: %s", elf_errmsg(-1)); goto err1; } + if (gelf_getehdr(e, &ehdr) == NULL) { + DPRINTFX("ERROR: gelf_getehdr() failed: %s", elf_errmsg(-1)); + goto err2; + } /* * Find the section we are looking for. */ @@ -575,7 +583,8 @@ proc_iter_symbyaddr(struct proc_handle * (mask & TYPE_FILE) == 0) continue; s = elf_strptr(e, stridx, sym.st_name); - sym.st_value += map->pr_vaddr; + if (ehdr.e_type != ET_EXEC) + sym.st_value += map->pr_vaddr; (*func)(cd, &sym, s); } error = 0;