-/* Unexec for DEC alpha. schoepf@sc.ZIB-Berlin.DE (Rainer Schoepf).
+/* Unexec for DEC alpha.
- Copyright (C) 1994 Free Software Foundation, Inc.
+ Copyright (C) 1994, 2000, 2001, 2002, 2003, 2004,
+ 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+Author: Rainer Schoepf <schoepf@sc.ZIB-Berlin.DE>
This file is part of GNU Emacs.
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
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. */
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
\f
#include <config.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdio.h>
-#include <varargs.h>
-#ifndef __NetBSD__
+#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>
# include <reloc.h>
# include <elf_abi.h>
#endif
-#else /* __NetBSD__ */
+#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
#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 _RDATA ".rdata"
#define _SDATA ".sdata"
#define _SBSS ".sbss"
-#endif /* __NetBSD__ */
+#endif /* __NetBSD__ || __OpenBSD__ */
+
+static void fatal_unexec __P ((char *, char *));
+static void mark_x __P ((char *));
-static void fatal_unexec ();
-static void mark_x ();
+static void update_dynamic_symbols __P ((char *, char *, int, struct aouthdr));
#define READ(_fd, _buffer, _size, _error_message, _error_arg) \
errno = EEOF; \
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
struct scnhdr section[_MIPS_NSCNS_MAX];
};
-
-
-/* Define name of label for entry point for the dumped executable. */
-
-#ifndef DEFAULT_ENTRY_ADDRESS
-#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;
#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);
nhdr.aout.bsize = 0;
if (entry_address == 0)
{
- extern DEFAULT_ENTRY_ADDRESS ();
- nhdr.aout.entry = (unsigned long)DEFAULT_ENTRY_ADDRESS;
+ extern __start ();
+ nhdr.aout.entry = (unsigned long)__start;
}
else
nhdr.aout.entry = entry_address;
}
-
+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__)
+#if !defined (__linux__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
typedef struct dynrel_info {
char * addr;
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);
}
-#endif /* not __linux__ and not __NetBSD__ */
+#endif /* not __linux__ and not __NetBSD__ and not __OpenBSD__ */
}
\f
fputs (".\n", stderr);
exit (1);
}
+
+/* arch-tag: 46316c49-ee08-4aa3-942b-00798902f5bd
+ (do not change this comment) */