annotate src/unexaix.c @ 48:56c54cf7c5b6 r19-16b90

Import from CVS: tag r19-16b90
author cvs
date Mon, 13 Aug 2007 08:56:04 +0200
parents 376386a54a3c
children e45d5e7c476e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 /* Synched up with: FSF 19.31. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Modified by Andrew.Vignaux@comp.vuw.ac.nz to get it to work :-) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * unexec.c - Convert a running program into an a.out file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * Author: Spencer W. Thomas
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * Computer Science Dept.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * University of Utah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * Date: Tue Mar 2 1982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * Modified heavily since then.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 * Updated for AIX 4.1.3 by Bill_Mann @ PraxisInt.com, Feb 1996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 * As of AIX 4.1, text, data, and bss are pre-relocated by the binder in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * such a way that the file can be mapped with code in one segment and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 * data/bss in another segment, without reading or copying the file, by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 * the AIX exec loader. Padding sections are omitted, nevertheless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 * small amounts of 'padding' still occurs between sections in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 * As modified, this code handles both 3.2 and 4.1 conventions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * Synopsis:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 * unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * char *new_name, *a_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 * unsigned data_start, bss_start, entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * Takes a snapshot of the program and makes an a.out format file in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * file named by the string argument new_name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * If a_name is non-NULL, the symbol table will be taken from the given file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 * On some machines, an existing a_name file is required.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 * The boundaries within the a.out file may be adjusted with the data_start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 * and bss_start arguments. Either or both may be given as 0 for defaults.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 * Data_start gives the boundary between the text segment and the data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 * segment of the program. The text segment can contain shared, read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 * program code and literal data, while the data segment is always unshared
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 * and unprotected. Data_start gives the lowest unprotected address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 * The value you specify may be rounded down to a suitable boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 * as required by the machine you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 * Specifying zero for data_start means the boundary between text and data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 * should not be the same as when the program was loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 * If NO_REMAP is defined, the argument data_start is ignored and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 * segment boundaries are never changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 * Bss_start indicates how much of the data segment is to be saved in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 * a.out file and restored when the program is executed. It gives the lowest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 * unsaved address, and is rounded up to a page boundary. The default when 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 * is given assumes that the entire data segment is to be stored, including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 * the previous data and bss as well as any additional storage allocated with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 * break (2).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 * The new file is set up to start at entry_address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 * If you make improvements I'd like to get them too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 * harpo!utah-cs!thomas, thomas@Utah-20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 /* There are several compilation parameters affecting unexec:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 * COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 Define this if your system uses COFF for executables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 Otherwise we assume you use Berkeley format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 * NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Define this if you do not want to try to save Emacs's pure data areas
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 as part of the text segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Saving them as text is good because it allows users to share more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 However, on machines that locate the text area far from the data area,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 the boundary cannot feasibly be moved. Such machines require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 NO_REMAP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 Also, remapping can cause trouble with the built-in startup routine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 /lib/crt0.o, which defines `environ' as an initialized variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Dumping `environ' as pure does not work! So, to use remapping,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 you must write a startup routine for your machine in Emacs's crt0.c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 If NO_REMAP is defined, Emacs uses the system's crt0.o.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 * SECTION_ALIGNMENT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Some machines that use COFF executables require that each section
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 start on a certain boundary *in the COFF file*. Such machines should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 define SECTION_ALIGNMENT to a mask of the low-order bits that must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 zero on such a boundary. This mask is used to control padding between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 segments in the COFF file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 If SECTION_ALIGNMENT is not defined, the segments are written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 consecutively with no attempt at alignment. This is right for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 unmodified system V.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 * SEGMENT_MASK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Some machines require that the beginnings and ends of segments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 *in core* be on certain boundaries. For most machines, a page
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 boundary is sufficient. That is the default. When a larger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 boundary is needed, define SEGMENT_MASK to a mask of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 the bits that must be zero on such a boundary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 * A_TEXT_OFFSET(HDR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 Some machines count the a.out header as part of the size of the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 segment (a_text); they may actually load the header into core as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 first data in the text segment. Some have additional padding between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 the header and the real text of the program that is counted in a_text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 For these machines, define A_TEXT_OFFSET(HDR) to examine the header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 structure HDR and return the number of bytes to add to `a_text'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 before writing it (above and beyond the number of bytes of actual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 program text). HDR's standard fields are already correct, except that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 this adjustment to the `a_text' field has not yet been made;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 thus, the amount of offset can depend on the data in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 * A_TEXT_SEEK(HDR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 If defined, this macro specifies the number of bytes to seek into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 a.out file before starting to write the text segment.a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 * EXEC_MAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 For machines using COFF, this macro, if defined, is a value stored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 into the magic number field of the output file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 * ADJUST_EXEC_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 This macro can be used to generate statements to adjust or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 initialize nonstandard fields in the file header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 * ADDR_CORRECT(ADDR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 Macro to correct an int which is the bit pattern of a pointer to a byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 into an int which is the number of a byte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 This macro has a default definition which is usually right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 This default definition is a no-op on most machines (where a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 pointer looks like an int) but not on all machines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 #define XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 #define COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 #define NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #define PERROR(arg) perror (arg); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 #define PERROR(file) report_error (file, new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 #include <a.out.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* Define getpagesize () if the system does not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Note that this may depend on symbols defined in a.out.h
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 #include "getpagesize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #ifndef makedev /* Try to detect types.h already loaded */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 extern char *start_of_text (); /* Start of text */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 extern char *start_of_data (); /* Start of initialized data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 extern int _data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 extern int _edata;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 extern int _text;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 extern int _etext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 extern int _end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 #ifndef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 #ifndef STRIDE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 #ifndef UMAX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 #ifndef sun386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 /* I have a suspicion that these are turned off on all systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 and can be deleted. Try it in version 19. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 #include <filehdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 #include <aouthdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 #include <scnhdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 #include <syms.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 #endif /* not sun386 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #endif /* not UMAX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 #endif /* Not STRIDE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #endif /* not USG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 static struct filehdr f_hdr; /* File header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 static struct aouthdr f_ohdr; /* Optional file header (a.out) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 long bias; /* Bias to add for growth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 long lnnoptr; /* Pointer to line-number info within file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 static long text_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 static long data_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #ifdef XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #define ALIGN(val, pwr) (((val) + ((1L<<(pwr))-1)) & ~((1L<<(pwr))-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 static long load_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 static long orig_load_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 static long orig_data_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 static ulong data_st; /* start of data area written out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #ifndef MAX_SECTIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 #define MAX_SECTIONS 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 #endif /* COFF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 static int pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 /* Correct an int which is the bit pattern of a pointer to a byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 into an int which is the number of a byte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 This is a no-op on ordinary machines, but not on all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 #ifndef ADDR_CORRECT /* Let m-*.h files override this definition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 static
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 report_error (file, fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 char *file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 static
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 report_error_1 (fd, msg, a1, a2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 char *msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 int a1, a2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 error (msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 fprintf (stderr, msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 static int make_hdr ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 static void mark_x ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 static int copy_text_and_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 static int copy_sym ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 * unexec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 * driving logic.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 char *new_name, *a_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 unsigned data_start, bss_start, entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 int new, a_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 if (a_name && (a_out = open (a_name, 0)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 if ((new = creat (new_name, 0666)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 if (make_hdr (new,a_out,data_start,bss_start,entry_address,a_name,new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 || copy_text_and_data (new) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 || copy_sym (new, a_out, a_name, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 || adjust_lnnoptrs (new, a_out, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 #ifdef XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 || unrelocate_symbols (new, a_out, a_name, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 /* unlink (new_name); /* Failed, unlink new a.out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 close (a_out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 * make_hdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 * Make the header in the new a.out from the header in core.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 * Modify the text and data sizes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 int new, a_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 unsigned data_start, bss_start, entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 char *a_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 char *new_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 int scns;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 unsigned int bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 struct scnhdr section[MAX_SECTIONS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 struct scnhdr * f_thdr; /* Text section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 struct scnhdr * f_dhdr; /* Data section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 struct scnhdr * f_bhdr; /* Bss section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 struct scnhdr * f_lhdr; /* Loader section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 struct scnhdr * f_tchdr; /* Typechk section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 struct scnhdr * f_dbhdr; /* Debug section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 struct scnhdr * f_xhdr; /* Except section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 load_scnptr = orig_load_scnptr = lnnoptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 pagemask = getpagesize () - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 /* Adjust text/data boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 #ifdef NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 data_start = (long) start_of_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 #endif /* NO_REMAP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 data_start = ADDR_CORRECT (data_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 #ifdef SEGMENT_MASK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 data_start = data_start & ~SEGMENT_MASK; /* (Down) to segment boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 bss_end = ADDR_CORRECT (sbrk (0)) + pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 bss_end &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 /* Adjust data/bss boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (bss_start != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 bss_start = (ADDR_CORRECT (bss_start) + pagemask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 /* (Up) to page bdry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 bss_start &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 if (bss_start > bss_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ERROR1 ("unexec: Specified bss_start (%u) is past end of program",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 bss_start = bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 if (data_start > bss_start) /* Can't have negative data size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 data_start, bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 /* Salvage as much info from the existing file as possible */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 f_thdr = NULL; f_dhdr = NULL; f_bhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 f_lhdr = NULL; f_tchdr = NULL; f_dbhdr = NULL; f_xhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 if (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if (f_hdr.f_nscns > MAX_SECTIONS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ERROR0 ("unexec: too many section headers -- increase MAX_SECTIONS");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 /* Loop through section headers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 if (read (a_out, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 #define CHECK_SCNHDR(ptr, name, flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 if (strcmp(s->s_name, name) == 0) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 if (s->s_flags != flags) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 fprintf(stderr, "unexec: %lx flags where %x expected in %s section.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (unsigned long)s->s_flags, flags, name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 if (ptr) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 fprintf(stderr, "unexec: duplicate section header for section %s.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ptr = s; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 CHECK_SCNHDR(f_thdr, _TEXT, STYP_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 CHECK_SCNHDR(f_dhdr, _DATA, STYP_DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 CHECK_SCNHDR(f_bhdr, _BSS, STYP_BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 CHECK_SCNHDR(f_lhdr, _LOADER, STYP_LOADER);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 CHECK_SCNHDR(f_dbhdr, _DEBUG, STYP_DEBUG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 CHECK_SCNHDR(f_tchdr, _TYPCHK, STYP_TYPCHK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 if (f_thdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ERROR1 ("unexec: couldn't find \"%s\" section", _TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 if (f_dhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ERROR1 ("unexec: couldn't find \"%s\" section", _DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 if (f_bhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ERROR1 ("unexec: couldn't find \"%s\" section", _BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ERROR0 ("can't build a COFF file from scratch yet");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 orig_data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 orig_load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 /* Now we alter the contents of all the f_*hdr variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 to correspond to what we want to dump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 /* Indicate that the reloc information is no longer valid for ld (bind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 we only update it enough to fake out the exec-time loader. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 f_hdr.f_flags |= (F_RELFLG | F_EXEC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #ifdef EXEC_MAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 f_ohdr.magic = EXEC_MAGIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 #ifndef NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 f_ohdr.tsize = data_start - f_ohdr.text_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 f_ohdr.text_start = (long) start_of_text ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 data_st = f_ohdr.data_start ? f_ohdr.data_start : (ulong) &_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 f_ohdr.dsize = bss_start - data_st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 f_ohdr.bsize = bss_end - bss_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 f_dhdr->s_size = f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 f_bhdr->s_size = f_ohdr.bsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 f_bhdr->s_paddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 f_bhdr->s_vaddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 /* fix scnptr's */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ulong ptr = section[0].s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 bias = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 if (s->s_flags & STYP_PAD) /* .pad sections omitted in AIX 4.1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 * the text_start should probably be o_algntext but that doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 * seem to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 if (f_ohdr.text_start != 0) /* && scns != 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 s->s_size = 512 - (ptr % 512);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (s->s_size == 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 s->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 s->s_scnptr = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 else if (s->s_flags & STYP_DATA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 s->s_scnptr = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 else if (!(s->s_flags & (STYP_TEXT | STYP_BSS)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 if (bias == -1) /* if first section after bss */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 bias = ptr - s->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 s->s_scnptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ptr = s->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ptr = ptr + s->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 /* fix other pointers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 if (s->s_relptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 s->s_relptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 if (s->s_lnnoptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 if (lnnoptr == 0) lnnoptr = s->s_lnnoptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 s->s_lnnoptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 if (f_hdr.f_symptr > 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 f_hdr.f_symptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 text_scnptr = f_thdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 #ifdef ADJUST_EXEC_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ADJUST_EXEC_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 #endif /* ADJUST_EXEC_HEADER */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 if (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 if (write (new, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 #endif /* COFF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 * Copy the text and data segments from memory to the new a.out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 copy_text_and_data (new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 int new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 char *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 lseek (new, (long) text_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ptr = start_of_text () + text_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 end = ptr + f_ohdr.tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 lseek (new, (long) data_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ptr = (char *) data_st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 end = ptr + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 #define UnexBlockSz (1<<12) /* read/write block size */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 write_segment (new, ptr, end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 int new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 char *ptr, *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 int i, nwrite, ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 char buf[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 char zeros[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 for (i = 0; ptr < end;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 /* distance to next block. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 nwrite = (((int) ptr + UnexBlockSz) & -UnexBlockSz) - (int) ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 /* But not beyond specified end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 if (nwrite > end - ptr) nwrite = end - ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ret = write (new, ptr, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 /* If write gets a page fault, it means we reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 a gap between the old text segment and the old data segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 This gap has probably been remapped into part of the text segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 So write zeros for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 if (ret == -1 && errno == EFAULT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 bzero (zeros, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 write (new, zeros, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 else if (nwrite != ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 sprintf (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "unexec write failure: addr 0x%lx, fileno %d, size 0x%x, wrote 0x%x, errno %d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (unsigned long)ptr, new, nwrite, ret, errno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 PERROR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 i += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ptr += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 * copy_sym
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 * Copy the relocation information and symbol table from the a.out to the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 copy_sym (new, a_out, a_name, new_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 int new, a_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 char *a_name, *new_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 char page[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 int n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 if (a_out < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 if (orig_load_scnptr == 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 if (lnnoptr && lnnoptr < orig_load_scnptr) /* if there is line number info */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 lseek (a_out, lnnoptr, 0); /* start copying from there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 lseek (a_out, orig_load_scnptr, 0); /* Position a.out to symtab. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 while ((n = read (a_out, page, sizeof page)) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 if (write (new, page, n) != n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 if (n < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 mark_x (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 int um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 int new = 0; /* for PERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 if (stat (name, &sbuf) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 if (chmod (name, sbuf.st_mode) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 * If the COFF file contains a symbol table and a line number section,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 * then any auxiliary entries that have values for x_lnnoptr must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 * be adjusted by the amount that the line number section has moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 * in the file (bias computed in make_hdr). The #@$%&* designers of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 * the auxiliary entry structures used the absolute file offsets for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 * the line number entry rather than an offset from the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 * line number section!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 * When I figure out how to scan through the symbol table and pick out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 * the auxiliary entries that need adjustment, this routine will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 * be fixed. As it is now, all such entries are wrong and sdb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 * will complain. Fred Fish, UniSoft Systems Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 * I believe this is now fixed correctly. Bill Mann
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 /* This function is probably very slow. Instead of reopening the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 file for input and output it should copy from the old to the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 using the two descriptors already open (WRITEDESC and READDESC).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 Instead of reading one small structure at a time it should use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 a reasonable size buffer. But I don't have time to work on such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 things, so I am installing it as submitted to me. -- RMS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 adjust_lnnoptrs (writedesc, readdesc, new_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 int writedesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 int readdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 char *new_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 int nsyms;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 int naux;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 int new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 #ifdef amdahl_uts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 SYMENT symentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 AUXENT auxentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 struct syment symentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 union auxent auxentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 if (!lnnoptr || !f_hdr.f_symptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 if ((new = open (new_name, 2)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 lseek (new, f_hdr.f_symptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 read (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 if (symentry.n_sclass == C_BINCL || symentry.n_sclass == C_EINCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 symentry.n_value += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 lseek (new, -SYMESZ, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 write (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 for (naux = symentry.n_numaux; naux-- != 0; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 read (new, &auxentry, AUXESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 nsyms++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 if (naux != 0 /* skip csect auxentry (last entry) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 && (symentry.n_sclass == C_EXT || symentry.n_sclass == C_HIDEXT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 lseek (new, -AUXESZ, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 write (new, &auxentry, AUXESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 #endif /* COFF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 #ifdef XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 /* It is probably a false economy to optimise this routine (it used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 read one LDREL and do do two lseeks per iteration) but the wrath of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 RMS (see above :-) would be too much to bear */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 unrelocate_symbols (new, a_out, a_name, new_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 int new, a_out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 char *a_name, *new_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 int l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 LDREL *ldrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 LDHDR ldhdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 LDREL ldrel_buf [20];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ulong t_reloc = (ulong) &_text - f_ohdr.text_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ulong d_reloc = (ulong) &_data - ALIGN(f_ohdr.data_start, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 int * p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 if (load_scnptr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 lseek (a_out, orig_load_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 if (read (a_out, &ldhdr, sizeof (ldhdr)) != sizeof (ldhdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 #define SYMNDX_TEXT 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 #define SYMNDX_DATA 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 #define SYMNDX_BSS 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 l = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 for (i = 0; i < ldhdr.l_nreloc; i++, l--, ldrel++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 if (l == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 lseek (a_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 orig_load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 l = ldhdr.l_nreloc - i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 if (l > sizeof (ldrel_buf) / LDRELSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 l = sizeof (ldrel_buf) / LDRELSZ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 if (read (a_out, ldrel_buf, l * LDRELSZ) != l * LDRELSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ldrel = ldrel_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 /* move the BSS loader symbols to the DATA segment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 if (ldrel->l_symndx == SYMNDX_BSS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 ldrel->l_symndx = SYMNDX_DATA;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 lseek (new,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 if (write (new, ldrel, LDRELSZ) != LDRELSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 if (ldrel->l_rsecnm == f_ohdr.o_sndata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 int orig_int;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 lseek (a_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 orig_data_scnptr + (ldrel->l_vaddr - f_ohdr.data_start), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 if (read (a_out, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 p = (int *) (ldrel->l_vaddr + d_reloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 switch (ldrel->l_symndx) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 case SYMNDX_TEXT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 orig_int = * p - t_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 case SYMNDX_DATA:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 case SYMNDX_BSS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 orig_int = * p - d_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 if (orig_int != * p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 lseek (new,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 data_scnptr + (ldrel->l_vaddr - f_ohdr.data_start), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 if (write (new, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 #endif /* XCOFF */