Mercurial > emacs
annotate src/unexmips.c @ 41498:d5de86d3c2c3
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 25 Nov 2001 17:45:36 +0000 |
parents | ee40177f6c68 |
children | 695cf19ef79e d7ddb3e565de |
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 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12420
diff
changeset
|
25 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12420
diff
changeset
|
26 Boston, MA 02111-1307, USA. */ |
486 | 27 |
28 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
29 #include <config.h> |
486 | 30 #include <sys/types.h> |
31 #include <sys/file.h> | |
32 #include <sys/stat.h> | |
33 #include <stdio.h> | |
34 #include <varargs.h> | |
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
35 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
36 #ifdef MACH |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
37 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
38 #include <a.out.h> |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
39 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
40 /* 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
|
41 #ifndef STYP_INIT |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
42 #define STYP_INIT 0x80000000 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
43 #endif |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
44 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
45 /* 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
|
46 #ifndef _RDATA |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
47 #define _RDATA ".rdata" |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
48 #define STYP_RDATA 0x00000100 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
49 #endif |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
50 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
51 /* Small ("near") data section. */ |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
52 #ifndef _SDATA |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
53 #define _SDATA ".sdata" |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
54 #define STYP_SDATA 0x00000200 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
55 #endif |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
56 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
57 /* Small ("near") bss section. */ |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
58 #ifndef _SBSS |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
59 #define _SBSS ".sbss" |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
60 #define STYP_SBSS 0x00000400 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
61 #endif |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
62 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
63 /* 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
|
64 hard way. This stinks. */ |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
65 typedef struct { |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
66 short magic; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
67 short vstamp; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
68 long ilineMax; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
69 struct { long foo, offset; } offsets[11]; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
70 } HDRR, *pHDRR; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
71 |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
72 #else /* not MACH */ |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
73 |
486 | 74 #include <filehdr.h> |
75 #include <aouthdr.h> | |
76 #include <scnhdr.h> | |
77 #include <sym.h> | |
78 | |
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
79 #endif /* not MACH */ |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
80 |
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
81 #if defined (IRIS_4D) || defined (sony) |
486 | 82 #include "getpagesize.h" |
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
83 #include <fcntl.h> |
486 | 84 #endif |
85 | |
86 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
|
87 static void mark_x (); |
486 | 88 |
89 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \ | |
90 errno = EEOF; \ | |
91 if (read (_fd, _buffer, _size) != _size) \ | |
92 fatal_unexec (_error_message, _error_arg); | |
93 | |
94 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \ | |
95 if (write (_fd, _buffer, _size) != _size) \ | |
96 fatal_unexec (_error_message, _error_arg); | |
97 | |
98 #define SEEK(_fd, _position, _error_message, _error_arg) \ | |
99 errno = EEOF; \ | |
100 if (lseek (_fd, _position, L_SET) != _position) \ | |
101 fatal_unexec (_error_message, _error_arg); | |
102 | |
103 extern int errno; | |
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
104 extern char *strerror (); |
486 | 105 #define EEOF -1 |
106 | |
107 static struct scnhdr *text_section; | |
108 static struct scnhdr *init_section; | |
109 static struct scnhdr *finit_section; | |
110 static struct scnhdr *rdata_section; | |
111 static struct scnhdr *data_section; | |
112 static struct scnhdr *lit8_section; | |
113 static struct scnhdr *lit4_section; | |
114 static struct scnhdr *sdata_section; | |
115 static struct scnhdr *sbss_section; | |
116 static struct scnhdr *bss_section; | |
117 | |
118 struct headers { | |
119 struct filehdr fhdr; | |
120 struct aouthdr aout; | |
121 struct scnhdr section[10]; | |
122 }; | |
123 | |
124 /* Define name of label for entry point for the dumped executable. */ | |
125 | |
126 #ifndef DEFAULT_ENTRY_ADDRESS | |
127 #define DEFAULT_ENTRY_ADDRESS __start | |
128 #endif | |
129 | |
130 unexec (new_name, a_name, data_start, bss_start, entry_address) | |
131 char *new_name, *a_name; | |
132 unsigned data_start, bss_start, entry_address; | |
133 { | |
134 int new, old; | |
135 int pagesize, brk; | |
136 int newsyms, symrel; | |
137 int nread; | |
138 struct headers hdr; | |
139 int i; | |
140 int vaddr, scnptr; | |
141 #define BUFSIZE 8192 | |
142 char buffer[BUFSIZE]; | |
143 | |
144 old = open (a_name, O_RDONLY, 0); | |
145 if (old < 0) fatal_unexec ("opening %s", a_name); | |
146 | |
147 new = creat (new_name, 0666); | |
148 if (new < 0) fatal_unexec ("creating %s", new_name); | |
149 | |
150 hdr = *((struct headers *)TEXT_START); | |
151 #ifdef MIPS2 | |
152 if (hdr.fhdr.f_magic != MIPSELMAGIC | |
153 && hdr.fhdr.f_magic != MIPSEBMAGIC | |
154 && hdr.fhdr.f_magic != (MIPSELMAGIC | 1) | |
155 && hdr.fhdr.f_magic != (MIPSEBMAGIC | 1)) | |
156 { | |
1486
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
157 fprintf (stderr, |
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
158 "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
|
159 hdr.fhdr.f_magic, |
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
160 MIPSELMAGIC, MIPSEBMAGIC, |
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
161 MIPSELMAGIC | 1, MIPSEBMAGIC | 1); |
486 | 162 exit(1); |
163 } | |
164 #else /* not MIPS2 */ | |
165 if (hdr.fhdr.f_magic != MIPSELMAGIC | |
166 && hdr.fhdr.f_magic != MIPSEBMAGIC) | |
167 { | |
168 fprintf (stderr, "unexec: input file magic number is %x, not %x or %x.\n", | |
169 hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC); | |
170 exit (1); | |
171 } | |
172 #endif /* not MIPS2 */ | |
173 if (hdr.fhdr.f_opthdr != sizeof (hdr.aout)) | |
174 { | |
175 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n", | |
176 hdr.fhdr.f_opthdr, sizeof (hdr.aout)); | |
177 exit (1); | |
178 } | |
179 if (hdr.aout.magic != ZMAGIC) | |
180 { | |
181 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n", | |
182 hdr.aout.magic, ZMAGIC); | |
183 exit (1); | |
184 } | |
185 | |
186 #define CHECK_SCNHDR(ptr, name, flags) \ | |
1094
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
187 ptr = NULL; \ |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
188 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
|
189 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
|
190 { \ |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
191 if (hdr.section[i].s_flags != flags) \ |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
192 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
|
193 hdr.section[i].s_flags, flags, name); \ |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
194 ptr = hdr.section + i; \ |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
195 } \ |
486 | 196 |
197 CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT); | |
198 CHECK_SCNHDR (init_section, _INIT, STYP_INIT); | |
199 CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA); | |
200 CHECK_SCNHDR (data_section, _DATA, STYP_DATA); | |
201 #ifdef _LIT8 | |
202 CHECK_SCNHDR (lit8_section, _LIT8, STYP_LIT8); | |
203 CHECK_SCNHDR (lit4_section, _LIT4, STYP_LIT4); | |
204 #endif /* _LIT8 */ | |
205 CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA); | |
206 CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS); | |
207 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
|
208 #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
|
209 but it doesn't indicate a real problem. */ |
486 | 210 if (i != hdr.fhdr.f_nscns) |
211 fprintf (stderr, "unexec: %d sections found instead of %d.\n", | |
212 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
|
213 #endif |
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
214 |
1a12c5f1c04d
[sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
1122
diff
changeset
|
215 text_section->s_scnptr = 0; |
486 | 216 |
217 pagesize = getpagesize (); | |
5969
999daf5b65b6
(unexec): Add cast to result of `sbrk'.
Richard M. Stallman <rms@gnu.org>
parents:
5521
diff
changeset
|
218 /* 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
|
219 brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize); |
486 | 220 hdr.aout.dsize = brk - DATA_START; |
221 hdr.aout.bsize = 0; | |
222 if (entry_address == 0) | |
223 { | |
224 extern DEFAULT_ENTRY_ADDRESS (); | |
225 hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS; | |
226 } | |
227 else | |
228 hdr.aout.entry = entry_address; | |
229 | |
230 hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize; | |
231 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
|
232 |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
233 /* 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
|
234 rdata_section->s_vaddr = DATA_START; |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
235 rdata_section->s_paddr = DATA_START; |
861c2997afee
(unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents:
568
diff
changeset
|
236 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
|
237 |
486 | 238 data_section->s_vaddr = data_start; |
239 data_section->s_paddr = data_start; | |
568 | 240 data_section->s_size = brk - data_start; |
486 | 241 data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size; |
242 vaddr = data_section->s_vaddr + data_section->s_size; | |
243 scnptr = data_section->s_scnptr + data_section->s_size; | |
244 if (lit8_section != NULL) | |
245 { | |
246 lit8_section->s_vaddr = vaddr; | |
247 lit8_section->s_paddr = vaddr; | |
248 lit8_section->s_size = 0; | |
249 lit8_section->s_scnptr = scnptr; | |
250 } | |
251 if (lit4_section != NULL) | |
252 { | |
253 lit4_section->s_vaddr = vaddr; | |
254 lit4_section->s_paddr = vaddr; | |
255 lit4_section->s_size = 0; | |
256 lit4_section->s_scnptr = scnptr; | |
257 } | |
258 if (sdata_section != NULL) | |
259 { | |
260 sdata_section->s_vaddr = vaddr; | |
261 sdata_section->s_paddr = vaddr; | |
262 sdata_section->s_size = 0; | |
263 sdata_section->s_scnptr = scnptr; | |
264 } | |
265 if (sbss_section != NULL) | |
266 { | |
267 sbss_section->s_vaddr = vaddr; | |
268 sbss_section->s_paddr = vaddr; | |
269 sbss_section->s_size = 0; | |
270 sbss_section->s_scnptr = scnptr; | |
271 } | |
272 if (bss_section != NULL) | |
273 { | |
274 bss_section->s_vaddr = vaddr; | |
275 bss_section->s_paddr = vaddr; | |
276 bss_section->s_size = 0; | |
277 bss_section->s_scnptr = scnptr; | |
278 } | |
279 | |
7151
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
280 WRITE (new, (char *)TEXT_START, hdr.aout.tsize, |
486 | 281 "writing text section to %s", new_name); |
7151
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
282 WRITE (new, (char *)DATA_START, hdr.aout.dsize, |
1edd14fa94ae
(unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents:
5969
diff
changeset
|
283 "writing data section to %s", new_name); |
486 | 284 |
285 SEEK (old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name); | |
286 errno = EEOF; | |
287 nread = read (old, buffer, BUFSIZE); | |
288 if (nread < sizeof (HDRR)) fatal_unexec ("reading symbols from %s", a_name); | |
289 newsyms = hdr.aout.tsize + hdr.aout.dsize; | |
290 symrel = newsyms - hdr.fhdr.f_symptr; | |
291 hdr.fhdr.f_symptr = newsyms; | |
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
292 #define symhdr ((pHDRR)buffer) |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
293 #ifdef MACH |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
294 for (i = 0; i < 11; i++) |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
295 symhdr->offsets[i].offset += symrel; |
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
296 #else |
486 | 297 symhdr->cbLineOffset += symrel; |
298 symhdr->cbDnOffset += symrel; | |
299 symhdr->cbPdOffset += symrel; | |
300 symhdr->cbSymOffset += symrel; | |
301 symhdr->cbOptOffset += symrel; | |
302 symhdr->cbAuxOffset += symrel; | |
303 symhdr->cbSsOffset += symrel; | |
304 symhdr->cbSsExtOffset += symrel; | |
305 symhdr->cbFdOffset += symrel; | |
306 symhdr->cbRfdOffset += symrel; | |
307 symhdr->cbExtOffset += symrel; | |
12420
0c728a1b2bed
[MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents:
7151
diff
changeset
|
308 #endif |
486 | 309 #undef symhdr |
310 do | |
311 { | |
312 if (write (new, buffer, nread) != nread) | |
313 fatal_unexec ("writing symbols to %s", new_name); | |
314 nread = read (old, buffer, BUFSIZE); | |
315 if (nread < 0) fatal_unexec ("reading symbols from %s", a_name); | |
316 #undef BUFSIZE | |
317 } while (nread != 0); | |
318 | |
319 SEEK (new, 0, "seeking to start of header in %s", new_name); | |
320 WRITE (new, &hdr, sizeof (hdr), | |
321 "writing header of %s", new_name); | |
322 | |
323 close (old); | |
324 close (new); | |
325 mark_x (new_name); | |
326 } | |
327 | |
328 /* | |
329 * mark_x | |
330 * | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
1486
diff
changeset
|
331 * After successfully building the new a.out, mark it executable |
486 | 332 */ |
333 | |
1122
42922d56e5a6
* unexmips.c (mark_x): Declare this as static void at the top of
Jim Blandy <jimb@redhat.com>
parents:
1094
diff
changeset
|
334 static void |
486 | 335 mark_x (name) |
336 char *name; | |
337 { | |
338 struct stat sbuf; | |
339 int um = umask (777); | |
340 umask (um); | |
341 if (stat (name, &sbuf) < 0) | |
342 fatal_unexec ("getting protection on %s", name); | |
343 sbuf.st_mode |= 0111 & ~um; | |
344 if (chmod (name, sbuf.st_mode) < 0) | |
345 fatal_unexec ("setting protection on %s", name); | |
346 } | |
347 | |
348 static void | |
349 fatal_unexec (s, va_alist) | |
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
350 va_dcl |
486 | 351 { |
352 va_list ap; | |
353 if (errno == EEOF) | |
354 fputs ("unexec: unexpected end of file, ", stderr); | |
355 else | |
5521
d1d144ed5b76
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
4696
diff
changeset
|
356 fprintf (stderr, "unexec: %s, ", strerror (errno)); |
486 | 357 va_start (ap); |
358 _doprnt (s, ap, stderr); | |
359 fputs (".\n", stderr); | |
360 exit (1); | |
361 } |