]> code.delx.au - gnu-emacs/blobdiff - src/unexalpha.c
Do not assume DST starts/ends on the same date in every year.
[gnu-emacs] / src / unexalpha.c
index 2adfd1fa57eaa3073d60b5da4f4ace44bbf57c41..ead259437f65465c4e5133cf8bc3d01df4dcdbb1 100644 (file)
@@ -1,6 +1,7 @@
 /* Unexec for DEC alpha.  schoepf@sc.ZIB-Berlin.DE (Rainer Schoepf).
 
-   Copyright (C) 1994 Free Software Foundation, Inc.
+   Copyright (C) 1994, 2000, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -16,8 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 \f
 #include <config.h>
@@ -26,7 +27,11 @@ Boston, MA 02111-1307, USA.  */
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <stdio.h>
-#include <varargs.h>
+#include <errno.h>
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#if !defined (__NetBSD__) && !defined (__OpenBSD__)
 #include <filehdr.h>
 #include <aouthdr.h>
 #include <scnhdr.h>
@@ -35,9 +40,51 @@ Boston, MA 02111-1307, USA.  */
 # include <reloc.h>
 # include <elf_abi.h>
 #endif
-
-static void fatal_unexec ();
-static void mark_x ();
+#else /* __NetBSD__ or __OpenBSD__ */
+/*
+ * NetBSD/Alpha does not have 'normal' user-land ECOFF support because
+ * there's no desire to support ECOFF as the executable format in the
+ * long term.
+ */
+#include <sys/exec_ecoff.h>
+
+/* Structures, constants, etc., that NetBSD defines strangely. */
+#define        filehdr         ecoff_filehdr
+#define        aouthdr         ecoff_aouthdr
+#define        scnhdr          ecoff_scnhdr
+#define        HDRR            struct ecoff_symhdr
+#define        pHDRR           HDRR *
+#define        cbHDRR          sizeof(HDRR)
+#ifdef __OpenBSD__
+#define        ALPHAMAGIC      ECOFF_MAGIC_NATIVE_ALPHA
+#else
+#define        ALPHAMAGIC      ECOFF_MAGIC_NETBSD_ALPHA
+#endif
+#define        ZMAGIC          ECOFF_ZMAGIC
+
+/* Misc. constants that NetBSD doesn't define at all. */
+#define        ALPHAUMAGIC     0617
+#define        _MIPS_NSCNS_MAX 35
+#define        STYP_TEXT       0x00000020
+#define        STYP_DATA       0x00000040
+#define        STYP_BSS        0x00000080
+#define        STYP_RDATA      0x00000100
+#define        STYP_SDATA      0x00000200
+#define        STYP_SBSS       0x00000400
+#define        STYP_INIT       0x80000000
+#define        _TEXT           ".text"
+#define        _DATA           ".data"
+#define        _BSS            ".bss"
+#define        _INIT           ".init"
+#define        _RDATA          ".rdata"
+#define        _SDATA          ".sdata"
+#define        _SBSS           ".sbss"
+#endif /* __NetBSD__ || __OpenBSD__ */
+
+static void fatal_unexec __P ((char *, char *));
+static void mark_x __P ((char *));
+
+static void update_dynamic_symbols __P ((char *, char *, int, struct aouthdr));
 
 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
        errno = EEOF; \
@@ -53,10 +100,11 @@ static void mark_x ();
        if (lseek (_fd, _position, L_SET) != _position) \
          fatal_unexec (_error_message, _error_arg);
 
-extern int errno;
-extern char *strerror ();
-
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#else
 void *sbrk ();
+#endif
 
 #define EEOF -1
 
