From xemacs-m  Mon Jun 16 19:29:35 1997
Received: from iria.mines.u-nancy.fr (galibert@iria.mines.u-nancy.fr [193.49.140.100])
	by xemacs.org (8.8.5/8.8.5) with SMTP id TAA07251
	for <xemacs-beta@xemacs.org>; Mon, 16 Jun 1997 19:29:34 -0500 (CDT)
Received: (from galibert@localhost) by iria.mines.u-nancy.fr (950413.SGI.8.6.12/950213.SGI.AUTOCF) id CAA12399; Tue, 17 Jun 1997 02:28:29 +0200
Message-ID: <19970617022828.55217@iria.mines.u-nancy.fr>
Date: Tue, 17 Jun 1997 02:28:28 +0200
From: Olivier Galibert <Olivier.Galibert@mines.u-nancy.fr>
To: Xemacs-beta ML <xemacs-beta@xemacs.org>
Subject: unexelfsgi.c upgrade
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=ocE+STaALJfprDB5
X-Mailer: Mutt 0.74


--ocE+STaALJfprDB5
Content-Type: text/plain; charset=us-ascii

Some things that Needed To Be Done(tm) into unexelfsgi:
- support for .sbss section (no more -G 0 needed, 0.00001% speed increase)
- support for Elf64 (64bits executables)

64b compilation shows another problem: in numerous places xemacs considers
that sizeof(int)==sizeof(void *). In SGI 64b model, sizeof(int)=4,
sizeof(void *)=8, sizeof(long)=8. Dumps core while executing my .emacs
(actually I was surprised to see it going that far :-).

