annotate src/unexaix.c @ 337:fbbf69b4e8a7 r21-0-66

Import from CVS: tag r21-0-66
author cvs
date Mon, 13 Aug 2007 10:51:02 +0200
parents 70ad99077275
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1 /* Dump an executable image.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
21 /* Synched up with: FSF 20.2. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
23 /* Originally based on the COFF unexec.c by Spencer W. Thomas.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 *
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
25 * Subsequently hacked on by
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
26 * Bill Mann <Bill_Man@praxisint.com>
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
27 * Andrew Vignaux <Andrew.Vignaux@comp.vuw.ac.nz>
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
28 * Mike Sperber <sperber@informatik.uni-tuebingen.de>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * Synopsis:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 * char *new_name, *a_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 * unsigned data_start, bss_start, entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * 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
36 * file named by the string argument new_name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 * 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
38 * On some machines, an existing a_name file is required.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 *
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
40 * data_start and entry_address are ignored.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 *
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
42 * bss_start indicates how much of the data segment is to be saved in the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * 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
44 * 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
45 * is given assumes that the entire data segment is to be stored, including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * the previous data and bss as well as any additional storage allocated with
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
47 * sbrk(2).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #define PERROR(arg) perror (arg); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #define PERROR(file) report_error (file, new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <a.out.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* Define getpagesize () if the system does not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 Note that this may depend on symbols defined in a.out.h
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #include "getpagesize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #include <errno.h>
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
68 #include <unistd.h>
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
69 #include <fcntl.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
71 extern char *start_of_text (void); /* Start of text */
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
72 extern char *start_of_data (void); /* Start of initialized data */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 extern int _data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 extern int _text;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
76
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #include <filehdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #include <aouthdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #include <scnhdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #include <syms.h>
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
81
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 static struct filehdr f_hdr; /* File header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 static struct aouthdr f_ohdr; /* Optional file header (a.out) */
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
84 static long bias; /* Bias to add for growth */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
85 static long lnnoptr; /* Pointer to line-number info within file */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 static long text_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 static long data_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #define ALIGN(val, pwr) (((val) + ((1L<<(pwr))-1)) & ~((1L<<(pwr))-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 static long load_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 static long orig_load_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 static long orig_data_scnptr;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
93 static int unrelocate_symbols (int, int, char *, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #ifndef MAX_SECTIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #define MAX_SECTIONS 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
99 static int adjust_lnnoptrs (int, int, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 static int pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 /* 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
104 into an int which is the number of a byte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 This is a no-op on ordinary machines, but not on all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #ifndef ADDR_CORRECT /* Let m-*.h files override this definition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
114 static void
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
115 report_error (char *file, int fd)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 if (fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif /* emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #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
126
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
127 static void
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
128 report_error_1 (int fd, char *msg, int a1, int a2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 error (msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 fprintf (stderr, msg, a1, a2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
139 static int make_hdr (int, int, unsigned, unsigned, unsigned, char *, char *);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
140 static void mark_x (char *);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
141 static int copy_text_and_data (int);
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
142 static int copy_sym (int, int, char *, char *);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
143 static void write_segment (int, char *, char *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 * unexec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 * driving logic.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 */
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
150 int unexec (char *new_name, char *a_name,
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
151 uintptr_t data_start,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
152 uintptr_t bss_start,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
153 uintptr_t entry_address)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 {
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
155 int new = -1, a_out = -1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
157 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 if ((new = creat (new_name, 0666)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 }
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
165 if (make_hdr (new, a_out,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
166 data_start, bss_start,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
167 entry_address,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
168 a_name, new_name) < 0
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 || copy_text_and_data (new) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 || copy_sym (new, a_out, a_name, new_name) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 || adjust_lnnoptrs (new, a_out, new_name) < 0
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
172 || unrelocate_symbols (new, a_out, a_name, new_name) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 close (a_out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 * make_hdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 * Make the header in the new a.out from the header in core.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 * Modify the text and data sizes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 static int
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
192 make_hdr (int new, int a_out,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
193 unsigned data_start, unsigned bss_start,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
194 unsigned entry_address,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
195 char *a_name, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 int scns;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 unsigned int bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 struct scnhdr section[MAX_SECTIONS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 struct scnhdr * f_thdr; /* Text section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 struct scnhdr * f_dhdr; /* Data section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 struct scnhdr * f_bhdr; /* Bss section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 struct scnhdr * f_lhdr; /* Loader section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 struct scnhdr * f_tchdr; /* Typechk section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 struct scnhdr * f_dbhdr; /* Debug section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 struct scnhdr * f_xhdr; /* Except section header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 load_scnptr = orig_load_scnptr = lnnoptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 pagemask = getpagesize () - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 /* Adjust text/data boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 data_start = (long) start_of_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 data_start = ADDR_CORRECT (data_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 bss_end = ADDR_CORRECT (sbrk (0)) + pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 bss_end &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 /* Adjust data/bss boundary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 if (bss_start != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 bss_start = (ADDR_CORRECT (bss_start) + pagemask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 /* (Up) to page bdry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 bss_start &= ~ pagemask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 if (bss_start > bss_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ERROR1 ("unexec: Specified bss_start (%u) is past end of program",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 bss_start = bss_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 if (data_start > bss_start) /* Can't have negative data size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ERROR2 ("unexec: data_start (%u) can't be greater than bss_start (%u)",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 data_start, bss_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 /* Salvage as much info from the existing file as possible */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 f_thdr = NULL; f_dhdr = NULL; f_bhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 f_lhdr = NULL; f_tchdr = NULL; f_dbhdr = NULL; f_xhdr = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 if (a_out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 PERROR (a_name);
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 (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 if (f_hdr.f_nscns > MAX_SECTIONS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ERROR0 ("unexec: too many section headers -- increase MAX_SECTIONS");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 /* Loop through section headers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 if (read (a_out, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #define CHECK_SCNHDR(ptr, name, flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 if (strcmp(s->s_name, name) == 0) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 if (s->s_flags != flags) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 fprintf(stderr, "unexec: %lx flags where %x expected in %s section.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (unsigned long)s->s_flags, flags, name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 if (ptr) { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 fprintf(stderr, "unexec: duplicate section header for section %s.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ptr = s; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 CHECK_SCNHDR(f_thdr, _TEXT, STYP_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 CHECK_SCNHDR(f_dhdr, _DATA, STYP_DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 CHECK_SCNHDR(f_bhdr, _BSS, STYP_BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 CHECK_SCNHDR(f_lhdr, _LOADER, STYP_LOADER);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 CHECK_SCNHDR(f_dbhdr, _DEBUG, STYP_DEBUG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 CHECK_SCNHDR(f_tchdr, _TYPCHK, STYP_TYPCHK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
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 (f_thdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
292 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _TEXT);
0
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 (f_dhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
296 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _DATA);
0
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 (f_bhdr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
300 ERROR1 ("unexec: couldn't find \"%s\" section", (int) _BSS);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ERROR0 ("can't build a COFF file from scratch yet");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 orig_data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 orig_load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 /* Now we alter the contents of all the f_*hdr variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 to correspond to what we want to dump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 /* Indicate that the reloc information is no longer valid for ld (bind);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 we only update it enough to fake out the exec-time loader. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 f_hdr.f_flags |= (F_RELFLG | F_EXEC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
317 f_ohdr.dsize = bss_start - f_ohdr.data_start;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 f_ohdr.bsize = bss_end - bss_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 f_dhdr->s_size = f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 f_bhdr->s_size = f_ohdr.bsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 f_bhdr->s_paddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 f_bhdr->s_vaddr = f_ohdr.data_start + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 /* fix scnptr's */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ulong ptr = section[0].s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
329 bias = -1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 if (s->s_flags & STYP_PAD) /* .pad sections omitted in AIX 4.1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 * the text_start should probably be o_algntext but that doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 * seem to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 if (f_ohdr.text_start != 0) /* && scns != 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 s->s_size = 512 - (ptr % 512);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 if (s->s_size == 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 s->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 s->s_scnptr = ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
348 else if (s->s_flags & STYP_DATA)
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
349 s->s_scnptr = ptr;
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
350 else if (!(s->s_flags & (STYP_TEXT | STYP_BSS)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 {
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
352 if (bias == -1) /* if first section after bss */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 bias = ptr - s->s_scnptr;
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
354
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
355 s->s_scnptr += bias;
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
356 ptr = s->s_scnptr;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
357 }
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
358
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ptr = ptr + s->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 }
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 /* fix other pointers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 for (scns = 0; scns < f_hdr.f_nscns; scns++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 if (s->s_relptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 s->s_relptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 if (s->s_lnnoptr != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 if (lnnoptr == 0) lnnoptr = s->s_lnnoptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 s->s_lnnoptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 if (f_hdr.f_symptr > 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 f_hdr.f_symptr += bias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 text_scnptr = f_thdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 data_scnptr = f_dhdr->s_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 }
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 (f_hdr.f_opthdr > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 for (scns = 0; scns < f_hdr.f_nscns; scns++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 struct scnhdr *s = &section[scns];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if (write (new, s, sizeof (*s)) != sizeof (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 /* ****************************************************************
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 * Copy the text and data segments from memory to the new a.out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
418 copy_text_and_data (int new)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 char *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
423 lseek (new, (long) text_scnptr, SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ptr = start_of_text () + text_scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 end = ptr + f_ohdr.tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
428 lseek (new, (long) data_scnptr, SEEK_SET);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
429 ptr = (char *) f_ohdr.data_start;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 end = ptr + f_ohdr.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 write_segment (new, ptr, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 return 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 #define UnexBlockSz (1<<12) /* read/write block size */
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
437 static void
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
438 write_segment (int new, char *ptr, char *end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 int i, nwrite, ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 char buf[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 char zeros[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 for (i = 0; ptr < end;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 /* distance to next block. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 nwrite = (((int) ptr + UnexBlockSz) & -UnexBlockSz) - (int) ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 /* But not beyond specified end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 if (nwrite > end - ptr) nwrite = end - ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ret = write (new, ptr, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 /* If write gets a page fault, it means we reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 a gap between the old text segment and the old data segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 This gap has probably been remapped into part of the text segment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 So write zeros for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 if (ret == -1 && errno == EFAULT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 219
diff changeset
458 memset (zeros, 0, nwrite);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 write (new, zeros, nwrite);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 else if (nwrite != ret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 sprintf (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 "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
465 (unsigned long)ptr, new, nwrite, ret, errno);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 PERROR (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 i += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ptr += nwrite;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 * copy_sym
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 * 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
477 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
479 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
480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 char page[UnexBlockSz];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 int n;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 if (a_out < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 if (orig_load_scnptr == 0L)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 if (lnnoptr && lnnoptr < orig_load_scnptr) /* if there is line number info */
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
491 lseek (a_out, lnnoptr, SEEK_SET); /* start copying from there */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 else
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
493 lseek (a_out, orig_load_scnptr, SEEK_SET); /* Position a.out to symtab. */
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 while ((n = read (a_out, page, sizeof page)) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (write (new, page, n) != n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 if (n < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 /* ****************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 static void
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
515 mark_x (char *name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 int um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 int new = 0; /* for PERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (stat (name, &sbuf) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 if (chmod (name, sbuf.st_mode) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 PERROR (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
532 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
533 adjust_lnnoptrs (int writedesc, int readdesc, char *new_name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 int nsyms;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 int naux;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 int new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 struct syment symentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 union auxent auxentry;
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 (!lnnoptr || !f_hdr.f_symptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 286
diff changeset
544 if ((new = open (new_name, O_RDWR)) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
550 lseek (new, f_hdr.f_symptr, SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 read (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 if (symentry.n_sclass == C_BINCL || symentry.n_sclass == C_EINCL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 symentry.n_value += bias;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
557 lseek (new, -SYMESZ, SEEK_CUR);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 write (new, &symentry, SYMESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 294
diff changeset
561 for (naux = symentry.n_numaux; naux-- != 0; )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 read (new, &auxentry, AUXESZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 nsyms++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 if (naux != 0 /* skip csect auxentry (last entry) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 && (symentry.n_sclass == C_EXT || symentry.n_sclass == C_HIDEXT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
569 lseek (new, -AUXESZ, SEEK_CUR);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 write (new, &auxentry, AUXESZ);
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 close (new);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
575
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
576 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
579 static int
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 207
diff changeset
580 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
581 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 LDHDR ldhdr;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
584 LDREL ldrel;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ulong t_reloc = (ulong) &_text - f_ohdr.text_start;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
586 #ifndef ALIGN_DATA_RELOC
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
587 ulong d_reloc = (ulong) &_data - f_ohdr.data_start;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
588 #else
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
589 /* This worked (and was needed) before AIX 4.2.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
590 I have no idea why. -- Mike */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ulong d_reloc = (ulong) &_data - ALIGN(f_ohdr.data_start, 2);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
592 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 int * p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 if (load_scnptr == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
598 lseek (a_out, orig_load_scnptr, SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 if (read (a_out, &ldhdr, sizeof (ldhdr)) != sizeof (ldhdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #define SYMNDX_TEXT 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 #define SYMNDX_DATA 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 #define SYMNDX_BSS 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
608 for (i = 0; i < ldhdr.l_nreloc; i++)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
609 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
610 lseek (a_out,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
611 orig_load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
612 SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
614 if (read (a_out, &ldrel, LDRELSZ) != LDRELSZ)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
615 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
616 PERROR (a_name);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
617 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 /* move the BSS loader symbols to the DATA segment */
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
620 if (ldrel.l_symndx == SYMNDX_BSS)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 {
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
622 ldrel.l_symndx = SYMNDX_DATA;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 lseek (new,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i,
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
626 SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
628 if (write (new, &ldrel, LDRELSZ) != LDRELSZ)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
634 if (ldrel.l_rsecnm == f_ohdr.o_sndata)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 int orig_int;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 lseek (a_out,
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
639 orig_data_scnptr + (ldrel.l_vaddr - f_ohdr.data_start),
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
640 SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 if (read (a_out, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 PERROR (a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
648 p = (int *) (ldrel.l_vaddr + d_reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
650 switch (ldrel.l_symndx) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 case SYMNDX_TEXT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 orig_int = * p - t_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 case SYMNDX_DATA:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 case SYMNDX_BSS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 orig_int = * p - d_reloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 }
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 (orig_int != * p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 lseek (new,
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
664 data_scnptr + (ldrel.l_vaddr - f_ohdr.data_start),
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
665 SEEK_SET);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 if (write (new, (void *) &orig_int, sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 != sizeof (orig_int))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 PERROR (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 }
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 }
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
674 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 }