annotate src/unexaix.c @ 267:966663fcf606 r20-5b32

Import from CVS: tag r20-5b32
author cvs
date Mon, 13 Aug 2007 10:26:29 +0200
parents 262b8bb4a523
children c42ec1d1cded
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
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
188 extern char *start_of_text (void); /* Start of text */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
189 extern char *start_of_data (void); /* Start of initialized data */
0
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;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
223 static unrelocate_symbols (int, int, char *, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 static ulong data_st; /* start of data area written out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 #ifndef MAX_SECTIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 #define MAX_SECTIONS 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
231 static adjust_lnnoptrs (int, int, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 #endif /* COFF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 static int pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 /* 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
237 into an int which is the number of a byte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 This is a no-op on ordinary machines, but not on all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 #ifndef ADDR_CORRECT /* Let m-*.h files override this definition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 static
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
248 report_error (char *file, int fd)
0
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
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
261 report_error_1 (int fd, char *msg, int a1, int a2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 error (msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 fprintf (stderr, msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
272 static int make_hdr (int, int, unsigned, unsigned, unsigned, char *, char *);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
273 static void mark_x (char *);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
274 static int copy_text_and_data (int);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
275 static int copy_sym (int, int, char *, char *);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
276 static write_segment (int, char *, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 * unexec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 * driving logic.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
283 int unexec (char *new_name, char *a_name,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
284 uintptr_t data_start,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
285 uintptr_t bss_start,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
286 uintptr_t entry_address)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 int new, a_out = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 if (a_name && (a_out = open (a_name, 0)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 if ((new = creat (new_name, 0666)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 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
299 || copy_text_and_data (new) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 || copy_sym (new, a_out, a_name, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 || adjust_lnnoptrs (new, a_out, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #ifdef XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 || unrelocate_symbols (new, a_out, a_name, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 close (new);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 0
diff changeset
310 /* unlink (new_name); */ /* Failed, unlink new a.out */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 close (a_out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 }
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 * make_hdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 * Make the header in the new a.out from the header in core.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 * Modify the text and data sizes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
328 make_hdr (int new, int a_out, unsigned data_start, unsigned bss_start, unsigned entry_address, char *a_name, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 int scns;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 unsigned int bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 struct scnhdr section[MAX_SECTIONS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 struct scnhdr * f_thdr; /* Text section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 struct scnhdr * f_dhdr; /* Data section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 struct scnhdr * f_bhdr; /* Bss section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 struct scnhdr * f_lhdr; /* Loader section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 struct scnhdr * f_tchdr; /* Typechk section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 struct scnhdr * f_dbhdr; /* Debug section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 struct scnhdr * f_xhdr; /* Except section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 load_scnptr = orig_load_scnptr = lnnoptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 pagemask = getpagesize () - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 /* Adjust text/data boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 #ifdef NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 data_start = (long) start_of_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 #endif /* NO_REMAP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 data_start = ADDR_CORRECT (data_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 #ifdef SEGMENT_MASK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 data_start = data_start & ~SEGMENT_MASK; /* (Down) to segment boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 bss_end = ADDR_CORRECT (sbrk (0)) + pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 bss_end &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 /* Adjust data/bss boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 if (bss_start != 0)
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_start = (ADDR_CORRECT (bss_start) + pagemask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 /* (Up) to page bdry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 bss_start &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (bss_start > bss_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ERROR1 ("unexec: Specified bss_start (%u) is past end of program",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 bss_start = bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 if (data_start > bss_start) /* Can't have negative data size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 data_start, bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 /* Salvage as much info from the existing file as possible */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 f_thdr = NULL; f_dhdr = NULL; f_bhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 f_lhdr = NULL; f_tchdr = NULL; f_dbhdr = NULL; f_xhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 }
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 (f_hdr.f_nscns > MAX_SECTIONS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ERROR0 ("unexec: too many section headers -- increase MAX_SECTIONS");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 /* Loop through section headers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 if (read (a_out, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 #define CHECK_SCNHDR(ptr, name, flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 if (strcmp(s->s_name, name) == 0) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 if (s->s_flags != flags) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 fprintf(stderr, "unexec: %lx flags where %x expected in %s section.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (unsigned long)s->s_flags, flags, name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 if (ptr) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 fprintf(stderr, "unexec: duplicate section header for section %s.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ptr = s; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 CHECK_SCNHDR(f_thdr, _TEXT, STYP_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 CHECK_SCNHDR(f_dhdr, _DATA, STYP_DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 CHECK_SCNHDR(f_bhdr, _BSS, STYP_BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 CHECK_SCNHDR(f_lhdr, _LOADER, STYP_LOADER);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 CHECK_SCNHDR(f_dbhdr, _DEBUG, STYP_DEBUG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 CHECK_SCNHDR(f_tchdr, _TYPCHK, STYP_TYPCHK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 if (f_thdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
433 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _TEXT);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 if (f_dhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
437 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _DATA);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 if (f_bhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
441 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _BSS);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ERROR0 ("can't build a COFF file from scratch yet");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 orig_data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 orig_load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 /* Now we alter the contents of all the f_*hdr variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 to correspond to what we want to dump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 /* Indicate that the reloc information is no longer valid for ld (bind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 we only update it enough to fake out the exec-time loader. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 f_hdr.f_flags |= (F_RELFLG | F_EXEC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 #ifdef EXEC_MAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 f_ohdr.magic = EXEC_MAGIC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 #ifndef NO_REMAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 f_ohdr.tsize = data_start - f_ohdr.text_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 f_ohdr.text_start = (long) start_of_text ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 data_st = f_ohdr.data_start ? f_ohdr.data_start : (ulong) &_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 f_ohdr.dsize = bss_start - data_st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 f_ohdr.bsize = bss_end - bss_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 f_dhdr->s_size = f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 f_bhdr->s_size = f_ohdr.bsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 f_bhdr->s_paddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 f_bhdr->s_vaddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 /* fix scnptr's */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ulong ptr = section[0].s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 bias = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 if (s->s_flags & STYP_PAD) /* .pad sections omitted in AIX 4.1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 * the text_start should probably be o_algntext but that doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 * seem to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 if (f_ohdr.text_start != 0) /* && scns != 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 s->s_size = 512 - (ptr % 512);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 if (s->s_size == 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 s->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 s->s_scnptr = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 else if (s->s_flags & STYP_DATA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 s->s_scnptr = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 else if (!(s->s_flags & (STYP_TEXT | STYP_BSS)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 if (bias == -1) /* if first section after bss */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 bias = ptr - s->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 s->s_scnptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ptr = s->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ptr = ptr + s->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 /* fix other pointers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (s->s_relptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 s->s_relptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (s->s_lnnoptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (lnnoptr == 0) lnnoptr = s->s_lnnoptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 s->s_lnnoptr += 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 }
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 (f_hdr.f_symptr > 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 f_hdr.f_symptr += bias;
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 text_scnptr = f_thdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 #ifdef ADJUST_EXEC_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ADJUST_EXEC_HEADER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 #endif /* ADJUST_EXEC_HEADER */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 }
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 (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 if (write (new, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 #endif /* COFF */
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 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 * Copy the text and data segments from memory to the new a.out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
573 copy_text_and_data (int new)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 char *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 lseek (new, (long) text_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ptr = start_of_text () + text_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 end = ptr + f_ohdr.tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 lseek (new, (long) data_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 ptr = (char *) data_st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 end = ptr + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 #define UnexBlockSz (1<<12) /* read/write block size */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
592 write_segment (int new, char *ptr, char *end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 int i, nwrite, ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 char buf[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 char zeros[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 for (i = 0; ptr < end;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 /* distance to next block. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 nwrite = (((int) ptr + UnexBlockSz) & -UnexBlockSz) - (int) ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 /* But not beyond specified end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 if (nwrite > end - ptr) nwrite = end - ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ret = write (new, ptr, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 /* If write gets a page fault, it means we reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 a gap between the old text segment and the old data segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 This gap has probably been remapped into part of the text segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 So write zeros for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 if (ret == -1 && errno == EFAULT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 bzero (zeros, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 write (new, zeros, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 else if (nwrite != ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 sprintf (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 "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
619 (unsigned long)ptr, new, nwrite, ret, errno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 PERROR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 i += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 ptr += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 * copy_sym
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 * 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
631 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
633 copy_sym (int new, int a_out, char *a_name, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 char page[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 int n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 if (a_out < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 if (orig_load_scnptr == 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 if (lnnoptr && lnnoptr < orig_load_scnptr) /* if there is line number info */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 lseek (a_out, lnnoptr, 0); /* start copying from there */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 lseek (a_out, orig_load_scnptr, 0); /* Position a.out to symtab. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 while ((n = read (a_out, page, sizeof page)) > 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 (write (new, page, n) != n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (n < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 static void
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
669 mark_x (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 int um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 int new = 0; /* for PERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 if (stat (name, &sbuf) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 if (chmod (name, sbuf.st_mode) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 * If the COFF file contains a symbol table and a line number section,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 * then any auxiliary entries that have values for x_lnnoptr must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 * be adjusted by the amount that the line number section has moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 * in the file (bias computed in make_hdr). The #@$%&* designers of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 * the auxiliary entry structures used the absolute file offsets for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 * the line number entry rather than an offset from the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 * line number section!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 * 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
696 * the auxiliary entries that need adjustment, this routine will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 * be fixed. As it is now, all such entries are wrong and sdb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 * will complain. Fred Fish, UniSoft Systems Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 * I believe this is now fixed correctly. Bill Mann
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 #ifdef COFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 /* This function is probably very slow. Instead of reopening the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 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
707 using the two descriptors already open (WRITEDESC and READDESC).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 Instead of reading one small structure at a time it should use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 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
710 things, so I am installing it as submitted to me. -- RMS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
712 adjust_lnnoptrs (int writedesc, int readdesc, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 int nsyms;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 int naux;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 int new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 #ifdef amdahl_uts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 SYMENT symentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 AUXENT auxentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 struct syment symentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 union auxent auxentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 if (!lnnoptr || !f_hdr.f_symptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 if ((new = open (new_name, 2)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 lseek (new, f_hdr.f_symptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 read (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 if (symentry.n_sclass == C_BINCL || symentry.n_sclass == C_EINCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 symentry.n_value += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 lseek (new, -SYMESZ, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 write (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 for (naux = symentry.n_numaux; naux-- != 0; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 read (new, &auxentry, AUXESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 nsyms++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 if (naux != 0 /* skip csect auxentry (last entry) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 && (symentry.n_sclass == C_EXT || symentry.n_sclass == C_HIDEXT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 lseek (new, -AUXESZ, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 write (new, &auxentry, AUXESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 #endif /* COFF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 #ifdef XCOFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 /* It is probably a false economy to optimise this routine (it used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 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
767 RMS (see above :-) would be too much to bear */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
769 unrelocate_symbols (int new, int a_out, char *a_name, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 int l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 LDREL *ldrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 LDHDR ldhdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 LDREL ldrel_buf [20];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ulong t_reloc = (ulong) &_text - f_ohdr.text_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 ulong d_reloc = (ulong) &_data - ALIGN(f_ohdr.data_start, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 int * p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 if (load_scnptr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 lseek (a_out, orig_load_scnptr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 if (read (a_out, &ldhdr, sizeof (ldhdr)) != sizeof (ldhdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 #define SYMNDX_TEXT 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 #define SYMNDX_DATA 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 #define SYMNDX_BSS 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 l = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 for (i = 0; i < ldhdr.l_nreloc; i++, l--, ldrel++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 if (l == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 lseek (a_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 orig_load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 l = ldhdr.l_nreloc - i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 if (l > sizeof (ldrel_buf) / LDRELSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 l = sizeof (ldrel_buf) / LDRELSZ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 if (read (a_out, ldrel_buf, l * LDRELSZ) != l * LDRELSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ldrel = ldrel_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 /* move the BSS loader symbols to the DATA segment */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 if (ldrel->l_symndx == SYMNDX_BSS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ldrel->l_symndx = SYMNDX_DATA;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 lseek (new,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 0);
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 (write (new, ldrel, LDRELSZ) != 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 (new_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 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 if (ldrel->l_rsecnm == f_ohdr.o_sndata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 int orig_int;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 lseek (a_out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 orig_data_scnptr + (ldrel->l_vaddr - f_ohdr.data_start), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 if (read (a_out, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 p = (int *) (ldrel->l_vaddr + d_reloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 switch (ldrel->l_symndx) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 case SYMNDX_TEXT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 orig_int = * p - t_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 case SYMNDX_DATA:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 case SYMNDX_BSS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 orig_int = * p - d_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 if (orig_int != * p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 lseek (new,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 data_scnptr + (ldrel->l_vaddr - f_ohdr.data_start), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 if (write (new, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 #endif /* XCOFF */