From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 24 21:22:06 2014 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4C5492DE; Mon, 24 Nov 2014 21:22:06 +0000 (UTC) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id E97263D7; Mon, 24 Nov 2014 21:22:04 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id XAA08789; Mon, 24 Nov 2014 23:23:55 +0200 (EET) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1Xt157-000ClE-Jl; Mon, 24 Nov 2014 23:22:01 +0200 Message-ID: <5473A156.6070502@FreeBSD.org> Date: Mon, 24 Nov 2014 23:21:26 +0200 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Mark Johnston , Rui Paulo Subject: Re: DTrace: stack() does not print kernel module functions for i386 References: <20141109093632.GV53947@kib.kiev.ua> <9011F920-3092-4E61-9CDC-68FD9092BB7D@me.com> <201411131336.12334.jhb@freebsd.org> <20141123021856.GA54708@raichu> In-Reply-To: <20141123021856.GA54708@raichu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: Konstantin Belousov , freebsd-hackers@FreeBSD.org, freebsd-dtrace@FreeBSD.org, Shrikanth Kamath X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Nov 2014 21:22:06 -0000 On 23/11/2014 04:18, Mark Johnston wrote: > On Thu, Nov 13, 2014 at 07:49:27PM -0800, Rui Paulo wrote: >> On Nov 13, 2014, at 10:36, John Baldwin wrote: >>> Why have the #ifdef? In theory other platforms besides amd64 could use >>> sys/kern/link_elf_obj.c. It doesn't hurt to just let the code always accept >>> both ET_DYN and ET_REL does it? >> >> No, it doesn't hurt. > > The suggested patch doesn't seem quite right; there are other functions > in dt_module.c with the same assignment (i.e. > "is_elf_obj = ehdr.e_type == ET_REL"), but the same modification is not > correct in all cases - fixing it everywhere breaks stack() again - and > "is_elf_obj" seems like the wrong name if DSOs are counted as well. > > The root of the problem is that dmp->dm_*_va offsets don't have the kld > load address taken into account on i386, since they're currently set based > only on the ELF section addresses. This is handled by > dmp->dm_reloc_offset for symbols, but that's a separate case. > > When is_elf_obj is true, we include the load address when setting the > dmp->dm_*_va fields. I suggest we do that unconditionally, and only set > elements of dmp->dm_sec_offsets if is_elf_obj is true. This fixes the > bug for me on i386. Any opinions? This totally makes sense to me. Thank you! > diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c > index e3905c1..9dd52b5 100644 > --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c > +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c > @@ -1211,13 +1211,13 @@ dt_module_update(dtrace_hdl_t *dtp, struct kld_file_stat *k_stat) > #if defined(__FreeBSD__) > if (sh.sh_size == 0) > continue; > - if (is_elf_obj && (sh.sh_type == SHT_PROGBITS || > - sh.sh_type == SHT_NOBITS)) { > + if (sh.sh_type == SHT_PROGBITS || sh.sh_type == SHT_NOBITS) { > alignmask = sh.sh_addralign - 1; > mapbase += alignmask; > mapbase &= ~alignmask; > sh.sh_addr = mapbase; > - dmp->dm_sec_offsets[elf_ndxscn(sp)] = sh.sh_addr; > + if (is_elf_obj) > + dmp->dm_sec_offsets[elf_ndxscn(sp)] = sh.sh_addr; > mapbase += sh.sh_size; > } > #endif > -- Andriy Gapon