comparison src/unexcw.c @ 446:1ccc32a20af4 r21-2-38

Import from CVS: tag r21-2-38
author cvs
date Mon, 13 Aug 2007 11:37:21 +0200
parents 576fb035e263
children 3078fd1074e8
comparison
equal deleted inserted replaced
445:34f3776fcf0e 446:1ccc32a20af4
51 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) 51 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
52 #define ALIGN_ALLOC(addr) \ 52 #define ALIGN_ALLOC(addr) \
53 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK) 53 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
54 /* Note that all sections must be aligned on a 0x1000 boundary so 54 /* Note that all sections must be aligned on a 0x1000 boundary so
55 this is the minimum size that our dummy bss can be. */ 55 this is the minimum size that our dummy bss can be. */
56 #ifdef BROKEN_GDB
56 #define BSS_PAD_SIZE 0x1000 57 #define BSS_PAD_SIZE 0x1000
58 #else
59 #define BSS_PAD_SIZE 0
60 #endif
57 61
58 /* To prevent zero-initialized variables from being placed into the bss 62 /* To prevent zero-initialized variables from being placed into the bss
59 section, use non-zero values to represent an uninitialized state. */ 63 section, use non-zero values to represent an uninitialized state. */
60 #define UNINIT_PTR ((void *) 0xF0A0F0A0) 64 #define UNINIT_PTR ((void *) 0xF0A0F0A0)
61 #define UNINIT_LONG (0xF0A0F0A0L) 65 #define UNINIT_LONG (0xF0A0F0A0L)
119 { 123 {
120 PERROR (a_name); 124 PERROR (a_name);
121 } 125 }
122 126
123 if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, 127 if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
124 CREAT_MODE)) < 0) 128 0755)) < 0)
125 { 129 {
126 PERROR (new_name); 130 PERROR (new_name);
127 } 131 }
128 132
129 /* Get the interesting section info, like start and size of .bss... */ 133 /* Get the interesting section info, like start and size of .bss... */
304 #endif 308 #endif
305 f_data.s_size += file_sz_change; 309 f_data.s_size += file_sz_change;
306 lseek (a_new, 0, SEEK_SET); 310 lseek (a_new, 0, SEEK_SET);
307 /* write file header */ 311 /* write file header */
308 f_hdr.f_symptr += file_sz_change; 312 f_hdr.f_symptr += file_sz_change;
313 #ifndef BROKEN_GDB
314 f_hdr.f_nscns--;
315 #endif
309 316
310 printf("writing file header\n"); 317 printf("writing file header\n");
311 if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr)) 318 if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr))
312 { 319 {
313 PERROR("failed to write file header"); 320 PERROR("failed to write file header");
331 338
332 if (write(a_new, &f_text, sizeof(f_text)) != sizeof(f_text)) 339 if (write(a_new, &f_text, sizeof(f_text)) != sizeof(f_text))
333 { 340 {
334 PERROR("failed to write text header"); 341 PERROR("failed to write text header");
335 } 342 }
336 343 #ifdef BROKEN_GDB
337 /* Write small bss section. */ 344 /* Write small bss section. */
338 if (!sections_reversed) 345 if (!sections_reversed)
339 { 346 {
340 f_bss.s_size = BSS_PAD_SIZE; 347 f_bss.s_size = BSS_PAD_SIZE;
341 f_bss.s_paddr = BSS_PAD_SIZE; 348 f_bss.s_paddr = BSS_PAD_SIZE;
343 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss)) 350 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
344 { 351 {
345 PERROR("failed to write bss header"); 352 PERROR("failed to write bss header");
346 } 353 }
347 } 354 }
348 355 #endif
349 /* write new data header */ 356 /* write new data header */
350 printf("writing .data header\n"); 357 printf("writing .data header\n");
351 358
352 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data)) 359 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data))
353 { 360 {
354 PERROR("failed to write data header"); 361 PERROR("failed to write data header");
355 } 362 }
356 363 #ifdef BROKEN_GDB
357 /* Write small bss section. */ 364 /* Write small bss section. */
358 if (sections_reversed) 365 if (sections_reversed)
359 { 366 {
360 f_bss.s_size = BSS_PAD_SIZE; 367 f_bss.s_size = BSS_PAD_SIZE;
361 f_bss.s_paddr = BSS_PAD_SIZE; 368 f_bss.s_paddr = BSS_PAD_SIZE;
363 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss)) 370 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
364 { 371 {
365 PERROR("failed to write bss header"); 372 PERROR("failed to write bss header");
366 } 373 }
367 } 374 }
368 375 #endif
369 printf("writing following data header\n"); 376 printf("writing following data header\n");
370 f_nextdata.s_scnptr += file_sz_change; 377 f_nextdata.s_scnptr += file_sz_change;
371 if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change; 378 if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
372 if (f_nextdata.s_relptr != 0) f_nextdata.s_relptr += file_sz_change; 379 if (f_nextdata.s_relptr != 0) f_nextdata.s_relptr += file_sz_change;
373 if (write(a_new, &f_nextdata, sizeof(f_nextdata)) != sizeof(f_nextdata)) 380 if (write(a_new, &f_nextdata, sizeof(f_nextdata)) != sizeof(f_nextdata))
390 if (write(a_new, &section, sizeof(section)) != sizeof(section)) 397 if (write(a_new, &section, sizeof(section)) != sizeof(section))
391 { 398 {
392 PERROR("failed to write data header"); 399 PERROR("failed to write data header");
393 } 400 }
394 } 401 }
395 402 #ifndef BROKEN_GDB
403 /* dump bss to maintain offsets */
404 memset(&f_bss, 0, sizeof(f_bss));
405 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
406 {
407 PERROR("failed to write bss header");
408 }
409 #endif
396 size=lseek(a_new, 0, SEEK_CUR); 410 size=lseek(a_new, 0, SEEK_CUR);
397 CHECK_AOUT_POS(size); 411 CHECK_AOUT_POS(size);
398 412
399 /* copy eveything else until start of data */ 413 /* copy eveything else until start of data */
400 size = f_data_s_scnptr - lseek (a_out, 0, SEEK_CUR); 414 size = f_data_s_scnptr - lseek (a_out, 0, SEEK_CUR);