From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66138 invoked by alias); 20 Mar 2018 22:32:07 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 66120 invoked by uid 89); 20 Mar 2018 22:32:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=dozens X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Mar 2018 22:32:05 +0000 Received: from librem.wildebeest.org (deer0x01.wildebeest.org [172.31.17.131]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 22799302BB23 for ; Tue, 20 Mar 2018 23:32:03 +0100 (CET) Received: by librem.wildebeest.org (Postfix, from userid 1000) id D560614064F; Tue, 20 Mar 2018 23:32:02 +0100 (CET) Date: Tue, 20 Mar 2018 22:32:00 -0000 From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: Re: [PATCH] libdwfl: Use process_vm_readv when available. Message-ID: <20180320223202.GE6269@wildebeest.org> References: <20180318004323.21340-1-mark@klomp.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180318004323.21340-1-mark@klomp.org> User-Agent: Mutt/1.9.3 (2018-01-21) X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q1/txt/msg00086.txt.bz2 On Sun, Mar 18, 2018 at 01:43:23AM +0100, Mark Wielaard wrote: > If possible use process_vm_readv to read 4K blocks instead of fetching > each word individually with ptrace. For unwinding this often means we > only have to do one process_vm_readv of the stack instead of dozens of > ptrace calls. There is one 4K cache per process, cleared whenever a > thread is detached. It seems to work well, but the GCC undefined sanitizer (configure --enable-sanitize-undefined) found an issue in the run-backtrace-native-biarch.sh testcase (from x86_64 to i686) when reading unaligned data. To fix that don't assign to the Dwarf_Word directly when unaligned, but use memcpy (which gcc seems to inline). diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index ea65618f..6295e391 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -144,7 +144,10 @@ read_cached_memory (struct __libdwfl_pid_arg *pid_arg, if (addr >= mem_cache->addr && addr - mem_cache->addr < mem_cache->len) { d = &mem_cache->buf[addr - mem_cache->addr]; - *result = *(unsigned long *) d; + if ((((uintptr_t) d) & (sizeof (unsigned long) - 1)) == 0) + *result = *(unsigned long *) d; + else + memcpy (result, d, sizeof (unsigned long)); return true; } @@ -165,7 +168,10 @@ read_cached_memory (struct __libdwfl_pid_arg *pid_arg, mem_cache->len = res; d = &mem_cache->buf[addr - mem_cache->addr]; - *result = *((unsigned long *) d); + if ((((uintptr_t) d) & (sizeof (unsigned long) - 1)) == 0) + *result = *(unsigned long *) d; + else + memcpy (result, d, sizeof (unsigned long)); return true; } #endif /* HAVE_PROCESS_VM_READV */