summaryrefslogtreecommitdiff
path: root/src/unexsunos4.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-09-17 10:22:21 +0000
committerRichard M. Stallman <rms@gnu.org>1994-09-17 10:22:21 +0000
commitfbb4a474248ce2796a7d6fbdcdaa4f46d7f4304d (patch)
tree2c5d14d770fc109ba71fd443dd54d1eec8acc35a /src/unexsunos4.c
parent0fb5f251090a273648d9215dc26b00aaa30c3c18 (diff)
downloademacs-fbb4a474248ce2796a7d6fbdcdaa4f46d7f4304d.tar.gz
[SUNOS4]: Include link.h.
(unexec) [SUNOS4]: Cancel relocations that ld.so did.
Diffstat (limited to 'src/unexsunos4.c')
-rw-r--r--src/unexsunos4.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/unexsunos4.c b/src/unexsunos4.c
index 53c3dc13bf9..d8cac642168 100644
--- a/src/unexsunos4.c
+++ b/src/unexsunos4.c
@@ -1,3 +1,22 @@
+/* Unexec for Sunos 4 using shared libraries.
+ Copyright (C) 1990, 1994 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+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.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+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, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
/* Contributed by Viktor Dukhovni. */
/*
* Unexec for Berkeley a.out format + SUNOS shared libraries
@@ -37,6 +56,10 @@
#include <config.h>
#endif
+#ifdef SUNOS4
+#include <link.h>
+#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -183,6 +206,56 @@ unexec (new_name, a_name, bndry, bss_start, entry)
lseek (new, N_TRELOFF (nhdr), L_SET);
write (new, old + N_TRELOFF (ohdr), stat.st_size - N_TRELOFF (ohdr));
+ /* Some other BSD systems use this file.
+ We don't know whether this change is right for them. */
+#ifdef SUNOS4
+ /* Undo the relocations done at startup by ld.so.
+ It will do these relocations again when we start the dumped Emacs.
+ Doing them twice gives incorrect results. */
+ {
+ extern struct link_dynamic _DYNAMIC;
+ unsigned long taddr = N_TXTADDR (ohdr);
+ unsigned long rel, erel;
+ unsigned rel_size;
+
+ if (_DYNAMIC.ld_version < 2)
+ {
+ rel = _DYNAMIC.ld_un.ld_1->ld_rel;
+ erel = _DYNAMIC.ld_un.ld_1->ld_hash;
+ }
+ else
+ {
+ rel = _DYNAMIC.ld_un.ld_2->ld_rel;
+ erel = _DYNAMIC.ld_un.ld_2->ld_hash;
+ }
+
+ switch (ohdr.a_machtype)
+ {
+ case M_68010:
+ case M_68020:
+ rel_size = 8; /* sizeof(struct reloc_info_m68k) */
+ break;
+ case M_SPARC:
+ rel_size = 12; /* sizeof(struct reloc_info_sparc) */
+ break;
+ case M_OLDSUN2:
+ default:
+ fatal ("unknown machine type in unexec!\n");
+ }
+
+ for (; rel < erel; rel += rel_size)
+ {
+ unsigned long rpos = *(unsigned long *)(taddr + rel) - taddr;
+
+ if (rpos < (unsigned long)&data_start - taddr)
+ continue;
+
+ lseek (new, N_TXTOFF (nhdr) + rpos, L_SET);
+ write (new, old + N_TXTOFF (ohdr) + rpos, sizeof (unsigned long));
+ }
+ }
+#endif /* SUNOS4 */
+
fchmod (new, 0755);
}