So:
- Should we fix it ?
- If yes, should we:
  - change all these ints to long (I don't like that)
  - have the configure find a pointer_t type which would be the smallest
    integral type (int, long or long long) in which a pointer can fit and
    use it when needed.

As a side effect, the upgrade obsoletes some part of the s/irix6-0.h and
m/iris4d.h files which are then removed by the patch, which in turn
obsoletes my message in PROBLEMS. Please remove it, the -n32 can be
used out of the box after this patch.

  OG.

--ocE+STaALJfprDB5
Content-Type: text/plain; charset=us-ascii
Content-Description: unexelfsgi.c++
Content-Disposition: attachment; filename="sgi.diff"

--- src/unexelfsgi.c.orig	Sun Jun 15 04:31:51 1997
+++ src/unexelfsgi.c	Tue Jun 17 01:10:03 1997
@@ -479,7 +479,12 @@
 	     new_bss_addr - roundup(old_bss_addr,0x1000)
 
      */
-
+  /* Still more mods... Olivier Galibert 19971705
+     - support for .sbss section (automagically changed to data without
+       name change)
+     - support for 64bits ABI (will need a bunch of fixes in the rest
+       of the code before it works
+     */
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -493,6 +498,26 @@
 #include <sym.h> /* for HDRR declaration */
 #include <sys/mman.h>
 
+/* in 64bits mode, use 64bits elf */
+#ifdef _ABI64
+typedef Elf64_Shdr l_Elf_Shdr;
+typedef Elf64_Phdr l_Elf_Phdr;
+typedef Elf64_Ehdr l_Elf_Ehdr;
+typedef Elf64_Addr l_Elf_Addr;
+typedef Elf64_Word l_Elf_Word;
+typedef Elf64_Off  l_Elf_Off;
+typedef Elf64_Sym  l_Elf_Sym;
+#else
+typedef Elf32_Shdr l_Elf_Shdr;
+typedef Elf32_Phdr l_Elf_Phdr;
+typedef Elf32_Ehdr l_Elf_Ehdr;
+typedef Elf32_Addr l_Elf_Addr;
+typedef Elf32_Word l_Elf_Word;
+typedef Elf32_Off  l_Elf_Off;
+typedef Elf32_Sym  l_Elf_Sym;
+#endif
+
+
 #ifndef emacs
 #define fatal(a, b, c) fprintf(stderr, a, b, c), exit(1)
 #else
@@ -504,13 +529,13 @@
  */
 
 #define OLD_SECTION_H(n) \
-     (*(Elf32_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
+     (*(l_Elf_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
 #define NEW_SECTION_H(n) \
-     (*(Elf32_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
+     (*(l_Elf_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
 #define OLD_PROGRAM_H(n) \
-     (*(Elf32_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
+     (*(l_Elf_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
 #define NEW_PROGRAM_H(n) \
-     (*(Elf32_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
+     (*(l_Elf_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
 
 #define PATCH_INDEX(n) \
   do { \
@@ -542,8 +567,8 @@
      char *name;
      char *section_names;
      char *file_name;
-     Elf32_Ehdr *old_file_h;
-     Elf32_Shdr *old_section_h;
+     l_Elf_Ehdr *old_file_h;
+     l_Elf_Shdr *old_section_h;
      int noerror;
 {
   int idx;
@@ -591,18 +616,18 @@
 
   /* Pointers to the file, program and section headers for the old and new
      files.  */
-  Elf32_Ehdr *old_file_h, *new_file_h;
-  Elf32_Phdr *old_program_h, *new_program_h;
-  Elf32_Shdr *old_section_h, *new_section_h;
+  l_Elf_Ehdr *old_file_h, *new_file_h;
+  l_Elf_Phdr *old_program_h, *new_program_h;
+  l_Elf_Shdr *old_section_h, *new_section_h;
 
   /* Point to the section name table in the old file.  */
   char *old_section_names;
 
-  Elf32_Addr old_bss_addr, new_bss_addr;
-  Elf32_Word old_bss_size, new_data2_size;
-  Elf32_Off  new_data2_offset;
-  Elf32_Addr new_data2_addr;
-  Elf32_Addr new_offsets_shift;
+  l_Elf_Addr old_bss_addr, new_bss_addr;
+  l_Elf_Word old_bss_size, new_data2_size;
+  l_Elf_Off  new_data2_offset;
+  l_Elf_Addr new_data2_addr;
+  l_Elf_Addr new_offsets_shift;
 
   int n, nn, old_bss_index, old_data_index, new_data2_index;
   int old_mdebug_index;
@@ -630,9 +655,9 @@
 
   /* Get pointers to headers & section names.  */
 
-  old_file_h = (Elf32_Ehdr *) old_base;
-  old_program_h = (Elf32_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
-  old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
+  old_file_h = (l_Elf_Ehdr *) old_base;
+  old_program_h = (l_Elf_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
+  old_section_h = (l_Elf_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
   old_section_names
     = (char *) old_base + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset;
 
@@ -656,7 +681,7 @@
   old_bss_size	    = OLD_SECTION_H (old_bss_index).sh_size;
 #if defined(emacs) || !defined(DEBUG)
   bss_end	    = (unsigned int) sbrk (0);
-  new_bss_addr	    = (Elf32_Addr) bss_end;
+  new_bss_addr	    = (l_Elf_Addr) bss_end;
 #else
   new_bss_addr	    = old_bss_addr + old_bss_size + 0x1234;
 #endif
@@ -702,10 +727,10 @@
   if (new_base == (caddr_t) -1)
     fatal ("Can't mmap (%s): errno %d\n", new_name, errno);
 
-  new_file_h = (Elf32_Ehdr *) new_base;
-  new_program_h = (Elf32_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
+  new_file_h = (l_Elf_Ehdr *) new_base;
+  new_program_h = (l_Elf_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
   new_section_h
-    = (Elf32_Shdr *) ((byte *) new_base + old_file_h->e_shoff
+    = (l_Elf_Shdr *) ((byte *) new_base + old_file_h->e_shoff
 		      + new_offsets_shift);
 
   /* Make our new file, program and section headers as copies of the
@@ -857,17 +882,26 @@
 	  && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM)
 	PATCH_INDEX (NEW_SECTION_H (nn).sh_info);
       
+      /* Fix the type and alignment for the .sbss section */
+      if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sbss"))
+	{
+	  NEW_SECTION_H (nn).sh_type = SHT_PROGBITS;
+	  NEW_SECTION_H (nn).sh_offset = round_up (NEW_SECTION_H (nn).sh_offset,
+						   NEW_SECTION_H (nn).sh_addralign);
+	}
+
       /* Now, start to copy the content of sections. */
       if (NEW_SECTION_H (nn).sh_type == SHT_NULL
 	  || NEW_SECTION_H (nn).sh_type == SHT_NOBITS)
 	continue;
       
-      /* Write out the sections. .data and .data1 (and data2, called
+      /* Write out the sections. .data, .data1 nad .sbss (and data2, called
 	 ".data" in the strings table) get copied from the current process
 	 instead of the old file.  */
       if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data")
 	  || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data1")
-	  || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".got"))
+	  || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".got")
+	  || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sbss"))
 	src = (caddr_t) OLD_SECTION_H (n).sh_addr;
       else
 	src = old_base + OLD_SECTION_H (n).sh_offset;
@@ -932,9 +966,9 @@
       if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB
 	  || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM)
 	{
-	  Elf32_Shdr *spt = &NEW_SECTION_H (nn);
+	  l_Elf_Shdr *spt = &NEW_SECTION_H (nn);
 	  unsigned int num = spt->sh_size / spt->sh_entsize;
-	  Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H (nn).sh_offset
+	  l_Elf_Sym * sym = (l_Elf_Sym *) (NEW_SECTION_H (nn).sh_offset
 					   + new_base);
 	  for (; num--; sym++)
 	    {
--- src/s/irix6-0.h~	Sun Mar 16 04:06:47 1997
+++ src/s/irix6-0.h	Sun Jun 15 02:00:27 1997
@@ -2,14 +2,6 @@
 
 #include "irix5-3.h"
 
-/* Irix 6 tries to do 64 bits, but doesn't do it fully,
-   so inhibit that.  */
-#define IRIX_FORCE_32_BITS
-
-#ifndef __GNUC__
-#define LD_SWITCH_SYSTEM -32
-#endif
-
 /* This macro definition, which we inherited from irix5-0.h,
    is needed in configure on Irix 5, but gets in the way there
    on Irix 6.  So get rid of it except in Makefile.in where we need it.  */
--- src/m/iris4d.h~	Wed Dec 18 23:44:11 1996
+++ src/m/iris4d.h	Sun Jun 15 02:01:10 1997
@@ -118,7 +118,7 @@
 
 #undef LIBS_MACHINE
 /* -lsun in case using Yellow Pages for passwords.  */
-#define LIBS_MACHINE -lmld
+#define LIBS_MACHINE
 #define LIBS_DEBUG
 
 /* Define this if you have a fairly recent system,
@@ -152,13 +152,3 @@
 
 #undef STACK_DIRECTION
 #define STACK_DIRECTION -1
-
-#ifndef __GNUC__
-/* Turn off some "helpful" error checks for type mismatches
-   that we can't fix without breaking other machines.  */
-#ifdef IRIX_FORCE_32_BITS
-#ifdef THIS_IS_MAKEFILE
-#define C_SWITCH_MACHINE -32
-#endif
-#endif /* IRIX_FORCE_32_BITS */
-#endif /* not __GNUC__ */

--ocE+STaALJfprDB5--

