Changeset 609 for branches/GNU/src/binutils/bfd/aout-adobe.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/aout-adobe.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* BFD back-end for a.out.adobe binaries. 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 3 2002 3 4 Free Software Foundation, Inc. 4 5 Written by Cygnus Support. Based on bout.c. … … 27 28 28 29 #include "aout/stab_gnu.h" 29 #include "libaout.h" /* BFD a.out internal data structures */30 #include "libaout.h" /* BFD a.out internal data structures. */ 30 31 31 32 /* Forward decl. */ 32 33 extern const bfd_target a_out_adobe_vec; 33 34 34 static const bfd_target *aout_adobe_callback PARAMS ((bfd *)); 35 36 extern boolean aout_32_slurp_symbol_table PARAMS ((bfd *abfd)); 37 extern boolean aout_32_write_syms PARAMS ((bfd *)); 38 static void aout_adobe_write_section PARAMS ((bfd *abfd, sec_ptr sect)); 35 static const bfd_target *aout_adobe_callback 36 PARAMS ((bfd *)); 37 extern bfd_boolean aout_32_slurp_symbol_table 38 PARAMS ((bfd *abfd)); 39 extern bfd_boolean aout_32_write_syms 40 PARAMS ((bfd *)); 41 static void aout_adobe_write_section 42 PARAMS ((bfd *abfd, sec_ptr sect)); 43 static const bfd_target * aout_adobe_object_p 44 PARAMS ((bfd *)); 45 static bfd_boolean aout_adobe_mkobject 46 PARAMS ((bfd *)); 47 static bfd_boolean aout_adobe_write_object_contents 48 PARAMS ((bfd *)); 49 static bfd_boolean aout_adobe_set_section_contents 50 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); 51 static bfd_boolean aout_adobe_set_arch_mach 52 PARAMS ((bfd *, enum bfd_architecture, unsigned long)); 53 static int aout_adobe_sizeof_headers 54 PARAMS ((bfd *, bfd_boolean)); 39 55 40 56 /* Swaps the information in an executable header taken from a raw byte … … 42 58 43 59 void aout_adobe_swap_exec_header_in 44 PARAMS ((bfd *abfd, struct external_exec *raw_bytes, 45 struct internal_exec *execp)); 60 PARAMS ((bfd *, struct external_exec *, struct internal_exec *)); 46 61 47 62 void … … 54 69 55 70 /* Now fill in fields in the execp, from the bytes in the raw data. */ 56 execp->a_info = bfd_h_get_32 (abfd, bytes->e_info);71 execp->a_info = H_GET_32 (abfd, bytes->e_info); 57 72 execp->a_text = GET_WORD (abfd, bytes->e_text); 58 73 execp->a_data = GET_WORD (abfd, bytes->e_data); … … 67 82 supplied buffer ready for writing to disk. */ 68 83 69 PROTO(void, aout_adobe_swap_exec_header_out, 70 (bfd *abfd, 71 struct internal_exec *execp, 72 struct external_exec *raw_bytes)); 84 void aout_adobe_swap_exec_header_out 85 PARAMS ((bfd *, struct internal_exec *, struct external_exec *)); 86 73 87 void 74 88 aout_adobe_swap_exec_header_out (abfd, execp, raw_bytes) … … 81 95 /* Now fill in fields in the raw data, from the fields in the exec 82 96 struct. */ 83 bfd_h_put_32 (abfd, execp->a_info , bytes->e_info);97 H_PUT_32 (abfd, execp->a_info , bytes->e_info); 84 98 PUT_WORD (abfd, execp->a_text , bytes->e_text); 85 99 PUT_WORD (abfd, execp->a_data , bytes->e_data); … … 98 112 struct external_exec exec_bytes; 99 113 char *targ; 100 101 if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) 102 != EXEC_BYTES_SIZE)114 bfd_size_type amt = EXEC_BYTES_SIZE; 115 116 if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt) 103 117 { 104 118 if (bfd_get_error () != bfd_error_system_call) … … 107 121 } 108 122 109 anexec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);123 anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info); 110 124 111 125 /* Normally we just compare for the magic number. … … 143 157 struct external_segdesc ext[1]; 144 158 char *section_name; 145 char try_again[30]; /* name and number*/159 char try_again[30]; /* Name and number. */ 146 160 char *newname; 147 161 int trynum; … … 149 163 150 164 /* Architecture and machine type -- unknown in this format. */ 151 bfd_set_arch_mach (abfd, bfd_arch_unknown, 0 );165 bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L); 152 166 153 167 /* The positions of the string table and symbol table. */ … … 156 170 157 171 /* Suck up the section information from the file, one section at a time. */ 158 159 172 for (;;) 160 173 { 161 if (bfd_read ((PTR) ext, 1, sizeof (*ext), abfd) != sizeof (*ext)) 174 bfd_size_type amt = sizeof (*ext); 175 if (bfd_bread ((PTR) ext, amt, abfd) != amt) 162 176 { 163 177 if (bfd_get_error () != bfd_error_system_call) 164 178 bfd_set_error (bfd_error_wrong_format); 179 165 180 return 0; 166 181 } … … 188 203 (*_bfd_error_handler) 189 204 (_("%s: Unknown section type in a.out.adobe file: %x\n"), 190 bfd_ get_filename (abfd), ext->e_type[0]);205 bfd_archive_filename (abfd), ext->e_type[0]); 191 206 goto no_more_sections; 192 207 } … … 194 209 /* First one is called ".text" or whatever; subsequent ones are 195 210 ".text1", ".text2", ... */ 196 197 211 bfd_set_error (bfd_error_no_error); 198 212 sect = bfd_make_section (abfd, section_name); 199 213 trynum = 0; 214 200 215 while (!sect) 201 216 { … … 210 225 if (sect->name == try_again) 211 226 { 212 newname = (char *) bfd_zalloc (abfd, strlen (sect->name)); 227 amt = strlen (sect->name); 228 newname = (char *) bfd_zalloc (abfd, amt); 213 229 if (newname == NULL) 214 230 return 0; … … 221 237 /* Assumed big-endian. */ 222 238 sect->_raw_size = ((ext->e_size[0] << 8) 223 | ext->e_size[1] << 8 )224 | ext->e_size[2];239 | ext->e_size[1] << 8 240 | ext->e_size[2]); 225 241 sect->_cooked_size = sect->_raw_size; 226 sect->vma = bfd_h_get_32 (abfd, ext->e_virtbase);227 sect->filepos = bfd_h_get_32 (abfd, ext->e_filebase);242 sect->vma = H_GET_32 (abfd, ext->e_virtbase); 243 sect->filepos = H_GET_32 (abfd, ext->e_filebase); 228 244 /* FIXME XXX alignment? */ 229 245 … … 241 257 sect->reloc_count = execp->a_drsize; 242 258 break; 259 260 default: 261 break; 243 262 } 244 263 } … … 254 273 } 255 274 256 struct bout_data_struct { 257 struct aoutdata a; 258 struct internal_exec e; 259 }; 260 261 static boolean 275 struct bout_data_struct 276 { 277 struct aoutdata a; 278 struct internal_exec e; 279 }; 280 281 static bfd_boolean 262 282 aout_adobe_mkobject (abfd) 263 283 bfd *abfd; 264 284 { 265 285 struct bout_data_struct *rawptr; 266 267 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, sizeof (struct bout_data_struct)); 286 bfd_size_type amt = sizeof (struct bout_data_struct); 287 288 rawptr = (struct bout_data_struct *) bfd_zalloc (abfd, amt); 268 289 if (rawptr == NULL) 269 return false;290 return FALSE; 270 291 271 292 abfd->tdata.bout_data = rawptr; … … 278 299 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; 279 300 280 return true;281 } 282 283 static b oolean301 return TRUE; 302 } 303 304 static bfd_boolean 284 305 aout_adobe_write_object_contents (abfd) 285 306 bfd *abfd; … … 288 309 static struct external_segdesc sentinel[1]; /* Initialized to zero. */ 289 310 asection *sect; 311 bfd_size_type amt; 290 312 291 313 exec_hdr (abfd)->a_info = ZMAGIC; … … 325 347 aout_adobe_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr); 326 348 349 amt = EXEC_BYTES_SIZE; 327 350 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 328 || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd) 329 != EXEC_BYTES_SIZE)) 330 return false; 351 || bfd_bwrite ((PTR) &swapped_hdr, amt, abfd) != amt) 352 return FALSE; 331 353 332 354 /* Now write out the section information. Text first, data next, rest … … 334 356 335 357 for (sect = abfd->sections; sect; sect = sect->next) 336 { 337 if (sect->flags & SEC_CODE) 338 { 339 aout_adobe_write_section (abfd, sect); 340 } 341 } 358 if (sect->flags & SEC_CODE) 359 aout_adobe_write_section (abfd, sect); 360 342 361 for (sect = abfd->sections; sect; sect = sect->next) 343 { 344 if (sect->flags & SEC_DATA) 345 { 346 aout_adobe_write_section (abfd, sect); 347 } 348 } 362 if (sect->flags & SEC_DATA) 363 aout_adobe_write_section (abfd, sect); 364 349 365 for (sect = abfd->sections; sect; sect = sect->next) 350 { 351 if (!(sect->flags & (SEC_CODE | SEC_DATA))) 352 { 353 aout_adobe_write_section (abfd, sect); 354 } 355 } 366 if (!(sect->flags & (SEC_CODE | SEC_DATA))) 367 aout_adobe_write_section (abfd, sect); 356 368 357 369 /* Write final `sentinel` section header (with type of 0). */ 358 if (bfd_write ((PTR) sentinel, 1, sizeof (*sentinel), abfd)359 != sizeof (*sentinel))360 return false;370 amt = sizeof (*sentinel); 371 if (bfd_bwrite ((PTR) sentinel, amt, abfd) != amt) 372 return FALSE; 361 373 362 374 /* Now write out reloc info, followed by syms and strings. */ … … 365 377 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET) 366 378 != 0) 367 return false;379 return FALSE; 368 380 369 381 if (! aout_32_write_syms (abfd)) 370 return false;382 return FALSE; 371 383 372 384 if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*exec_hdr (abfd))), SEEK_SET) 373 385 != 0) 374 return false;386 return FALSE; 375 387 376 388 for (sect = abfd->sections; sect; sect = sect->next) 377 { 378 if (sect->flags & SEC_CODE) 379 { 380 if (!aout_32_squirt_out_relocs (abfd, sect)) 381 return false; 382 } 383 } 389 if (sect->flags & SEC_CODE) 390 if (!aout_32_squirt_out_relocs (abfd, sect)) 391 return FALSE; 384 392 385 393 if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*exec_hdr (abfd))), SEEK_SET) 386 394 != 0) 387 return false;395 return FALSE; 388 396 389 397 for (sect = abfd->sections; sect; sect = sect->next) 390 { 391 if (sect->flags & SEC_DATA) 392 { 393 if (!aout_32_squirt_out_relocs (abfd, sect)) 394 return false; 395 } 396 } 398 if (sect->flags & SEC_DATA) 399 if (!aout_32_squirt_out_relocs (abfd, sect)) 400 return FALSE; 397 401 } 398 return true; 402 403 return TRUE; 399 404 } 400 405 … … 408 413 409 414 410 static b oolean415 static bfd_boolean 411 416 aout_adobe_set_section_contents (abfd, section, location, offset, count) 412 417 bfd *abfd; … … 420 425 421 426 /* Set by bfd.c handler. */ 422 if ( abfd->output_has_begun == false)427 if (! abfd->output_has_begun) 423 428 { 424 429 /* Assign file offsets to sections. Text sections are first, and 425 430 are contiguous. Then data sections. Everything else at the end. */ 426 427 431 section_start = N_TXTOFF (ignore<-->me); 428 432 … … 462 466 going. */ 463 467 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0) 464 return false; 465 466 if (count != 0) 467 { 468 return (bfd_write ((PTR) location, 1, count, abfd) == count) ? true : false; 469 } 470 return true; 471 } 472 473 static boolean 468 return FALSE; 469 470 if (count == 0) 471 return TRUE; 472 473 return bfd_bwrite ((PTR) location, count, abfd) == count; 474 } 475 476 static bfd_boolean 474 477 aout_adobe_set_arch_mach (abfd, arch, machine) 475 478 bfd *abfd; … … 478 481 { 479 482 if (! bfd_default_set_arch_mach (abfd, arch, machine)) 480 return false;483 return FALSE; 481 484 482 485 if (arch == bfd_arch_unknown 483 486 || arch == bfd_arch_m68k) 484 return true;485 486 return false;487 return TRUE; 488 489 return FALSE; 487 490 } 488 491 … … 490 493 aout_adobe_sizeof_headers (ignore_abfd, ignore) 491 494 bfd *ignore_abfd ATTRIBUTE_UNUSED; 492 b oolean ignore ATTRIBUTE_UNUSED;495 bfd_boolean ignore ATTRIBUTE_UNUSED; 493 496 { 494 497 return sizeof (struct internal_exec); … … 515 518 #define aout_32_bfd_relax_section bfd_generic_relax_section 516 519 #define aout_32_bfd_gc_sections bfd_generic_gc_sections 520 #define aout_32_bfd_merge_sections bfd_generic_merge_sections 521 #define aout_32_bfd_discard_group bfd_generic_discard_group 517 522 #define aout_32_bfd_link_hash_table_create \ 518 523 _bfd_generic_link_hash_table_create 524 #define aout_32_bfd_link_hash_table_free \ 525 _bfd_generic_link_hash_table_free 519 526 #define aout_32_bfd_link_add_symbols _bfd_generic_link_add_symbols 527 #define aout_32_bfd_link_just_syms _bfd_generic_link_just_syms 520 528 #define aout_32_bfd_final_link _bfd_generic_final_link 521 529 #define aout_32_bfd_link_split_section _bfd_generic_link_split_section 522 530 523 const bfd_target a_out_adobe_vec = { 524 "a.out.adobe", /* name */ 525 bfd_target_aout_flavour, 526 BFD_ENDIAN_BIG, /* data byte order is unknown (big assumed) */ 527 BFD_ENDIAN_BIG, /* hdr byte order is big */ 528 (HAS_RELOC | EXEC_P | /* object flags */ 529 HAS_LINENO | HAS_DEBUG | 530 HAS_SYMS | HAS_LOCALS | WP_TEXT ), 531 /* section flags */ 532 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC), 533 '_', /* symbol leading char */ 534 ' ', /* ar_pad_char */ 535 16, /* ar_max_namelen */ 536 537 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 538 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 539 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ 540 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 541 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 542 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ 543 {_bfd_dummy_target, aout_adobe_object_p, /* bfd_check_format */ 544 bfd_generic_archive_p, _bfd_dummy_target}, 545 {bfd_false, aout_adobe_mkobject, /* bfd_set_format */ 546 _bfd_generic_mkarchive, bfd_false}, 547 {bfd_false, aout_adobe_write_object_contents, /* bfd_write_contents */ 548 _bfd_write_archive_contents, bfd_false}, 549 550 BFD_JUMP_TABLE_GENERIC (aout_32), 551 BFD_JUMP_TABLE_COPY (_bfd_generic), 552 BFD_JUMP_TABLE_CORE (_bfd_nocore), 553 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd), 554 BFD_JUMP_TABLE_SYMBOLS (aout_32), 555 BFD_JUMP_TABLE_RELOCS (aout_32), 556 BFD_JUMP_TABLE_WRITE (aout_32), 557 BFD_JUMP_TABLE_LINK (aout_32), 558 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 559 560 NULL, 561 562 (PTR) 0 563 }; 531 const bfd_target a_out_adobe_vec = 532 { 533 "a.out.adobe", /* name */ 534 bfd_target_aout_flavour, 535 BFD_ENDIAN_BIG, /* data byte order is unknown (big assumed) */ 536 BFD_ENDIAN_BIG, /* hdr byte order is big */ 537 (HAS_RELOC | EXEC_P | /* object flags */ 538 HAS_LINENO | HAS_DEBUG | 539 HAS_SYMS | HAS_LOCALS | WP_TEXT ), 540 /* section flags */ 541 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC), 542 '_', /* symbol leading char */ 543 ' ', /* ar_pad_char */ 544 16, /* ar_max_namelen */ 545 546 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 547 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 548 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ 549 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 550 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 551 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ 552 {_bfd_dummy_target, aout_adobe_object_p, /* bfd_check_format */ 553 bfd_generic_archive_p, _bfd_dummy_target}, 554 {bfd_false, aout_adobe_mkobject, /* bfd_set_format */ 555 _bfd_generic_mkarchive, bfd_false}, 556 {bfd_false, aout_adobe_write_object_contents,/* bfd_write_contents */ 557 _bfd_write_archive_contents, bfd_false}, 558 559 BFD_JUMP_TABLE_GENERIC (aout_32), 560 BFD_JUMP_TABLE_COPY (_bfd_generic), 561 BFD_JUMP_TABLE_CORE (_bfd_nocore), 562 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd), 563 BFD_JUMP_TABLE_SYMBOLS (aout_32), 564 BFD_JUMP_TABLE_RELOCS (aout_32), 565 BFD_JUMP_TABLE_WRITE (aout_32), 566 BFD_JUMP_TABLE_LINK (aout_32), 567 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 568 569 NULL, 570 571 (PTR) 0 572 }; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.