Mercurial > emacs
comparison src/unexelf.c @ 14251:9cacb2dd365c
(unexec): Undo data relocations unconditionally, not #ifdef SOLARIS2.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Sun, 21 Jan 1996 04:16:54 +0000 |
parents | ee40177f6c68 |
children | 52c43dd2a83b |
comparison
equal
deleted
inserted
replaced
14250:61fe711e4ae4 | 14251:9cacb2dd365c |
---|---|
99 **** SECTION HEADER TABLE **** | 99 **** SECTION HEADER TABLE **** |
100 [No] Type Flags Addr Offset Size Name | 100 [No] Type Flags Addr Offset Size Name |
101 Link Info Adralgn Entsize | 101 Link Info Adralgn Entsize |
102 | 102 |
103 [1] 1 2 0x80480d4 0xd4 0x13 .interp | 103 [1] 1 2 0x80480d4 0xd4 0x13 .interp |
104 0 0 0x1 0 | 104 0 0 0x1 0 |
105 | 105 |
106 [2] 5 2 0x80480e8 0xe8 0x388 .hash | 106 [2] 5 2 0x80480e8 0xe8 0x388 .hash |
107 3 0 0x4 0x4 | 107 3 0 0x4 0x4 |
108 | 108 |
109 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym | 109 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym |
110 4 1 0x4 0x10 | 110 4 1 0x4 0x10 |
111 | 111 |
112 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | 112 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr |
113 0 0 0x1 0 | 113 0 0 0x1 0 |
114 | 114 |
115 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt | 115 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt |
116 3 7 0x4 0x8 | 116 3 7 0x4 0x8 |
117 | 117 |
118 [6] 1 6 0x8049348 0x1348 0x3 .init | 118 [6] 1 6 0x8049348 0x1348 0x3 .init |
119 0 0 0x4 0 | 119 0 0 0x4 0 |
120 | 120 |
121 [7] 1 6 0x804934c 0x134c 0x680 .plt | 121 [7] 1 6 0x804934c 0x134c 0x680 .plt |
122 0 0 0x4 0x4 | 122 0 0 0x4 0x4 |
123 | 123 |
124 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text | 124 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text |
125 0 0 0x4 0 | 125 0 0 0x4 0 |
126 | 126 |
127 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | 127 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini |
128 0 0 0x4 0 | 128 0 0 0x4 0 |
129 | 129 |
130 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata | 130 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata |
131 0 0 0x4 0 | 131 0 0 0x4 0 |
132 | 132 |
133 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | 133 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 |
134 0 0 0x4 0 | 134 0 0 0x4 0 |
135 | 135 |
136 [12] 1 3 0x8088330 0x3f330 0x20afc .data | 136 [12] 1 3 0x8088330 0x3f330 0x20afc .data |
137 0 0 0x4 0 | 137 0 0 0x4 0 |
138 | 138 |
139 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | 139 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 |
140 0 0 0x4 0 | 140 0 0 0x4 0 |
141 | 141 |
142 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | 142 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got |
143 0 0 0x4 0x4 | 143 0 0 0x4 0x4 |
144 | 144 |
145 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic | 145 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic |
146 4 0 0x4 0x8 | 146 4 0 0x4 0x8 |
147 | 147 |
148 [16] 8 3 0x80a98f4 0x608f4 0x449c .bss | 148 [16] 8 3 0x80a98f4 0x608f4 0x449c .bss |
149 0 0 0x4 0 | 149 0 0 0x4 0 |
150 | 150 |
151 [17] 2 0 0 0x608f4 0x9b90 .symtab | 151 [17] 2 0 0 0x608f4 0x9b90 .symtab |
152 18 371 0x4 0x10 | 152 18 371 0x4 0x10 |
153 | 153 |
154 [18] 3 0 0 0x6a484 0x8526 .strtab | 154 [18] 3 0 0 0x6a484 0x8526 .strtab |
155 0 0 0x1 0 | 155 0 0 0x1 0 |
156 | 156 |
157 [19] 3 0 0 0x729aa 0x93 .shstrtab | 157 [19] 3 0 0 0x729aa 0x93 .shstrtab |
158 0 0 0x1 0 | 158 0 0 0x1 0 |
159 | 159 |
160 [20] 1 0 0 0x72a3d 0x68b7 .comment | 160 [20] 1 0 0 0x72a3d 0x68b7 .comment |
161 0 0 0x1 0 | 161 0 0 0x1 0 |
162 | 162 |
163 raid:/nfs/raid/src/dist-18.56/src> dump -h xemacs | 163 raid:/nfs/raid/src/dist-18.56/src> dump -h xemacs |
164 | 164 |
165 xemacs: | 165 xemacs: |
166 | 166 |
167 **** SECTION HEADER TABLE **** | 167 **** SECTION HEADER TABLE **** |
168 [No] Type Flags Addr Offset Size Name | 168 [No] Type Flags Addr Offset Size Name |
169 Link Info Adralgn Entsize | 169 Link Info Adralgn Entsize |
170 | 170 |
171 [1] 1 2 0x80480d4 0xd4 0x13 .interp | 171 [1] 1 2 0x80480d4 0xd4 0x13 .interp |
172 0 0 0x1 0 | 172 0 0 0x1 0 |
173 | 173 |
174 [2] 5 2 0x80480e8 0xe8 0x388 .hash | 174 [2] 5 2 0x80480e8 0xe8 0x388 .hash |
175 3 0 0x4 0x4 | 175 3 0 0x4 0x4 |
176 | 176 |
177 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym | 177 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym |
178 4 1 0x4 0x10 | 178 4 1 0x4 0x10 |
179 | 179 |
180 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | 180 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr |
181 0 0 0x1 0 | 181 0 0 0x1 0 |
182 | 182 |
183 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt | 183 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt |
184 3 7 0x4 0x8 | 184 3 7 0x4 0x8 |
185 | 185 |
186 [6] 1 6 0x8049348 0x1348 0x3 .init | 186 [6] 1 6 0x8049348 0x1348 0x3 .init |
187 0 0 0x4 0 | 187 0 0 0x4 0 |
188 | 188 |
189 [7] 1 6 0x804934c 0x134c 0x680 .plt | 189 [7] 1 6 0x804934c 0x134c 0x680 .plt |
190 0 0 0x4 0x4 | 190 0 0 0x4 0x4 |
191 | 191 |
192 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text | 192 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text |
193 0 0 0x4 0 | 193 0 0 0x4 0 |
194 | 194 |
195 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | 195 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini |
196 0 0 0x4 0 | 196 0 0 0x4 0 |
197 | 197 |
198 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata | 198 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata |
199 0 0 0x4 0 | 199 0 0 0x4 0 |
200 | 200 |
201 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | 201 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 |
202 0 0 0x4 0 | 202 0 0 0x4 0 |
203 | 203 |
204 [12] 1 3 0x8088330 0x3f330 0x20afc .data | 204 [12] 1 3 0x8088330 0x3f330 0x20afc .data |
205 0 0 0x4 0 | 205 0 0 0x4 0 |
206 | 206 |
207 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | 207 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 |
208 0 0 0x4 0 | 208 0 0 0x4 0 |
209 | 209 |
210 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | 210 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got |
211 0 0 0x4 0x4 | 211 0 0 0x4 0x4 |
212 | 212 |
213 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic | 213 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic |
214 4 0 0x4 0x8 | 214 4 0 0x4 0x8 |
215 | 215 |
216 [16] 8 3 0x80c6800 0x7d800 0 .bss | 216 [16] 8 3 0x80c6800 0x7d800 0 .bss |
217 0 0 0x4 0 | 217 0 0 0x4 0 |
218 | 218 |
219 [17] 2 0 0 0x7d800 0x9b90 .symtab | 219 [17] 2 0 0 0x7d800 0x9b90 .symtab |
220 18 371 0x4 0x10 | 220 18 371 0x4 0x10 |
221 | 221 |
222 [18] 3 0 0 0x87390 0x8526 .strtab | 222 [18] 3 0 0 0x87390 0x8526 .strtab |
223 0 0 0x1 0 | 223 0 0 0x1 0 |
224 | 224 |
225 [19] 3 0 0 0x8f8b6 0x93 .shstrtab | 225 [19] 3 0 0 0x8f8b6 0x93 .shstrtab |
226 0 0 0x1 0 | 226 0 0 0x1 0 |
227 | 227 |
228 [20] 1 0 0 0x8f949 0x68b7 .comment | 228 [20] 1 0 0 0x8f949 0x68b7 .comment |
229 0 0 0x1 0 | 229 0 0 0x1 0 |
230 | 230 |
231 [21] 1 3 0x80a98f4 0x608f4 0x1cf0c .data | 231 [21] 1 3 0x80a98f4 0x608f4 0x1cf0c .data |
232 0 0 0x4 0 | 232 0 0 0x4 0 |
233 | 233 |
234 * This is an example of how the file header is changed. "Shoff" is | 234 * This is an example of how the file header is changed. "Shoff" is |
235 * the section header offset within the file. Since that table is | 235 * the section header offset within the file. Since that table is |
236 * after the new .data section, it is moved. "Shnum" is the number of | 236 * after the new .data section, it is moved. "Shnum" is the number of |
237 * sections, which we increment. | 237 * sections, which we increment. |
277 temacs: | 277 temacs: |
278 ***** PROGRAM EXECUTION HEADER ***** | 278 ***** PROGRAM EXECUTION HEADER ***** |
279 Type Offset Vaddr Paddr | 279 Type Offset Vaddr Paddr |
280 Filesz Memsz Flags Align | 280 Filesz Memsz Flags Align |
281 | 281 |
282 6 0x34 0x8048034 0 | 282 6 0x34 0x8048034 0 |
283 0xa0 0xa0 5 0 | 283 0xa0 0xa0 5 0 |
284 | 284 |
285 3 0xd4 0 0 | 285 3 0xd4 0 0 |
286 0x13 0 4 0 | 286 0x13 0 4 0 |
287 | 287 |
288 1 0x34 0x8048034 0 | 288 1 0x34 0x8048034 0 |
289 0x3f2f9 0x3f2f9 5 0x1000 | 289 0x3f2f9 0x3f2f9 5 0x1000 |
290 | 290 |
291 1 0x3f330 0x8088330 0 | 291 1 0x3f330 0x8088330 0 |
292 0x215c4 0x25a60 7 0x1000 | 292 0x215c4 0x25a60 7 0x1000 |
293 | 293 |
294 2 0x60874 0x80a9874 0 | 294 2 0x60874 0x80a9874 0 |
295 0x80 0 7 0 | 295 0x80 0 7 0 |
296 | 296 |
297 raid:/nfs/raid/src/dist-18.56/src> dump -o xemacs | 297 raid:/nfs/raid/src/dist-18.56/src> dump -o xemacs |
298 | 298 |
299 xemacs: | 299 xemacs: |
300 ***** PROGRAM EXECUTION HEADER ***** | 300 ***** PROGRAM EXECUTION HEADER ***** |
301 Type Offset Vaddr Paddr | 301 Type Offset Vaddr Paddr |
302 Filesz Memsz Flags Align | 302 Filesz Memsz Flags Align |
303 | 303 |
304 6 0x34 0x8048034 0 | 304 6 0x34 0x8048034 0 |
305 0xa0 0xa0 5 0 | 305 0xa0 0xa0 5 0 |
306 | 306 |
307 3 0xd4 0 0 | 307 3 0xd4 0 0 |
308 0x13 0 4 0 | 308 0x13 0 4 0 |
309 | 309 |
310 1 0x34 0x8048034 0 | 310 1 0x34 0x8048034 0 |
311 0x3f2f9 0x3f2f9 5 0x1000 | 311 0x3f2f9 0x3f2f9 5 0x1000 |
312 | 312 |
313 1 0x3f330 0x8088330 0 | 313 1 0x3f330 0x8088330 0 |
314 0x3e4d0 0x3e4d0 7 0x1000 | 314 0x3e4d0 0x3e4d0 7 0x1000 |
315 | 315 |
316 2 0x60874 0x80a9874 0 | 316 2 0x60874 0x80a9874 0 |
317 0x80 0 7 0 | 317 0x80 0 7 0 |
318 | 318 |
319 | 319 |
320 */ | 320 */ |
321 | 321 |
322 /* Modified by wtien@urbana.mcd.mot.com of Motorola Inc. | 322 /* Modified by wtien@urbana.mcd.mot.com of Motorola Inc. |
323 * | 323 * |
324 * The above mechanism does not work if the unexeced ELF file is being | 324 * The above mechanism does not work if the unexeced ELF file is being |
325 * re-layout by other applications (such as `strip'). All the applications | 325 * re-layout by other applications (such as `strip'). All the applications |
326 * that re-layout the internal of ELF will layout all sections in ascending | 326 * that re-layout the internal of ELF will layout all sections in ascending |
327 * order of their file offsets. After the re-layout, the data2 section will | 327 * order of their file offsets. After the re-layout, the data2 section will |
328 * still be the LAST section in the section header vector, but its file offset | 328 * still be the LAST section in the section header vector, but its file offset |
329 * is now being pushed far away down, and causes part of it not to be mapped | 329 * is now being pushed far away down, and causes part of it not to be mapped |
330 * in (ie. not covered by the load segment entry in PHDR vector), therefore | 330 * in (ie. not covered by the load segment entry in PHDR vector), therefore |
331 * causes the new binary to fail. | 331 * causes the new binary to fail. |
332 * | 332 * |
333 * The solution is to modify the unexec algorithm to insert the new data2 | 333 * The solution is to modify the unexec algorithm to insert the new data2 |
334 * section header right before the new bss section header, so their file | 334 * section header right before the new bss section header, so their file |
335 * offsets will be in the ascending order. Since some of the section's (all | 335 * offsets will be in the ascending order. Since some of the section's (all |
336 * sections AFTER the bss section) indexes are now changed, we also need to | 336 * sections AFTER the bss section) indexes are now changed, we also need to |
337 * modify some fields to make them point to the right sections. This is done | 337 * modify some fields to make them point to the right sections. This is done |
338 * by macro PATCH_INDEX. All the fields that need to be patched are: | 338 * by macro PATCH_INDEX. All the fields that need to be patched are: |
339 * | 339 * |
340 * 1. ELF header e_shstrndx field. | 340 * 1. ELF header e_shstrndx field. |
341 * 2. section header sh_link and sh_info field. | 341 * 2. section header sh_link and sh_info field. |
342 * 3. symbol table entry st_shndx field. | 342 * 3. symbol table entry st_shndx field. |
343 * | 343 * |
344 * The above example now should look like: | 344 * The above example now should look like: |
346 **** SECTION HEADER TABLE **** | 346 **** SECTION HEADER TABLE **** |
347 [No] Type Flags Addr Offset Size Name | 347 [No] Type Flags Addr Offset Size Name |
348 Link Info Adralgn Entsize | 348 Link Info Adralgn Entsize |
349 | 349 |
350 [1] 1 2 0x80480d4 0xd4 0x13 .interp | 350 [1] 1 2 0x80480d4 0xd4 0x13 .interp |
351 0 0 0x1 0 | 351 0 0 0x1 0 |
352 | 352 |
353 [2] 5 2 0x80480e8 0xe8 0x388 .hash | 353 [2] 5 2 0x80480e8 0xe8 0x388 .hash |
354 3 0 0x4 0x4 | 354 3 0 0x4 0x4 |
355 | 355 |
356 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym | 356 [3] 11 2 0x8048470 0x470 0x7f0 .dynsym |
357 4 1 0x4 0x10 | 357 4 1 0x4 0x10 |
358 | 358 |
359 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr | 359 [4] 3 2 0x8048c60 0xc60 0x3ad .dynstr |
360 0 0 0x1 0 | 360 0 0 0x1 0 |
361 | 361 |
362 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt | 362 [5] 9 2 0x8049010 0x1010 0x338 .rel.plt |
363 3 7 0x4 0x8 | 363 3 7 0x4 0x8 |
364 | 364 |
365 [6] 1 6 0x8049348 0x1348 0x3 .init | 365 [6] 1 6 0x8049348 0x1348 0x3 .init |
366 0 0 0x4 0 | 366 0 0 0x4 0 |
367 | 367 |
368 [7] 1 6 0x804934c 0x134c 0x680 .plt | 368 [7] 1 6 0x804934c 0x134c 0x680 .plt |
369 0 0 0x4 0x4 | 369 0 0 0x4 0x4 |
370 | 370 |
371 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text | 371 [8] 1 6 0x80499cc 0x19cc 0x3c56f .text |
372 0 0 0x4 0 | 372 0 0 0x4 0 |
373 | 373 |
374 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini | 374 [9] 1 6 0x8085f3c 0x3df3c 0x3 .fini |
375 0 0 0x4 0 | 375 0 0 0x4 0 |
376 | 376 |
377 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata | 377 [10] 1 2 0x8085f40 0x3df40 0x69c .rodata |
378 0 0 0x4 0 | 378 0 0 0x4 0 |
379 | 379 |
380 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 | 380 [11] 1 2 0x80865dc 0x3e5dc 0xd51 .rodata1 |
381 0 0 0x4 0 | 381 0 0 0x4 0 |
382 | 382 |
383 [12] 1 3 0x8088330 0x3f330 0x20afc .data | 383 [12] 1 3 0x8088330 0x3f330 0x20afc .data |
384 0 0 0x4 0 | 384 0 0 0x4 0 |
385 | 385 |
386 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 | 386 [13] 1 3 0x80a8e2c 0x5fe2c 0x89d .data1 |
387 0 0 0x4 0 | 387 0 0 0x4 0 |
388 | 388 |
389 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got | 389 [14] 1 3 0x80a96cc 0x606cc 0x1a8 .got |
390 0 0 0x4 0x4 | 390 0 0 0x4 0x4 |
391 | 391 |
392 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic | 392 [15] 6 3 0x80a9874 0x60874 0x80 .dynamic |
393 4 0 0x4 0x8 | 393 4 0 0x4 0x8 |
394 | 394 |
395 [16] 1 3 0x80a98f4 0x608f4 0x1cf0c .data | 395 [16] 1 3 0x80a98f4 0x608f4 0x1cf0c .data |
396 0 0 0x4 0 | 396 0 0 0x4 0 |
397 | 397 |
398 [17] 8 3 0x80c6800 0x7d800 0 .bss | 398 [17] 8 3 0x80c6800 0x7d800 0 .bss |
399 0 0 0x4 0 | 399 0 0 0x4 0 |
400 | 400 |
401 [18] 2 0 0 0x7d800 0x9b90 .symtab | 401 [18] 2 0 0 0x7d800 0x9b90 .symtab |
402 19 371 0x4 0x10 | 402 19 371 0x4 0x10 |
403 | 403 |
404 [19] 3 0 0 0x87390 0x8526 .strtab | 404 [19] 3 0 0 0x87390 0x8526 .strtab |
405 0 0 0x1 0 | 405 0 0 0x1 0 |
406 | 406 |
407 [20] 3 0 0 0x8f8b6 0x93 .shstrtab | 407 [20] 3 0 0 0x8f8b6 0x93 .shstrtab |
408 0 0 0x1 0 | 408 0 0 0x1 0 |
409 | 409 |
410 [21] 1 0 0 0x8f949 0x68b7 .comment | 410 [21] 1 0 0 0x8f949 0x68b7 .comment |
411 0 0 0x1 0 | 411 0 0 0x1 0 |
412 | 412 |
413 */ | 413 */ |
414 | 414 |
415 #include <sys/types.h> | 415 #include <sys/types.h> |
416 #include <stdio.h> | 416 #include <stdio.h> |
682 ".data")) | 682 ".data")) |
683 break; | 683 break; |
684 if (old_data_index == old_file_h->e_shnum) | 684 if (old_data_index == old_file_h->e_shnum) |
685 fatal ("Can't find .data in %s.\n", old_name, 0); | 685 fatal ("Can't find .data in %s.\n", old_name, 0); |
686 | 686 |
687 /* Walk through all section headers, insert the new data2 section right | 687 /* Walk through all section headers, insert the new data2 section right |
688 before the new bss section. */ | 688 before the new bss section. */ |
689 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) | 689 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) |
690 { | 690 { |
691 caddr_t src; | 691 caddr_t src; |
692 /* If it is bss section, insert the new data2 section before it. */ | 692 /* If it is bss section, insert the new data2 section before it. */ |
693 if (n == old_bss_index) | 693 if (n == old_bss_index) |
694 { | 694 { |
695 /* Steal the data section header for this data2 section. */ | 695 /* Steal the data section header for this data2 section. */ |
696 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), | 696 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), |
697 new_file_h->e_shentsize); | 697 new_file_h->e_shentsize); |
698 | 698 |
699 NEW_SECTION_H (nn).sh_addr = new_data2_addr; | 699 NEW_SECTION_H (nn).sh_addr = new_data2_addr; |
700 NEW_SECTION_H (nn).sh_offset = new_data2_offset; | 700 NEW_SECTION_H (nn).sh_offset = new_data2_offset; |
701 NEW_SECTION_H (nn).sh_size = new_data2_size; | 701 NEW_SECTION_H (nn).sh_size = new_data2_size; |
702 /* Use the bss section's alignment. This will assure that the | 702 /* Use the bss section's alignment. This will assure that the |
703 new data2 section always be placed in the same spot as the old | 703 new data2 section always be placed in the same spot as the old |
704 bss section by any other application. */ | 704 bss section by any other application. */ |
705 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (n).sh_addralign; | 705 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (n).sh_addralign; |
706 | 706 |
707 /* Now copy over what we have in the memory now. */ | 707 /* Now copy over what we have in the memory now. */ |
708 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, | 708 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, |
709 (caddr_t) OLD_SECTION_H (n).sh_addr, | 709 (caddr_t) OLD_SECTION_H (n).sh_addr, |
710 new_data2_size); | 710 new_data2_size); |
711 nn++; | 711 nn++; |
712 } | 712 } |
713 | 713 |
714 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), | 714 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), |
715 old_file_h->e_shentsize); | 715 old_file_h->e_shentsize); |
716 | 716 |
717 /* The new bss section's size is zero, and its file offset and virtual | 717 /* The new bss section's size is zero, and its file offset and virtual |
718 address should be off by NEW_DATA2_SIZE. */ | 718 address should be off by NEW_DATA2_SIZE. */ |
719 if (n == old_bss_index) | 719 if (n == old_bss_index) |
720 { | 720 { |
721 /* NN should be `old_bss_index + 1' at this point. */ | 721 /* NN should be `old_bss_index + 1' at this point. */ |
722 NEW_SECTION_H (nn).sh_offset += new_data2_size; | 722 NEW_SECTION_H (nn).sh_offset += new_data2_size; |
723 NEW_SECTION_H (nn).sh_addr += new_data2_size; | 723 NEW_SECTION_H (nn).sh_addr += new_data2_size; |
724 /* Let the new bss section address alignment be the same as the | 724 /* Let the new bss section address alignment be the same as the |
725 section address alignment followed the old bss section, so | 725 section address alignment followed the old bss section, so |
726 this section will be placed in exactly the same place. */ | 726 this section will be placed in exactly the same place. */ |
727 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign; | 727 NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign; |
728 NEW_SECTION_H (nn).sh_size = 0; | 728 NEW_SECTION_H (nn).sh_size = 0; |
729 } | 729 } |
730 else | 730 else |
739 if (NEW_SECTION_H (nn).sh_offset > new_file_h->e_shoff) | 739 if (NEW_SECTION_H (nn).sh_offset > new_file_h->e_shoff) |
740 NEW_SECTION_H (nn).sh_offset += new_file_h->e_shentsize; | 740 NEW_SECTION_H (nn).sh_offset += new_file_h->e_shentsize; |
741 } | 741 } |
742 | 742 |
743 /* If any section hdr refers to the section after the new .data | 743 /* If any section hdr refers to the section after the new .data |
744 section, make it refer to next one because we have inserted | 744 section, make it refer to next one because we have inserted |
745 a new section in between. */ | 745 a new section in between. */ |
746 | 746 |
747 PATCH_INDEX (NEW_SECTION_H (nn).sh_link); | 747 PATCH_INDEX (NEW_SECTION_H (nn).sh_link); |
748 /* For symbol tables, info is a symbol table index, | 748 /* For symbol tables, info is a symbol table index, |
749 so don't change it. */ | 749 so don't change it. */ |
750 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB | 750 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB |
751 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) | 751 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) |
753 | 753 |
754 /* Now, start to copy the content of sections. */ | 754 /* Now, start to copy the content of sections. */ |
755 if (NEW_SECTION_H (nn).sh_type == SHT_NULL | 755 if (NEW_SECTION_H (nn).sh_type == SHT_NULL |
756 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) | 756 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) |
757 continue; | 757 continue; |
758 | 758 |
759 /* Write out the sections. .data and .data1 (and data2, called | 759 /* Write out the sections. .data and .data1 (and data2, called |
760 ".data" in the strings table) get copied from the current process | 760 ".data" in the strings table) get copied from the current process |
761 instead of the old file. */ | 761 instead of the old file. */ |
762 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") | 762 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") |
763 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 763 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
764 ".data1")) | 764 ".data1")) |
765 src = (caddr_t) OLD_SECTION_H (n).sh_addr; | 765 src = (caddr_t) OLD_SECTION_H (n).sh_addr; |
766 else | 766 else |
767 src = old_base + OLD_SECTION_H (n).sh_offset; | 767 src = old_base + OLD_SECTION_H (n).sh_offset; |
768 | 768 |
769 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, | 769 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, |
770 NEW_SECTION_H (nn).sh_size); | 770 NEW_SECTION_H (nn).sh_size); |
771 | 771 |
772 /* If it is the symbol table, its st_shndx field needs to be patched. */ | 772 /* If it is the symbol table, its st_shndx field needs to be patched. */ |
773 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB | 773 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB |
774 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) | 774 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) |
775 { | 775 { |
776 Elf32_Shdr *spt = &NEW_SECTION_H (nn); | 776 Elf32_Shdr *spt = &NEW_SECTION_H (nn); |
777 unsigned int num = spt->sh_size / spt->sh_entsize; | 777 unsigned int num = spt->sh_size / spt->sh_entsize; |
778 Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H (nn).sh_offset + | 778 Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H (nn).sh_offset + |
779 new_base); | 779 new_base); |
780 for (; num--; sym++) | 780 for (; num--; sym++) |
781 { | 781 { |
782 if ((sym->st_shndx == SHN_UNDEF) | 782 if ((sym->st_shndx == SHN_UNDEF) |
783 || (sym->st_shndx == SHN_ABS) | 783 || (sym->st_shndx == SHN_ABS) |
784 || (sym->st_shndx == SHN_COMMON)) | 784 || (sym->st_shndx == SHN_COMMON)) |
785 continue; | 785 continue; |
786 | 786 |
787 PATCH_INDEX (sym->st_shndx); | 787 PATCH_INDEX (sym->st_shndx); |
788 } | 788 } |
789 } | 789 } |
790 } | 790 } |
791 | 791 |
808 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 | 808 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 |
809 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) | 809 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) |
810 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); | 810 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); |
811 } | 811 } |
812 | 812 |
813 #ifdef SOLARIS2 | |
814 /* This loop seeks out relocation sections for the data section, so | 813 /* This loop seeks out relocation sections for the data section, so |
815 that it can undo relocations performed by the runtime linker. */ | 814 that it can undo relocations performed by the runtime linker. */ |
816 for (n = new_file_h->e_shnum - 1; n; n--) | 815 for (n = new_file_h->e_shnum - 1; n; n--) |
817 { | 816 { |
818 Elf32_Shdr section = NEW_SECTION_H (n); | 817 Elf32_Shdr section = NEW_SECTION_H (n); |
819 switch (section.sh_type) { | 818 switch (section.sh_type) { |
820 default: | 819 default: |
821 break; | 820 break; |
822 case SHT_REL: | 821 case SHT_REL: |
823 case SHT_RELA: | 822 case SHT_RELA: |
824 /* This code handles two different size structs, but there | 823 /* This code handles two different size structs, but there should |
825 should be no harm in that provided that r_offset is always | 824 be no harm in that provided that r_offset is always the first |
826 the first member. */ | 825 member. */ |
827 nn = section.sh_info; | 826 nn = section.sh_info; |
828 if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data") | 827 if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data") |
829 || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | 828 || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), |
830 ".data1")) | 829 ".data1")) |
831 { | 830 { |
840 } | 839 } |
841 } | 840 } |
842 break; | 841 break; |
843 } | 842 } |
844 } | 843 } |
845 #endif | |
846 | 844 |
847 #ifdef UNEXEC_USE_MAP_PRIVATE | 845 #ifdef UNEXEC_USE_MAP_PRIVATE |
848 if (lseek (new_file, 0, SEEK_SET) == -1) | 846 if (lseek (new_file, 0, SEEK_SET) == -1) |
849 fatal ("Can't rewind (%s): errno %d\n", new_name, errno); | 847 fatal ("Can't rewind (%s): errno %d\n", new_name, errno); |
850 | 848 |