]>
Commit | Line | Data |
---|---|---|
f9832001 JR |
1 | diff -u -r -x *.orig -x *.rej -x nohup* -x DOC -x *.info* -x config.* -x *.log -x Installation -x Makefile* -x *.el -x *.elc -x *.o -N /tmp/xemacs-20.4/src/gmalloc.c xemacs-20.4/src/gmalloc.c |
2 | --- /tmp/xemacs-20.4/src/gmalloc.c Wed Sep 3 05:39:39 1997 | |
3 | +++ xemacs-20.4/src/gmalloc.c Tue Dec 9 11:02:50 1997 | |
4 | @@ -1288,7 +1288,7 @@ | |
5 | /* It is best not to declare this and cast its result on foreign operating | |
6 | systems with potentially hostile include files. */ | |
7 | #if !(defined(linux) && defined(sparc)) | |
8 | -extern __ptr_t __sbrk __P ((int increment)); | |
9 | +/* extern __ptr_t __sbrk __P ((int increment)); */ | |
10 | #endif | |
11 | #endif | |
12 | #endif | |
13 | diff -u -r -x *.orig -x *.rej -x nohup* -x DOC -x *.info* -x config.* -x *.log -x Installation -x Makefile* -x *.el -x *.elc -x *.o -N /tmp/xemacs-20.4/src/m/alpha.h xemacs-20.4/src/m/alpha.h | |
14 | --- /tmp/xemacs-20.4/src/m/alpha.h Sun Jul 20 00:12:25 1997 | |
15 | +++ xemacs-20.4/src/m/alpha.h Tue Dec 9 11:05:07 1997 | |
16 | @@ -25,7 +25,7 @@ | |
17 | USUAL-OPSYS="note" | |
18 | ||
19 | NOTE-START | |
20 | -Use -opsystem=osf1 | |
21 | +Use -opsystem=linux | |
22 | NOTE-END | |
23 | ||
24 | */ | |
25 | @@ -106,7 +106,14 @@ | |
26 | Define neither one if an assembler-language alloca | |
27 | in the file alloca.s should be used. */ | |
28 | ||
29 | +/* If compiling with GCC, let GCC implement alloca. */ | |
30 | +#if defined(__GNUC__) && !defined(alloca) | |
31 | +#define alloca(n) __builtin_alloca(n) | |
32 | #define HAVE_ALLOCA | |
33 | +#else | |
34 | +#define HAVE_ALLOCA | |
35 | +#endif | |
36 | + | |
37 | ||
38 | /* GNU malloc and the relocating allocator do not work together | |
39 | with X. [Who wrote that?] */ | |
40 | @@ -149,8 +156,10 @@ | |
41 | ||
42 | /* Describe layout of the address space in an executing process. */ | |
43 | ||
44 | +#ifndef __ELF__ | |
45 | #define TEXT_START 0x120000000 | |
46 | #define DATA_START 0x140000000 | |
47 | +#endif | |
48 | ||
49 | #if 0 /* #### XEmacs: see below */ | |
50 | /* This is necessary for mem-limits.h, so that start_of_data gives | |
51 | @@ -174,17 +183,18 @@ | |
52 | ||
53 | #ifdef OSF1 | |
54 | #define LIBS_DEBUG | |
55 | +#define UNEXEC "unexalpha.o" | |
56 | #define START_FILES "pre-crt0.o " | |
57 | #endif /* OSF1 */ | |
58 | ||
59 | #ifdef LINUX | |
60 | /* This controls a conditional in main. */ | |
61 | -#define LINUX_SBRK_BUG | |
62 | +#define UNEXEC unexelf1.o | |
63 | +#undef LINUX_SBRK_BUG */ | |
64 | #endif /* LINUX */ | |
65 | ||
66 | /* The program to be used for unexec. */ | |
67 | ||
68 | -#define UNEXEC "unexalpha.o" | |
69 | ||
70 | #if 0 | |
71 | ||
72 | @@ -218,10 +228,10 @@ | |
73 | while (0) | |
74 | #endif /* OSF1 */ | |
75 | ||
76 | -#ifdef linux | |
77 | +#ifndef linux | |
78 | #define COFF | |
79 | #define TEXT_END ({ extern int _etext; &_etext; }) | |
80 | -#define DATA_END ({ extern int _EDATA; &_EDATA; }) | |
81 | +#define DATA_END ({ extern int _EDATA; &_EDATA; }) */ | |
82 | #endif /* linux */ | |
83 | ||
84 | /* XEmacs: The Dec CC compiler (but apparently not GCC, which uses different | |
85 | diff -u -r -x *.orig -x *.rej -x nohup* -x DOC -x *.info* -x config.* -x *.log -x Installation -x Makefile* -x *.el -x *.elc -x *.o -N /tmp/xemacs-20.4/src/s/linux.h xemacs-20.4/src/s/linux.h | |
86 | --- /tmp/xemacs-20.4/src/s/linux.h Thu Jun 26 04:32:38 1997 | |
87 | +++ xemacs-20.4/src/s/linux.h Tue Dec 9 11:07:11 1997 | |
88 | @@ -145,13 +145,13 @@ | |
89 | #define HAVE_RINT 1 | |
90 | ||
91 | #ifdef __ELF__ | |
92 | -#define UNEXEC "unexelf.o" | |
93 | -#define UNEXEC_USE_MAP_PRIVATE | |
94 | +/* #define UNEXEC "unexelf.o" */ | |
95 | +/* #define UNEXEC_USE_MAP_PRIVATE */ | |
96 | /* mrb - Ordinary link is simple and effective */ | |
97 | -#define ORDINARY_LINK | |
98 | -#undef LIB_STANDARD | |
99 | -#undef START_FILES | |
100 | -#undef LIB_GCC | |
101 | +/* #define ORDINARY_LINK */ | |
102 | +/* #undef LIB_STANDARD */ | |
103 | +/* #undef START_FILES */ | |
104 | +/* #undef LIB_GCC */ | |
105 | #endif /* __ELF__ */ | |
106 | ||
107 | #ifdef LINUX_QMAGIC | |
108 | diff -u -r -x *.orig -x *.rej -x nohup* -x DOC -x *.info* -x config.* -x *.log -x Installation -x Makefile* -x *.el -x *.elc -x *.o -N /tmp/xemacs-20.4/src/unexelf1.c xemacs-20.4/src/unexelf1.c | |
109 | --- /tmp/xemacs-20.4/src/unexelf1.c Thu Jan 1 01:00:00 1970 | |
110 | +++ xemacs-20.4/src/unexelf1.c Tue Dec 9 11:02:51 1997 | |
111 | @@ -0,0 +1,1073 @@ | |
112 | +/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992 | |
113 | + Free Software Foundation, Inc. | |
114 | + | |
115 | +This file is part of GNU Emacs. | |
116 | + | |
117 | +GNU Emacs is free software; you can redistribute it and/or modify | |
118 | +it under the terms of the GNU General Public License as published by | |
119 | +the Free Software Foundation; either version 2, or (at your option) | |
120 | +any later version. | |
121 | + | |
122 | +GNU Emacs is distributed in the hope that it will be useful, | |
123 | +but WITHOUT ANY WARRANTY; without even the implied warranty of | |
124 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
125 | +GNU General Public License for more details. | |
126 | + | |
127 | +You should have received a copy of the GNU General Public License | |
128 | +along with GNU Emacs; see the file COPYING. If not, write to | |
129 | +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
130 | +Boston, MA 02111-1307, USA. | |
131 | + | |
132 | +In other words, you are welcome to use, share and improve this program. | |
133 | +You are forbidden to forbid anyone else to use, share and improve | |
134 | +what you give them. Help stamp out software-hoarding! */ | |
135 | + | |
136 | + | |
137 | +/* | |
138 | + * unexec.c - Convert a running program into an a.out file. | |
139 | + * | |
140 | + * Author: Spencer W. Thomas | |
141 | + * Computer Science Dept. | |
142 | + * University of Utah | |
143 | + * Date: Tue Mar 2 1982 | |
144 | + * Modified heavily since then. | |
145 | + * | |
146 | + * Synopsis: | |
147 | + * unexec (new_name, old_name, data_start, bss_start, entry_address) | |
148 | + * char *new_name, *old_name; | |
149 | + * unsigned data_start, bss_start, entry_address; | |
150 | + * | |
151 | + * Takes a snapshot of the program and makes an a.out format file in the | |
152 | + * file named by the string argument new_name. | |
153 | + * If old_name is non-NULL, the symbol table will be taken from the given file. | |
154 | + * On some machines, an existing old_name file is required. | |
155 | + * | |
156 | + * The boundaries within the a.out file may be adjusted with the data_start | |
157 | + * and bss_start arguments. Either or both may be given as 0 for defaults. | |
158 | + * | |
159 | + * Data_start gives the boundary between the text segment and the data | |
160 | + * segment of the program. The text segment can contain shared, read-only | |
161 | + * program code and literal data, while the data segment is always unshared | |
162 | + * and unprotected. Data_start gives the lowest unprotected address. | |
163 | + * The value you specify may be rounded down to a suitable boundary | |
164 | + * as required by the machine you are using. | |
165 | + * | |
166 | + * Specifying zero for data_start means the boundary between text and data | |
167 | + * should not be the same as when the program was loaded. | |
168 | + * If NO_REMAP is defined, the argument data_start is ignored and the | |
169 | + * segment boundaries are never changed. | |
170 | + * | |
171 | + * Bss_start indicates how much of the data segment is to be saved in the | |
172 | + * a.out file and restored when the program is executed. It gives the lowest | |
173 | + * unsaved address, and is rounded up to a page boundary. The default when 0 | |
174 | + * is given assumes that the entire data segment is to be stored, including | |
175 | + * the previous data and bss as well as any additional storage allocated with | |
176 | + * break (2). | |
177 | + * | |
178 | + * The new file is set up to start at entry_address. | |
179 | + * | |
180 | + * If you make improvements I'd like to get them too. | |
181 | + * harpo!utah-cs!thomas, thomas@Utah-20 | |
182 | + * | |
183 | + */ | |
184 | + | |
185 | +/* Even more heavily modified by james@bigtex.cactus.org of Dell Computer Co. | |
186 | + * ELF support added. | |
187 | + * | |
188 | + * Basic theory: the data space of the running process needs to be | |
189 | + * dumped to the output file. Normally we would just enlarge the size | |
190 | + * of .data, scooting everything down. But we can't do that in ELF, | |
191 | + * because there is often something between the .data space and the | |
192 | + * .bss space. | |
193 | + * | |
194 | + * In the temacs dump below, notice that the Global Offset Table | |
195 | + * (.got) and the Dynamic link data (.dynamic) come between .data1 and | |
196 | + * .bss. It does not work to overlap .data with these fields. | |
197 | + * | |
198 | + * The solution is to create a new .data segment. This segment is | |
199 | + * filled with data from the current process. Since the contents of | |
200 | + * various sections refer to sections by index, the new .data segment | |
201 | + * is made the last in the table to avoid changing any existing index. | |
202 | + | |
203 | + * This is an example of how the section headers are changed. "Addr" | |
204 | + * is a process virtual address. "Offset" is a file offset. | |
205 | + | |
206 | +raid:/nfs/raid/src/dist-18.56/src> dump -h temacs | |
207 | + | |
208 | +temacs: | |
209 | + | |
210 | + **** SECTION HEADER TABLE **** | |
211 | +[No] Type Flags Addr Offset Size Name | |
212 | + Link Info Adralgn Entsize | |
213 | + | |
214 | +[1] 1 2 0x80480d4 0xd4 0x13 .interp | |
215 | + 0 0 0x1 0 | |
216 | + | |
217 | +[2] 5 2 0x80480e8 0xe8 0x388 .hash | |
218 | + 3 0 0x4 0x4 | |
219 | + | |
220 | +[3] 11 2 0x8048470 0x470 0x7f0 .dynsym | |
221 | + 4 1 0x4 0x10 | |
222 | + | |
223 | +[4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | |
224 | + 0 0 0x1 0 | |
225 | + | |
226 | +[5] 9 2 0x8049010 0x1010 0x338 .rel.plt | |
227 | + 3 7 0x4 0x8 | |
228 | + | |
229 | +[6] 1 6 0x8049348 0x1348 0x3 .init | |
230 | + 0 0 0x4 0 | |
231 | + | |
232 | +[7] 1 6 0x804934c 0x134c 0x680 .plt | |
233 | + 0 0 0x4 0x4 | |
234 | + | |
235 | +[8] 1 6 0x80499cc 0x19cc 0x3c56f .text | |
236 | + 0 0 0x4 0 | |
237 | + | |
238 | +[9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | |
239 | + 0 0 0x4 0 | |
240 | + | |
241 | +[10] 1 2 0x8085f40 0x3df40 0x69c .rodata | |
242 | + 0 0 0x4 0 | |
243 | + | |
244 | +[11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | |
245 | + 0 0 0x4 0 | |
246 | + | |
247 | +[12] 1 3 0x8088330 0x3f330 0x20afc .data | |
248 | + 0 0 0x4 0 | |
249 | + | |
250 | +[13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | |
251 | + 0 0 0x4 0 | |
252 | + | |
253 | +[14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | |
254 | + 0 0 0x4 0x4 | |
255 | + | |
256 | +[15] 6 3 0x80a9874 0x60874 0x80 .dynamic | |
257 | + 4 0 0x4 0x8 | |
258 | + | |
259 | +[16] 8 3 0x80a98f4 0x608f4 0x449c .bss | |
260 | + 0 0 0x4 0 | |
261 | + | |
262 | +[17] 2 0 0 0x608f4 0x9b90 .symtab | |
263 | + 18 371 0x4 0x10 | |
264 | + | |
265 | +[18] 3 0 0 0x6a484 0x8526 .strtab | |
266 | + 0 0 0x1 0 | |
267 | + | |
268 | +[19] 3 0 0 0x729aa 0x93 .shstrtab | |
269 | + 0 0 0x1 0 | |
270 | + | |
271 | +[20] 1 0 0 0x72a3d 0x68b7 .comment | |
272 | + 0 0 0x1 0 | |
273 | + | |
274 | +raid:/nfs/raid/src/dist-18.56/src> dump -h xemacs | |
275 | + | |
276 | +xemacs: | |
277 | + | |
278 | + **** SECTION HEADER TABLE **** | |
279 | +[No] Type Flags Addr Offset Size Name | |
280 | + Link Info Adralgn Entsize | |
281 | + | |
282 | +[1] 1 2 0x80480d4 0xd4 0x13 .interp | |
283 | + 0 0 0x1 0 | |
284 | + | |
285 | +[2] 5 2 0x80480e8 0xe8 0x388 .hash | |
286 | + 3 0 0x4 0x4 | |
287 | + | |
288 | +[3] 11 2 0x8048470 0x470 0x7f0 .dynsym | |
289 | + 4 1 0x4 0x10 | |
290 | + | |
291 | +[4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | |
292 | + 0 0 0x1 0 | |
293 | + | |
294 | +[5] 9 2 0x8049010 0x1010 0x338 .rel.plt | |
295 | + 3 7 0x4 0x8 | |
296 | + | |
297 | +[6] 1 6 0x8049348 0x1348 0x3 .init | |
298 | + 0 0 0x4 0 | |
299 | + | |
300 | +[7] 1 6 0x804934c 0x134c 0x680 .plt | |
301 | + 0 0 0x4 0x4 | |
302 | + | |
303 | +[8] 1 6 0x80499cc 0x19cc 0x3c56f .text | |
304 | + 0 0 0x4 0 | |
305 | + | |
306 | +[9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | |
307 | + 0 0 0x4 0 | |
308 | + | |
309 | +[10] 1 2 0x8085f40 0x3df40 0x69c .rodata | |
310 | + 0 0 0x4 0 | |
311 | + | |
312 | +[11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | |
313 | + 0 0 0x4 0 | |
314 | + | |
315 | +[12] 1 3 0x8088330 0x3f330 0x20afc .data | |
316 | + 0 0 0x4 0 | |
317 | + | |
318 | +[13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | |
319 | + 0 0 0x4 0 | |
320 | + | |
321 | +[14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | |
322 | + 0 0 0x4 0x4 | |
323 | + | |
324 | +[15] 6 3 0x80a9874 0x60874 0x80 .dynamic | |
325 | + 4 0 0x4 0x8 | |
326 | + | |
327 | +[16] 8 3 0x80c6800 0x7d800 0 .bss | |
328 | + 0 0 0x4 0 | |
329 | + | |
330 | +[17] 2 0 0 0x7d800 0x9b90 .symtab | |
331 | + 18 371 0x4 0x10 | |
332 | + | |
333 | +[18] 3 0 0 0x87390 0x8526 .strtab | |
334 | + 0 0 0x1 0 | |
335 | + | |
336 | +[19] 3 0 0 0x8f8b6 0x93 .shstrtab | |
337 | + 0 0 0x1 0 | |
338 | + | |
339 | +[20] 1 0 0 0x8f949 0x68b7 .comment | |
340 | + 0 0 0x1 0 | |
341 | + | |
342 | +[21] 1 3 0x80a98f4 0x608f4 0x1cf0c .data | |
343 | + 0 0 0x4 0 | |
344 | + | |
345 | + * This is an example of how the file header is changed. "Shoff" is | |
346 | + * the section header offset within the file. Since that table is | |
347 | + * after the new .data section, it is moved. "Shnum" is the number of | |
348 | + * sections, which we increment. | |
349 | + * | |
350 | + * "Phoff" is the file offset to the program header. "Phentsize" and | |
351 | + * "Shentsz" are the program and section header entries sizes respectively. | |
352 | + * These can be larger than the apparent struct sizes. | |
353 | + | |
354 | +raid:/nfs/raid/src/dist-18.56/src> dump -f temacs | |
355 | + | |
356 | +temacs: | |
357 | + | |
358 | + **** ELF HEADER **** | |
359 | +Class Data Type Machine Version | |
360 | +Entry Phoff Shoff Flags Ehsize | |
361 | +Phentsize Phnum Shentsz Shnum Shstrndx | |
362 | + | |
363 | +1 1 2 3 1 | |
364 | +0x80499cc 0x34 0x792f4 0 0x34 | |
365 | +0x20 5 0x28 21 19 | |
366 | + | |
367 | +raid:/nfs/raid/src/dist-18.56/src> dump -f xemacs | |
368 | + | |
369 | +xemacs: | |
370 | + | |
371 | + **** ELF HEADER **** | |
372 | +Class Data Type Machine Version | |
373 | +Entry Phoff Shoff Flags Ehsize | |
374 | +Phentsize Phnum Shentsz Shnum Shstrndx | |
375 | + | |
376 | +1 1 2 3 1 | |
377 | +0x80499cc 0x34 0x96200 0 0x34 | |
378 | +0x20 5 0x28 22 19 | |
379 | + | |
380 | + * These are the program headers. "Offset" is the file offset to the | |
381 | + * segment. "Vaddr" is the memory load address. "Filesz" is the | |
382 | + * segment size as it appears in the file, and "Memsz" is the size in | |
383 | + * memory. Below, the third segment is the code and the fourth is the | |
384 | + * data: the difference between Filesz and Memsz is .bss | |
385 | + | |
386 | +raid:/nfs/raid/src/dist-18.56/src> dump -o temacs | |
387 | + | |
388 | +temacs: | |
389 | + ***** PROGRAM EXECUTION HEADER ***** | |
390 | +Type Offset Vaddr Paddr | |
391 | +Filesz Memsz Flags Align | |
392 | + | |
393 | +6 0x34 0x8048034 0 | |
394 | +0xa0 0xa0 5 0 | |
395 | + | |
396 | +3 0xd4 0 0 | |
397 | +0x13 0 4 0 | |
398 | + | |
399 | +1 0x34 0x8048034 0 | |
400 | +0x3f2f9 0x3f2f9 5 0x1000 | |
401 | + | |
402 | +1 0x3f330 0x8088330 0 | |
403 | +0x215c4 0x25a60 7 0x1000 | |
404 | + | |
405 | +2 0x60874 0x80a9874 0 | |
406 | +0x80 0 7 0 | |
407 | + | |
408 | +raid:/nfs/raid/src/dist-18.56/src> dump -o xemacs | |
409 | + | |
410 | +xemacs: | |
411 | + ***** PROGRAM EXECUTION HEADER ***** | |
412 | +Type Offset Vaddr Paddr | |
413 | +Filesz Memsz Flags Align | |
414 | + | |
415 | +6 0x34 0x8048034 0 | |
416 | +0xa0 0xa0 5 0 | |
417 | + | |
418 | +3 0xd4 0 0 | |
419 | +0x13 0 4 0 | |
420 | + | |
421 | +1 0x34 0x8048034 0 | |
422 | +0x3f2f9 0x3f2f9 5 0x1000 | |
423 | + | |
424 | +1 0x3f330 0x8088330 0 | |
425 | +0x3e4d0 0x3e4d0 7 0x1000 | |
426 | + | |
427 | +2 0x60874 0x80a9874 0 | |
428 | +0x80 0 7 0 | |
429 | + | |
430 | + | |
431 | + */ | |
432 | +\f | |
433 | +/* Modified by wtien@urbana.mcd.mot.com of Motorola Inc. | |
434 | + * | |
435 | + * The above mechanism does not work if the unexeced ELF file is being | |
436 | + * re-layout by other applications (such as `strip'). All the applications | |
437 | + * that re-layout the internal of ELF will layout all sections in ascending | |
438 | + * order of their file offsets. After the re-layout, the data2 section will | |
439 | + * still be the LAST section in the section header vector, but its file offset | |
440 | + * is now being pushed far away down, and causes part of it not to be mapped | |
441 | + * in (ie. not covered by the load segment entry in PHDR vector), therefore | |
442 | + * causes the new binary to fail. | |
443 | + * | |
444 | + * The solution is to modify the unexec algorithm to insert the new data2 | |
445 | + * section header right before the new bss section header, so their file | |
446 | + * offsets will be in the ascending order. Since some of the section's (all | |
447 | + * sections AFTER the bss section) indexes are now changed, we also need to | |
448 | + * modify some fields to make them point to the right sections. This is done | |
449 | + * by macro PATCH_INDEX. All the fields that need to be patched are: | |
450 | + * | |
451 | + * 1. ELF header e_shstrndx field. | |
452 | + * 2. section header sh_link and sh_info field. | |
453 | + * 3. symbol table entry st_shndx field. | |
454 | + * | |
455 | + * The above example now should look like: | |
456 | + | |
457 | + **** SECTION HEADER TABLE **** | |
458 | +[No] Type Flags Addr Offset Size Name | |
459 | + Link Info Adralgn Entsize | |
460 | + | |
461 | +[1] 1 2 0x80480d4 0xd4 0x13 .interp | |
462 | + 0 0 0x1 0 | |
463 | + | |
464 | +[2] 5 2 0x80480e8 0xe8 0x388 .hash | |
465 | + 3 0 0x4 0x4 | |
466 | + | |
467 | +[3] 11 2 0x8048470 0x470 0x7f0 .dynsym | |
468 | + 4 1 0x4 0x10 | |
469 | + | |
470 | +[4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | |
471 | + 0 0 0x1 0 | |
472 | + | |
473 | +[5] 9 2 0x8049010 0x1010 0x338 .rel.plt | |
474 | + 3 7 0x4 0x8 | |
475 | + | |
476 | +[6] 1 6 0x8049348 0x1348 0x3 .init | |
477 | + 0 0 0x4 0 | |
478 | + | |
479 | +[7] 1 6 0x804934c 0x134c 0x680 .plt | |
480 | + 0 0 0x4 0x4 | |
481 | + | |
482 | +[8] 1 6 0x80499cc 0x19cc 0x3c56f .text | |
483 | + 0 0 0x4 0 | |
484 | + | |
485 | +[9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | |
486 | + 0 0 0x4 0 | |
487 | + | |
488 | +[10] 1 2 0x8085f40 0x3df40 0x69c .rodata | |
489 | + 0 0 0x4 0 | |
490 | + | |
491 | +[11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | |
492 | + 0 0 0x4 0 | |
493 | + | |
494 | +[12] 1 3 0x8088330 0x3f330 0x20afc .data | |
495 | + 0 0 0x4 0 | |
496 | + | |
497 | +[13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | |
498 | + 0 0 0x4 0 | |
499 | + | |
500 | +[14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | |
501 | + 0 0 0x4 0x4 | |
502 | + | |
503 | +[15] 6 3 0x80a9874 0x60874 0x80 .dynamic | |
504 | + 4 0 0x4 0x8 | |
505 | + | |
506 | +[16] 1 3 0x80a98f4 0x608f4 0x1cf0c .data | |
507 | + 0 0 0x4 0 | |
508 | + | |
509 | +[17] 8 3 0x80c6800 0x7d800 0 .bss | |
510 | + 0 0 0x4 0 | |
511 | + | |
512 | +[18] 2 0 0 0x7d800 0x9b90 .symtab | |
513 | + 19 371 0x4 0x10 | |
514 | + | |
515 | +[19] 3 0 0 0x87390 0x8526 .strtab | |
516 | + 0 0 0x1 0 | |
517 | + | |
518 | +[20] 3 0 0 0x8f8b6 0x93 .shstrtab | |
519 | + 0 0 0x1 0 | |
520 | + | |
521 | +[21] 1 0 0 0x8f949 0x68b7 .comment | |
522 | + 0 0 0x1 0 | |
523 | + | |
524 | + */ | |
525 | +\f | |
526 | +#include <sys/types.h> | |
527 | +#include <stdio.h> | |
528 | +#include <sys/stat.h> | |
529 | +#include <memory.h> | |
530 | +#include <string.h> | |
531 | +#include <errno.h> | |
532 | +#include <unistd.h> | |
533 | +#include <fcntl.h> | |
534 | +#if !defined (__NetBSD__) && !defined (__OpenBSD__) | |
535 | +#include <elf.h> | |
536 | +#endif | |
537 | +#include <sys/mman.h> | |
538 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
539 | +#include <sys/elf_mips.h> | |
540 | +#include <sym.h> | |
541 | +#endif /* __sony_news && _SYSTYPE_SYSV */ | |
542 | + | |
543 | +#ifdef __NetBSD__ | |
544 | +/* | |
545 | + * NetBSD does not have normal-looking user-land ELF support. | |
546 | + */ | |
547 | +# ifdef __alpha__ | |
548 | +# define ELFSIZE 64 | |
549 | +# else | |
550 | +# define ELFSIZE 32 | |
551 | +# endif | |
552 | +# include <sys/exec_elf.h> | |
553 | + | |
554 | +# define PT_LOAD Elf_pt_load | |
555 | +# define SHT_SYMTAB Elf_sht_symtab | |
556 | +# define SHT_DYNSYM Elf_sht_dynsym | |
557 | +# define SHT_NULL Elf_sht_null | |
558 | +# define SHT_NOBITS Elf_sht_nobits | |
559 | +# define SHT_REL Elf_sht_rel | |
560 | +# define SHT_RELA Elf_sht_rela | |
561 | + | |
562 | +# define SHN_UNDEF Elf_eshn_undefined | |
563 | +# define SHN_ABS Elf_eshn_absolute | |
564 | +# define SHN_COMMON Elf_eshn_common | |
565 | + | |
566 | +/* | |
567 | + * The magic of picking the right size types is handled by the ELFSIZE | |
568 | + * definition above. | |
569 | + */ | |
570 | +# ifdef __STDC__ | |
571 | +# define ElfW(type) Elf_##type | |
572 | +# else | |
573 | +# define ElfW(type) Elf_/**/type | |
574 | +# endif | |
575 | + | |
576 | +# ifdef __alpha__ | |
577 | +# include <sys/exec_ecoff.h> | |
578 | +# define HDRR struct ecoff_symhdr | |
579 | +# define pHDRR HDRR * | |
580 | +# endif | |
581 | +#endif /* __NetBSD__ */ | |
582 | + | |
583 | +#ifdef __OpenBSD__ | |
584 | +# include <sys/exec_elf.h> | |
585 | +#endif | |
586 | + | |
587 | +#if __GNU_LIBRARY__ - 0 >= 6 | |
588 | +# include <link.h> /* get ElfW etc */ | |
589 | +#endif | |
590 | + | |
591 | +#ifndef ElfW | |
592 | +# ifdef __STDC__ | |
593 | +# define ElfW(type) Elf32_##type | |
594 | +# else | |
595 | +# define ElfW(type) Elf32_/**/type | |
596 | +# endif | |
597 | +#endif | |
598 | + | |
599 | +#ifndef emacs | |
600 | +#define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) | |
601 | +#else | |
602 | +#include <config.h> | |
603 | +extern void fatal (char *, ...); | |
604 | +#endif | |
605 | + | |
606 | +#ifndef ELF_BSS_SECTION_NAME | |
607 | +#define ELF_BSS_SECTION_NAME ".bss" | |
608 | +#endif | |
609 | + | |
610 | +/* Get the address of a particular section or program header entry, | |
611 | + * accounting for the size of the entries. | |
612 | + */ | |
613 | +/* | |
614 | + On PPC Reference Platform running Solaris 2.5.1 | |
615 | + the plt section is also of type NOBI like the bss section. | |
616 | + (not really stored) and therefore sections after the bss | |
617 | + section start at the plt offset. The plt section is always | |
618 | + the one just before the bss section. | |
619 | + Thus, we modify the test from | |
620 | + if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) | |
621 | + to | |
622 | + if (NEW_SECTION_H (nn).sh_offset >= | |
623 | + OLD_SECTION_H (old_bss_index-1).sh_offset) | |
624 | + This is just a hack. We should put the new data section | |
625 | + before the .plt section. | |
626 | + And we should not have this routine at all but use | |
627 | + the libelf library to read the old file and create the new | |
628 | + file. | |
629 | + The changed code is minimal and depends on prep set in m/prep.h | |
630 | + Erik Deumens | |
631 | + Quantum Theory Project | |
632 | + University of Florida | |
633 | + deumens@qtp.ufl.edu | |
634 | + Apr 23, 1996 | |
635 | + */ | |
636 | + | |
637 | +#define OLD_SECTION_H(n) \ | |
638 | + (*(ElfW(Shdr) *) ((byte *) old_section_h + old_file_h->e_shentsize * (n))) | |
639 | +#define NEW_SECTION_H(n) \ | |
640 | + (*(ElfW(Shdr) *) ((byte *) new_section_h + new_file_h->e_shentsize * (n))) | |
641 | +#define OLD_PROGRAM_H(n) \ | |
642 | + (*(ElfW(Phdr) *) ((byte *) old_program_h + old_file_h->e_phentsize * (n))) | |
643 | +#define NEW_PROGRAM_H(n) \ | |
644 | + (*(ElfW(Phdr) *) ((byte *) new_program_h + new_file_h->e_phentsize * (n))) | |
645 | + | |
646 | +#define PATCH_INDEX(n) \ | |
647 | + do { \ | |
648 | + if ((int) (n) >= old_bss_index) \ | |
649 | + (n)++; } while (0) | |
650 | +typedef unsigned char byte; | |
651 | + | |
652 | +/* Round X up to a multiple of Y. */ | |
653 | + | |
654 | +int | |
655 | +round_up (x, y) | |
656 | + int x, y; | |
657 | +{ | |
658 | + int rem = x % y; | |
659 | + if (rem == 0) | |
660 | + return x; | |
661 | + return x - rem + y; | |
662 | +} | |
663 | + | |
664 | +/* **************************************************************** | |
665 | + * unexec | |
666 | + * | |
667 | + * driving logic. | |
668 | + * | |
669 | + * In ELF, this works by replacing the old .bss section with a new | |
670 | + * .data section, and inserting an empty .bss immediately afterwards. | |
671 | + * | |
672 | + */ | |
673 | +void | |
674 | +unexec (new_name, old_name, data_start, bss_start, entry_address) | |
675 | + char *new_name, *old_name; | |
676 | + unsigned data_start, bss_start, entry_address; | |
677 | +{ | |
678 | + int new_file, old_file, new_file_size; | |
679 | + | |
680 | + /* Pointers to the base of the image of the two files. */ | |
681 | + caddr_t old_base, new_base; | |
682 | + | |
683 | + /* Pointers to the file, program and section headers for the old and new | |
684 | + * files. | |
685 | + */ | |
686 | + ElfW(Ehdr) *old_file_h, *new_file_h; | |
687 | + ElfW(Phdr) *old_program_h, *new_program_h; | |
688 | + ElfW(Shdr) *old_section_h, *new_section_h; | |
689 | + | |
690 | + /* Point to the section name table in the old file */ | |
691 | + char *old_section_names; | |
692 | + | |
693 | + ElfW(Addr) old_bss_addr, new_bss_addr; | |
694 | + ElfW(Word) old_bss_size, new_data2_size; | |
695 | + ElfW(Off) new_data2_offset; | |
696 | + ElfW(Addr) new_data2_addr; | |
697 | + | |
698 | + int n, nn, old_bss_index, old_data_index, new_data2_index; | |
699 | +#if defined ( __sony_news) && defined (_SYSTYPE_SYSV) | |
700 | + int old_sbss_index, old_mdebug_index; | |
701 | +#endif /* __sony_news && _SYSTYPE_SYSV */ | |
702 | + struct stat stat_buf; | |
703 | + | |
704 | + /* Open the old file & map it into the address space. */ | |
705 | + | |
706 | + old_file = open (old_name, O_RDONLY); | |
707 | + | |
708 | + if (old_file < 0) | |
709 | + fatal ("Can't open %s for reading: errno %d\n", old_name, errno); | |
710 | + | |
711 | + if (fstat (old_file, &stat_buf) == -1) | |
712 | + fatal ("Can't fstat (%s): errno %d\n", old_name, errno); | |
713 | + | |
714 | + old_base = mmap ((caddr_t) 0, stat_buf.st_size, PROT_READ, MAP_SHARED, | |
715 | + old_file, 0); | |
716 | + | |
717 | + if (old_base == (caddr_t) -1) | |
718 | + fatal ("Can't mmap (%s): errno %d\n", old_name, errno); | |
719 | + | |
720 | +#ifdef DEBUG | |
721 | + fprintf (stderr, "mmap (%s, %x) -> %x\n", old_name, stat_buf.st_size, | |
722 | + old_base); | |
723 | +#endif | |
724 | + | |
725 | + /* Get pointers to headers & section names */ | |
726 | + | |
727 | + old_file_h = (ElfW(Ehdr) *) old_base; | |
728 | + old_program_h = (ElfW(Phdr) *) ((byte *) old_base + old_file_h->e_phoff); | |
729 | + old_section_h = (ElfW(Shdr) *) ((byte *) old_base + old_file_h->e_shoff); | |
730 | + old_section_names = (char *) old_base | |
731 | + + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; | |
732 | + | |
733 | + /* Find the old .bss section. Figure out parameters of the new | |
734 | + * data2 and bss sections. | |
735 | + */ | |
736 | + | |
737 | + for (old_bss_index = 1; old_bss_index < (int) old_file_h->e_shnum; | |
738 | + old_bss_index++) | |
739 | + { | |
740 | +#ifdef DEBUG | |
741 | + fprintf (stderr, "Looking for .bss - found %s\n", | |
742 | + old_section_names + OLD_SECTION_H (old_bss_index).sh_name); | |
743 | +#endif | |
744 | + if (!strcmp (old_section_names + OLD_SECTION_H (old_bss_index).sh_name, | |
745 | + ELF_BSS_SECTION_NAME)) | |
746 | + break; | |
747 | + } | |
748 | + if (old_bss_index == old_file_h->e_shnum) | |
749 | + fatal ("Can't find .bss in %s.\n", old_name, 0); | |
750 | + | |
751 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
752 | + for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum; | |
753 | + old_sbss_index++) | |
754 | + { | |
755 | +#ifdef DEBUG | |
756 | + fprintf (stderr, "Looking for .sbss - found %s\n", | |
757 | + old_section_names + OLD_SECTION_H (old_sbss_index).sh_name); | |
758 | +#endif | |
759 | + if (!strcmp (old_section_names + OLD_SECTION_H (old_sbss_index).sh_name, | |
760 | + ".sbss")) | |
761 | + break; | |
762 | + } | |
763 | + if (old_sbss_index == old_file_h->e_shnum) | |
764 | + { | |
765 | + old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr; | |
766 | + old_bss_size = OLD_SECTION_H(old_bss_index).sh_size; | |
767 | + new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset; | |
768 | + new_data2_index = old_bss_index; | |
769 | + } | |
770 | + else | |
771 | + { | |
772 | + old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr; | |
773 | + old_bss_size = OLD_SECTION_H(old_bss_index).sh_size | |
774 | + + OLD_SECTION_H(old_sbss_index).sh_size; | |
775 | + new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset; | |
776 | + new_data2_index = old_sbss_index; | |
777 | + } | |
778 | + | |
779 | + for (old_mdebug_index = 1; old_mdebug_index < (int) old_file_h->e_shnum; | |
780 | + old_mdebug_index++) | |
781 | + { | |
782 | +#ifdef DEBUG | |
783 | + fprintf (stderr, "Looking for .mdebug - found %s\n", | |
784 | + old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name); | |
785 | +#endif | |
786 | + if (!strcmp (old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name, | |
787 | + ".mdebug")) | |
788 | + break; | |
789 | + } | |
790 | + if (old_mdebug_index == old_file_h->e_shnum) | |
791 | + old_mdebug_index = 0; | |
792 | +#else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
793 | + old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; | |
794 | + old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; | |
795 | +#endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
796 | +#if defined (emacs) || !defined (DEBUG) | |
797 | + new_bss_addr = (ElfW(Addr)) sbrk (0); | |
798 | +#else | |
799 | + new_bss_addr = old_bss_addr + old_bss_size + 0x1234; | |
800 | +#endif | |
801 | + new_data2_addr = old_bss_addr; | |
802 | + new_data2_size = new_bss_addr - old_bss_addr; | |
803 | +#if !defined (__sony_news) || !defined (_SYSTYPE_SYSV) | |
804 | + new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset; | |
805 | +#endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
806 | + | |
807 | +#ifdef DEBUG | |
808 | + fprintf (stderr, "old_bss_index %d\n", old_bss_index); | |
809 | + fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); | |
810 | + fprintf (stderr, "old_bss_size %x\n", old_bss_size); | |
811 | + fprintf (stderr, "new_bss_addr %x\n", new_bss_addr); | |
812 | + fprintf (stderr, "new_data2_addr %x\n", new_data2_addr); | |
813 | + fprintf (stderr, "new_data2_size %x\n", new_data2_size); | |
814 | + fprintf (stderr, "new_data2_offset %x\n", new_data2_offset); | |
815 | +#endif | |
816 | + | |
817 | + if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size) | |
818 | + fatal (".bss shrank when undumping???\n", 0, 0); | |
819 | + | |
820 | + /* Set the output file to the right size and mmap it. Set | |
821 | + * pointers to various interesting objects. stat_buf still has | |
822 | + * old_file data. | |
823 | + */ | |
824 | + | |
825 | + new_file = open (new_name, O_RDWR | O_CREAT, 0666); | |
826 | + if (new_file < 0) | |
827 | + fatal ("Can't creat (%s): errno %d\n", new_name, errno); | |
828 | + | |
829 | + new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_size; | |
830 | + | |
831 | + if (ftruncate (new_file, new_file_size)) | |
832 | + fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno); | |
833 | + | |
834 | +#ifdef UNEXEC_USE_MAP_PRIVATE | |
835 | + new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE, | |
836 | + MAP_PRIVATE, new_file, 0); | |
837 | +#else | |
838 | + new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE, | |
839 | + MAP_SHARED, new_file, 0); | |
840 | +#endif | |
841 | + | |
842 | + if (new_base == (caddr_t) -1) | |
843 | + fatal ("Can't mmap (%s): errno %d\n", new_name, errno); | |
844 | + | |
845 | + new_file_h = (ElfW(Ehdr) *) new_base; | |
846 | + new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff); | |
847 | + new_section_h = (ElfW(Shdr) *) | |
848 | + ((byte *) new_base + old_file_h->e_shoff + new_data2_size); | |
849 | + | |
850 | + /* Make our new file, program and section headers as copies of the | |
851 | + * originals. | |
852 | + */ | |
853 | + | |
854 | + memcpy (new_file_h, old_file_h, old_file_h->e_ehsize); | |
855 | + memcpy (new_program_h, old_program_h, | |
856 | + old_file_h->e_phnum * old_file_h->e_phentsize); | |
857 | + | |
858 | + /* Modify the e_shstrndx if necessary. */ | |
859 | + PATCH_INDEX (new_file_h->e_shstrndx); | |
860 | + | |
861 | + /* Fix up file header. We'll add one section. Section header is | |
862 | + * further away now. | |
863 | + */ | |
864 | + | |
865 | + new_file_h->e_shoff += new_data2_size; | |
866 | + new_file_h->e_shnum += 1; | |
867 | + | |
868 | +#ifdef DEBUG | |
869 | + fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff); | |
870 | + fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum); | |
871 | + fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff); | |
872 | + fprintf (stderr, "New section count %d\n", new_file_h->e_shnum); | |
873 | +#endif | |
874 | + | |
875 | + /* Fix up a new program header. Extend the writable data segment so | |
876 | + * that the bss area is covered too. Find that segment by looking | |
877 | + * for a segment that ends just before the .bss area. Make sure | |
878 | + * that no segments are above the new .data2. Put a loop at the end | |
879 | + * to adjust the offset and address of any segment that is above | |
880 | + * data2, just in case we decide to allow this later. | |
881 | + */ | |
882 | + | |
883 | + for (n = new_file_h->e_phnum - 1; n >= 0; n--) | |
884 | + { | |
885 | + /* Compute maximum of all requirements for alignment of section. */ | |
886 | + int alignment = (NEW_PROGRAM_H (n)).p_align; | |
887 | + if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) | |
888 | + alignment = OLD_SECTION_H (old_bss_index).sh_addralign; | |
889 | + | |
890 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
891 | + if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz | |
892 | + > round_up (old_bss_addr, alignment)) | |
893 | + fatal ("Program segment above .bss in %s\n", old_name, 0); | |
894 | +#else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
895 | + if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr) | |
896 | + fatal ("Program segment above .bss in %s\n", old_name, 0); | |
897 | +#endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
898 | + | |
899 | + if (NEW_PROGRAM_H (n).p_type == PT_LOAD | |
900 | + && (round_up ((NEW_PROGRAM_H (n)).p_vaddr | |
901 | + + (NEW_PROGRAM_H (n)).p_filesz, | |
902 | + alignment) | |
903 | + == round_up (old_bss_addr, alignment))) | |
904 | + break; | |
905 | + } | |
906 | + if (n < 0) | |
907 | + fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0); | |
908 | + | |
909 | + NEW_PROGRAM_H (n).p_filesz += new_data2_size; | |
910 | + NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz; | |
911 | + | |
912 | +#if 0 /* Maybe allow section after data2 - does this ever happen? */ | |
913 | + for (n = new_file_h->e_phnum - 1; n >= 0; n--) | |
914 | + { | |
915 | + if (NEW_PROGRAM_H (n).p_vaddr | |
916 | + && NEW_PROGRAM_H (n).p_vaddr >= new_data2_addr) | |
917 | + NEW_PROGRAM_H (n).p_vaddr += new_data2_size - old_bss_size; | |
918 | + | |
919 | + if (NEW_PROGRAM_H (n).p_offset >= new_data2_offset) | |
920 | + NEW_PROGRAM_H (n).p_offset += new_data2_size; | |
921 | + } | |
922 | +#endif | |
923 | + | |
924 | + /* Fix up section headers based on new .data2 section. Any section | |
925 | + * whose offset or virtual address is after the new .data2 section | |
926 | + * gets its value adjusted. .bss size becomes zero and new address | |
927 | + * is set. data2 section header gets added by copying the existing | |
928 | + * .data header and modifying the offset, address and size. | |
929 | + */ | |
930 | + for (old_data_index = 1; old_data_index < (int) old_file_h->e_shnum; | |
931 | + old_data_index++) | |
932 | + if (!strcmp (old_section_names + OLD_SECTION_H (old_data_index).sh_name, | |
933 | + ".data")) | |
934 | + break; | |
935 | + if (old_data_index == old_file_h->e_shnum) | |
936 | + fatal ("Can't find .data in %s.\n", old_name, 0); | |
937 | + | |
938 | + /* Walk through all section headers, insert the new data2 section right | |
939 | + before the new bss section. */ | |
940 | + for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) | |
941 | + { | |
942 | + caddr_t src; | |
943 | + int temp_index; | |
944 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
945 | + /* If it is (s)bss section, insert the new data2 section before it. */ | |
946 | + /* new_data2_index is the index of either old_sbss or old_bss, that was | |
947 | + chosen as a section for new_data2. */ | |
948 | + temp_index = new_data2_index; | |
949 | +#else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
950 | + /* If it is bss section, insert the new data2 section before it. */ | |
951 | + temp_index = old_bss_index; | |
952 | +#endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
953 | + if (n == temp_index) | |
954 | + { | |
955 | + /* Steal the data section header for this data2 section. */ | |
956 | + memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), | |
957 | + new_file_h->e_shentsize); | |
958 | + | |
959 | + NEW_SECTION_H (nn).sh_addr = new_data2_addr; | |
960 | + NEW_SECTION_H (nn).sh_offset = new_data2_offset; | |
961 | + NEW_SECTION_H (nn).sh_size = new_data2_size; | |
962 | + /* Use the bss section's alignment. This will assure that the | |
963 | + new data2 section always be placed in the same spot as the old | |
964 | + bss section by any other application. */ | |
965 | + NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (n).sh_addralign; | |
966 | + | |
967 | + /* Now copy over what we have in the memory now. */ | |
968 | + memcpy (NEW_SECTION_H (nn).sh_offset + new_base, | |
969 | + (caddr_t) OLD_SECTION_H (n).sh_addr, | |
970 | + new_data2_size); | |
971 | + nn++; | |
972 | + } | |
973 | + | |
974 | + memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), | |
975 | + old_file_h->e_shentsize); | |
976 | + | |
977 | + if (n == old_bss_index | |
978 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
979 | + /* The new bss and sbss section's size is zero, and its file offset | |
980 | + and virtual address should be off by NEW_DATA2_SIZE. */ | |
981 | + || n == old_sbss_index | |
982 | +#endif /* __sony_news and _SYSTYPE_SYSV */ | |
983 | + ) | |
984 | + { | |
985 | + /* NN should be `old_bss_index + 1' at this point. */ | |
986 | + NEW_SECTION_H (nn).sh_offset += new_data2_size; | |
987 | + NEW_SECTION_H (nn).sh_addr += new_data2_size; | |
988 | + /* Let the new bss section address alignment be the same as the | |
989 | + section address alignment followed the old bss section, so | |
990 | + this section will be placed in exactly the same place. */ | |
991 | + NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign; | |
992 | + NEW_SECTION_H (nn).sh_size = 0; | |
993 | + } | |
994 | + else | |
995 | + { | |
996 | + /* Any section that was original placed AFTER the bss | |
997 | + section should now be off by NEW_DATA2_SIZE. */ | |
998 | +#ifdef SOLARIS_POWERPC | |
999 | + /* On PPC Reference Platform running Solaris 2.5.1 | |
1000 | + the plt section is also of type NOBI like the bss section. | |
1001 | + (not really stored) and therefore sections after the bss | |
1002 | + section start at the plt offset. The plt section is always | |
1003 | + the one just before the bss section. | |
1004 | + It would be better to put the new data section before | |
1005 | + the .plt section, or use libelf instead. | |
1006 | + Erik Deumens, deumens@qtp.ufl.edu. */ | |
1007 | + if (NEW_SECTION_H (nn).sh_offset | |
1008 | + >= OLD_SECTION_H (old_bss_index-1).sh_offset) | |
1009 | + NEW_SECTION_H (nn).sh_offset += new_data2_size; | |
1010 | +#else | |
1011 | + if (round_up (NEW_SECTION_H (nn).sh_offset, | |
1012 | + OLD_SECTION_H (old_bss_index).sh_addralign) | |
1013 | + >= new_data2_offset) | |
1014 | + NEW_SECTION_H (nn).sh_offset += new_data2_size; | |
1015 | +#endif | |
1016 | + /* Any section that was originally placed after the section | |
1017 | + header table should now be off by the size of one section | |
1018 | + header table entry. */ | |
1019 | + if (NEW_SECTION_H (nn).sh_offset > new_file_h->e_shoff) | |
1020 | + NEW_SECTION_H (nn).sh_offset += new_file_h->e_shentsize; | |
1021 | + } | |
1022 | + | |
1023 | + /* If any section hdr refers to the section after the new .data | |
1024 | + section, make it refer to next one because we have inserted | |
1025 | + a new section in between. */ | |
1026 | + | |
1027 | + PATCH_INDEX (NEW_SECTION_H (nn).sh_link); | |
1028 | + /* For symbol tables, info is a symbol table index, | |
1029 | + so don't change it. */ | |
1030 | + if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB | |
1031 | + && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) | |
1032 | + PATCH_INDEX (NEW_SECTION_H (nn).sh_info); | |
1033 | + | |
1034 | + /* Now, start to copy the content of sections. */ | |
1035 | + if (NEW_SECTION_H (nn).sh_type == SHT_NULL | |
1036 | + || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) | |
1037 | + continue; | |
1038 | + | |
1039 | + /* Write out the sections. .data and .data1 (and data2, called | |
1040 | + ".data" in the strings table) get copied from the current process | |
1041 | + instead of the old file. */ | |
1042 | + if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") | |
1043 | +#ifdef _nec_ews_svr4 /* hir, 1994.6.13 */ | |
1044 | + || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name), | |
1045 | + ".sdata") | |
1046 | +#endif | |
1047 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
1048 | + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
1049 | + ".sdata") | |
1050 | + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
1051 | + ".lit4") | |
1052 | + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
1053 | + ".lit8") | |
1054 | +#endif /* __sony_news && _SYSTYPE_SYSV */ | |
1055 | + || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
1056 | + ".data1")) | |
1057 | + src = (caddr_t) OLD_SECTION_H (n).sh_addr; | |
1058 | + else | |
1059 | + src = old_base + OLD_SECTION_H (n).sh_offset; | |
1060 | + | |
1061 | + memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, | |
1062 | + NEW_SECTION_H (nn).sh_size); | |
1063 | + | |
1064 | +#if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
1065 | + if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index) | |
1066 | + { | |
1067 | + int diff = NEW_SECTION_H(nn).sh_offset | |
1068 | + - OLD_SECTION_H(old_mdebug_index).sh_offset; | |
1069 | + HDRR *phdr = (HDRR *)(NEW_SECTION_H (nn).sh_offset + new_base); | |
1070 | + | |
1071 | + if (diff) | |
1072 | + { | |
1073 | + phdr->cbLineOffset += diff; | |
1074 | + phdr->cbDnOffset += diff; | |
1075 | + phdr->cbPdOffset += diff; | |
1076 | + phdr->cbSymOffset += diff; | |
1077 | + phdr->cbOptOffset += diff; | |
1078 | + phdr->cbAuxOffset += diff; | |
1079 | + phdr->cbSsOffset += diff; | |
1080 | + phdr->cbSsExtOffset += diff; | |
1081 | + phdr->cbFdOffset += diff; | |
1082 | + phdr->cbRfdOffset += diff; | |
1083 | + phdr->cbExtOffset += diff; | |
1084 | + } | |
1085 | + } | |
1086 | +#endif /* __sony_news && _SYSTYPE_SYSV */ | |
1087 | + /* If it is the symbol table, its st_shndx field needs to be patched. */ | |
1088 | + if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB | |
1089 | + || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) | |
1090 | + { | |
1091 | + ElfW(Shdr) *spt = &NEW_SECTION_H (nn); | |
1092 | + unsigned int num = spt->sh_size / spt->sh_entsize; | |
1093 | + ElfW(Sym) * sym = (ElfW(Sym) *) (NEW_SECTION_H (nn).sh_offset + | |
1094 | + new_base); | |
1095 | + for (; num--; sym++) | |
1096 | + { | |
1097 | + if ((sym->st_shndx == SHN_UNDEF) | |
1098 | + || (sym->st_shndx == SHN_ABS) | |
1099 | + || (sym->st_shndx == SHN_COMMON)) | |
1100 | + continue; | |
1101 | + | |
1102 | + PATCH_INDEX (sym->st_shndx); | |
1103 | + } | |
1104 | + } | |
1105 | + } | |
1106 | + | |
1107 | + /* Update the symbol values of _edata and _end. */ | |
1108 | + for (n = new_file_h->e_shnum - 1; n; n--) | |
1109 | + { | |
1110 | + byte *symnames; | |
1111 | + ElfW(Sym) *symp, *symendp; | |
1112 | + | |
1113 | + if (NEW_SECTION_H (n).sh_type != SHT_DYNSYM | |
1114 | + && NEW_SECTION_H (n).sh_type != SHT_SYMTAB) | |
1115 | + continue; | |
1116 | + | |
1117 | + symnames = ((byte *) new_base | |
1118 | + + NEW_SECTION_H (NEW_SECTION_H (n).sh_link).sh_offset); | |
1119 | + symp = (ElfW(Sym) *) (NEW_SECTION_H (n).sh_offset + new_base); | |
1120 | + symendp = (ElfW(Sym) *) ((byte *)symp + NEW_SECTION_H (n).sh_size); | |
1121 | + | |
1122 | + for (; symp < symendp; symp ++) | |
1123 | + if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 | |
1124 | + || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) | |
1125 | + memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); | |
1126 | + } | |
1127 | + | |
1128 | + /* This loop seeks out relocation sections for the data section, so | |
1129 | + that it can undo relocations performed by the runtime linker. */ | |
1130 | + for (n = new_file_h->e_shnum - 1; n; n--) | |
1131 | + { | |
1132 | + ElfW(Shdr) section = NEW_SECTION_H (n); | |
1133 | + switch (section.sh_type) { | |
1134 | + default: | |
1135 | + break; | |
1136 | + case SHT_REL: | |
1137 | + case SHT_RELA: | |
1138 | + /* This code handles two different size structs, but there should | |
1139 | + be no harm in that provided that r_offset is always the first | |
1140 | + member. */ | |
1141 | + nn = section.sh_info; | |
1142 | + if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data") | |
1143 | + || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | |
1144 | + ".data1")) | |
1145 | + { | |
1146 | + ElfW(Addr) offset = NEW_SECTION_H (nn).sh_addr - | |
1147 | + NEW_SECTION_H (nn).sh_offset; | |
1148 | + caddr_t reloc = old_base + section.sh_offset, end; | |
1149 | + for (end = reloc + section.sh_size; reloc < end; | |
1150 | + reloc += section.sh_entsize) | |
1151 | + { | |
1152 | + ElfW(Addr) addr = ((ElfW(Rel) *) reloc)->r_offset - offset; | |
1153 | + memcpy (new_base + addr, old_base + addr, sizeof(ElfW(Addr))); | |
1154 | + } | |
1155 | + } | |
1156 | + break; | |
1157 | + } | |
1158 | + } | |
1159 | + | |
1160 | +#ifdef UNEXEC_USE_MAP_PRIVATE | |
1161 | + if (lseek (new_file, 0, SEEK_SET) == -1) | |
1162 | + fatal ("Can't rewind (%s): errno %d\n", new_name, errno); | |
1163 | + | |
1164 | + if (write (new_file, new_base, new_file_size) != new_file_size) | |
1165 | + fatal ("Can't write (%s): errno %d\n", new_name, errno); | |
1166 | +#endif | |
1167 | + | |
1168 | + /* Close the files and make the new file executable. */ | |
1169 | + | |
1170 | + if (close (old_file)) | |
1171 | + fatal ("Can't close (%s): errno %d\n", old_name, errno); | |
1172 | + | |
1173 | + if (close (new_file)) | |
1174 | + fatal ("Can't close (%s): errno %d\n", new_name, errno); | |
1175 | + | |
1176 | + if (stat (new_name, &stat_buf) == -1) | |
1177 | + fatal ("Can't stat (%s): errno %d\n", new_name, errno); | |
1178 | + | |
1179 | + n = umask (777); | |
1180 | + umask (n); | |
1181 | + stat_buf.st_mode |= 0111 & ~n; | |
1182 | + if (chmod (new_name, stat_buf.st_mode) == -1) | |
1183 | + fatal ("Can't chmod (%s): errno %d\n", new_name, errno); | |
1184 | +} | |
1185 | --- xemacs-20.4/src/Makefile.in.in.sav Mon Nov 17 20:17:53 1997 | |
1186 | +++ xemacs-20.4/src/Makefile.in.in Thu Feb 12 18:20:12 1998 | |
1187 | @@ -66,7 +66,7 @@ | |
1188 | ld_switch_shared=@ld_switch_shared@ | |
1189 | start_files=@start_files@ | |
1190 | start_flags=@start_flags@ | |
1191 | -LD=@ld@ | |
1192 | +LD=gcc -nostdlib | |
1193 | lib_gcc=@lib_gcc@ | |
1194 | ||
1195 | #define NOT_C_CODE |