From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chip Coldwell Newsgroups: gmane.emacs.devel Subject: Re: seg-fault in unexelf.c Date: Fri, 21 Jul 2006 16:53:19 -0400 (EDT) Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: sea.gmane.org 1153515218 7514 80.91.229.2 (21 Jul 2006 20:53:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 21 Jul 2006 20:53:38 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 21 22:53:37 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G4204-0007PE-EP for ged-emacs-devel@m.gmane.org; Fri, 21 Jul 2006 22:53:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G4204-00005L-2U for ged-emacs-devel@m.gmane.org; Fri, 21 Jul 2006 16:53:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G41zs-00005G-B9 for emacs-devel@gnu.org; Fri, 21 Jul 2006 16:53:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G41zp-000054-RH for emacs-devel@gnu.org; Fri, 21 Jul 2006 16:53:19 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G41zp-000051-MZ for emacs-devel@gnu.org; Fri, 21 Jul 2006 16:53:17 -0400 Original-Received: from [66.187.233.31] (helo=mx1.redhat.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1G420J-0003El-Pg for emacs-devel@gnu.org; Fri, 21 Jul 2006 16:53:48 -0400 Original-Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6LKrGV4029474 for ; Fri, 21 Jul 2006 16:53:16 -0400 Original-Received: from mail.boston.redhat.com (mail.boston.redhat.com [172.16.76.12]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6LKrG9H028267 for ; Fri, 21 Jul 2006 16:53:16 -0400 Original-Received: from dhcp83-29.boston.redhat.com (dhcp83-29.boston.redhat.com [172.16.83.29]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id k6LKrGRT024335 for ; Fri, 21 Jul 2006 16:53:16 -0400 Original-To: emacs-devel@gnu.org In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:57449 Archived-At: On Fri, 21 Jul 2006, Chip Coldwell wrote: > > If I build the temacs binary with no compiler optimization (gcc (GCC) > 4.1.0 20060304 (Red Hat 4.1.0-3)), the command above seg-faults in the > unexec function (file unexelf.c) while executing this line: > > memcpy (NEW_SECTION_H (nn).sh_offset + new_base, > (caddr_t) OLD_SECTION_H (n).sh_addr, > new_data2_size); [ ... ] > The problem is that the Linux kernel has set up the process virtual > memory with a hole in it, and when the memcpy steps into this hole, it > seg-faults. To paraphrase: the memcpy uses the .bss section start address from the temacs ELF file for the lower bound, and sbrk(0) from the running temacs process for its upper bound of a copy from the process address space to the new ELF file .data section it is creating, but the Linux kernel can set up the process address space such that there are holes in the virtual address space between these two addresses. Stepping into such a hole gets you a segmentation fault. A colleague suggested that one (crude) way to cope with this would be signal(SIGSEGV, SIG_IGN); before the memcpy and signal(SIGSEGV, SIG_DFL); afterwards, although it might be better to unroll the memcpy to do just a page at a time if taking this approach. Chip -- Charles M. "Chip" Coldwell Senior Software Engineer Red Hat, Inc 978-392-2426