Mercurial > emacs
annotate src/unexmips.c @ 12682:66b3d052d4fe
(shared-lisp-mode-map): Don't bind TAB, just set indent-line-function.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Wed, 26 Jul 1995 22:21:02 +0000 |
| parents | 0c728a1b2bed |
| children | ee40177f6c68 |
| rev | line source |
|---|---|
| 486 | 1 /* Unexec for MIPS (including IRIS4D). |
| 2 Note that the GNU project considers support for MIPS operation | |
| 3 a peripheral activity which should not be allowed to divert effort | |
| 4 from development of the GNU system. Changes in this code will be | |
| 5 installed when users send them in, but aside from that | |
| 6 we don't plan to think about it, or about whether other Emacs | |
| 7 maintenance might break it. | |
| 8 | |
|
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
9 Copyright (C) 1988, 1994 Free Software Foundation, Inc. |
| 486 | 10 |
| 11 This file is part of GNU Emacs. | |
| 12 | |
| 13 GNU Emacs is free software; you can redistribute it and/or modify | |
| 14 it under the terms of the GNU General Public License as published by | |
|
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
15 the Free Software Foundation; either version 2, or (at your option) |
| 486 | 16 any later version. |
| 17 | |
| 18 GNU Emacs is distributed in the hope that it will be useful, | |
| 19 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 GNU General Public License for more details. | |
| 22 | |
| 23 You should have received a copy of the GNU General Public License | |
| 24 along with GNU Emacs; see the file COPYING. If not, write to | |
| 25 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
| 26 | |
| 27 | |
|
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
28 #include <config.h> |
| 486 | 29 #include <sys/types.h> |
| 30 #include <sys/file.h> | |
| 31 #include <sys/stat.h> | |
| 32 #include <stdio.h> | |
| 33 #include <varargs.h> | |
|
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
34 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
35 #ifdef MACH |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
36 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
37 #include <a.out.h> |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
38 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
39 /* I don't know why this isn't defined. */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
40 #ifndef STYP_INIT |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
41 #define STYP_INIT 0x80000000 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
42 #endif |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
43 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
44 /* I don't know why this isn't defined. */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
45 #ifndef _RDATA |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
46 #define _RDATA ".rdata" |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
47 #define STYP_RDATA 0x00000100 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
48 #endif |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
49 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
50 /* Small ("near") data section. */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
51 #ifndef _SDATA |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
52 #define _SDATA ".sdata" |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
53 #define STYP_SDATA 0x00000200 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
54 #endif |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
55 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
56 /* Small ("near") bss section. */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
57 #ifndef _SBSS |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
58 #define _SBSS ".sbss" |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
59 #define STYP_SBSS 0x00000400 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
60 #endif |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
61 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
62 /* We don't seem to have a sym.h or syms.h anywhere, so we'll do it the |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
63 hard way. This stinks. */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
64 typedef struct { |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
65 short magic; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
66 short vstamp; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
67 long ilineMax; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
68 struct { long foo, offset; } offsets[11]; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
69 } HDRR, *pHDRR; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
70 |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
71 #else /* not MACH */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
72 |
| 486 | 73 #include <filehdr.h> |
| 74 #include <aouthdr.h> | |
| 75 #include <scnhdr.h> | |
| 76 #include <sym.h> | |
| 77 | |
|
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
78 #endif /* not MACH */ |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
79 |
|
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
80 #if defined (IRIS_4D) || defined (sony) |
| 486 | 81 #include "getpagesize.h" |
|
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
82 #include <fcntl.h> |
| 486 | 83 #endif |
| 84 | |
| 85 static void fatal_unexec (); | |
|
1122
42922d56e5a6
* unexmips.c (mark_x): Declare this as static void at the top of
Jim Blandy <jimb@redhat.com>
parents:
1094
diff
changeset
|
86 static void mark_x (); |
| 486 | 87 |
| 88 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \ | |
| 89 errno = EEOF; \ | |
| 90 if (read (_fd, _buffer, _size) != _size) \ | |
| 91 fatal_unexec (_error_message, _error_arg); | |
| 92 | |
| 93 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \ | |
| 94 if (write (_fd, _buffer, _size) != _size) \ | |
| 95 fatal_unexec (_error_message, _error_arg); | |
| 96 | |
| 97 #define SEEK(_fd, _position, _error_message, _error_arg) \ | |
| 98 errno = EEOF; \ | |
| 99 if (lseek (_fd, _position, L_SET) != _position) \ | |
| 100 fatal_unexec (_error_message, _error_arg); | |
| 101 | |
| 102 extern int errno; | |
|
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
103 extern char *strerror (); |
| 486 | 104 #define EEOF -1 |
| 105 | |
| 106 static struct scnhdr *text_section; | |
| 107 static struct scnhdr *init_section; | |
| 108 static struct scnhdr *finit_section; | |
| 109 static struct scnhdr *rdata_section; | |
| 110 static struct scnhdr *data_section; | |
| 111 static struct scnhdr *lit8_section; | |
| 112 static struct scnhdr *lit4_section; | |
| 113 static struct scnhdr *sdata_section; | |
| 114 static struct scnhdr *sbss_section; | |
| 115 static struct scnhdr *bss_section; | |
| 116 | |
| 117 struct headers { | |
| 118 struct filehdr fhdr; | |
| 119 struct aouthdr aout; | |
| 120 struct scnhdr section[10]; | |
| 121 }; | |
| 122 | |
| 123 /* Define name of label for entry point for the dumped executable. */ | |
| 124 | |
| 125 #ifndef DEFAULT_ENTRY_ADDRESS | |
| 126 #define DEFAULT_ENTRY_ADDRESS __start | |
| 127 #endif | |
| 128 | |
| 129 unexec (new_name, a_name, data_start, bss_start, entry_address) | |
| 130 char *new_name, *a_name; | |
| 131 unsigned data_start, bss_start, entry_address; | |
| 132 { | |
| 133 int new, old; | |
| 134 int pagesize, brk; | |
| 135 int newsyms, symrel; | |
| 136 int nread; | |
| 137 struct headers hdr; | |
| 138 int i; | |
| 139 int vaddr, scnptr; | |
| 140 #define BUFSIZE 8192 | |
| 141 char buffer[BUFSIZE]; | |
| 142 | |
| 143 old = open (a_name, O_RDONLY, 0); | |
| 144 if (old < 0) fatal_unexec ("opening %s", a_name); | |
| 145 | |
| 146 new = creat (new_name, 0666); | |
| 147 if (new < 0) fatal_unexec ("creating %s", new_name); | |
| 148 | |
| 149 hdr = *((struct headers *)TEXT_START); | |
| 150 #ifdef MIPS2 | |
| 151 if (hdr.fhdr.f_magic != MIPSELMAGIC | |
| 152 && hdr.fhdr.f_magic != MIPSEBMAGIC | |
| 153 && hdr.fhdr.f_magic != (MIPSELMAGIC | 1) | |
| 154 && hdr.fhdr.f_magic != (MIPSEBMAGIC | 1)) | |
| 155 { | |
|
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
156 fprintf (stderr, |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
157 "unexec: input file magic number is %x, not %x, %x, %x or %x.\n", |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
158 hdr.fhdr.f_magic, |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
159 MIPSELMAGIC, MIPSEBMAGIC, |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
160 MIPSELMAGIC | 1, MIPSEBMAGIC | 1); |
| 486 | 161 exit(1); |
| 162 } | |
| 163 #else /* not MIPS2 */ | |
| 164 if (hdr.fhdr.f_magic != MIPSELMAGIC | |
| 165 && hdr.fhdr.f_magic != MIPSEBMAGIC) | |
| 166 { | |
| 167 fprintf (stderr, "unexec: input file magic number is %x, not %x or %x.\n", | |
| 168 hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC); | |
| 169 exit (1); | |
| 170 } | |
| 171 #endif /* not MIPS2 */ | |
| 172 if (hdr.fhdr.f_opthdr != sizeof (hdr.aout)) | |
| 173 { | |
| 174 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n", | |
| 175 hdr.fhdr.f_opthdr, sizeof (hdr.aout)); | |
| 176 exit (1); | |
| 177 } | |
| 178 if (hdr.aout.magic != ZMAGIC) | |
| 179 { | |
| 180 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n", | |
| 181 hdr.aout.magic, ZMAGIC); | |
| 182 exit (1); | |
| 183 } | |
| 184 | |
| 185 #define CHECK_SCNHDR(ptr, name, flags) \ | |
|
1094
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
186 ptr = NULL; \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
187 for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++) \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
188 if (strcmp (hdr.section[i].s_name, name) == 0) \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
189 { \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
190 if (hdr.section[i].s_flags != flags) \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
191 fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
192 hdr.section[i].s_flags, flags, name); \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
193 ptr = hdr.section + i; \ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
194 } \ |
| 486 | 195 |
| 196 CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT); | |
| 197 CHECK_SCNHDR (init_section, _INIT, STYP_INIT); | |
| 198 CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA); | |
| 199 CHECK_SCNHDR (data_section, _DATA, STYP_DATA); | |
| 200 #ifdef _LIT8 | |
| 201 CHECK_SCNHDR (lit8_section, _LIT8, STYP_LIT8); | |
| 202 CHECK_SCNHDR (lit4_section, _LIT4, STYP_LIT4); | |
| 203 #endif /* _LIT8 */ | |
| 204 CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA); | |
| 205 CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS); | |
| 206 CHECK_SCNHDR (bss_section, _BSS, STYP_BSS); | |
|
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
207 #if 0 /* Apparently this error check goes off on irix 3.3, |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
208 but it doesn't indicate a real problem. */ |
| 486 | 209 if (i != hdr.fhdr.f_nscns) |
| 210 fprintf (stderr, "unexec: %d sections found instead of %d.\n", | |
| 211 i, hdr.fhdr.f_nscns); | |
|
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
212 #endif |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
213 |
|
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
214 text_section->s_scnptr = 0; |
| 486 | 215 |
| 216 pagesize = getpagesize (); | |
|
5969
999daf5b65b6
(unexec): Add cast to result of `sbrk'.
Richard M. Stallman <rms@gnu.org>
parents:
5521
diff
changeset
|
217 /* Casting to int avoids compiler error on NEWS-OS 5.0.2. */ |
|
999daf5b65b6
(unexec): Add cast to result of `sbrk'.
Richard M. Stallman <rms@gnu.org>
parents:
5521
diff
changeset
|
218 brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize); |
| 486 | 219 hdr.aout.dsize = brk - DATA_START; |
| 220 hdr.aout.bsize = 0; | |
| 221 if (entry_address == 0) | |
| 222 { | |
| 223 extern DEFAULT_ENTRY_ADDRESS (); | |
| 224 hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS; | |
| 225 } | |
| 226 else | |
| 227 hdr.aout.entry = entry_address; | |
| 228 | |
| 229 hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize; | |
| 230 rdata_section->s_size = data_start - DATA_START; | |
|
1094
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
231 |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
232 /* Adjust start and virtual addresses of rdata_section, too. */ |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
233 rdata_section->s_vaddr = DATA_START; |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
234 rdata_section->s_paddr = DATA_START; |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
235 rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize; |
|
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
236 |
| 486 | 237 data_section->s_vaddr = data_start; |
| 238 data_section->s_paddr = data_start; | |
| 568 | 239 data_section->s_size = brk - data_start; |
| 486 | 240 data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size; |
| 241 vaddr = data_section->s_vaddr + data_section->s_size; | |
| 242 scnptr = data_section->s_scnptr + data_section->s_size; | |
| 243 if (lit8_section != NULL) | |
| 244 { | |
| 245 lit8_section->s_vaddr = vaddr; | |
| 246 lit8_section->s_paddr = vaddr; | |
| 247 lit8_section->s_size = 0; | |
| 248 lit8_section->s_scnptr = scnptr; | |
| 249 } | |
| 250 if (lit4_section != NULL) | |
| 251 { | |
| 252 lit4_section->s_vaddr = vaddr; | |
| 253 lit4_section->s_paddr = vaddr; | |
| 254 lit4_section->s_size = 0; | |
| 255 lit4_section->s_scnptr = scnptr; | |
| 256 } | |
| 257 if (sdata_section != NULL) | |
| 258 { | |
| 259 sdata_section->s_vaddr = vaddr; | |
| 260 sdata_section->s_paddr = vaddr; | |
| 261 sdata_section->s_size = 0; | |
| 262 sdata_section->s_scnptr = scnptr; | |
| 263 } | |
| 264 if (sbss_section != NULL) | |
| 265 { | |
| 266 sbss_section->s_vaddr = vaddr; | |
| 267 sbss_section->s_paddr = vaddr; | |
| 268 sbss_section->s_size = 0; | |
| 269 sbss_section->s_scnptr = scnptr; | |
| 270 } | |
| 271 if (bss_section != NULL) | |
| 272 { | |
| 273 bss_section->s_vaddr = vaddr; | |
| 274 bss_section->s_paddr = vaddr; | |
| 275 bss_section->s_size = 0; | |
| 276 bss_section->s_scnptr = scnptr; | |
| 277 } | |
| 278 | |
|
7151
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
279 WRITE (new, (char *)TEXT_START, hdr.aout.tsize, |
| 486 | 280 "writing text section to %s", new_name); |
|
7151
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
281 WRITE (new, (char *)DATA_START, hdr.aout.dsize, |
|
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
282 "writing data section to %s", new_name); |
| 486 | 283 |
| 284 SEEK (old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name); | |
| 285 errno = EEOF; | |
| 286 nread = read (old, buffer, BUFSIZE); | |
| 287 if (nread < sizeof (HDRR)) fatal_unexec ("reading symbols from %s", a_name); | |
| 288 newsyms = hdr.aout.tsize + hdr.aout.dsize; | |
| 289 symrel = newsyms - hdr.fhdr.f_symptr; | |
| 290 hdr.fhdr.f_symptr = newsyms; | |
|
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
291 #define symhdr ((pHDRR)buffer) |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
292 #ifdef MACH |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
293 for (i = 0; i < 11; i++) |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
294 symhdr->offsets[i].offset += symrel; |
|
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
295 #else |
| 486 | 296 symhdr->cbLineOffset += symrel; |
| 297 symhdr->cbDnOffset += symrel; | |
| 298 symhdr->cbPdOffset += symrel; | |
| 299 symhdr->cbSymOffset += symrel; | |
| 300 symhdr->cbOptOffset += symrel; | |
| 301 symhdr->cbAuxOffset += symrel; | |
| 302 symhdr->cbSsOffset += symrel; | |
| 303 symhdr->cbSsExtOffset += symrel; | |
| 304 symhdr->cbFdOffset += symrel; | |
| 305 symhdr->cbRfdOffset += symrel; | |
| 306 symhdr->cbExtOffset += symrel; | |
|
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
307 #endif |
| 486 | 308 #undef symhdr |
| 309 do | |
| 310 { | |
| 311 if (write (new, buffer, nread) != nread) | |
| 312 fatal_unexec ("writing symbols to %s", new_name); | |
| 313 nread = read (old, buffer, BUFSIZE); | |
| 314 if (nread < 0) fatal_unexec ("reading symbols from %s", a_name); | |
| 315 #undef BUFSIZE | |
| 316 } while (nread != 0); | |
| 317 | |
| 318 SEEK (new, 0, "seeking to start of header in %s", new_name); | |
| 319 WRITE (new, &hdr, sizeof (hdr), | |
| 320 "writing header of %s", new_name); | |
| 321 | |
| 322 close (old); | |
| 323 close (new); | |
| 324 mark_x (new_name); | |
| 325 } | |
| 326 | |
| 327 /* | |
| 328 * mark_x | |
| 329 * | |
|
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
1486
diff
changeset
|
330 * After successfully building the new a.out, mark it executable |
| 486 | 331 */ |
| 332 | |
|
1122
42922d56e5a6
* unexmips.c (mark_x): Declare this as static void at the top of
Jim Blandy <jimb@redhat.com>
parents:
1094
diff
changeset
|
333 static void |
| 486 | 334 mark_x (name) |
| 335 char *name; | |
| 336 { | |
| 337 struct stat sbuf; | |
| 338 int um = umask (777); | |
| 339 umask (um); | |
| 340 if (stat (name, &sbuf) < 0) | |
| 341 fatal_unexec ("getting protection on %s", name); | |
| 342 sbuf.st_mode |= 0111 & ~um; | |
| 343 if (chmod (name, sbuf.st_mode) < 0) | |
| 344 fatal_unexec ("setting protection on %s", name); | |
| 345 } | |
| 346 | |
| 347 static void | |
| 348 fatal_unexec (s, va_alist) | |
|
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
349 va_dcl |
| 486 | 350 { |
| 351 va_list ap; | |
| 352 if (errno == EEOF) | |
| 353 fputs ("unexec: unexpected end of file, ", stderr); | |
| 354 else | |
|
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
355 fprintf (stderr, "unexec: %s, ", strerror (errno)); |
| 486 | 356 va_start (ap); |
| 357 _doprnt (s, ap, stderr); | |
| 358 fputs (".\n", stderr); | |
| 359 exit (1); | |
| 360 } |
