From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Nozomu Ando Newsgroups: gmane.emacs.devel Subject: patch for unexmacosx.c: supporting non-prebound dynamic library Date: Sun, 12 Oct 2003 23:34:00 +0900 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <1E88B416-FCC1-11D7-A154-000A958F13D0@mac.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 (Apple Message framework v604) Content-Type: multipart/mixed; boundary=Apple-Mail-10--384789338 X-Trace: sea.gmane.org 1065969295 4126 80.91.224.253 (12 Oct 2003 14:34:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 12 Oct 2003 14:34:55 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Oct 12 16:34:53 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A8hJ7-0001AQ-00 for ; Sun, 12 Oct 2003 16:34:53 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1A8hJ7-0001lH-00 for ; Sun, 12 Oct 2003 16:34:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A8hJ1-0006lo-77 for emacs-devel@quimby.gnus.org; Sun, 12 Oct 2003 10:34:47 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1A8hIu-0006lZ-57 for emacs-devel@gnu.org; Sun, 12 Oct 2003 10:34:40 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1A8hIN-0006cV-PF for emacs-devel@gnu.org; Sun, 12 Oct 2003 10:34:39 -0400 Original-Received: from [17.250.248.89] (helo=smtpout.mac.com) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A8hIN-0006br-32 for emacs-devel@gnu.org; Sun, 12 Oct 2003 10:34:07 -0400 Original-Received: from mac.com (smtpin08-en2 [10.13.10.153]) by smtpout.mac.com (Xserve/MantshX 2.0) with ESMTP id h9CEY59D003025 for ; Sun, 12 Oct 2003 07:34:05 -0700 (PDT) Original-Received: from [192.168.2.198] (v221119156219.4v6.dion.ne.jp [221.119.156.219]) (authenticated bits=0) by mac.com (Xserve/smtpin08/MantshX 3.0) with ESMTP id h9CEY3bo021099 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NO) for ; Sun, 12 Oct 2003 07:34:04 -0700 (PDT) Original-To: emacs-devel@gnu.org X-Mailer: Apple Mail (2.604) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:17040 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:17040 --Apple-Mail-10--384789338 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Hello all, On Mac OS X, emacs of CVS HEAD cannot unexec with non-prebound dynamically linked library (e.g. libXaw.dylib). I have written some code for handle this situation. With the following patch, I have built Emacs/Carbon and Emacs/X11-dylib on Mac OS X successfully, and the both seem to work fine. I hope this helps. Regards, Nozomu Ando --Apple-Mail-10--384789338 Content-Transfer-Encoding: 7bit Content-Type: text/plain; x-unix-mode=0644; name="patch-unexmacosx.txt" Content-Disposition: attachment; filename=patch-unexmacosx.txt Index: mac/INSTALL =================================================================== RCS file: /cvsroot/emacs/emacs/mac/INSTALL,v retrieving revision 1.14 diff -u -r1.14 INSTALL --- mac/INSTALL 4 Feb 2003 14:12:13 -0000 1.14 +++ mac/INSTALL 12 Oct 2003 13:23:01 -0000 @@ -58,16 +58,11 @@ correctly. You may want to create a symlink or alias to this path to quickly access both the terminal and GUI versions. -If you are building Emacs to run on Mac OS X and X Window, you need to -create a directory containing statically-linked X libraries. +If you are building Emacs to run on Mac OS X and X Window, +instead of typing `./configure' above, type - sudo mkdir /usr/X11R6/libstatic - cd /usr/X11R6/libstatic - sudo ln -s ../lib/lib*.a ../lib/X11 . + ./configure --without-carbon --with-x -Instead of typing `./configure' above, type - - ./configure --without-carbon --with-x --x-libraries=/usr/X11R6/libstatic To use colors in a terminal, put the following lines in the file ~/.termcap and log in again. @@ -159,11 +154,6 @@ $prefix/bin/emacs to reduce disk space. Note, this option may removed in the future. -If you are intending to build a binary distribution for X windows, you -will probably want to follow the directions above to create static -X11R6 libraries and run the make-package script like this - -./make-package --with-x -C,--x-libraries=/usr/X11R6/libstatic For usage of other options, use the --help option. Index: src/unexmacosx.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/unexmacosx.c,v retrieving revision 1.7 diff -u -r1.7 unexmacosx.c --- src/unexmacosx.c 1 Sep 2003 15:45:57 -0000 1.7 +++ src/unexmacosx.c 12 Oct 2003 13:23:04 -0000 @@ -95,6 +95,10 @@ #include #include #include +#include +#if defined (__ppc__) +#include +#endif #include #define VERBOSE 1 @@ -158,6 +162,11 @@ malloc_zone_t *emacs_zone; +/* file offset of input file's data segment */ +off_t data_segment_old_fileoff; + +struct segment_command *data_segment_scp; + /* Read n bytes from infd into memory starting at address dest. Return true if successful, false otherwise. */ static int @@ -763,6 +772,65 @@ curr_header_offset += lc->cmdsize; } +/* Fix up relocation entries. */ +static void +unrelocate (const char *name, off_t reloff, int nrel) +{ + int i, unreloc_count; + struct relocation_info reloc_info; + struct scattered_relocation_info *sc_reloc_info + = (struct scattered_relocation_info *) &reloc_info; + + for (unreloc_count = 0, i = 0; i < nrel; i++) + { + if (lseek (infd, reloff, L_SET) != reloff) + unexec_error ("unrelocate: %s:%d cannot seek to reloc_info", name, i); + if (!unexec_read (&reloc_info, sizeof (reloc_info))) + unexec_error ("unrelocate: %s:%d cannot read reloc_info", name, i); + reloff += sizeof (reloc_info); + + if (sc_reloc_info->r_scattered == 0) + switch (reloc_info.r_type) + { + case GENERIC_RELOC_VANILLA: + if (reloc_info.r_address >= data_segment_scp->vmaddr + && reloc_info.r_address < (data_segment_scp->vmaddr + + data_segment_scp->vmsize)) + { + off_t src_off = data_segment_old_fileoff + + reloc_info.r_address - data_segment_scp->vmaddr; + off_t dst_off = data_segment_scp->fileoff + + reloc_info.r_address - data_segment_scp->vmaddr; + + if (!unexec_copy (dst_off, src_off, 1 << reloc_info.r_length)) + unexec_error ("unrelocate: %s:%d cannot copy original value", + name, i); + unreloc_count++; + } + break; + default: + unexec_error ("unrelocate: %s:%d cannot handle type = %d", + name, i, reloc_info.r_type); + } + else + switch (sc_reloc_info->r_type) + { +#if defined (__ppc__) + case PPC_RELOC_PB_LA_PTR: + /* nothing to do for prebound lazy pointer */ + break; +#endif + default: + unexec_error ("unrelocate: %s:%d cannot handle scattered type = %d", + name, i, sc_reloc_info->r_type); + } + } + + if (nrel > 0) + printf ("Fixed up %d/%d %s relocation entries in data segment.\n", + unreloc_count, nrel, name); +} + /* Copy a LC_DYSYMTAB load command from the input file to the output file, adjusting the file offset fields. */ static void @@ -770,10 +838,8 @@ { struct dysymtab_command *dstp = (struct dysymtab_command *) lc; - /* If Mach-O executable is not prebound, relocation entries need - fixing up. This is not supported currently. */ - if (!(mh.flags & MH_PREBOUND) && (dstp->nextrel != 0 || dstp->nlocrel != 0)) - unexec_error ("cannot handle LC_DYSYMTAB with relocation entries"); + unrelocate ("local", dstp->locreloff, dstp->nlocrel); + unrelocate ("external", dstp->extreloff, dstp->nextrel); if (dstp->nextrel > 0) { dstp->extreloff += delta; @@ -845,6 +911,11 @@ struct segment_command *scp = (struct segment_command *) lca[i]; if (strncmp (scp->segname, SEG_DATA, 16) == 0) { + /* save data segment file offset and segment_command for + unrelocate */ + data_segment_old_fileoff = scp->fileoff; + data_segment_scp = scp; + copy_data_segment (lca[i]); } else --Apple-Mail-10--384789338 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel --Apple-Mail-10--384789338--