@@ -96,6 +144,7 @@ struct headers {
 #define DEFAULT_ENTRY_ADDRESS __start
 #endif
 \f
+void
 unexec (new_name, a_name, data_start, bss_start, entry_address)
      char *new_name, *a_name;
      unsigned long data_start, bss_start, entry_address;
@@ -149,7 +198,7 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
   if (nhdr.fhdr.f_opthdr != sizeof (nhdr.aout))
     {
       fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n",
-              nhdr.fhdr.f_opthdr, sizeof (nhdr.aout));
+              nhdr.fhdr.f_opthdr, (int)sizeof (nhdr.aout));
       exit (1);
     }
   if (nhdr.aout.magic != ZMAGIC)
@@ -194,10 +243,10 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
 #endif
 #ifdef _PDATA
   CHECK_SCNHDR (pdata_section, _PDATA, STYP_PDATA);
-#endif _PDATA
+#endif /* _PDATA */
 #ifdef _GOT
   CHECK_SCNHDR (got_section,   _GOT,   STYP_GOT);
-#endif _GOT
+#endif /* _GOT */
   CHECK_SCNHDR (data_section,  _DATA,  STYP_DATA);
 #ifdef _XDATA
   CHECK_SCNHDR (xdata_section, _XDATA, STYP_XDATA);
@@ -361,8 +410,9 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
         stat.st_size - ohdr.fhdr.f_symptr - cbHDRR,
         "writing symbol table of %s", new_name);
 
-#ifndef __linux__
-  update_dynamic_symbols (oldptr, new_name, new, nhdr.aout);
+#ifdef _REL_DYN
+  if (rel_dyn_section)
+    update_dynamic_symbols (oldptr, new_name, new, nhdr.aout);
 #endif
 
 #undef symhdr
@@ -377,16 +427,15 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
 }
 
 
-
-
-#ifndef __linux__
-
+static void
 update_dynamic_symbols (old, new_name, new, aout)
      char *old;                        /* Pointer to old executable */
      char *new_name;            /* Name of new executable */
      int new;                  /* File descriptor for new executable */
      struct aouthdr aout;      /* a.out info from the file header */
 {
+#if !defined (__linux__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
+
   typedef struct dynrel_info {
     char * addr;
     unsigned type:8;
@@ -428,7 +477,7 @@ update_dynamic_symbols (old, new_name, new, aout)
          4. len is the size of the object reference in bytes --
             currently only 4 (long) and 8 (quad) are supported.
            */
-      register unsigned long reladdr = rd_base[i].addr - old_data_scnhdr.s_vaddr;
+      register unsigned long reladdr = (long)rd_base[i].addr - old_data_scnhdr.s_vaddr;
       char * oldref = old + old_data_scnhdr.s_scnptr + reladdr;
       unsigned long newref = aout.tsize + reladdr;
       int len;
@@ -437,12 +486,12 @@ update_dynamic_symbols (old, new_name, new, aout)
       fprintf (stderr, "...relocated\n");
 #endif
 
-      if (rd_base[i].type == R_REFLONG) 
+      if (rd_base[i].type == R_REFLONG)
        len = 4;
-      else if (rd_base[i].type == R_REFQUAD) 
+      else if (rd_base[i].type == R_REFQUAD)
        len = 8;
       else
-       fatal_unexec ("unrecognized relocation type in .dyn.rel section (symbol #%d)", i);
+       fatal_unexec ("unrecognized relocation type in .dyn.rel section (symbol #%d)", (char *) i);
 
       SEEK (new, newref, "seeking to dynamic symbol in %s", new_name);
       WRITE (new, oldref, len, "writing old dynrel info in %s", new_name);
@@ -455,10 +504,9 @@ update_dynamic_symbols (old, new_name, new, aout)
 
   }
 
+#endif /* not __linux__ and not __NetBSD__ and not __OpenBSD__ */
 }
 
-#endif /* !__linux__ */
-
 \f
 /*
  * mark_x
@@ -493,3 +541,6 @@ fatal_unexec (s, arg)
   fputs (".\n", stderr);
   exit (1);
 }
+
+/* arch-tag: 46316c49-ee08-4aa3-942b-00798902f5bd
+   (do not change this comment) */