🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99796

unexec.c and COFF encapsulation

#99796
From: James Clark
Date: Wed, 02 May 1990 17:03
180 lines
5589 bytes
I tried to compile Emacs 18.55 using gcc 1.37, (configured with
i386g), gas and GNU ld and a 386 PC running 386/ix 2.0.1 (a variant of
System V R3.2). I used m-intel386.h and s-usg5-3.h.  I got a working
temacs but xemacs core dumped immediately and gdb wouldn't debug it.

Here are some changes to unexec.c ifdef'ed on COFF_ENCAPSULATE that
worked for me.  Note that m-intel386.h defines NO_REMAP: I don't know
whether these changes will work on systems that don't define NO_REMAP.
It requires the a.out.{encap,gnu}.h from the binutils or gdb
distributions.

James Clark
jjc@jclark.uucp

*** /usr/local/emacs/src/unexec.c	Thu Jan 26 14:30:55 1989
--- unexec.c	Wed May  2 17:41:33 1990
***************
*** 241,251 ****
--- 241,260 ----
  #define PERROR(file) report_error (file, new)
  #endif
  
+ #ifdef COFF_ENCAPSULATE
+ #undef COFF
+ #endif
+ 
  #ifndef CANNOT_DUMP  /* all rest of file!  */
  
  #ifndef CANNOT_UNEXEC /* most of rest of file */
  
+ #ifdef COFF_ENCAPSULATE
+ #include "a.out.encap.h"
+ #else
  #include <a.out.h>
+ #endif
+ 
  /* Define getpagesize () if the system does not.
     Note that this may depend on symbols defined in a.out.h
   */
***************
*** 312,318 ****
  
  #else /* not HPUX */
  
! #if defined (USG) && !defined (IBMRTAIX) && !defined (IRIS)
  static struct bhdr hdr, ohdr;
  #define a_magic fmagic
  #define a_text tsize
--- 321,327 ----
  
  #else /* not HPUX */
  
! #if defined (USG) && !defined (IBMRTAIX) && !defined (IRIS) && !defined (COFF_ENCAPSULATE)
  static struct bhdr hdr, ohdr;
  #define a_magic fmagic
  #define a_text tsize
***************
*** 337,342 ****
--- 346,355 ----
  
  #endif /* not COFF */
  
+ #ifdef COFF_ENCAPSULATE
+ struct coffheader coffheader;
+ #endif
+ 
  static int pagemask;
  
  /* Correct an int which is the bit pattern of a pointer to a byte
***************
*** 619,625 ****
--- 632,699 ----
    return (0);
  
  #else /* if not COFF */
+ #ifdef COFF_ENCAPSULATE
+   if (a_out >= 0)
+     {
+       if (read (a_out, &coffheader, sizeof coffheader) != sizeof coffheader)
+ 	{
+ 	  PERROR (a_name);
+ 	}
+ 
+       if (coffheader.f_magic != COFF_MAGIC)
+ 	{
+ 	  ERROR1 ("invalid magic number in %s", a_name);
+ 	}
+ 
+       if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr)
+ 	{
+ 	  PERROR (a_name);
+ 	}
+ 
+       if (N_BADMAG (ohdr))
+ 	{
+ 	  ERROR1 ("invalid magic number in %s", a_name);
+ 	}
+       hdr = ohdr;
+     }
+   else
+     {
+       ERROR0 ("can't build a COFF file from scratch yet");
+     }
+ 
+   {
+     struct coffscn *tp = &coffheader.scns[0]; /* text section */
+     struct coffscn *dp = &coffheader.scns[1]; /* data section */
+     struct coffscn *bp = &coffheader.scns[2]; /* bss section */
+ 
+ #ifndef NO_REMAP
+     coffheader.text_start = tp->s_vaddr = tp->s_paddr = (long)start_of_text ();
+     coffheader.tsize = tp->s_size = hdr.a_text = data_start - tp->s_paddr;
+     coffheader.data_start = dp->s_vaddr = dp->s_paddr = data_start;
+     dp->s_scnptr = tp->s_scnptr + tp->s_size;
+ #endif /* not NO_REMAP */
+     /* Set the size of the data segment. */
+     coffheader.dsize = dp->s_size = hdr.a_data = bss_start - dp->s_paddr;
+     /* Set the starting address of the bss segment. */
+     bp->s_vaddr = bp->s_paddr = dp->s_vaddr + dp->s_size;
+     /* Set the size of the bss segment. */
+     coffheader.bsize = bp->s_size = hdr.a_bss = bss_end - bss_start;
+   }
+ 
+   if (write (new, &coffheader, sizeof coffheader) != sizeof coffheader)
+     {
+       PERROR (new_name);
+     }
+ 
+   if (write (new, &hdr, sizeof hdr) != sizeof hdr)
+     {
+       PERROR (new_name);
+     }
  
+   return 0;
+ 
+ #else /* if not COFF_ENCAPSULATE */
+ 
    /* Get symbol table info from header of a.out file if given one. */
    if (a_out >= 0)
      {
***************
*** 676,681 ****
--- 750,756 ----
  
    return 0;
  
+ #endif /* not COFF_ENCAPSULATE */
  #endif /* not COFF */
  }
  
***************
*** 703,709 ****
--- 778,794 ----
    write_segment (new, ptr, end);
  
  #else /* if not COFF */
+ #ifdef COFF_ENCAPSULATE
+   lseek (new, (long) coffheader.scns[0].s_scnptr, 0);
+   ptr = (char *) coffheader.text_start;
+   end = ptr + coffheader.tsize;
+   write_segment (new, ptr, end);
  
+   lseek (new, (long) coffheader.scns[1].s_scnptr, 0);
+   ptr = (char *) coffheader.data_start;
+   end = ptr + coffheader.dsize;
+   write_segment (new, ptr, end);
+ #else /* if not COFF_ENCAPULATE */
  /* Some machines count the header as part of the text segment.
     That is to say, the header appears in core
     just before the address that start_of_text () returns.
***************
*** 738,743 ****
--- 823,829 ----
  /*  lseek (new, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */
    write_segment (new, ptr, end);
  
+ #endif
  #endif /* not COFF */
  
    return 0;
Technical Details
Message-ID: <9005021703.AA11227@jclark.uucp>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!spdcc!snorkelwacker!tut.cis.ohio-state.edu!relay.eu.net!jclark!jjc

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,b6df877518d770b3,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-05-03 01:10:49 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!spdcc!snorkelwacker!tut.cis.ohio-state.edu!relay.eu.net!jclark!jjc
From: jclark!jjc@relay.eu.net (James Clark)
Newsgroups: gnu.emacs.bug
Subject: unexec.c and COFF encapsulation
Message-ID: <9005021703.AA11227@jclark.uucp>
Date: 2 May 90 17:03:33 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 180
Posted: Wed May  2 18:03:33 1990