Mercurial > emacs
annotate src/unexcoff.c @ 109766:af33651be88b
add lisp/gnus/gnus-sync.el
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Fri, 13 Aug 2010 10:50:01 +0000 |
parents | 03608262c6d4 |
children | 77eca36a3f0b 7d18e1db65fe 8186d147fb99 |
rev | line source |
---|---|
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68651
diff
changeset
|
1 /* Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 2001, 2002, 2003, |
106815 | 2 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
172 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91702
diff
changeset
|
6 GNU Emacs is free software: you can redistribute it and/or modify |
172 | 7 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91702
diff
changeset
|
8 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91702
diff
changeset
|
9 (at your option) any later version. |
172 | 10 |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91702
diff
changeset
|
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
172 | 18 |
19 | |
20 /* | |
109628
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
21 * unexcoff.c - Convert a running program into an a.out or COFF file. |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
22 * |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
23 * ================================================================== |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
24 * Note: This file is currently used only by the MSDOS (a.k.a. DJGPP) |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
25 * build of Emacs. If you are not interested in the MSDOS build, you |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
26 * are looking at the wrong version of unexec! |
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
27 * ================================================================== |
172 | 28 * |
29 * Author: Spencer W. Thomas | |
30 * Computer Science Dept. | |
31 * University of Utah | |
32 * Date: Tue Mar 2 1982 | |
109628
8e2c7c31861b
Rename src/unexec.c => src/unexcoff.c.
Eli Zaretskii <eliz@gnu.org>
parents:
109570
diff
changeset
|
33 * Originally under the name unexec.c. |
172 | 34 * Modified heavily since then. |
35 * | |
36 * Synopsis: | |
37 * unexec (new_name, a_name, data_start, bss_start, entry_address) | |
38 * char *new_name, *a_name; | |
39 * unsigned data_start, bss_start, entry_address; | |
40 * | |
41 * Takes a snapshot of the program and makes an a.out format file in the | |
42 * file named by the string argument new_name. | |
43 * If a_name is non-NULL, the symbol table will be taken from the given file. | |
44 * On some machines, an existing a_name file is required. | |
45 * | |
46 * The boundaries within the a.out file may be adjusted with the data_start | |
47 * and bss_start arguments. Either or both may be given as 0 for defaults. | |
48 * | |
49 * Data_start gives the boundary between the text segment and the data | |
50 * segment of the program. The text segment can contain shared, read-only | |
51 * program code and literal data, while the data segment is always unshared | |
52 * and unprotected. Data_start gives the lowest unprotected address. | |
53 * The value you specify may be rounded down to a suitable boundary | |
54 * as required by the machine you are using. | |
55 * | |
56 * Specifying zero for data_start means the boundary between text and data | |
57 * should not be the same as when the program was loaded. | |
58 * | |
59 * Bss_start indicates how much of the data segment is to be saved in the | |
60 * a.out file and restored when the program is executed. It gives the lowest | |
61 * unsaved address, and is rounded up to a page boundary. The default when 0 | |
62 * is given assumes that the entire data segment is to be stored, including | |
63 * the previous data and bss as well as any additional storage allocated with | |
64 * break (2). | |
65 * | |
66 * The new file is set up to start at entry_address. | |
67 * | |
68 * If you make improvements I'd like to get them too. | |
69 * harpo!utah-cs!thomas, thomas@Utah-20 | |
70 * | |
71 */ | |
72 | |
73 /* Modified to support SysVr3 shared libraries by James Van Artsdalen | |
74 * of Dell Computer Corporation. james@bigtex.cactus.org. | |
75 */ | |
76 | |
77 #ifndef emacs | |
78 #define PERROR(arg) perror (arg); return -1 | |
79 #else | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4319
diff
changeset
|
80 #include <config.h> |
172 | 81 #define PERROR(file) report_error (file, new) |
82 #endif | |
83 | |
84 #ifndef CANNOT_DUMP /* all rest of file! */ | |
85 | |
96926
baf6162e41d4
Remove code depending on !COFF and USG, the file is
Dan Nicolaescu <dann@ics.uci.edu>
parents:
96732
diff
changeset
|
86 #ifdef HAVE_COFF_H |
29650
2411aacca614
(toplevel) [COFF]: Include coff.h.
Gerd Moellmann <gerd@gnu.org>
parents:
22647
diff
changeset
|
87 #include <coff.h> |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
88 #ifdef MSDOS |
14975
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
89 #include <fcntl.h> /* for O_RDONLY, O_RDWR */ |
15732
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
90 #include <crt0.h> /* for _crt0_startup_flags and its bits */ |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
91 static int save_djgpp_startup_flags; |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
92 #define filehdr external_filehdr |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
93 #define scnhdr external_scnhdr |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
94 #define syment external_syment |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
95 #define auxent external_auxent |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
96 #define n_numaux e_numaux |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
97 #define n_type e_type |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
98 struct aouthdr |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
99 { |
7626
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
100 unsigned short magic; /* type of file */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
101 unsigned short vstamp; /* version stamp */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
102 unsigned long tsize; /* text size in bytes, padded to FW bdry*/ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
103 unsigned long dsize; /* initialized data " " */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
104 unsigned long bsize; /* uninitialized data " " */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
105 unsigned long entry; /* entry pt. */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
106 unsigned long text_start;/* base of text used for this file */ |
7ae305576201
[MSDOS]: Don't include files from the dos extender
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
107 unsigned long data_start;/* base of data used for this file */ |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
108 }; |
29668
1e6eeead2f1d
(toplevel): Fix last change, so as not to deprive MSDOS
Eli Zaretskii <eliz@gnu.org>
parents:
29650
diff
changeset
|
109 #endif /* not MSDOS */ |
96926
baf6162e41d4
Remove code depending on !COFF and USG, the file is
Dan Nicolaescu <dann@ics.uci.edu>
parents:
96732
diff
changeset
|
110 #else /* not HAVE_COFF_H */ |
172 | 111 #include <a.out.h> |
96926
baf6162e41d4
Remove code depending on !COFF and USG, the file is
Dan Nicolaescu <dann@ics.uci.edu>
parents:
96732
diff
changeset
|
112 #endif /* not HAVE_COFF_H */ |
485 | 113 |
9699 | 114 /* Define getpagesize if the system does not. |
115 Note that this may depend on symbols defined in a.out.h. */ | |
172 | 116 #include "getpagesize.h" |
117 | |
118 #ifndef makedev /* Try to detect types.h already loaded */ | |
119 #include <sys/types.h> | |
485 | 120 #endif /* makedev */ |
172 | 121 #include <stdio.h> |
122 #include <sys/stat.h> | |
123 #include <errno.h> | |
124 | |
96926
baf6162e41d4
Remove code depending on !COFF and USG, the file is
Dan Nicolaescu <dann@ics.uci.edu>
parents:
96732
diff
changeset
|
125 #include <sys/file.h> |
7921
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
126 |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
127 #ifndef O_RDONLY |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
128 #define O_RDONLY 0 |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
129 #endif |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
130 #ifndef O_RDWR |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
131 #define O_RDWR 2 |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
132 #endif |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
133 |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
134 |
172 | 135 extern char *start_of_text (); /* Start of text */ |
136 extern char *start_of_data (); /* Start of initialized data */ | |
137 | |
138 static long block_copy_start; /* Old executable start point */ | |
139 static struct filehdr f_hdr; /* File header */ | |
140 static struct aouthdr f_ohdr; /* Optional file header (a.out) */ | |
141 long bias; /* Bias to add for growth */ | |
142 long lnnoptr; /* Pointer to line-number info within file */ | |
143 #define SYMS_START block_copy_start | |
144 | |
145 static long text_scnptr; | |
146 static long data_scnptr; | |
147 | |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
148 static long coff_offset; |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
149 |
172 | 150 static int pagemask; |
151 | |
152 /* Correct an int which is the bit pattern of a pointer to a byte | |
153 into an int which is the number of a byte. | |
154 This is a no-op on ordinary machines, but not on all. */ | |
155 | |
156 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0) | |
157 | |
158 #ifdef emacs | |
159 | |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105426
diff
changeset
|
160 #include <setjmp.h> |
7921
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
161 #include "lisp.h" |
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
162 |
172 | 163 static |
164 report_error (file, fd) | |
165 char *file; | |
166 int fd; | |
167 { | |
168 if (fd) | |
169 close (fd); | |
7921
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
170 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil)); |
172 | 171 } |
172 #endif /* emacs */ | |
173 | |
174 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 | |
175 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 | |
176 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 | |
177 | |
178 static | |
179 report_error_1 (fd, msg, a1, a2) | |
180 int fd; | |
181 char *msg; | |
182 int a1, a2; | |
183 { | |
184 close (fd); | |
185 #ifdef emacs | |
186 error (msg, a1, a2); | |
187 #else | |
188 fprintf (stderr, msg, a1, a2); | |
189 fprintf (stderr, "\n"); | |
190 #endif | |
191 } | |
192 | |
193 static int make_hdr (); | |
194 static int copy_text_and_data (); | |
195 static int copy_sym (); | |
196 static void mark_x (); | |
197 | |
198 /* **************************************************************** | |
199 * make_hdr | |
200 * | |
201 * Make the header in the new a.out from the header in core. | |
202 * Modify the text and data sizes. | |
203 */ | |
204 static int | |
205 make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | |
206 int new, a_out; | |
207 unsigned data_start, bss_start, entry_address; | |
208 char *a_name; | |
209 char *new_name; | |
210 { | |
211 int tem; | |
212 auto struct scnhdr f_thdr; /* Text section header */ | |
213 auto struct scnhdr f_dhdr; /* Data section header */ | |
214 auto struct scnhdr f_bhdr; /* Bss section header */ | |
215 auto struct scnhdr scntemp; /* Temporary section header */ | |
216 register int scns; | |
217 unsigned int bss_end; | |
218 | |
219 pagemask = getpagesize () - 1; | |
220 | |
221 /* Adjust text/data boundary. */ | |
222 data_start = (int) start_of_data (); | |
223 data_start = ADDR_CORRECT (data_start); | |
224 data_start = data_start & ~pagemask; /* (Down) to page boundary. */ | |
225 | |
226 bss_end = ADDR_CORRECT (sbrk (0)) + pagemask; | |
227 bss_end &= ~ pagemask; | |
228 | |
229 /* Adjust data/bss boundary. */ | |
230 if (bss_start != 0) | |
231 { | |
232 bss_start = (ADDR_CORRECT (bss_start) + pagemask); | |
233 /* (Up) to page bdry. */ | |
234 bss_start &= ~ pagemask; | |
235 if (bss_start > bss_end) | |
236 { | |
237 ERROR1 ("unexec: Specified bss_start (%u) is past end of program", | |
238 bss_start); | |
239 } | |
240 } | |
241 else | |
242 bss_start = bss_end; | |
243 | |
244 if (data_start > bss_start) /* Can't have negative data size. */ | |
245 { | |
246 ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)", | |
247 data_start, bss_start); | |
248 } | |
249 | |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
250 coff_offset = 0L; /* stays zero, except in DJGPP */ |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
251 |
172 | 252 /* Salvage as much info from the existing file as possible */ |
253 if (a_out >= 0) | |
254 { | |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
255 #ifdef MSDOS |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
256 /* Support the coff-go32-exe format with a prepended stub, since |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
257 this is what GCC 2.8.0 and later generates by default in DJGPP. */ |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
258 unsigned short mz_header[3]; |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
259 |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
260 if (read (a_out, &mz_header, sizeof (mz_header)) != sizeof (mz_header)) |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
261 { |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
262 PERROR (a_name); |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
263 } |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
264 if (mz_header[0] == 0x5a4d || mz_header[0] == 0x4d5a) /* "MZ" or "ZM" */ |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
265 { |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
266 coff_offset = (long)mz_header[2] * 512L; |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
267 if (mz_header[1]) |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
268 coff_offset += (long)mz_header[1] - 512L; |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
269 lseek (a_out, coff_offset, 0); |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
270 } |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
271 else |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
272 lseek (a_out, 0L, 0); |
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
273 #endif /* MSDOS */ |
172 | 274 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) |
275 { | |
276 PERROR (a_name); | |
277 } | |
278 block_copy_start += sizeof (f_hdr); | |
279 if (f_hdr.f_opthdr > 0) | |
280 { | |
281 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) | |
282 { | |
283 PERROR (a_name); | |
284 } | |
285 block_copy_start += sizeof (f_ohdr); | |
286 } | |
287 /* Loop through section headers, copying them in */ | |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
288 lseek (a_out, coff_offset + sizeof (f_hdr) + f_hdr.f_opthdr, 0); |
172 | 289 for (scns = f_hdr.f_nscns; scns > 0; scns--) { |
290 if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) | |
291 { | |
292 PERROR (a_name); | |
293 } | |
294 if (scntemp.s_scnptr > 0L) | |
295 { | |
296 if (block_copy_start < scntemp.s_scnptr + scntemp.s_size) | |
297 block_copy_start = scntemp.s_scnptr + scntemp.s_size; | |
298 } | |
299 if (strcmp (scntemp.s_name, ".text") == 0) | |
300 { | |
301 f_thdr = scntemp; | |
302 } | |
303 else if (strcmp (scntemp.s_name, ".data") == 0) | |
304 { | |
305 f_dhdr = scntemp; | |
306 } | |
307 else if (strcmp (scntemp.s_name, ".bss") == 0) | |
308 { | |
309 f_bhdr = scntemp; | |
310 } | |
311 } | |
312 } | |
313 else | |
314 { | |
315 ERROR0 ("can't build a COFF file from scratch yet"); | |
316 } | |
317 | |
318 /* Now we alter the contents of all the f_*hdr variables | |
319 to correspond to what we want to dump. */ | |
320 | |
321 f_hdr.f_flags |= (F_RELFLG | F_EXEC); | |
322 f_ohdr.text_start = (long) start_of_text (); | |
323 f_ohdr.tsize = data_start - f_ohdr.text_start; | |
324 f_ohdr.data_start = data_start; | |
325 f_ohdr.dsize = bss_start - f_ohdr.data_start; | |
326 f_ohdr.bsize = bss_end - bss_start; | |
327 f_thdr.s_size = f_ohdr.tsize; | |
328 f_thdr.s_scnptr = sizeof (f_hdr) + sizeof (f_ohdr); | |
329 f_thdr.s_scnptr += (f_hdr.f_nscns) * (sizeof (f_thdr)); | |
330 lnnoptr = f_thdr.s_lnnoptr; | |
331 text_scnptr = f_thdr.s_scnptr; | |
332 f_dhdr.s_paddr = f_ohdr.data_start; | |
333 f_dhdr.s_vaddr = f_ohdr.data_start; | |
334 f_dhdr.s_size = f_ohdr.dsize; | |
335 f_dhdr.s_scnptr = f_thdr.s_scnptr + f_thdr.s_size; | |
336 data_scnptr = f_dhdr.s_scnptr; | |
337 f_bhdr.s_paddr = f_ohdr.data_start + f_ohdr.dsize; | |
338 f_bhdr.s_vaddr = f_ohdr.data_start + f_ohdr.dsize; | |
339 f_bhdr.s_size = f_ohdr.bsize; | |
340 f_bhdr.s_scnptr = 0L; | |
341 bias = f_dhdr.s_scnptr + f_dhdr.s_size - block_copy_start; | |
342 | |
343 if (f_hdr.f_symptr > 0L) | |
344 { | |
345 f_hdr.f_symptr += bias; | |
346 } | |
347 | |
348 if (f_thdr.s_lnnoptr > 0L) | |
349 { | |
350 f_thdr.s_lnnoptr += bias; | |
351 } | |
352 | |
353 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) | |
354 { | |
355 PERROR (new_name); | |
356 } | |
357 | |
358 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) | |
359 { | |
360 PERROR (new_name); | |
361 } | |
362 | |
363 if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) | |
364 { | |
365 PERROR (new_name); | |
366 } | |
367 | |
368 if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) | |
369 { | |
370 PERROR (new_name); | |
371 } | |
372 | |
373 if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) | |
374 { | |
375 PERROR (new_name); | |
376 } | |
377 | |
378 return (0); | |
379 | |
380 } | |
381 | |
60728
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
382 write_segment (new, ptr, end) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
383 int new; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
384 register char *ptr, *end; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
385 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
386 register int i, nwrite, ret; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
387 char buf[80]; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
388 /* This is the normal amount to write at once. |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
389 It is the size of block that NFS uses. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
390 int writesize = 1 << 13; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
391 int pagesize = getpagesize (); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
392 char zeros[1 << 13]; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
393 |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
107737
diff
changeset
|
394 memset (zeros, 0, sizeof (zeros)); |
60728
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
395 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
396 for (i = 0; ptr < end;) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
397 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
398 /* Distance to next multiple of writesize. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
399 nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
400 /* But not beyond specified end. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
401 if (nwrite > end - ptr) nwrite = end - ptr; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
402 ret = write (new, ptr, nwrite); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
403 /* If write gets a page fault, it means we reached |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
404 a gap between the old text segment and the old data segment. |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
405 This gap has probably been remapped into part of the text segment. |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
406 So write zeros for it. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
407 if (ret == -1 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
408 #ifdef EFAULT |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
409 && errno == EFAULT |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
410 #endif |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
411 ) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
412 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
413 /* Write only a page of zeros at once, |
105426
d0a6d64c3cfc
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
100951
diff
changeset
|
414 so that we don't overshoot the start |
60728
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
415 of the valid memory in the old data segment. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
416 if (nwrite > pagesize) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
417 nwrite = pagesize; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
418 write (new, zeros, nwrite); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
419 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
420 #if 0 /* Now that we have can ask `write' to write more than a page, |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
421 it is legit for write do less than the whole amount specified. */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
422 else if (nwrite != ret) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
423 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
424 sprintf (buf, |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
425 "unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d", |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
426 ptr, new, nwrite, ret, errno); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
427 PERROR (buf); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
428 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
429 #endif |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
430 i += nwrite; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
431 ptr += nwrite; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
432 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
433 } |
172 | 434 /* **************************************************************** |
435 * copy_text_and_data | |
436 * | |
437 * Copy the text and data segments from memory to the new a.out | |
438 */ | |
439 static int | |
440 copy_text_and_data (new, a_out) | |
441 int new, a_out; | |
442 { | |
443 register char *end; | |
444 register char *ptr; | |
445 | |
14975
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
446 #ifdef MSDOS |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
447 /* Dump the original table of exception handlers, not the one |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
448 where our exception hooks are registered. */ |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
449 __djgpp_exception_toggle (); |
15732
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
450 |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
451 /* Switch off startup flags that might have been set at runtime |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
452 and which might change the way that dumped Emacs works. */ |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
453 save_djgpp_startup_flags = _crt0_startup_flags; |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
454 _crt0_startup_flags &= ~(_CRT0_FLAG_NO_LFN | _CRT0_FLAG_NEARPTR); |
14975
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
455 #endif |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
456 |
172 | 457 lseek (new, (long) text_scnptr, 0); |
458 ptr = (char *) f_ohdr.text_start; | |
459 end = ptr + f_ohdr.tsize; | |
460 write_segment (new, ptr, end); | |
461 | |
462 lseek (new, (long) data_scnptr, 0); | |
463 ptr = (char *) f_ohdr.data_start; | |
464 end = ptr + f_ohdr.dsize; | |
465 write_segment (new, ptr, end); | |
466 | |
14975
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
467 #ifdef MSDOS |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
468 /* Restore our exception hooks. */ |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
469 __djgpp_exception_toggle (); |
15732
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
470 |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
471 /* Restore the startup flags. */ |
c24b00e705ba
(copy_text_and_data) [DJGPP >= 2]: Switch off two bits
Karl Heuer <kwzh@gnu.org>
parents:
14975
diff
changeset
|
472 _crt0_startup_flags = save_djgpp_startup_flags; |
14975
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
473 #endif |
7b91ceb19771
[DJGPP v2]: Include fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
474 |
172 | 475 |
476 return 0; | |
477 } | |
478 | |
479 /* **************************************************************** | |
480 * copy_sym | |
481 * | |
482 * Copy the relocation information and symbol table from the a.out to the new | |
483 */ | |
484 static int | |
485 copy_sym (new, a_out, a_name, new_name) | |
486 int new, a_out; | |
487 char *a_name, *new_name; | |
488 { | |
489 char page[1024]; | |
490 int n; | |
491 | |
492 if (a_out < 0) | |
493 return 0; | |
494 | |
495 if (SYMS_START == 0L) | |
496 return 0; | |
497 | |
498 if (lnnoptr) /* if there is line number info */ | |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
499 lseek (a_out, coff_offset + lnnoptr, 0); /* start copying from there */ |
172 | 500 else |
22647
1f418e353dd7
[COFF]: New variable coff_offset.
Richard M. Stallman <rms@gnu.org>
parents:
15732
diff
changeset
|
501 lseek (a_out, coff_offset + SYMS_START, 0); /* Position a.out to symtab. */ |
172 | 502 |
503 while ((n = read (a_out, page, sizeof page)) > 0) | |
504 { | |
505 if (write (new, page, n) != n) | |
506 { | |
507 PERROR (new_name); | |
508 } | |
509 } | |
510 if (n < 0) | |
511 { | |
512 PERROR (a_name); | |
513 } | |
514 return 0; | |
515 } | |
516 | |
517 /* **************************************************************** | |
518 * mark_x | |
519 * | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2917
diff
changeset
|
520 * After successfully building the new a.out, mark it executable |
172 | 521 */ |
522 static void | |
523 mark_x (name) | |
524 char *name; | |
525 { | |
526 struct stat sbuf; | |
527 int um; | |
528 int new = 0; /* for PERROR */ | |
529 | |
530 um = umask (777); | |
531 umask (um); | |
532 if (stat (name, &sbuf) == -1) | |
533 { | |
534 PERROR (name); | |
535 } | |
536 sbuf.st_mode |= 0111 & ~um; | |
537 if (chmod (name, sbuf.st_mode) == -1) | |
538 PERROR (name); | |
539 } | |
540 | |
541 | |
542 /* | |
543 * If the COFF file contains a symbol table and a line number section, | |
544 * then any auxiliary entries that have values for x_lnnoptr must | |
545 * be adjusted by the amount that the line number section has moved | |
546 * in the file (bias computed in make_hdr). The #@$%&* designers of | |
547 * the auxiliary entry structures used the absolute file offsets for | |
548 * the line number entry rather than an offset from the start of the | |
549 * line number section! | |
550 * | |
551 * When I figure out how to scan through the symbol table and pick out | |
552 * the auxiliary entries that need adjustment, this routine will | |
553 * be fixed. As it is now, all such entries are wrong and sdb | |
554 * will complain. Fred Fish, UniSoft Systems Inc. | |
555 */ | |
556 | |
557 /* This function is probably very slow. Instead of reopening the new | |
558 file for input and output it should copy from the old to the new | |
559 using the two descriptors already open (WRITEDESC and READDESC). | |
560 Instead of reading one small structure at a time it should use | |
561 a reasonable size buffer. But I don't have time to work on such | |
562 things, so I am installing it as submitted to me. -- RMS. */ | |
563 | |
564 adjust_lnnoptrs (writedesc, readdesc, new_name) | |
565 int writedesc; | |
566 int readdesc; | |
567 char *new_name; | |
568 { | |
569 register int nsyms; | |
570 register int new; | |
571 struct syment symentry; | |
572 union auxent auxentry; | |
573 | |
574 if (!lnnoptr || !f_hdr.f_symptr) | |
575 return 0; | |
576 | |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
577 #ifdef MSDOS |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
578 if ((new = writedesc) < 0) |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
579 #else |
7921
b3a5b629fe26
Include <sys/file.h> and [USG5] <fcntl.h> to define O_* macros.
Roland McGrath <roland@gnu.org>
parents:
7626
diff
changeset
|
580 if ((new = open (new_name, O_RDWR)) < 0) |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
581 #endif |
172 | 582 { |
583 PERROR (new_name); | |
584 return -1; | |
585 } | |
586 | |
587 lseek (new, f_hdr.f_symptr, 0); | |
588 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) | |
589 { | |
590 read (new, &symentry, SYMESZ); | |
591 if (symentry.n_numaux) | |
592 { | |
593 read (new, &auxentry, AUXESZ); | |
594 nsyms++; | |
1937
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
595 if (ISFCN (symentry.n_type) || symentry.n_type == 0x2400) |
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
596 { |
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
597 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; |
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
598 lseek (new, -AUXESZ, 1); |
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
599 write (new, &auxentry, AUXESZ); |
087889e85644
(Fforward_comment): New function.
Richard M. Stallman <rms@gnu.org>
parents:
620
diff
changeset
|
600 } |
172 | 601 } |
602 } | |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
603 #ifndef MSDOS |
172 | 604 close (new); |
5500
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
605 #endif |
6f6637309b38
[MSDOS]: Don't #include <a.out.h>, but use other headers.
Richard M. Stallman <rms@gnu.org>
parents:
4973
diff
changeset
|
606 return 0; |
172 | 607 } |
608 | |
109168
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
609 extern unsigned start __asm__ ("start"); |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
610 |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
611 /* |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
612 * Return the address of the start of the text segment prior to |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
613 * doing an unexec. After unexec the return value is undefined. |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
614 * See crt0.c for further explanation and _start. |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
615 * |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
616 */ |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
617 |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
618 char * |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
619 start_of_text (void) |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
620 { |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
621 return ((char *) &start); |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
622 } |
fb5779a6cf4b
Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
109165
diff
changeset
|
623 |
60728
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
624 /* **************************************************************** |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
625 * unexec |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
626 * |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
627 * driving logic. |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
628 */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
629 unexec (new_name, a_name, data_start, bss_start, entry_address) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
630 char *new_name, *a_name; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
631 unsigned data_start, bss_start, entry_address; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
632 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
633 int new, a_out = -1; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
634 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
635 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
636 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
637 PERROR (a_name); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
638 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
639 if ((new = creat (new_name, 0666)) < 0) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
640 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
641 PERROR (new_name); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
642 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
643 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
644 if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
645 || copy_text_and_data (new, a_out) < 0 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
646 || copy_sym (new, a_out, a_name, new_name) < 0 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
647 || adjust_lnnoptrs (new, a_out, new_name) < 0 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
648 ) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
649 { |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
650 close (new); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
651 /* unlink (new_name); /* Failed, unlink new a.out */ |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
652 return -1; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
653 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
654 |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
655 close (new); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
656 if (a_out >= 0) |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
657 close (a_out); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
658 mark_x (new_name); |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
659 return 0; |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
660 } |
1e22d789c8c7
(write_segment, unexec): Move these functions to avoid forward
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
661 |
172 | 662 #endif /* not CANNOT_DUMP */ |
52401 | 663 |
664 /* arch-tag: 62409b69-e27a-4a7c-9413-0210d6b54e7f | |
665 (do not change this comment) */ |