comparison src/unexcw.c @ 269:b2472a1930f2 r20-5b33

Import from CVS: tag r20-5b33
author cvs
date Mon, 13 Aug 2007 10:27:19 +0200
parents 727739f917cb
children 90d73dddcdc4
comparison
equal deleted inserted replaced
268:6ced69ccd85f 269:b2472a1930f2
67 /* Cached info about the .bss section in the executable. */ 67 /* Cached info about the .bss section in the executable. */
68 void* bss_start = UNINIT_PTR; 68 void* bss_start = UNINIT_PTR;
69 unsigned long bss_size = UNINIT_LONG; 69 unsigned long bss_size = UNINIT_LONG;
70 FILHDR f_hdr; 70 FILHDR f_hdr;
71 PEAOUTHDR f_ohdr; 71 PEAOUTHDR f_ohdr;
72 SCNHDR f_data, f_bss, f_text, f_idata; 72 SCNHDR f_data, f_bss, f_text, f_nextdata;
73 73
74 #define PERROR(arg) perror(arg);exit(-1) 74 #define PERROR(arg) perror(arg);exit(-1)
75 #define CHECK_AOUT_POS(a) \ 75 #define CHECK_AOUT_POS(a) \
76 if (lseek(a_out, 0, SEEK_CUR) != a) \ 76 if (lseek(a_out, 0, SEEK_CUR) != a) \
77 { \ 77 { \
194 not any of the library data (if library data is included, 194 not any of the library data (if library data is included,
195 then a dumped Emacs won't run on system versions other 195 then a dumped Emacs won't run on system versions other
196 than the one Emacs was dumped on). */ 196 than the one Emacs was dumped on). */
197 data_size = (unsigned long)my_edata - (unsigned long)data_start_va; 197 data_size = (unsigned long)my_edata - (unsigned long)data_start_va;
198 198
199 /* The .idata section. */ 199 /* The following data section. */
200 if (read (a_out, &f_idata, sizeof (f_idata)) != sizeof (f_idata) 200 if (read (a_out, &f_nextdata, sizeof (f_nextdata)) != sizeof (f_nextdata)
201 && 201 &&
202 strcmp (f_idata.s_name, ".rdata")) 202 strcmp (&f_nextdata.s_name[2], "data"))
203 { 203 {
204 PERROR ("no .idata section"); 204 PERROR ("no other data section");
205 } 205 }
206 } 206 }
207 207
208 /* The dump routines. */ 208 /* The dump routines. */
209 209
237 f_data_s_scnptr = f_data.s_scnptr; 237 f_data_s_scnptr = f_data.s_scnptr;
238 f_data_s_vaddr = f_data.s_vaddr; 238 f_data_s_vaddr = f_data.s_vaddr;
239 f_data.s_vaddr = f_bss.s_vaddr; 239 f_data.s_vaddr = f_bss.s_vaddr;
240 f_data.s_paddr += new_bss_size; 240 f_data.s_paddr += new_bss_size;
241 #if 0 241 #if 0
242 if (f_data.s_size + f_idata.s_size != f_ohdr.dsize) 242 if (f_data.s_size + f_nextdata.s_size != f_ohdr.dsize)
243 { 243 {
244 printf("section size doesn't tally with dsize %lx != %lx\n", 244 printf("section size doesn't tally with dsize %lx != %lx\n",
245 f_data.s_size + f_idata.s_size, f_ohdr.dsize); 245 f_data.s_size + f_nextdata.s_size, f_ohdr.dsize);
246 } 246 }
247 #endif 247 #endif
248 f_data.s_size += new_bss_size; 248 f_data.s_size += new_bss_size;
249 lseek (a_new, 0, SEEK_SET); 249 lseek (a_new, 0, SEEK_SET);
250 /* write file header */ 250 /* write file header */
283 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data)) 283 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data))
284 { 284 {
285 PERROR("failed to write data header"); 285 PERROR("failed to write data header");
286 } 286 }
287 287
288 printf("writing .idata header\n"); 288 printf("writing following data header\n");
289 f_idata.s_scnptr += file_sz_change; 289 f_nextdata.s_scnptr += file_sz_change;
290 if (f_idata.s_lnnoptr != 0) f_idata.s_lnnoptr += file_sz_change; 290 if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
291 if (f_idata.s_relptr != 0) f_idata.s_relptr += file_sz_change; 291 if (f_nextdata.s_relptr != 0) f_nextdata.s_relptr += file_sz_change;
292 if (write(a_new, &f_idata, sizeof(f_idata)) != sizeof(f_idata)) 292 if (write(a_new, &f_nextdata, sizeof(f_nextdata)) != sizeof(f_nextdata))
293 { 293 {
294 PERROR("failed to write idata header"); 294 PERROR("failed to write nextdata header");
295 } 295 }
296 296
297 /* copy other section headers adjusting the file offset */ 297 /* copy other section headers adjusting the file offset */
298 for (i=0; i<(f_hdr.f_nscns-3); i++) 298 for (i=0; i<(f_hdr.f_nscns-3); i++)
299 { 299 {
359 } 359 }
360 /* were going to use free again ... */ 360 /* were going to use free again ... */
361 static_heap_dumped = 0; 361 static_heap_dumped = 0;
362 362
363 size = lseek(a_out, f_data_s_scnptr + data_size, SEEK_SET); 363 size = lseek(a_out, f_data_s_scnptr + data_size, SEEK_SET);
364 size = f_idata.s_scnptr - size; 364 size = f_nextdata.s_scnptr - size;
365 dup_file_area(a_out, a_new, size); 365 dup_file_area(a_out, a_new, size);
366 366
367 // lseek(a_out, f_idata.s_scnptr, SEEK_CUR); 367 // lseek(a_out, f_nextdata.s_scnptr, SEEK_CUR);
368 CHECK_AOUT_POS(f_idata.s_scnptr); 368 CHECK_AOUT_POS(f_nextdata.s_scnptr);
369 /* now dump - idata don't need to do this cygwin ds is in .data! */ 369 /* now dump - nextdata don't need to do this cygwin ds is in .data! */
370 printf ("dumping .idata section... %lx bytes\n", f_idata.s_size); 370 printf ("dumping following data section... %lx bytes\n", f_nextdata.s_size);
371 371
372 dup_file_area(a_out,a_new,f_idata.s_size); 372 dup_file_area(a_out,a_new,f_nextdata.s_size);
373 373
374 /* write rest of file */ 374 /* write rest of file */
375 printf ("writing rest of file\n"); 375 printf ("writing rest of file\n");
376 size = lseek(a_out, 0, SEEK_END); 376 size = lseek(a_out, 0, SEEK_END);
377 size = size - (f_idata.s_scnptr + f_idata.s_size); /* length remaining in a_out */ 377 size = size - (f_nextdata.s_scnptr + f_nextdata.s_size); /* length remaining in a_out */
378 lseek(a_out, f_idata.s_scnptr + f_idata.s_size, SEEK_SET); 378 lseek(a_out, f_nextdata.s_scnptr + f_nextdata.s_size, SEEK_SET);
379 379
380 dup_file_area(a_out, a_new, size); 380 dup_file_area(a_out, a_new, size);
381 } 381 }
382 382
383 /* 383 /*