unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Chip Coldwell <coldwell@redhat.com>
Subject: seg-fault in unexelf.c
Date: Fri, 21 Jul 2006 13:59:12 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0607211342320.2372@localhost.localdomain> (raw)


I have been having a problem building emacs on GNU/Linux (in
particular, the Fedora Core 5 distribution).  The build process runs
the following command in the src/ subdirectory:

./temacs -l loadup -batch dump

to cause the temacs binary (essentially emacs without the Lisp code
loaded) to set up the Lisp environment in the process address space
and then create a new ELF file with a new .data section that contains
the .data and .bss sections from the temacs process.

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);

I unrolled the memcpy thus:

 	  p = NEW_SECTION_H (nn).sh_offset + new_base;
 	  q = (caddr_t) OLD_SECTION_H (n).sh_addr;
 	  for(i=0; i<new_data2_size; i++)
 	    p[i] = q[i];

ran the debugger and found the segfault happens when

(gdb) p/x q+i
$5 = 0x82f0000
(gdb) p/x i
$8 = 0xed160
(gdb) p/x new_bss_addr
$10 = 0x852a000

In the meantime, if I look in /proc/[PID]/maps I find this:

08048000-081fa000 r-xp 00000000 fd:00 1311728    /home/coldwell/rpm/BUILD/emacs-21.4/src/temacs
081fa000-08203000 rw-p 001b2000 fd:00 1311728    /home/coldwell/rpm/BUILD/emacs-21.4/src/temacs
08203000-082f0000 rw-p 08203000 00:00 0 
08337000-0852a000 rw-p 08337000 00:00 0          [heap]
b730e000-b7da3000 rw-p b730e000 00:00 0

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.

Here are more details.  "new_data2_size" is computed from (paraphrasing)

new_data2_size = sbrk(0) - OLD_SECTION_H (old_bss_index).sh_addr

In other words, the size of the new data section is determined to be
the top of the heap of the current temacs process minus the bottom of
the .bss in the temacs ELF file on disk.

"readelf -S temacs" gives

  [20] .data             PROGBITS        081fa880 1b2880 008610 00  WA  0   0 32
  [21] .bss              NOBITS          08202ea0 1bae90 0ec6d0 00  WA  0   0 32

Chip

-- 
Charles M. "Chip" Coldwell
Senior Software Engineer
Red Hat, Inc
978-392-2426

             reply	other threads:[~2006-07-21 17:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-21 17:59 Chip Coldwell [this message]
2006-07-21 20:53 ` seg-fault in unexelf.c Chip Coldwell
2006-07-22  0:33 ` Nick Roberts
2006-07-22 12:37   ` Chip Coldwell
2006-07-22 12:50     ` Nick Roberts
2006-07-22  4:39 ` Richard Stallman
2006-07-22 12:27   ` Chip Coldwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0607211342320.2372@localhost.localdomain \
    --to=coldwell@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).