GNU Binutils with patches for OS216
Revision | e84d6fca26caaf6b02718efa0f1a4fb0d344348c (tree) |
---|---|
Time | 2002-11-13 00:44:24 |
Author | Alan Modra <amodra@gmai...> |
Commiter | Alan Modra |
* bfd.c (struct bfd_preserve): New.
(bfd_preserve_save): New function.
(bfd_preserve_restore): Ditto.
(bfd_preserve_finish): Ditto.
* bfd-in2.h: Regenerate.
* mach-o.c: Formatting.
(bfd_mach_o_scan_read_symtab_symbol): Make "value" unsigned.
(bfd_mach_o_object_p): Use bfd_preserve_save/restore/finish.
(bfd_mach_o_core_p): Ditto.
(bfd_mach_o_scan): Pass in mdata.
* mach-o.h (bfd_mach_o_scan): Update prototype.
* pef.c: Formatting.
(bfd_pef_object_p): Use bfd_preserve_save/restore/finish.
(bfd_pef_xlib_object_p): Ditto.
(bfd_pef_scan): Pass in mdata. Move version check to bfd_pef_object_p.
* pef.h (bfd_pef_scan): Update prototype.
* xsym.c: Formatting, K&R fixes.
(bfd_sym_object_p): Use bfd_preserve_save/restore/finish.
(bfd_sym_scan): New function split out from bfd_sym_object_p.
* xsym.h (bfd_sym_scan): Declare.
* elfcode.h (elf_object_p): Use bfd_preserve_save/restore/finish.
(elf_core_file_p): Likewise.
* targets.c (_bfd_target_vector): Revert 2002-11-08 change.
@@ -1,3 +1,30 @@ | ||
1 | +2002-11-13 Klee Dienes <kdienes@apple.com> | |
2 | + Alan Modra <amodra@bigpond.net.au> | |
3 | + | |
4 | + * bfd.c (struct bfd_preserve): New. | |
5 | + (bfd_preserve_save): New function. | |
6 | + (bfd_preserve_restore): Ditto. | |
7 | + (bfd_preserve_finish): Ditto. | |
8 | + * bfd-in2.h: Regenerate. | |
9 | + * mach-o.c: Formatting. | |
10 | + (bfd_mach_o_scan_read_symtab_symbol): Make "value" unsigned. | |
11 | + (bfd_mach_o_object_p): Use bfd_preserve_save/restore/finish. | |
12 | + (bfd_mach_o_core_p): Ditto. | |
13 | + (bfd_mach_o_scan): Pass in mdata. | |
14 | + * mach-o.h (bfd_mach_o_scan): Update prototype. | |
15 | + * pef.c: Formatting. | |
16 | + (bfd_pef_object_p): Use bfd_preserve_save/restore/finish. | |
17 | + (bfd_pef_xlib_object_p): Ditto. | |
18 | + (bfd_pef_scan): Pass in mdata. Move version check to bfd_pef_object_p. | |
19 | + * pef.h (bfd_pef_scan): Update prototype. | |
20 | + * xsym.c: Formatting, K&R fixes. | |
21 | + (bfd_sym_object_p): Use bfd_preserve_save/restore/finish. | |
22 | + (bfd_sym_scan): New function split out from bfd_sym_object_p. | |
23 | + * xsym.h (bfd_sym_scan): Declare. | |
24 | + * elfcode.h (elf_object_p): Use bfd_preserve_save/restore/finish. | |
25 | + (elf_core_file_p): Likewise. | |
26 | + * targets.c (_bfd_target_vector): Revert 2002-11-08 change. | |
27 | + | |
1 | 28 | 2002-11-12 Nick Clifton <nickc@redhat.com> |
2 | 29 | |
3 | 30 | * po/da.po: Updated Danish translation. |
@@ -3739,6 +3739,27 @@ extern bfd_byte *bfd_get_relocated_section_contents | ||
3739 | 3739 | boolean |
3740 | 3740 | bfd_alt_mach_code PARAMS ((bfd *abfd, int alternative)); |
3741 | 3741 | |
3742 | +struct bfd_preserve | |
3743 | +{ | |
3744 | + PTR marker; | |
3745 | + PTR tdata; | |
3746 | + flagword flags; | |
3747 | + const struct bfd_arch_info *arch_info; | |
3748 | + struct sec *sections; | |
3749 | + struct sec **section_tail; | |
3750 | + unsigned int section_count; | |
3751 | + struct bfd_hash_table section_htab; | |
3752 | +}; | |
3753 | + | |
3754 | +boolean | |
3755 | +bfd_preserve_save PARAMS ((bfd *, struct bfd_preserve *)); | |
3756 | + | |
3757 | +void | |
3758 | +bfd_preserve_restore PARAMS ((bfd *, struct bfd_preserve *)); | |
3759 | + | |
3760 | +void | |
3761 | +bfd_preserve_finish PARAMS ((bfd *, struct bfd_preserve *)); | |
3762 | + | |
3742 | 3763 | /* Extracted from archive.c. */ |
3743 | 3764 | symindex |
3744 | 3765 | bfd_get_next_mapent PARAMS ((bfd *abfd, symindex previous, carsym **sym)); |
@@ -1392,3 +1392,133 @@ bfd_alt_mach_code (abfd, alternative) | ||
1392 | 1392 | |
1393 | 1393 | return false; |
1394 | 1394 | } |
1395 | + | |
1396 | +/* | |
1397 | +CODE_FRAGMENT | |
1398 | + | |
1399 | +.struct bfd_preserve | |
1400 | +.{ | |
1401 | +. PTR marker; | |
1402 | +. PTR tdata; | |
1403 | +. flagword flags; | |
1404 | +. const struct bfd_arch_info *arch_info; | |
1405 | +. struct sec *sections; | |
1406 | +. struct sec **section_tail; | |
1407 | +. unsigned int section_count; | |
1408 | +. struct bfd_hash_table section_htab; | |
1409 | +.}; | |
1410 | +. | |
1411 | +*/ | |
1412 | + | |
1413 | +/* | |
1414 | +FUNCTION | |
1415 | + bfd_preserve_save | |
1416 | + | |
1417 | +SYNOPSIS | |
1418 | + boolean bfd_preserve_save (bfd *, struct bfd_preserve *); | |
1419 | + | |
1420 | +DESCRIPTION | |
1421 | + When testing an object for compatibility with a particular | |
1422 | + target back-end, the back-end object_p function needs to set | |
1423 | + up certain fields in the bfd on successfully recognizing the | |
1424 | + object. This typically happens in a piecemeal fashion, with | |
1425 | + failures possible at many points. On failure, the bfd is | |
1426 | + supposed to be restored to its initial state, which is | |
1427 | + virtually impossible. However, restoring a subset of the bfd | |
1428 | + state works in practice. This function stores the subset and | |
1429 | + reinitializes the bfd. | |
1430 | + | |
1431 | +*/ | |
1432 | + | |
1433 | +boolean | |
1434 | +bfd_preserve_save (abfd, preserve) | |
1435 | + bfd *abfd; | |
1436 | + struct bfd_preserve *preserve; | |
1437 | +{ | |
1438 | + preserve->tdata = abfd->tdata.any; | |
1439 | + preserve->arch_info = abfd->arch_info; | |
1440 | + preserve->flags = abfd->flags; | |
1441 | + | |
1442 | + preserve->sections = abfd->sections; | |
1443 | + preserve->section_tail = abfd->section_tail; | |
1444 | + preserve->section_count = abfd->section_count; | |
1445 | + preserve->section_htab = abfd->section_htab; | |
1446 | + | |
1447 | + if (! bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc)) | |
1448 | + return false; | |
1449 | + | |
1450 | + abfd->tdata.any = NULL; | |
1451 | + abfd->arch_info = &bfd_default_arch_struct; | |
1452 | + abfd->flags = 0; | |
1453 | + | |
1454 | + abfd->sections = NULL; | |
1455 | + abfd->section_tail = &abfd->sections; | |
1456 | + abfd->section_count = 0; | |
1457 | + | |
1458 | + return true; | |
1459 | +} | |
1460 | + | |
1461 | +/* | |
1462 | +FUNCTION | |
1463 | + bfd_preserve_restore | |
1464 | + | |
1465 | +SYNOPSIS | |
1466 | + void bfd_preserve_restore (bfd *, struct bfd_preserve *); | |
1467 | + | |
1468 | +DESCRIPTION | |
1469 | + This function restores bfd state saved by bfd_preserve_save. | |
1470 | + If MARKER is non-NULL in struct bfd_preserve then that block | |
1471 | + and all subsequently bfd_alloc'd memory is freed. | |
1472 | + | |
1473 | +*/ | |
1474 | + | |
1475 | +void | |
1476 | +bfd_preserve_restore (abfd, preserve) | |
1477 | + bfd *abfd; | |
1478 | + struct bfd_preserve *preserve; | |
1479 | +{ | |
1480 | + bfd_hash_table_free (&abfd->section_htab); | |
1481 | + | |
1482 | + abfd->tdata.any = preserve->tdata; | |
1483 | + abfd->arch_info = preserve->arch_info; | |
1484 | + abfd->flags = preserve->flags; | |
1485 | + | |
1486 | + abfd->section_htab = preserve->section_htab; | |
1487 | + abfd->sections = preserve->sections; | |
1488 | + abfd->section_tail = preserve->section_tail; | |
1489 | + abfd->section_count = preserve->section_count; | |
1490 | + | |
1491 | + /* bfd_release frees all memory more recently bfd_alloc'd than | |
1492 | + its arg, as well as its arg. */ | |
1493 | + if (preserve->marker != NULL) | |
1494 | + { | |
1495 | + bfd_release (abfd, preserve->marker); | |
1496 | + preserve->marker = NULL; | |
1497 | + } | |
1498 | +} | |
1499 | + | |
1500 | +/* | |
1501 | +FUNCTION | |
1502 | + bfd_preserve_finish | |
1503 | + | |
1504 | +SYNOPSIS | |
1505 | + void bfd_preserve_finish (bfd *, struct bfd_preserve *); | |
1506 | + | |
1507 | +DESCRIPTION | |
1508 | + This function should be called when the bfd state saved by | |
1509 | + bfd_preserve_save is no longer needed. ie. when the back-end | |
1510 | + object_p function returns with success. | |
1511 | + | |
1512 | +*/ | |
1513 | + | |
1514 | +void | |
1515 | +bfd_preserve_finish (abfd, preserve) | |
1516 | + bfd *abfd ATTRIBUTE_UNUSED; | |
1517 | + struct bfd_preserve *preserve; | |
1518 | +{ | |
1519 | + /* It would be nice to be able to free more memory here, eg. old | |
1520 | + tdata, but that's not possible since these blocks are sitting | |
1521 | + inside bfd_alloc'd memory. The section hash is on a separate | |
1522 | + objalloc. */ | |
1523 | + bfd_hash_table_free (&preserve->section_htab); | |
1524 | +} |
@@ -505,16 +505,6 @@ elf_file_p (x_ehdrp) | ||
505 | 505 | && (x_ehdrp->e_ident[EI_MAG3] == ELFMAG3)); |
506 | 506 | } |
507 | 507 | |
508 | -struct bfd_preserve | |
509 | -{ | |
510 | - const struct bfd_arch_info *arch_info; | |
511 | - struct elf_obj_tdata *tdata; | |
512 | - struct bfd_hash_table section_htab; | |
513 | - struct sec *sections; | |
514 | - struct sec **section_tail; | |
515 | - unsigned int section_count; | |
516 | -}; | |
517 | - | |
518 | 508 | /* Check to see if the file associated with ABFD matches the target vector |
519 | 509 | that ABFD points to. |
520 | 510 |
@@ -536,11 +526,10 @@ elf_object_p (abfd) | ||
536 | 526 | char *shstrtab; /* Internal copy of section header stringtab */ |
537 | 527 | struct elf_backend_data *ebd; |
538 | 528 | struct bfd_preserve preserve; |
539 | - struct elf_obj_tdata *new_tdata = NULL; | |
540 | 529 | asection *s; |
541 | 530 | bfd_size_type amt; |
542 | 531 | |
543 | - preserve.arch_info = abfd->arch_info; | |
532 | + preserve.marker = NULL; | |
544 | 533 | |
545 | 534 | /* Read in the ELF header in external format. */ |
546 | 535 |
@@ -584,24 +573,14 @@ elf_object_p (abfd) | ||
584 | 573 | the tdata pointer in the bfd. */ |
585 | 574 | |
586 | 575 | amt = sizeof (struct elf_obj_tdata); |
587 | - new_tdata = (struct elf_obj_tdata *) bfd_zalloc (abfd, amt); | |
588 | - if (new_tdata == NULL) | |
576 | + preserve.marker = bfd_zalloc (abfd, amt); | |
577 | + if (preserve.marker == NULL) | |
589 | 578 | goto got_no_match; |
590 | - preserve.tdata = elf_tdata (abfd); | |
591 | - elf_tdata (abfd) = new_tdata; | |
592 | - | |
593 | - /* Clear section information, since there might be a recognized bfd that | |
594 | - we now check if we can replace, and we don't want to append to it. */ | |
595 | - preserve.sections = abfd->sections; | |
596 | - preserve.section_tail = abfd->section_tail; | |
597 | - preserve.section_count = abfd->section_count; | |
598 | - preserve.section_htab = abfd->section_htab; | |
599 | - abfd->sections = NULL; | |
600 | - abfd->section_tail = &abfd->sections; | |
601 | - abfd->section_count = 0; | |
602 | - if (!bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc)) | |
579 | + if (!bfd_preserve_save (abfd, &preserve)) | |
603 | 580 | goto got_no_match; |
604 | 581 | |
582 | + elf_tdata (abfd) = preserve.marker; | |
583 | + | |
605 | 584 | /* Now that we know the byte order, swap in the rest of the header */ |
606 | 585 | i_ehdrp = elf_elfheader (abfd); |
607 | 586 | elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp); |
@@ -633,8 +612,10 @@ elf_object_p (abfd) | ||
633 | 612 | /* Check that the ELF e_machine field matches what this particular |
634 | 613 | BFD format expects. */ |
635 | 614 | if (ebd->elf_machine_code != i_ehdrp->e_machine |
636 | - && (ebd->elf_machine_alt1 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt1) | |
637 | - && (ebd->elf_machine_alt2 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt2)) | |
615 | + && (ebd->elf_machine_alt1 == 0 | |
616 | + || i_ehdrp->e_machine != ebd->elf_machine_alt1) | |
617 | + && (ebd->elf_machine_alt2 == 0 | |
618 | + || i_ehdrp->e_machine != ebd->elf_machine_alt2)) | |
638 | 619 | { |
639 | 620 | const bfd_target * const *target_ptr; |
640 | 621 |
@@ -844,11 +825,8 @@ elf_object_p (abfd) | ||
844 | 825 | } |
845 | 826 | } |
846 | 827 | |
847 | - /* It would be nice to be able to free more memory here, eg. old | |
848 | - elf_elfsections, old tdata, but that's not possible since these | |
849 | - blocks are sitting inside obj_alloc'd memory. */ | |
850 | - bfd_hash_table_free (&preserve.section_htab); | |
851 | - return (abfd->xvec); | |
828 | + bfd_preserve_finish (abfd, &preserve); | |
829 | + return abfd->xvec; | |
852 | 830 | |
853 | 831 | got_wrong_format_error: |
854 | 832 | /* There is way too much undoing of half-known state here. The caller, |
@@ -864,17 +842,8 @@ elf_object_p (abfd) | ||
864 | 842 | |
865 | 843 | got_no_match: |
866 | 844 | abfd->arch_info = preserve.arch_info; |
867 | - if (new_tdata != NULL) | |
868 | - { | |
869 | - /* bfd_release frees all memory more recently bfd_alloc'd than | |
870 | - its arg, as well as its arg. */ | |
871 | - bfd_release (abfd, new_tdata); | |
872 | - elf_tdata (abfd) = preserve.tdata; | |
873 | - abfd->section_htab = preserve.section_htab; | |
874 | - abfd->sections = preserve.sections; | |
875 | - abfd->section_tail = preserve.section_tail; | |
876 | - abfd->section_count = preserve.section_count; | |
877 | - } | |
845 | + if (preserve.marker != NULL) | |
846 | + bfd_preserve_restore (abfd, &preserve); | |
878 | 847 | return NULL; |
879 | 848 | } |
880 | 849 |
@@ -691,7 +691,7 @@ bfd_mach_o_scan_read_symtab_symbol (abfd, sym, s, i) | ||
691 | 691 | unsigned char type = -1; |
692 | 692 | unsigned char section = -1; |
693 | 693 | short desc = -1; |
694 | - long value = -1; | |
694 | + unsigned long value = -1; | |
695 | 695 | unsigned long stroff = -1; |
696 | 696 | unsigned int symtype = -1; |
697 | 697 |
@@ -1374,7 +1374,8 @@ bfd_mach_o_scan_read_segment (abfd, command) | ||
1374 | 1374 | { |
1375 | 1375 | bfd_vma segoff = command->offset + 48 + 8 + (i * 68); |
1376 | 1376 | |
1377 | - if (bfd_mach_o_scan_read_section (abfd, &seg->sections[i], segoff) != 0) | |
1377 | + if (bfd_mach_o_scan_read_section (abfd, &seg->sections[i], | |
1378 | + segoff) != 0) | |
1378 | 1379 | return -1; |
1379 | 1380 | } |
1380 | 1381 | } |
@@ -1455,7 +1456,8 @@ bfd_mach_o_scan_read_command (abfd, command) | ||
1455 | 1456 | return -1; |
1456 | 1457 | |
1457 | 1458 | command->type = (bfd_h_get_32 (abfd, buf) & ~BFD_MACH_O_LC_REQ_DYLD); |
1458 | - command->type_required = (bfd_h_get_32 (abfd, buf) & BFD_MACH_O_LC_REQ_DYLD) ? 1 : 0; | |
1459 | + command->type_required = (bfd_h_get_32 (abfd, buf) & BFD_MACH_O_LC_REQ_DYLD | |
1460 | + ? 1 : 0); | |
1459 | 1461 | command->len = bfd_h_get_32 (abfd, buf + 4); |
1460 | 1462 | |
1461 | 1463 | switch (command->type) |
@@ -1531,20 +1533,24 @@ bfd_mach_o_flatten_sections (abfd) | ||
1531 | 1533 | { |
1532 | 1534 | if (mdata->commands[i].type == BFD_MACH_O_LC_SEGMENT) |
1533 | 1535 | { |
1534 | - bfd_mach_o_segment_command *seg = &mdata->commands[i].command.segment; | |
1536 | + bfd_mach_o_segment_command *seg; | |
1537 | + | |
1538 | + seg = &mdata->commands[i].command.segment; | |
1535 | 1539 | mdata->nsects += seg->nsects; |
1536 | 1540 | } |
1537 | 1541 | } |
1538 | 1542 | |
1539 | - mdata->sections = bfd_alloc (abfd, mdata->nsects * sizeof (bfd_mach_o_section *)); | |
1543 | + mdata->sections = bfd_alloc (abfd, | |
1544 | + mdata->nsects * sizeof (bfd_mach_o_section *)); | |
1540 | 1545 | csect = 0; |
1541 | 1546 | |
1542 | 1547 | for (i = 0; i < mdata->header.ncmds; i++) |
1543 | 1548 | { |
1544 | 1549 | if (mdata->commands[i].type == BFD_MACH_O_LC_SEGMENT) |
1545 | 1550 | { |
1546 | - bfd_mach_o_segment_command *seg = &mdata->commands[i].command.segment; | |
1551 | + bfd_mach_o_segment_command *seg; | |
1547 | 1552 | |
1553 | + seg = &mdata->commands[i].command.segment; | |
1548 | 1554 | BFD_ASSERT (csect + seg->nsects <= mdata->nsects); |
1549 | 1555 | |
1550 | 1556 | for (j = 0; j < seg->nsects; j++) |
@@ -1579,7 +1585,8 @@ bfd_mach_o_scan_start_address (abfd) | ||
1579 | 1585 | for (i = 0; i < cmd->nflavours; i++) |
1580 | 1586 | { |
1581 | 1587 | if ((mdata->header.cputype == BFD_MACH_O_CPU_TYPE_I386) |
1582 | - && (cmd->flavours[i].flavour == (unsigned long) BFD_MACH_O_i386_THREAD_STATE)) | |
1588 | + && (cmd->flavours[i].flavour | |
1589 | + == (unsigned long) BFD_MACH_O_i386_THREAD_STATE)) | |
1583 | 1590 | { |
1584 | 1591 | unsigned char buf[4]; |
1585 | 1592 |
@@ -1608,27 +1615,24 @@ bfd_mach_o_scan_start_address (abfd) | ||
1608 | 1615 | } |
1609 | 1616 | |
1610 | 1617 | int |
1611 | -bfd_mach_o_scan (abfd, header) | |
1618 | +bfd_mach_o_scan (abfd, header, mdata) | |
1612 | 1619 | bfd *abfd; |
1613 | 1620 | bfd_mach_o_header *header; |
1621 | + bfd_mach_o_data_struct *mdata; | |
1614 | 1622 | { |
1615 | 1623 | unsigned int i; |
1616 | - bfd_mach_o_data_struct *mdata = NULL; | |
1617 | 1624 | enum bfd_architecture cputype; |
1618 | 1625 | unsigned long cpusubtype; |
1619 | 1626 | |
1620 | - mdata = ((bfd_mach_o_data_struct *) | |
1621 | - bfd_alloc (abfd, sizeof (bfd_mach_o_data_struct))); | |
1622 | - if (mdata == NULL) | |
1623 | - return -1; | |
1624 | - | |
1625 | 1627 | mdata->header = *header; |
1626 | 1628 | mdata->symbols = NULL; |
1627 | 1629 | |
1628 | - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); | |
1630 | + abfd->flags = (abfd->xvec->object_flags | |
1631 | + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); | |
1629 | 1632 | abfd->tdata.mach_o_data = mdata; |
1630 | 1633 | |
1631 | - bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype, &cputype, &cpusubtype); | |
1634 | + bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype, | |
1635 | + &cputype, &cpusubtype); | |
1632 | 1636 | if (cputype == bfd_arch_unknown) |
1633 | 1637 | { |
1634 | 1638 | fprintf (stderr, "bfd_mach_o_scan: unknown architecture 0x%lx/0x%lx\n", |
@@ -1712,84 +1716,99 @@ const bfd_target * | ||
1712 | 1716 | bfd_mach_o_object_p (abfd) |
1713 | 1717 | bfd *abfd; |
1714 | 1718 | { |
1719 | + struct bfd_preserve preserve; | |
1715 | 1720 | bfd_mach_o_header header; |
1716 | 1721 | |
1722 | + preserve.marker = NULL; | |
1717 | 1723 | if (bfd_mach_o_read_header (abfd, &header) != 0) |
1718 | - { | |
1719 | - bfd_set_error (bfd_error_wrong_format); | |
1720 | - return NULL; | |
1721 | - } | |
1724 | + goto wrong; | |
1722 | 1725 | |
1723 | - if (! ((header.byteorder == BFD_ENDIAN_BIG) | |
1724 | - || (header.byteorder == BFD_ENDIAN_LITTLE))) | |
1726 | + if (! (header.byteorder == BFD_ENDIAN_BIG | |
1727 | + || header.byteorder == BFD_ENDIAN_LITTLE)) | |
1725 | 1728 | { |
1726 | - fprintf (stderr, "unknown header byte-order value 0x%lx\n", (long) header.byteorder); | |
1727 | - bfd_set_error (bfd_error_wrong_format); | |
1728 | - return NULL; | |
1729 | + fprintf (stderr, "unknown header byte-order value 0x%lx\n", | |
1730 | + (long) header.byteorder); | |
1731 | + goto wrong; | |
1729 | 1732 | } |
1730 | 1733 | |
1731 | - if (! (((header.byteorder == BFD_ENDIAN_BIG) | |
1732 | - && (abfd->xvec->byteorder == BFD_ENDIAN_BIG) | |
1733 | - && (abfd->xvec->header_byteorder == BFD_ENDIAN_BIG)) | |
1734 | - || | |
1735 | - ((header.byteorder == BFD_ENDIAN_LITTLE) | |
1736 | - && (abfd->xvec->byteorder == BFD_ENDIAN_LITTLE) | |
1737 | - && (abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE)))) | |
1738 | - { | |
1739 | - bfd_set_error (bfd_error_wrong_format); | |
1740 | - return NULL; | |
1741 | - } | |
1734 | + if (! ((header.byteorder == BFD_ENDIAN_BIG | |
1735 | + && abfd->xvec->byteorder == BFD_ENDIAN_BIG | |
1736 | + && abfd->xvec->header_byteorder == BFD_ENDIAN_BIG) | |
1737 | + || (header.byteorder == BFD_ENDIAN_LITTLE | |
1738 | + && abfd->xvec->byteorder == BFD_ENDIAN_LITTLE | |
1739 | + && abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE))) | |
1740 | + goto wrong; | |
1742 | 1741 | |
1743 | - abfd->tdata.mach_o_data = NULL; | |
1742 | + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct)); | |
1743 | + if (preserve.marker == NULL | |
1744 | + || !bfd_preserve_save (abfd, &preserve)) | |
1745 | + goto fail; | |
1744 | 1746 | |
1745 | - if (bfd_mach_o_scan (abfd, &header) != 0) | |
1746 | - { | |
1747 | - abfd->tdata.mach_o_data = NULL; | |
1748 | - bfd_set_error (bfd_error_wrong_format); | |
1749 | - return NULL; | |
1750 | - } | |
1747 | + if (bfd_mach_o_scan (abfd, &header, | |
1748 | + (bfd_mach_o_data_struct *) preserve.marker) != 0) | |
1749 | + goto wrong; | |
1751 | 1750 | |
1751 | + bfd_preserve_finish (abfd, &preserve); | |
1752 | 1752 | return abfd->xvec; |
1753 | + | |
1754 | + wrong: | |
1755 | + bfd_set_error (bfd_error_wrong_format); | |
1756 | + | |
1757 | + fail: | |
1758 | + if (preserve.marker != NULL) | |
1759 | + bfd_preserve_restore (abfd, &preserve); | |
1760 | + return NULL; | |
1753 | 1761 | } |
1754 | 1762 | |
1755 | 1763 | const bfd_target * |
1756 | 1764 | bfd_mach_o_core_p (abfd) |
1757 | 1765 | bfd *abfd; |
1758 | 1766 | { |
1767 | + struct bfd_preserve preserve; | |
1759 | 1768 | bfd_mach_o_header header; |
1760 | 1769 | |
1761 | - bfd_set_error (bfd_error_wrong_format); | |
1762 | - | |
1770 | + preserve.marker = NULL; | |
1763 | 1771 | if (bfd_mach_o_read_header (abfd, &header) != 0) |
1764 | - return NULL; | |
1772 | + goto wrong; | |
1765 | 1773 | |
1766 | - if (! ((header.byteorder == BFD_ENDIAN_BIG) | |
1767 | - || (header.byteorder == BFD_ENDIAN_LITTLE))) | |
1774 | + if (! (header.byteorder == BFD_ENDIAN_BIG | |
1775 | + || header.byteorder == BFD_ENDIAN_LITTLE)) | |
1768 | 1776 | { |
1769 | - fprintf (stderr, "unknown header byte-order value 0x%lx\n", (long) header.byteorder); | |
1777 | + fprintf (stderr, "unknown header byte-order value 0x%lx\n", | |
1778 | + (long) header.byteorder); | |
1770 | 1779 | abort (); |
1771 | 1780 | } |
1772 | 1781 | |
1773 | - if (! (((header.byteorder == BFD_ENDIAN_BIG) | |
1774 | - && (abfd->xvec->byteorder == BFD_ENDIAN_BIG) | |
1775 | - && (abfd->xvec->header_byteorder == BFD_ENDIAN_BIG)) | |
1776 | - || | |
1777 | - ((header.byteorder == BFD_ENDIAN_LITTLE) | |
1778 | - && (abfd->xvec->byteorder == BFD_ENDIAN_LITTLE) | |
1779 | - && (abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE)))) | |
1780 | - return NULL; | |
1782 | + if (! ((header.byteorder == BFD_ENDIAN_BIG | |
1783 | + && abfd->xvec->byteorder == BFD_ENDIAN_BIG | |
1784 | + && abfd->xvec->header_byteorder == BFD_ENDIAN_BIG) | |
1785 | + || (header.byteorder == BFD_ENDIAN_LITTLE | |
1786 | + && abfd->xvec->byteorder == BFD_ENDIAN_LITTLE | |
1787 | + && abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE))) | |
1788 | + goto wrong; | |
1781 | 1789 | |
1782 | 1790 | if (header.filetype != BFD_MACH_O_MH_CORE) |
1783 | - return NULL; | |
1791 | + goto wrong; | |
1784 | 1792 | |
1785 | - abfd->tdata.mach_o_data = NULL; | |
1786 | - if (bfd_mach_o_scan (abfd, &header) != 0) | |
1787 | - { | |
1788 | - abfd->tdata.mach_o_data = NULL; | |
1789 | - return NULL; | |
1790 | - } | |
1793 | + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct)); | |
1794 | + if (preserve.marker == NULL | |
1795 | + || !bfd_preserve_save (abfd, &preserve)) | |
1796 | + goto fail; | |
1791 | 1797 | |
1798 | + if (bfd_mach_o_scan (abfd, &header, | |
1799 | + (bfd_mach_o_data_struct *) preserve.marker) != 0) | |
1800 | + goto wrong; | |
1801 | + | |
1802 | + bfd_preserve_finish (abfd, &preserve); | |
1792 | 1803 | return abfd->xvec; |
1804 | + | |
1805 | + wrong: | |
1806 | + bfd_set_error (bfd_error_wrong_format); | |
1807 | + | |
1808 | + fail: | |
1809 | + if (preserve.marker != NULL) | |
1810 | + bfd_preserve_restore (abfd, &preserve); | |
1811 | + return NULL; | |
1793 | 1812 | } |
1794 | 1813 | |
1795 | 1814 | typedef struct mach_o_fat_archentry |
@@ -1813,35 +1832,35 @@ const bfd_target * | ||
1813 | 1832 | bfd_mach_o_archive_p (abfd) |
1814 | 1833 | bfd *abfd; |
1815 | 1834 | { |
1816 | - mach_o_fat_data_struct *adata; | |
1835 | + mach_o_fat_data_struct *adata = NULL; | |
1817 | 1836 | unsigned char buf[20]; |
1818 | 1837 | unsigned long i; |
1819 | 1838 | |
1820 | 1839 | bfd_seek (abfd, 0, SEEK_SET); |
1821 | 1840 | if (bfd_bread ((PTR) buf, 8, abfd) != 8) |
1822 | - return NULL; | |
1841 | + goto error; | |
1823 | 1842 | |
1824 | 1843 | adata = (mach_o_fat_data_struct *) |
1825 | 1844 | bfd_alloc (abfd, sizeof (mach_o_fat_data_struct)); |
1826 | 1845 | if (adata == NULL) |
1827 | - return NULL; | |
1846 | + goto error; | |
1828 | 1847 | |
1829 | 1848 | adata->magic = bfd_getb32 (buf); |
1830 | 1849 | adata->nfat_arch = bfd_getb32 (buf + 4); |
1831 | 1850 | if (adata->magic != 0xcafebabe) |
1832 | - return NULL; | |
1851 | + goto error; | |
1833 | 1852 | |
1834 | 1853 | adata->archentries = (mach_o_fat_archentry *) |
1835 | 1854 | bfd_alloc (abfd, adata->nfat_arch * sizeof (mach_o_fat_archentry)); |
1836 | 1855 | if (adata->archentries == NULL) |
1837 | - return NULL; | |
1856 | + goto error; | |
1838 | 1857 | |
1839 | 1858 | for (i = 0; i < adata->nfat_arch; i++) |
1840 | 1859 | { |
1841 | 1860 | bfd_seek (abfd, 8 + 20 * i, SEEK_SET); |
1842 | 1861 | |
1843 | 1862 | if (bfd_bread ((PTR) buf, 20, abfd) != 20) |
1844 | - return NULL; | |
1863 | + goto error; | |
1845 | 1864 | adata->archentries[i].cputype = bfd_getb32 (buf); |
1846 | 1865 | adata->archentries[i].cpusubtype = bfd_getb32 (buf + 4); |
1847 | 1866 | adata->archentries[i].offset = bfd_getb32 (buf + 8); |
@@ -1852,6 +1871,12 @@ bfd_mach_o_archive_p (abfd) | ||
1852 | 1871 | |
1853 | 1872 | abfd->tdata.mach_o_fat_data = adata; |
1854 | 1873 | return abfd->xvec; |
1874 | + | |
1875 | + error: | |
1876 | + if (adata != NULL) | |
1877 | + bfd_release (abfd, adata); | |
1878 | + bfd_set_error (bfd_error_wrong_format); | |
1879 | + return NULL; | |
1855 | 1880 | } |
1856 | 1881 | |
1857 | 1882 | bfd * |
@@ -1859,10 +1884,11 @@ bfd_mach_o_openr_next_archived_file (archive, prev) | ||
1859 | 1884 | bfd *archive; |
1860 | 1885 | bfd *prev; |
1861 | 1886 | { |
1862 | - mach_o_fat_data_struct *adata = (mach_o_fat_data_struct *) archive->tdata.mach_o_fat_data; | |
1887 | + mach_o_fat_data_struct *adata; | |
1863 | 1888 | mach_o_fat_archentry *entry = NULL; |
1864 | 1889 | unsigned long i; |
1865 | 1890 | |
1891 | + adata = (mach_o_fat_data_struct *) archive->tdata.mach_o_fat_data; | |
1866 | 1892 | BFD_ASSERT (adata != NULL); |
1867 | 1893 | |
1868 | 1894 | /* Find index of previous entry. */ |
@@ -1913,9 +1939,12 @@ bfd_mach_o_openr_next_archived_file (archive, prev) | ||
1913 | 1939 | return entry->abfd; |
1914 | 1940 | } |
1915 | 1941 | |
1916 | -int bfd_mach_o_lookup_section | |
1917 | - (bfd *abfd, asection *section, | |
1918 | - bfd_mach_o_load_command **mcommand, bfd_mach_o_section **msection) | |
1942 | +int | |
1943 | +bfd_mach_o_lookup_section (abfd, section, mcommand, msection) | |
1944 | + bfd *abfd; | |
1945 | + asection *section; | |
1946 | + bfd_mach_o_load_command **mcommand; | |
1947 | + bfd_mach_o_section **msection; | |
1919 | 1948 | { |
1920 | 1949 | struct mach_o_data_struct *md = abfd->tdata.mach_o_data; |
1921 | 1950 | unsigned int i, j, num; |
@@ -1962,9 +1991,10 @@ int bfd_mach_o_lookup_section | ||
1962 | 1991 | } |
1963 | 1992 | |
1964 | 1993 | int |
1965 | -bfd_mach_o_lookup_command | |
1966 | - (bfd *abfd, bfd_mach_o_load_command_type type, | |
1967 | - bfd_mach_o_load_command **mcommand) | |
1994 | +bfd_mach_o_lookup_command (abfd, type, mcommand) | |
1995 | + bfd *abfd; | |
1996 | + bfd_mach_o_load_command_type type; | |
1997 | + bfd_mach_o_load_command **mcommand; | |
1968 | 1998 | { |
1969 | 1999 | struct mach_o_data_struct *md = NULL; |
1970 | 2000 | bfd_mach_o_load_command *ncmd = NULL; |
@@ -2011,7 +2041,7 @@ bfd_mach_o_stack_addr (type) | ||
2011 | 2041 | case BFD_MACH_O_CPU_TYPE_I860: |
2012 | 2042 | return 0; |
2013 | 2043 | case BFD_MACH_O_CPU_TYPE_HPPA: |
2014 | - return (0xc0000000-0x04000000); | |
2044 | + return 0xc0000000 - 0x04000000; | |
2015 | 2045 | default: |
2016 | 2046 | return 0; |
2017 | 2047 | } |
@@ -2063,8 +2093,9 @@ bfd_mach_o_core_fetch_environment (abfd, rbuf, rlen) | ||
2063 | 2093 | |
2064 | 2094 | for (offset = 4; offset <= size; offset += 4) |
2065 | 2095 | { |
2066 | - unsigned long val = *((unsigned long *) (buf + size - offset)); | |
2096 | + unsigned long val; | |
2067 | 2097 | |
2098 | + val = *((unsigned long *) (buf + size - offset)); | |
2068 | 2099 | if (! found_nonnull) |
2069 | 2100 | { |
2070 | 2101 | if (val != 0) |
@@ -2072,9 +2103,11 @@ bfd_mach_o_core_fetch_environment (abfd, rbuf, rlen) | ||
2072 | 2103 | } |
2073 | 2104 | else if (val == 0x0) |
2074 | 2105 | { |
2075 | - unsigned long bottom = seg->fileoff + seg->filesize - offset; | |
2076 | - unsigned long top = seg->fileoff + seg->filesize - 4; | |
2106 | + unsigned long bottom; | |
2107 | + unsigned long top; | |
2077 | 2108 | |
2109 | + bottom = seg->fileoff + seg->filesize - offset; | |
2110 | + top = seg->fileoff + seg->filesize - 4; | |
2078 | 2111 | *rbuf = bfd_malloc (top - bottom); |
2079 | 2112 | *rlen = top - bottom; |
2080 | 2113 |
@@ -2159,4 +2192,3 @@ bfd_mach_o_core_file_matches_executable_p (core_bfd, exec_bfd) | ||
2159 | 2192 | #undef TARGET_STRING |
2160 | 2193 | #undef TARGET_BIG_ENDIAN |
2161 | 2194 | #undef TARGET_ARCHIVE |
2162 | - |
@@ -15,7 +15,7 @@ | ||
15 | 15 | GNU General Public License for more details. |
16 | 16 | |
17 | 17 | You should have received a copy of the GNU General Public License |
18 | - along with this program; if not, write to the Free Software | |
18 | + along with this program; if not, write to the Free Software | |
19 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 | 20 | |
21 | 21 | #ifndef _BFD_MACH_O_H_ |
@@ -127,13 +127,13 @@ bfd_mach_o_filetype; | ||
127 | 127 | typedef enum bfd_mach_o_section_type |
128 | 128 | { |
129 | 129 | /* Regular section. */ |
130 | - BFD_MACH_O_S_REGULAR = 0x0, | |
130 | + BFD_MACH_O_S_REGULAR = 0x0, | |
131 | 131 | |
132 | 132 | /* Zero fill on demand section. */ |
133 | 133 | BFD_MACH_O_S_ZEROFILL = 0x1, |
134 | 134 | |
135 | 135 | /* Section with only literal C strings. */ |
136 | - BFD_MACH_O_S_CSTRING_LITERALS = 0x2, | |
136 | + BFD_MACH_O_S_CSTRING_LITERALS = 0x2, | |
137 | 137 | |
138 | 138 | /* Section with only 4 byte literals. */ |
139 | 139 | BFD_MACH_O_S_4BYTE_LITERALS = 0x3, |
@@ -159,13 +159,13 @@ typedef enum bfd_mach_o_section_type | ||
159 | 159 | |
160 | 160 | /* Section with only non-lazy symbol pointers. */ |
161 | 161 | BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS = 0x6, |
162 | - | |
162 | + | |
163 | 163 | /* Section with only lazy symbol pointers. */ |
164 | 164 | BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7, |
165 | - | |
165 | + | |
166 | 166 | /* Section with only symbol stubs, byte size of stub in the reserved2 field. */ |
167 | 167 | BFD_MACH_O_S_SYMBOL_STUBS = 0x8, |
168 | - | |
168 | + | |
169 | 169 | /* Section with only function pointers for initialization. */ |
170 | 170 | BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9 |
171 | 171 | } |
@@ -232,7 +232,7 @@ bfd_mach_o_symtab_command; | ||
232 | 232 | |
233 | 233 | /* This is the second set of the symbolic information which is used to support |
234 | 234 | the data structures for the dynamicly link editor. |
235 | - | |
235 | + | |
236 | 236 | The original set of symbolic information in the symtab_command which contains |
237 | 237 | the symbol and string tables must also be present when this load command is |
238 | 238 | present. When this load command is present the symbol table is organized |
@@ -242,7 +242,7 @@ bfd_mach_o_symtab_command; | ||
242 | 242 | undefined external symbols (sorted by name) |
243 | 243 | In this load command there are offsets and counts to each of the three groups |
244 | 244 | of symbols. |
245 | - | |
245 | + | |
246 | 246 | This load command contains a the offsets and sizes of the following new |
247 | 247 | symbolic information tables: |
248 | 248 | table of contents |
@@ -258,7 +258,7 @@ bfd_mach_o_symtab_command; | ||
258 | 258 | module table - the file contains only one module so everything in the |
259 | 259 | file is part of the module. |
260 | 260 | reference symbol table - is the defined and undefined external symbols |
261 | - | |
261 | + | |
262 | 262 | For dynamicly linked shared library files this load command also contains |
263 | 263 | offsets and sizes to the pool of relocation entries for all sections |
264 | 264 | separated into two groups: |
@@ -274,11 +274,11 @@ typedef struct bfd_mach_o_dysymtab_command | ||
274 | 274 | local symbols (further grouped by the module they are from) |
275 | 275 | defined external symbols (further grouped by the module they are from) |
276 | 276 | undefined symbols |
277 | - | |
277 | + | |
278 | 278 | The local symbols are used only for debugging. The dynamic binding |
279 | 279 | process may have to use them to indicate to the debugger the local |
280 | 280 | symbols for a module that is being bound. |
281 | - | |
281 | + | |
282 | 282 | The last two groups are used by the dynamic binding process to do the |
283 | 283 | binding (indirectly through the module table and the reference symbol |
284 | 284 | table when this is a dynamicly linked shared library file). */ |
@@ -368,11 +368,11 @@ typedef struct bfd_mach_o_dysymtab_command | ||
368 | 368 | unsigned long locreloff; /* Offset to local relocation entries. */ |
369 | 369 | unsigned long nlocrel; /* Number of local relocation entries. */ |
370 | 370 | } |
371 | -bfd_mach_o_dysymtab_command; | |
371 | +bfd_mach_o_dysymtab_command; | |
372 | 372 | |
373 | -/* An indirect symbol table entry is simply a 32bit index into the symbol table | |
373 | +/* An indirect symbol table entry is simply a 32bit index into the symbol table | |
374 | 374 | to the symbol that the pointer or stub is refering to. Unless it is for a |
375 | - non-lazy symbol pointer section for a defined symbol which strip(1) as | |
375 | + non-lazy symbol pointer section for a defined symbol which strip(1) as | |
376 | 376 | removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the |
377 | 377 | symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */ |
378 | 378 |
@@ -390,7 +390,7 @@ bfd_mach_o_thread_flavour; | ||
390 | 390 | typedef struct bfd_mach_o_thread_command |
391 | 391 | { |
392 | 392 | unsigned long nflavours; |
393 | - bfd_mach_o_thread_flavour *flavours; | |
393 | + bfd_mach_o_thread_flavour *flavours; | |
394 | 394 | asection *section; |
395 | 395 | } |
396 | 396 | bfd_mach_o_thread_command; |
@@ -469,7 +469,7 @@ int bfd_mach_o_scan_read_symtab_strtab PARAMS ((bfd *, bfd_mach | ||
469 | 469 | int bfd_mach_o_scan_read_symtab_symbols PARAMS ((bfd *, bfd_mach_o_symtab_command *)); |
470 | 470 | int bfd_mach_o_scan_read_dysymtab_symbol PARAMS ((bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, asymbol *, unsigned long)); |
471 | 471 | int bfd_mach_o_scan_start_address PARAMS ((bfd *)); |
472 | -int bfd_mach_o_scan PARAMS ((bfd *, bfd_mach_o_header *)); | |
472 | +int bfd_mach_o_scan PARAMS ((bfd *, bfd_mach_o_header *, bfd_mach_o_data_struct *)); | |
473 | 473 | boolean bfd_mach_o_mkobject PARAMS ((bfd *)); |
474 | 474 | const bfd_target * bfd_mach_o_object_p PARAMS ((bfd *)); |
475 | 475 | const bfd_target * bfd_mach_o_core_p PARAMS ((bfd *)); |
@@ -15,7 +15,7 @@ | ||
15 | 15 | GNU General Public License for more details. |
16 | 16 | |
17 | 17 | You should have received a copy of the GNU General Public License |
18 | - along with this program; if not, write to the Free Software | |
18 | + along with this program; if not, write to the Free Software | |
19 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 | 20 | |
21 | 21 | #include <ctype.h> |
@@ -70,7 +70,7 @@ | ||
70 | 70 | static void bfd_pef_print_symbol |
71 | 71 | PARAMS ((bfd *abfd, PTR afile, asymbol *symbol, bfd_print_symbol_type how)); |
72 | 72 | static void bfd_pef_convert_architecture |
73 | -PARAMS ((unsigned long architecture, | |
73 | +PARAMS ((unsigned long architecture, | |
74 | 74 | enum bfd_architecture *type, unsigned long *subtype)); |
75 | 75 | static boolean bfd_pef_mkobject PARAMS ((bfd *abfd)); |
76 | 76 | static int bfd_pef_parse_traceback_table |
@@ -78,7 +78,8 @@ PARAMS ((bfd *abfd, asection *section, unsigned char *buf, | ||
78 | 78 | size_t len, size_t pos, asymbol *sym, FILE *file)); |
79 | 79 | static const char *bfd_pef_section_name PARAMS ((bfd_pef_section *section)); |
80 | 80 | static unsigned long bfd_pef_section_flags PARAMS ((bfd_pef_section *section)); |
81 | -static asection *bfd_pef_make_bfd_section PARAMS ((bfd *abfd, bfd_pef_section *section)); | |
81 | +static asection *bfd_pef_make_bfd_section | |
82 | +PARAMS ((bfd *abfd, bfd_pef_section *section)); | |
82 | 83 | static int bfd_pef_read_header PARAMS ((bfd *abfd, bfd_pef_header *header)); |
83 | 84 | static const bfd_target *bfd_pef_object_p PARAMS ((bfd *)); |
84 | 85 | static int bfd_pef_parse_traceback_tables |
@@ -86,9 +87,10 @@ PARAMS ((bfd *abfd, asection *sec, unsigned char *buf, | ||
86 | 87 | size_t len, long *nsym, asymbol **csym)); |
87 | 88 | static int bfd_pef_parse_function_stub |
88 | 89 | PARAMS ((bfd *abfd, unsigned char *buf, size_t len, unsigned long *offset)); |
89 | -static int bfd_pef_parse_function_stubs | |
90 | +static int bfd_pef_parse_function_stubs | |
90 | 91 | PARAMS ((bfd *abfd, asection *codesec, unsigned char *codebuf, size_t codelen, |
91 | - unsigned char *loaderbuf, size_t loaderlen, unsigned long *nsym, asymbol **csym)); | |
92 | + unsigned char *loaderbuf, size_t loaderlen, unsigned long *nsym, | |
93 | + asymbol **csym)); | |
92 | 94 | static long bfd_pef_parse_symbols PARAMS ((bfd *abfd, asymbol **csym)); |
93 | 95 | static long bfd_pef_count_symbols PARAMS ((bfd *abfd)); |
94 | 96 | static long bfd_pef_get_symtab_upper_bound PARAMS ((bfd *)); |
@@ -97,7 +99,8 @@ static asymbol *bfd_pef_make_empty_symbol PARAMS ((bfd *)); | ||
97 | 99 | static void bfd_pef_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *)); |
98 | 100 | static int bfd_pef_sizeof_headers PARAMS ((bfd *, boolean)); |
99 | 101 | |
100 | -static int bfd_pef_xlib_read_header PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); | |
102 | +static int bfd_pef_xlib_read_header | |
103 | +PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); | |
101 | 104 | static int bfd_pef_xlib_scan PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); |
102 | 105 | static const bfd_target *bfd_pef_xlib_object_p PARAMS ((bfd *abfd)); |
103 | 106 |
@@ -109,29 +112,32 @@ bfd_pef_print_symbol (abfd, afile, symbol, how) | ||
109 | 112 | bfd_print_symbol_type how; |
110 | 113 | { |
111 | 114 | FILE *file = (FILE *) afile; |
112 | - switch (how) { | |
113 | - case bfd_print_symbol_name: | |
114 | - fprintf (file, "%s", symbol->name); | |
115 | - break; | |
116 | - default: | |
117 | - bfd_print_symbol_vandf (abfd, (PTR) file, symbol); | |
118 | - fprintf (file, " %-5s %s", symbol->section->name, symbol->name); | |
119 | - if (strncmp (symbol->name, "__traceback_", strlen ("__traceback_")) == 0) { | |
120 | - char *buf = alloca (symbol->udata.i); | |
121 | - size_t offset = symbol->value + 4; | |
122 | - size_t len = symbol->udata.i; | |
123 | - int ret; | |
124 | - | |
125 | - bfd_get_section_contents (abfd, symbol->section, buf, offset, len); | |
126 | - ret = bfd_pef_parse_traceback_table (abfd, symbol->section, buf, len, 0, NULL, file); | |
127 | - if (ret < 0) { | |
128 | - fprintf (file, " [ERROR]"); | |
129 | - } | |
115 | + switch (how) | |
116 | + { | |
117 | + case bfd_print_symbol_name: | |
118 | + fprintf (file, "%s", symbol->name); | |
119 | + break; | |
120 | + default: | |
121 | + bfd_print_symbol_vandf (abfd, (PTR) file, symbol); | |
122 | + fprintf (file, " %-5s %s", symbol->section->name, symbol->name); | |
123 | + if (strncmp (symbol->name, "__traceback_", strlen ("__traceback_")) == 0) | |
124 | + { | |
125 | + char *buf = alloca (symbol->udata.i); | |
126 | + size_t offset = symbol->value + 4; | |
127 | + size_t len = symbol->udata.i; | |
128 | + int ret; | |
129 | + | |
130 | + bfd_get_section_contents (abfd, symbol->section, buf, offset, len); | |
131 | + ret = bfd_pef_parse_traceback_table (abfd, symbol->section, buf, | |
132 | + len, 0, NULL, file); | |
133 | + if (ret < 0) | |
134 | + fprintf (file, " [ERROR]"); | |
135 | + } | |
130 | 136 | } |
131 | - } | |
132 | 137 | } |
133 | 138 | |
134 | -static void bfd_pef_convert_architecture (architecture, type, subtype) | |
139 | +static void | |
140 | +bfd_pef_convert_architecture (architecture, type, subtype) | |
135 | 141 | unsigned long architecture; |
136 | 142 | enum bfd_architecture *type; |
137 | 143 | unsigned long *subtype; |
@@ -141,7 +147,7 @@ static void bfd_pef_convert_architecture (architecture, type, subtype) | ||
141 | 147 | |
142 | 148 | const unsigned long ARCH_POWERPC = 0x70777063; /* 'pwpc' */ |
143 | 149 | const unsigned long ARCH_M68K = 0x6d36386b; /* 'm68k' */ |
144 | - | |
150 | + | |
145 | 151 | if (architecture == ARCH_POWERPC) |
146 | 152 | *type = bfd_arch_powerpc; |
147 | 153 | else if (architecture == ARCH_M68K) |
@@ -169,8 +175,9 @@ bfd_pef_parse_traceback_table (abfd, section, buf, len, pos, sym, file) | ||
169 | 175 | size_t offset; |
170 | 176 | const char *s; |
171 | 177 | asymbol tmpsymbol; |
172 | - | |
173 | - if (sym == NULL) { sym = &tmpsymbol; } | |
178 | + | |
179 | + if (sym == NULL) | |
180 | + sym = &tmpsymbol; | |
174 | 181 | |
175 | 182 | sym->name = NULL; |
176 | 183 | sym->value = 0; |
@@ -181,150 +188,150 @@ bfd_pef_parse_traceback_table (abfd, section, buf, len, pos, sym, file) | ||
181 | 188 | |
182 | 189 | /* memcpy is fine since all fields are unsigned char */ |
183 | 190 | |
184 | - if ((pos + 8) > len) { return -1; } | |
191 | + if ((pos + 8) > len) | |
192 | + return -1; | |
185 | 193 | memcpy (&table, buf + pos, 8); |
186 | - | |
187 | - /* calling code relies on returned symbols having a name and correct offset */ | |
188 | 194 | |
189 | - if ((table.lang != TB_C) && (table.lang != TB_CPLUSPLUS)) { | |
195 | + /* calling code relies on returned symbols having a name and | |
196 | + correct offset */ | |
197 | + | |
198 | + if ((table.lang != TB_C) && (table.lang != TB_CPLUSPLUS)) | |
190 | 199 | return -1; |
191 | - } | |
192 | - if (! (table.flags2 & TB_NAME_PRESENT)) { | |
200 | + | |
201 | + if (! (table.flags2 & TB_NAME_PRESENT)) | |
193 | 202 | return -1; |
194 | - } | |
195 | - if (! table.flags1 & TB_HAS_TBOFF) { | |
203 | + | |
204 | + if (! table.flags1 & TB_HAS_TBOFF) | |
196 | 205 | return -1; |
197 | - } | |
198 | 206 | |
199 | 207 | offset = 8; |
200 | 208 | |
201 | - if ((table.flags5 & TB_FLOATPARAMS) || (table.fixedparams)) { | |
202 | - offset += 4; | |
203 | - } | |
209 | + if ((table.flags5 & TB_FLOATPARAMS) || (table.fixedparams)) | |
210 | + offset += 4; | |
204 | 211 | |
205 | - if (table.flags1 & TB_HAS_TBOFF) { | |
212 | + if (table.flags1 & TB_HAS_TBOFF) | |
213 | + { | |
214 | + struct traceback_table_tboff off; | |
206 | 215 | |
207 | - struct traceback_table_tboff off; | |
208 | - | |
209 | - if ((pos + offset + 4) > len) { return -1; } | |
210 | - off.tb_offset = bfd_getb32 (buf + pos + offset); | |
211 | - offset += 4; | |
216 | + if ((pos + offset + 4) > len) | |
217 | + return -1; | |
218 | + off.tb_offset = bfd_getb32 (buf + pos + offset); | |
219 | + offset += 4; | |
212 | 220 | |
213 | - /* need to subtract 4 because the offset includes the 0x0L | |
214 | - preceding the table */ | |
221 | + /* need to subtract 4 because the offset includes the 0x0L | |
222 | + preceding the table */ | |
215 | 223 | |
216 | - if (file != NULL) { | |
217 | - fprintf (file, " [offset = 0x%lx]", off.tb_offset); | |
218 | - } | |
224 | + if (file != NULL) | |
225 | + fprintf (file, " [offset = 0x%lx]", off.tb_offset); | |
219 | 226 | |
220 | - if ((file == NULL) && ((off.tb_offset + 4) > (pos + offset))) { | |
221 | - return -1; | |
227 | + if ((file == NULL) && ((off.tb_offset + 4) > (pos + offset))) | |
228 | + return -1; | |
229 | + | |
230 | + sym->value = pos - off.tb_offset - 4; | |
222 | 231 | } |
223 | - sym->value = pos - off.tb_offset - 4; | |
224 | - } | |
225 | 232 | |
226 | - if (table.flags2 & TB_INT_HNDL) { | |
233 | + if (table.flags2 & TB_INT_HNDL) | |
227 | 234 | offset += 4; |
228 | - } | |
229 | 235 | |
230 | - if (table.flags1 & TB_HAS_CTL) { | |
236 | + if (table.flags1 & TB_HAS_CTL) | |
237 | + { | |
238 | + struct traceback_table_anchors anchors; | |
231 | 239 | |
232 | - struct traceback_table_anchors anchors; | |
240 | + if ((pos + offset + 4) > len) | |
241 | + return -1; | |
242 | + anchors.ctl_info = bfd_getb32 (buf + pos + offset); | |
243 | + offset += 4; | |
233 | 244 | |
234 | - if ((pos + offset + 4) > len) { return -1; } | |
235 | - anchors.ctl_info = bfd_getb32 (buf + pos + offset); | |
236 | - offset += 4; | |
245 | + if (anchors.ctl_info > 1024) | |
246 | + return -1; | |
237 | 247 | |
238 | - if (anchors.ctl_info > 1024) { | |
239 | - return -1; | |
248 | + offset += anchors.ctl_info * 4; | |
240 | 249 | } |
241 | 250 | |
242 | - offset += anchors.ctl_info * 4; | |
243 | - } | |
251 | + if (table.flags2 & TB_NAME_PRESENT) | |
252 | + { | |
253 | + struct traceback_table_routine name; | |
254 | + char *namebuf; | |
244 | 255 | |
245 | - if (table.flags2 & TB_NAME_PRESENT) { | |
256 | + if ((pos + offset + 2) > len) | |
257 | + return -1; | |
258 | + name.name_len = bfd_getb16 (buf + pos + offset); | |
259 | + offset += 2; | |
246 | 260 | |
247 | - struct traceback_table_routine name; | |
248 | - char *namebuf; | |
261 | + if (name.name_len > 4096) | |
262 | + return -1; | |
249 | 263 | |
250 | - if ((pos + offset + 2) > len) { return -1; } | |
251 | - name.name_len = bfd_getb16 (buf + pos + offset); | |
252 | - offset += 2; | |
264 | + if ((pos + offset + name.name_len) > len) | |
265 | + return -1; | |
253 | 266 | |
254 | - if (name.name_len > 4096) { return -1; } | |
267 | + namebuf = (char *) bfd_alloc (abfd, name.name_len + 1); | |
268 | + if (namebuf == NULL) | |
269 | + return -1; | |
255 | 270 | |
256 | - if ((pos + offset + name.name_len) > len) { return -1; } | |
271 | + memcpy (namebuf, buf + pos + offset, name.name_len); | |
272 | + namebuf[name.name_len] = '\0'; | |
257 | 273 | |
258 | - namebuf = (char *) bfd_alloc (abfd, name.name_len + 1); | |
259 | - if (namebuf == NULL) { return -1; } | |
274 | + /* strip leading period inserted by compiler */ | |
275 | + if (namebuf[0] == '.') | |
276 | + memmove (namebuf, namebuf + 1, name.name_len + 1); | |
260 | 277 | |
261 | - memcpy (namebuf, buf + pos + offset, name.name_len); | |
262 | - namebuf[name.name_len] = '\0'; | |
263 | - | |
264 | - /* strip leading period inserted by compiler */ | |
265 | - if (namebuf[0] == '.') { | |
266 | - memmove (namebuf, namebuf + 1, name.name_len + 1); | |
267 | - } | |
278 | + sym->name = namebuf; | |
268 | 279 | |
269 | - sym->name = namebuf; | |
280 | + for (s = sym->name; (*s != '\0'); s++) | |
281 | + if (! isprint (*s)) | |
282 | + return -1; | |
270 | 283 | |
271 | - for (s = sym->name; (*s != '\0'); s++) { | |
272 | - if (! isprint (*s)) { | |
273 | - return -1; | |
274 | - } | |
284 | + offset += name.name_len; | |
275 | 285 | } |
276 | 286 | |
277 | - offset += name.name_len; | |
278 | - } | |
279 | - | |
280 | - if (table.flags2 & TB_USES_ALLOCA) { | |
287 | + if (table.flags2 & TB_USES_ALLOCA) | |
281 | 288 | offset += 4; |
282 | - } | |
283 | 289 | |
284 | - if (table.flags4 & TB_HAS_VEC_INFO) { | |
290 | + if (table.flags4 & TB_HAS_VEC_INFO) | |
285 | 291 | offset += 4; |
286 | - } | |
287 | 292 | |
288 | - if (file != NULL) { | |
293 | + if (file != NULL) | |
289 | 294 | fprintf (file, " [length = 0x%lx]", (long) offset); |
290 | - } | |
295 | + | |
291 | 296 | return offset; |
292 | 297 | } |
293 | 298 | |
294 | 299 | static const char *bfd_pef_section_name (section) |
295 | 300 | bfd_pef_section *section; |
296 | 301 | { |
297 | - switch (section->section_kind) { | |
298 | - case BFD_PEF_SECTION_CODE: return "code"; | |
299 | - case BFD_PEF_SECTION_UNPACKED_DATA: return "unpacked-data"; | |
300 | - case BFD_PEF_SECTION_PACKED_DATA: return "packed-data"; | |
301 | - case BFD_PEF_SECTION_CONSTANT: return "constant"; | |
302 | - case BFD_PEF_SECTION_LOADER: return "loader"; | |
303 | - case BFD_PEF_SECTION_DEBUG: return "debug"; | |
304 | - case BFD_PEF_SECTION_EXEC_DATA: return "exec-data"; | |
305 | - case BFD_PEF_SECTION_EXCEPTION: return "exception"; | |
306 | - case BFD_PEF_SECTION_TRACEBACK: return "traceback"; | |
307 | - default: return "unknown"; | |
308 | - } | |
302 | + switch (section->section_kind) | |
303 | + { | |
304 | + case BFD_PEF_SECTION_CODE: return "code"; | |
305 | + case BFD_PEF_SECTION_UNPACKED_DATA: return "unpacked-data"; | |
306 | + case BFD_PEF_SECTION_PACKED_DATA: return "packed-data"; | |
307 | + case BFD_PEF_SECTION_CONSTANT: return "constant"; | |
308 | + case BFD_PEF_SECTION_LOADER: return "loader"; | |
309 | + case BFD_PEF_SECTION_DEBUG: return "debug"; | |
310 | + case BFD_PEF_SECTION_EXEC_DATA: return "exec-data"; | |
311 | + case BFD_PEF_SECTION_EXCEPTION: return "exception"; | |
312 | + case BFD_PEF_SECTION_TRACEBACK: return "traceback"; | |
313 | + default: return "unknown"; | |
314 | + } | |
309 | 315 | } |
310 | 316 | |
311 | 317 | static unsigned long bfd_pef_section_flags (section) |
312 | 318 | bfd_pef_section *section; |
313 | 319 | { |
314 | - switch (section->section_kind) { | |
315 | - case BFD_PEF_SECTION_CODE: | |
316 | - return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_CODE; | |
317 | - case BFD_PEF_SECTION_UNPACKED_DATA: | |
318 | - case BFD_PEF_SECTION_PACKED_DATA: | |
319 | - case BFD_PEF_SECTION_CONSTANT: | |
320 | - case BFD_PEF_SECTION_LOADER: | |
321 | - case BFD_PEF_SECTION_DEBUG: | |
322 | - case BFD_PEF_SECTION_EXEC_DATA: | |
323 | - case BFD_PEF_SECTION_EXCEPTION: | |
324 | - case BFD_PEF_SECTION_TRACEBACK: | |
325 | - default: | |
326 | - return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; | |
327 | - } | |
320 | + switch (section->section_kind) | |
321 | + { | |
322 | + case BFD_PEF_SECTION_CODE: | |
323 | + return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_CODE; | |
324 | + case BFD_PEF_SECTION_UNPACKED_DATA: | |
325 | + case BFD_PEF_SECTION_PACKED_DATA: | |
326 | + case BFD_PEF_SECTION_CONSTANT: | |
327 | + case BFD_PEF_SECTION_LOADER: | |
328 | + case BFD_PEF_SECTION_DEBUG: | |
329 | + case BFD_PEF_SECTION_EXEC_DATA: | |
330 | + case BFD_PEF_SECTION_EXCEPTION: | |
331 | + case BFD_PEF_SECTION_TRACEBACK: | |
332 | + default: | |
333 | + return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; | |
334 | + } | |
328 | 335 | } |
329 | 336 | |
330 | 337 | static asection * |
@@ -336,8 +343,9 @@ bfd_pef_make_bfd_section (abfd, section) | ||
336 | 343 | const char *name = bfd_pef_section_name (section); |
337 | 344 | |
338 | 345 | bfdsec = bfd_make_section_anyway (abfd, name); |
339 | - if (bfdsec == NULL) { return NULL; } | |
340 | - | |
346 | + if (bfdsec == NULL) | |
347 | + return NULL; | |
348 | + | |
341 | 349 | bfdsec->vma = section->default_address + section->container_offset; |
342 | 350 | bfdsec->lma = section->default_address + section->container_offset; |
343 | 351 | bfdsec->_raw_size = section->container_length; |
@@ -417,9 +425,10 @@ int bfd_pef_scan_section (abfd, section) | ||
417 | 425 | bfd_pef_section *section; |
418 | 426 | { |
419 | 427 | unsigned char buf[28]; |
420 | - | |
428 | + | |
421 | 429 | bfd_seek (abfd, section->header_offset, SEEK_SET); |
422 | - if (bfd_bread ((PTR) buf, 28, abfd) != 28) { return -1; } | |
430 | + if (bfd_bread ((PTR) buf, 28, abfd) != 28) | |
431 | + return -1; | |
423 | 432 | |
424 | 433 | section->name_offset = bfd_h_get_32 (abfd, buf); |
425 | 434 | section->default_address = bfd_h_get_32 (abfd, buf + 4); |
@@ -433,7 +442,8 @@ int bfd_pef_scan_section (abfd, section) | ||
433 | 442 | section->reserved = buf[27]; |
434 | 443 | |
435 | 444 | section->bfd_section = bfd_pef_make_bfd_section (abfd, section); |
436 | - if (section->bfd_section == NULL) { return -1; } | |
445 | + if (section->bfd_section == NULL) | |
446 | + return -1; | |
437 | 447 | |
438 | 448 | return 0; |
439 | 449 | } |
@@ -450,14 +460,19 @@ bfd_pef_print_loader_header (abfd, header, file) | ||
450 | 460 | fprintf (file, "init_offset: %lu\n", header->init_offset); |
451 | 461 | fprintf (file, "term_section: %ld\n", header->term_section); |
452 | 462 | fprintf (file, "term_offset: %lu\n", header->term_offset); |
453 | - fprintf (file, "imported_library_count: %lu\n", header->imported_library_count); | |
454 | - fprintf (file, "total_imported_symbol_count: %lu\n", header->total_imported_symbol_count); | |
463 | + fprintf (file, "imported_library_count: %lu\n", | |
464 | + header->imported_library_count); | |
465 | + fprintf (file, "total_imported_symbol_count: %lu\n", | |
466 | + header->total_imported_symbol_count); | |
455 | 467 | fprintf (file, "reloc_section_count: %lu\n", header->reloc_section_count); |
456 | 468 | fprintf (file, "reloc_instr_offset: %lu\n", header->reloc_instr_offset); |
457 | - fprintf (file, "loader_strings_offset: %lu\n", header->loader_strings_offset); | |
469 | + fprintf (file, "loader_strings_offset: %lu\n", | |
470 | + header->loader_strings_offset); | |
458 | 471 | fprintf (file, "export_hash_offset: %lu\n", header->export_hash_offset); |
459 | - fprintf (file, "export_hash_table_power: %lu\n", header->export_hash_table_power); | |
460 | - fprintf (file, "exported_symbol_count: %lu\n", header->exported_symbol_count); | |
472 | + fprintf (file, "export_hash_table_power: %lu\n", | |
473 | + header->export_hash_table_power); | |
474 | + fprintf (file, "exported_symbol_count: %lu\n", | |
475 | + header->exported_symbol_count); | |
461 | 476 | } |
462 | 477 | |
463 | 478 | int |
@@ -472,18 +487,33 @@ bfd_pef_print_loader_section (abfd, file) | ||
472 | 487 | int ret; |
473 | 488 | |
474 | 489 | loadersec = bfd_get_section_by_name (abfd, "loader"); |
475 | - if (loadersec == NULL) { return -1; } | |
476 | - | |
490 | + if (loadersec == NULL) | |
491 | + return -1; | |
492 | + | |
477 | 493 | loaderlen = bfd_section_size (abfd, loadersec); |
478 | 494 | loaderbuf = (unsigned char *) bfd_malloc (loaderlen); |
479 | 495 | if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) |
480 | - { free (loaderbuf); return -1; } | |
496 | + { | |
497 | + free (loaderbuf); | |
498 | + return -1; | |
499 | + } | |
481 | 500 | if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) |
482 | - { free (loaderbuf); return -1; } | |
501 | + { | |
502 | + free (loaderbuf); | |
503 | + return -1; | |
504 | + } | |
483 | 505 | |
484 | - if (loaderlen < 56) { free (loaderbuf); return -1; } | |
506 | + if (loaderlen < 56) | |
507 | + { | |
508 | + free (loaderbuf); | |
509 | + return -1; | |
510 | + } | |
485 | 511 | ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); |
486 | - if (ret < 0) { free (loaderbuf); return -1; } | |
512 | + if (ret < 0) | |
513 | + { | |
514 | + free (loaderbuf); | |
515 | + return -1; | |
516 | + } | |
487 | 517 | |
488 | 518 | bfd_pef_print_loader_header (abfd, &header, file); |
489 | 519 | return 0; |
@@ -502,89 +532,97 @@ bfd_pef_scan_start_address (abfd) | ||
502 | 532 | int ret; |
503 | 533 | |
504 | 534 | loadersec = bfd_get_section_by_name (abfd, "loader"); |
505 | - if (loadersec == NULL) { goto end; } | |
506 | - | |
535 | + if (loadersec == NULL) | |
536 | + goto end; | |
537 | + | |
507 | 538 | loaderlen = bfd_section_size (abfd, loadersec); |
508 | 539 | loaderbuf = (unsigned char *) bfd_malloc (loaderlen); |
509 | - if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) { goto error; } | |
510 | - if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) { goto error; } | |
540 | + if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) | |
541 | + goto error; | |
542 | + if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) | |
543 | + goto error; | |
511 | 544 | |
512 | - if (loaderlen < 56) { goto error; } | |
545 | + if (loaderlen < 56) | |
546 | + goto error; | |
513 | 547 | ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); |
514 | - if (ret < 0) { goto error; } | |
548 | + if (ret < 0) | |
549 | + goto error; | |
550 | + | |
551 | + if (header.main_section < 0) | |
552 | + goto end; | |
553 | + | |
554 | + for (section = abfd->sections; section != NULL; section = section->next) | |
555 | + if ((section->index + 1) == header.main_section) | |
556 | + break; | |
515 | 557 | |
516 | - if (header.main_section < 0) { goto end; } | |
558 | + if (section == NULL) | |
559 | + goto error; | |
517 | 560 | |
518 | - for (section = abfd->sections; section != NULL; section = section->next) { | |
519 | - if ((section->index + 1) == header.main_section) { break; } | |
520 | - } | |
521 | - | |
522 | - if (section == NULL) { goto error; } | |
523 | - | |
524 | 561 | abfd->start_address = section->vma + header.main_offset; |
525 | 562 | |
526 | 563 | end: |
527 | - if (loaderbuf != NULL) { free (loaderbuf); } | |
564 | + if (loaderbuf != NULL) | |
565 | + free (loaderbuf); | |
528 | 566 | return 0; |
529 | 567 | |
530 | 568 | error: |
531 | - if (loaderbuf != NULL) { free (loaderbuf); } | |
569 | + if (loaderbuf != NULL) | |
570 | + free (loaderbuf); | |
532 | 571 | return -1; |
533 | 572 | } |
534 | 573 | |
535 | 574 | int |
536 | -bfd_pef_scan (abfd, header) | |
575 | +bfd_pef_scan (abfd, header, mdata) | |
537 | 576 | bfd *abfd; |
538 | 577 | bfd_pef_header *header; |
578 | + bfd_pef_data_struct *mdata; | |
539 | 579 | { |
540 | 580 | unsigned int i; |
541 | - bfd_pef_data_struct *mdata = NULL; | |
542 | 581 | enum bfd_architecture cputype; |
543 | 582 | unsigned long cpusubtype; |
544 | 583 | |
545 | - if ((header->tag1 != BFD_PEF_TAG1) || (header->tag2 != BFD_PEF_TAG2)) { | |
546 | - return -1; | |
547 | - } | |
584 | + mdata->header = *header; | |
548 | 585 | |
549 | - mdata = ((bfd_pef_data_struct *) | |
550 | - bfd_alloc (abfd, sizeof (bfd_pef_data_struct))); | |
551 | - if (mdata == NULL) { return -1; } | |
552 | - | |
553 | 586 | bfd_pef_convert_architecture (header->architecture, &cputype, &cpusubtype); |
554 | - if (cputype == bfd_arch_unknown) { | |
555 | - fprintf (stderr, "bfd_pef_scan: unknown architecture 0x%lx\n", header->architecture); | |
556 | - return -1; | |
557 | - } | |
587 | + if (cputype == bfd_arch_unknown) | |
588 | + { | |
589 | + fprintf (stderr, "bfd_pef_scan: unknown architecture 0x%lx\n", | |
590 | + header->architecture); | |
591 | + return -1; | |
592 | + } | |
558 | 593 | bfd_set_arch_mach (abfd, cputype, cpusubtype); |
559 | 594 | |
560 | 595 | mdata->header = *header; |
561 | 596 | |
562 | - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); | |
597 | + abfd->flags = (abfd->xvec->object_flags | |
598 | + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); | |
563 | 599 | |
564 | - if (header->section_count != 0) { | |
565 | - | |
566 | - mdata->sections = | |
567 | - ((bfd_pef_section *) | |
568 | - bfd_alloc (abfd, header->section_count * sizeof (bfd_pef_section))); | |
569 | - if (mdata->sections == NULL) { return -1; } | |
600 | + if (header->section_count != 0) | |
601 | + { | |
602 | + mdata->sections = | |
603 | + ((bfd_pef_section *) | |
604 | + bfd_alloc (abfd, header->section_count * sizeof (bfd_pef_section))); | |
570 | 605 | |
571 | - for (i = 0; i < header->section_count; i++) { | |
572 | - bfd_pef_section *cur = &mdata->sections[i]; | |
573 | - cur->header_offset = 40 + (i * 28); | |
574 | - if (bfd_pef_scan_section (abfd, cur) < 0) { | |
606 | + if (mdata->sections == NULL) | |
575 | 607 | return -1; |
576 | - } | |
608 | + | |
609 | + for (i = 0; i < header->section_count; i++) | |
610 | + { | |
611 | + bfd_pef_section *cur = &mdata->sections[i]; | |
612 | + cur->header_offset = 40 + (i * 28); | |
613 | + if (bfd_pef_scan_section (abfd, cur) < 0) | |
614 | + return -1; | |
615 | + } | |
577 | 616 | } |
578 | - } | |
579 | 617 | |
580 | - if (bfd_pef_scan_start_address (abfd) < 0) { | |
618 | + if (bfd_pef_scan_start_address (abfd) < 0) | |
619 | + { | |
581 | 620 | #if 0 |
582 | - fprintf (stderr, "bfd_pef_scan: unable to scan start address: %s\n", | |
583 | - bfd_errmsg (bfd_get_error ())); | |
584 | - abfd->tdata.pef_data = NULL; | |
585 | - return -1; | |
621 | + fprintf (stderr, "bfd_pef_scan: unable to scan start address: %s\n", | |
622 | + bfd_errmsg (bfd_get_error ())); | |
623 | + return -1; | |
586 | 624 | #endif |
587 | - } | |
625 | + } | |
588 | 626 | |
589 | 627 | abfd->tdata.pef_data = mdata; |
590 | 628 |
@@ -600,7 +638,8 @@ bfd_pef_read_header (abfd, header) | ||
600 | 638 | |
601 | 639 | bfd_seek (abfd, 0, SEEK_SET); |
602 | 640 | |
603 | - if (bfd_bread ((PTR) buf, 40, abfd) != 40) { return -1; } | |
641 | + if (bfd_bread ((PTR) buf, 40, abfd) != 40) | |
642 | + return -1; | |
604 | 643 | |
605 | 644 | header->tag1 = bfd_getb32 (buf); |
606 | 645 | header->tag2 = bfd_getb32 (buf + 4); |
@@ -621,23 +660,35 @@ static const bfd_target * | ||
621 | 660 | bfd_pef_object_p (abfd) |
622 | 661 | bfd *abfd; |
623 | 662 | { |
663 | + struct bfd_preserve preserve; | |
624 | 664 | bfd_pef_header header; |
625 | - | |
626 | - abfd->tdata.pef_data = NULL; | |
627 | 665 | |
628 | - if (bfd_pef_read_header (abfd, &header) != 0) { | |
629 | - abfd->tdata.pef_data = NULL; | |
630 | - bfd_set_error (bfd_error_wrong_format); | |
631 | - return NULL; | |
632 | - } | |
666 | + preserve.marker = NULL; | |
667 | + if (bfd_pef_read_header (abfd, &header) != 0) | |
668 | + goto wrong; | |
633 | 669 | |
634 | - if (bfd_pef_scan (abfd, &header) != 0) { | |
635 | - abfd->tdata.pef_data = NULL; | |
636 | - bfd_set_error (bfd_error_wrong_format); | |
637 | - return NULL; | |
638 | - } | |
670 | + if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2) | |
671 | + goto wrong; | |
672 | + | |
673 | + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_pef_data_struct)); | |
674 | + if (preserve.marker == NULL | |
675 | + || !bfd_preserve_save (abfd, &preserve)) | |
676 | + goto fail; | |
639 | 677 | |
678 | + if (bfd_pef_scan (abfd, &header, | |
679 | + (bfd_pef_data_struct *) preserve.marker) != 0) | |
680 | + goto wrong; | |
681 | + | |
682 | + bfd_preserve_finish (abfd, &preserve); | |
640 | 683 | return abfd->xvec; |
684 | + | |
685 | + wrong: | |
686 | + bfd_set_error (bfd_error_wrong_format); | |
687 | + | |
688 | + fail: | |
689 | + if (preserve.marker != NULL) | |
690 | + bfd_preserve_restore (abfd, &preserve); | |
691 | + return NULL; | |
641 | 692 | } |
642 | 693 | |
643 | 694 | static int bfd_pef_parse_traceback_tables (abfd, sec, buf, len, nsym, csym) |
@@ -660,64 +711,65 @@ static int bfd_pef_parse_traceback_tables (abfd, sec, buf, len, nsym, csym) | ||
660 | 711 | unsigned long count = 0; |
661 | 712 | int ret; |
662 | 713 | |
663 | - for (;;) { | |
664 | - | |
665 | - /* we're reading symbols two at a time */ | |
714 | + for (;;) | |
715 | + { | |
716 | + /* we're reading symbols two at a time */ | |
666 | 717 | |
667 | - if (csym && ((csym[count] == NULL) || (csym[count + 1] == NULL))) { | |
668 | - break; | |
669 | - } | |
718 | + if (csym && ((csym[count] == NULL) || (csym[count + 1] == NULL))) | |
719 | + break; | |
670 | 720 | |
671 | - pos += 3; | |
672 | - pos -= (pos % 4); | |
721 | + pos += 3; | |
722 | + pos -= (pos % 4); | |
673 | 723 | |
674 | - while ((pos + 4) <= len) { | |
675 | - if (bfd_getb32 (buf + pos) == 0) { | |
676 | - break; | |
677 | - } | |
678 | - pos += 4; | |
679 | - } | |
724 | + while ((pos + 4) <= len) | |
725 | + { | |
726 | + if (bfd_getb32 (buf + pos) == 0) | |
727 | + break; | |
728 | + pos += 4; | |
729 | + } | |
680 | 730 | |
681 | - if ((pos + 4) > len) { | |
682 | - break; | |
683 | - } | |
684 | - | |
685 | - ret = bfd_pef_parse_traceback_table (abfd, sec, buf, len, pos + 4, &function, 0); | |
686 | - if (ret < 0) { | |
687 | - /* skip over 0x0L to advance to next possible traceback table */ | |
688 | - pos += 4; | |
689 | - continue; | |
690 | - } | |
691 | - | |
692 | - BFD_ASSERT (function.name != NULL); | |
731 | + if ((pos + 4) > len) | |
732 | + break; | |
693 | 733 | |
694 | - /* Don't bother to compute the name if we are just | |
695 | - counting symbols */ | |
734 | + ret = bfd_pef_parse_traceback_table (abfd, sec, buf, len, pos + 4, | |
735 | + &function, 0); | |
736 | + if (ret < 0) | |
737 | + { | |
738 | + /* skip over 0x0L to advance to next possible traceback table */ | |
739 | + pos += 4; | |
740 | + continue; | |
741 | + } | |
696 | 742 | |
697 | - if (csym) | |
698 | - { | |
699 | - tbnamelen = strlen (tbprefix) + strlen (function.name); | |
700 | - name = bfd_alloc (abfd, tbnamelen + 1); | |
701 | - if (name == NULL) { | |
702 | - bfd_release (abfd, (PTR) function.name); | |
703 | - function.name = NULL; | |
704 | - break; | |
743 | + BFD_ASSERT (function.name != NULL); | |
744 | + | |
745 | + /* Don't bother to compute the name if we are just | |
746 | + counting symbols */ | |
747 | + | |
748 | + if (csym) | |
749 | + { | |
750 | + tbnamelen = strlen (tbprefix) + strlen (function.name); | |
751 | + name = bfd_alloc (abfd, tbnamelen + 1); | |
752 | + if (name == NULL) | |
753 | + { | |
754 | + bfd_release (abfd, (PTR) function.name); | |
755 | + function.name = NULL; | |
756 | + break; | |
757 | + } | |
758 | + snprintf (name, tbnamelen + 1, "%s%s", tbprefix, function.name); | |
759 | + traceback.name = name; | |
760 | + traceback.value = pos; | |
761 | + traceback.the_bfd = abfd; | |
762 | + traceback.section = sec; | |
763 | + traceback.flags = 0; | |
764 | + traceback.udata.i = ret; | |
765 | + | |
766 | + *(csym[count]) = function; | |
767 | + *(csym[count + 1]) = traceback; | |
705 | 768 | } |
706 | - snprintf (name, tbnamelen + 1, "%s%s", tbprefix, function.name); | |
707 | - traceback.name = name; | |
708 | - traceback.value = pos; | |
709 | - traceback.the_bfd = abfd; | |
710 | - traceback.section = sec; | |
711 | - traceback.flags = 0; | |
712 | - traceback.udata.i = ret; | |
713 | - | |
714 | - *(csym[count]) = function; | |
715 | - *(csym[count + 1]) = traceback; | |
716 | - } | |
717 | 769 | |
718 | - pos += ret; | |
719 | - count += 2; | |
720 | - } | |
770 | + pos += ret; | |
771 | + count += 2; | |
772 | + } | |
721 | 773 | |
722 | 774 | *nsym = count; |
723 | 775 | return 0; |
@@ -731,21 +783,27 @@ static int bfd_pef_parse_function_stub (abfd, buf, len, offset) | ||
731 | 783 | { |
732 | 784 | BFD_ASSERT (len == 24); |
733 | 785 | |
734 | - if ((bfd_getb32 (buf) & 0xffff0000) != 0x81820000) { return -1; } | |
735 | - if (bfd_getb32 (buf + 4) != 0x90410014) { return -1; } | |
736 | - if (bfd_getb32 (buf + 8) != 0x800c0000) { return -1; } | |
737 | - if (bfd_getb32 (buf + 12) != 0x804c0004) { return -1; } | |
738 | - if (bfd_getb32 (buf + 16) != 0x7c0903a6) { return -1; } | |
739 | - if (bfd_getb32 (buf + 20) != 0x4e800420) { return -1; } | |
740 | - | |
741 | - if (offset != NULL) { | |
786 | + if ((bfd_getb32 (buf) & 0xffff0000) != 0x81820000) | |
787 | + return -1; | |
788 | + if (bfd_getb32 (buf + 4) != 0x90410014) | |
789 | + return -1; | |
790 | + if (bfd_getb32 (buf + 8) != 0x800c0000) | |
791 | + return -1; | |
792 | + if (bfd_getb32 (buf + 12) != 0x804c0004) | |
793 | + return -1; | |
794 | + if (bfd_getb32 (buf + 16) != 0x7c0903a6) | |
795 | + return -1; | |
796 | + if (bfd_getb32 (buf + 20) != 0x4e800420) | |
797 | + return -1; | |
798 | + | |
799 | + if (offset != NULL) | |
742 | 800 | *offset = (bfd_getb32 (buf) & 0x0000ffff) / 4; |
743 | - } | |
744 | 801 | |
745 | 802 | return 0; |
746 | 803 | } |
747 | 804 | |
748 | -static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, loaderbuf, loaderlen, nsym, csym) | |
805 | +static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, | |
806 | + loaderbuf, loaderlen, nsym, csym) | |
749 | 807 | bfd *abfd; |
750 | 808 | asection *codesec; |
751 | 809 | unsigned char *codebuf; |
@@ -767,113 +825,142 @@ static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, loader | ||
767 | 825 | unsigned long i; |
768 | 826 | int ret; |
769 | 827 | |
770 | - if (loaderlen < 56) { goto error; } | |
828 | + if (loaderlen < 56) | |
829 | + goto error; | |
771 | 830 | |
772 | 831 | ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); |
773 | - if (ret < 0) { goto error; } | |
832 | + if (ret < 0) | |
833 | + goto error; | |
774 | 834 | |
775 | 835 | libraries = (bfd_pef_imported_library *) bfd_malloc |
776 | 836 | (header.imported_library_count * sizeof (bfd_pef_imported_library)); |
777 | 837 | imports = (bfd_pef_imported_symbol *) bfd_malloc |
778 | 838 | (header.total_imported_symbol_count * sizeof (bfd_pef_imported_symbol)); |
779 | - | |
780 | - if (loaderlen < (56 + (header.imported_library_count * 24))) { goto error; } | |
781 | - for (i = 0; i < header.imported_library_count; i++) { | |
782 | - ret = bfd_pef_parse_imported_library | |
783 | - (abfd, loaderbuf + 56 + (i * 24), 24, &libraries[i]); | |
784 | - if (ret < 0) { goto error; } | |
785 | - } | |
786 | - | |
787 | - if (loaderlen < (56 + (header.imported_library_count * 24) + (header.total_imported_symbol_count * 4))) | |
788 | - { goto error; } | |
789 | - for (i = 0; i < header.total_imported_symbol_count; i++) { | |
790 | - ret = bfd_pef_parse_imported_symbol | |
791 | - (abfd, loaderbuf + 56 + (header.imported_library_count * 24) + (i * 4), 4, &imports[i]); | |
792 | - if (ret < 0) { goto error; } | |
793 | - } | |
794 | - | |
839 | + | |
840 | + if (loaderlen < (56 + (header.imported_library_count * 24))) | |
841 | + goto error; | |
842 | + for (i = 0; i < header.imported_library_count; i++) | |
843 | + { | |
844 | + ret = bfd_pef_parse_imported_library | |
845 | + (abfd, loaderbuf + 56 + (i * 24), 24, &libraries[i]); | |
846 | + if (ret < 0) | |
847 | + goto error; | |
848 | + } | |
849 | + | |
850 | + if (loaderlen < (56 + (header.imported_library_count * 24) | |
851 | + + (header.total_imported_symbol_count * 4))) | |
852 | + goto error; | |
853 | + for (i = 0; i < header.total_imported_symbol_count; i++) | |
854 | + { | |
855 | + ret = (bfd_pef_parse_imported_symbol | |
856 | + (abfd, | |
857 | + loaderbuf + 56 + (header.imported_library_count * 24) + (i * 4), | |
858 | + 4, &imports[i])); | |
859 | + if (ret < 0) | |
860 | + goto error; | |
861 | + } | |
862 | + | |
795 | 863 | codepos = 0; |
796 | 864 | |
797 | - for (;;) { | |
865 | + for (;;) | |
866 | + { | |
867 | + asymbol sym; | |
868 | + const char *symname; | |
869 | + char *name; | |
870 | + unsigned long index; | |
871 | + int ret; | |
798 | 872 | |
799 | - asymbol sym; | |
800 | - const char *symname; | |
801 | - char *name; | |
802 | - unsigned long index; | |
803 | - int ret; | |
873 | + if (csym && (csym[count] == NULL)) | |
874 | + break; | |
804 | 875 | |
805 | - if (csym && (csym[count] == NULL)) { break; } | |
876 | + codepos += 3; | |
877 | + codepos -= (codepos % 4); | |
806 | 878 | |
807 | - codepos += 3; | |
808 | - codepos -= (codepos % 4); | |
879 | + while ((codepos + 4) <= codelen) | |
880 | + { | |
881 | + if ((bfd_getb32 (codebuf + codepos) & 0xffff0000) == 0x81820000) | |
882 | + break; | |
883 | + codepos += 4; | |
884 | + } | |
809 | 885 | |
810 | - while ((codepos + 4) <= codelen) { | |
811 | - if ((bfd_getb32 (codebuf + codepos) & 0xffff0000) == 0x81820000) { | |
886 | + if ((codepos + 4) > codelen) | |
812 | 887 | break; |
813 | - } | |
814 | - codepos += 4; | |
815 | - } | |
816 | 888 | |
817 | - if ((codepos + 4) > codelen) { | |
818 | - break; | |
819 | - } | |
889 | + ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &index); | |
890 | + if (ret < 0) | |
891 | + { | |
892 | + codepos += 24; | |
893 | + continue; | |
894 | + } | |
820 | 895 | |
821 | - ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &index); | |
822 | - if (ret < 0) { codepos += 24; continue; } | |
823 | - | |
824 | - if (index >= header.total_imported_symbol_count) { codepos += 24; continue; } | |
896 | + if (index >= header.total_imported_symbol_count) | |
897 | + { | |
898 | + codepos += 24; | |
899 | + continue; | |
900 | + } | |
825 | 901 | |
826 | - { | |
827 | - size_t max, namelen; | |
828 | - const char *s; | |
829 | - | |
830 | - if (loaderlen < (header.loader_strings_offset + imports[index].name)) { goto error; } | |
831 | - | |
832 | - max = loaderlen - (header.loader_strings_offset + imports[index].name); | |
833 | - symname = loaderbuf + header.loader_strings_offset + imports[index].name; | |
834 | - namelen = 0; | |
835 | - for (s = symname; s < (symname + max); s++) { | |
836 | - if (*s == '\0') { break; } | |
837 | - if (! isprint (*s)) { goto error; } | |
838 | - namelen++; | |
839 | - } | |
840 | - if (*s != '\0') { goto error; } | |
902 | + { | |
903 | + size_t max, namelen; | |
904 | + const char *s; | |
905 | + | |
906 | + if (loaderlen < (header.loader_strings_offset + imports[index].name)) | |
907 | + goto error; | |
908 | + | |
909 | + max = loaderlen - (header.loader_strings_offset + imports[index].name); | |
910 | + symname = loaderbuf + header.loader_strings_offset + imports[index].name; | |
911 | + namelen = 0; | |
912 | + for (s = symname; s < (symname + max); s++) | |
913 | + { | |
914 | + if (*s == '\0') | |
915 | + break; | |
916 | + if (! isprint (*s)) | |
917 | + goto error; | |
918 | + namelen++; | |
919 | + } | |
920 | + if (*s != '\0') | |
921 | + goto error; | |
922 | + | |
923 | + name = bfd_alloc (abfd, strlen (sprefix) + namelen + 1); | |
924 | + if (name == NULL) | |
925 | + break; | |
841 | 926 | |
842 | - name = bfd_alloc (abfd, strlen (sprefix) + namelen + 1); | |
843 | - if (name == NULL) { break; } | |
927 | + snprintf (name, strlen (sprefix) + namelen + 1, "%s%s", | |
928 | + sprefix, symname); | |
929 | + sym.name = name; | |
930 | + } | |
844 | 931 | |
845 | - snprintf (name, strlen (sprefix) + namelen + 1, "%s%s", sprefix, symname); | |
846 | - sym.name = name; | |
847 | - } | |
932 | + sym.value = codepos; | |
933 | + sym.the_bfd = abfd; | |
934 | + sym.section = codesec; | |
935 | + sym.flags = 0; | |
936 | + sym.udata.i = 0; | |
848 | 937 | |
849 | - sym.value = codepos; | |
850 | - sym.the_bfd = abfd; | |
851 | - sym.section = codesec; | |
852 | - sym.flags = 0; | |
853 | - sym.udata.i = 0; | |
938 | + codepos += 24; | |
854 | 939 | |
855 | - codepos += 24; | |
940 | + if (csym != NULL) | |
941 | + *(csym[count]) = sym; | |
856 | 942 | |
857 | - if (csym != NULL) { | |
858 | - *(csym[count]) = sym; | |
943 | + count++; | |
859 | 944 | } |
860 | - count++; | |
861 | - } | |
862 | 945 | |
863 | 946 | goto end; |
864 | 947 | |
865 | 948 | end: |
866 | - if (libraries != NULL) { free (libraries); } | |
867 | - if (imports != NULL) { free (imports); } | |
949 | + if (libraries != NULL) | |
950 | + free (libraries); | |
951 | + if (imports != NULL) | |
952 | + free (imports); | |
868 | 953 | *nsym = count; |
869 | 954 | return 0; |
870 | 955 | |
871 | 956 | error: |
872 | - if (libraries != NULL) { free (libraries); } | |
873 | - if (imports != NULL) { free (imports); } | |
957 | + if (libraries != NULL) | |
958 | + free (libraries); | |
959 | + if (imports != NULL) | |
960 | + free (imports); | |
874 | 961 | *nsym = count; |
875 | 962 | return -1; |
876 | -} | |
963 | +} | |
877 | 964 | |
878 | 965 | static long bfd_pef_parse_symbols (abfd, csym) |
879 | 966 | bfd *abfd; |
@@ -894,8 +981,10 @@ static long bfd_pef_parse_symbols (abfd, csym) | ||
894 | 981 | { |
895 | 982 | codelen = bfd_section_size (abfd, codesec); |
896 | 983 | codebuf = (unsigned char *) bfd_malloc (codelen); |
897 | - if (bfd_seek (abfd, codesec->filepos, SEEK_SET) < 0) { goto end; } | |
898 | - if (bfd_bread ((PTR) codebuf, codelen, abfd) != codelen) { goto end; } | |
984 | + if (bfd_seek (abfd, codesec->filepos, SEEK_SET) < 0) | |
985 | + goto end; | |
986 | + if (bfd_bread ((PTR) codebuf, codelen, abfd) != codelen) | |
987 | + goto end; | |
899 | 988 | } |
900 | 989 | |
901 | 990 | loadersec = bfd_get_section_by_name (abfd, "loader"); |
@@ -903,15 +992,18 @@ static long bfd_pef_parse_symbols (abfd, csym) | ||
903 | 992 | { |
904 | 993 | loaderlen = bfd_section_size (abfd, loadersec); |
905 | 994 | loaderbuf = (unsigned char *) bfd_malloc (loaderlen); |
906 | - if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) { goto end; } | |
907 | - if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) { goto end; } | |
995 | + if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) | |
996 | + goto end; | |
997 | + if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) | |
998 | + goto end; | |
908 | 999 | } |
909 | - | |
1000 | + | |
910 | 1001 | count = 0; |
911 | 1002 | if (codesec != NULL) |
912 | 1003 | { |
913 | 1004 | unsigned long ncount = 0; |
914 | - bfd_pef_parse_traceback_tables (abfd, codesec, codebuf, codelen, &ncount, csym); | |
1005 | + bfd_pef_parse_traceback_tables (abfd, codesec, codebuf, codelen, | |
1006 | + &ncount, csym); | |
915 | 1007 | count += ncount; |
916 | 1008 | } |
917 | 1009 |
@@ -923,18 +1015,17 @@ static long bfd_pef_parse_symbols (abfd, csym) | ||
923 | 1015 | (csym != NULL) ? (csym + count) : NULL); |
924 | 1016 | count += ncount; |
925 | 1017 | } |
926 | - | |
927 | - if (csym != NULL) { | |
1018 | + | |
1019 | + if (csym != NULL) | |
928 | 1020 | csym[count] = NULL; |
929 | - } | |
930 | - | |
1021 | + | |
931 | 1022 | end: |
932 | - if (codebuf != NULL) | |
1023 | + if (codebuf != NULL) | |
933 | 1024 | free (codebuf); |
934 | 1025 | |
935 | - if (loaderbuf != NULL) | |
936 | - free (loaderbuf); | |
937 | - | |
1026 | + if (loaderbuf != NULL) | |
1027 | + free (loaderbuf); | |
1028 | + | |
938 | 1029 | return count; |
939 | 1030 | } |
940 | 1031 |
@@ -950,7 +1041,8 @@ bfd_pef_get_symtab_upper_bound (abfd) | ||
950 | 1041 | bfd *abfd; |
951 | 1042 | { |
952 | 1043 | long nsyms = bfd_pef_count_symbols (abfd); |
953 | - if (nsyms < 0) { return nsyms; } | |
1044 | + if (nsyms < 0) | |
1045 | + return nsyms; | |
954 | 1046 | return ((nsyms + 1) * sizeof (asymbol *)); |
955 | 1047 | } |
956 | 1048 |
@@ -964,20 +1056,21 @@ bfd_pef_get_symtab (abfd, alocation) | ||
964 | 1056 | long ret; |
965 | 1057 | |
966 | 1058 | long nsyms = bfd_pef_count_symbols (abfd); |
967 | - if (nsyms < 0) { return nsyms; } | |
1059 | + if (nsyms < 0) | |
1060 | + return nsyms; | |
968 | 1061 | |
969 | 1062 | syms = bfd_alloc (abfd, nsyms * sizeof (asymbol)); |
970 | - if (syms == NULL) { return -1; } | |
1063 | + if (syms == NULL) | |
1064 | + return -1; | |
971 | 1065 | |
972 | - for (i = 0; i < nsyms; i++) { | |
1066 | + for (i = 0; i < nsyms; i++) | |
973 | 1067 | alocation[i] = &syms[i]; |
974 | - } | |
1068 | + | |
975 | 1069 | alocation[nsyms] = NULL; |
976 | 1070 | |
977 | 1071 | ret = bfd_pef_parse_symbols (abfd, alocation); |
978 | - if (ret != nsyms) { | |
1072 | + if (ret != nsyms) | |
979 | 1073 | return 0; |
980 | - } | |
981 | 1074 | |
982 | 1075 | return ret; |
983 | 1076 | } |
@@ -1056,7 +1149,7 @@ const bfd_target pef_vec = | ||
1056 | 1149 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
1057 | 1150 | |
1058 | 1151 | NULL, |
1059 | - | |
1152 | + | |
1060 | 1153 | NULL |
1061 | 1154 | }; |
1062 | 1155 |
@@ -1077,7 +1170,8 @@ bfd_pef_xlib_read_header (abfd, header) | ||
1077 | 1170 | |
1078 | 1171 | bfd_seek (abfd, 0, SEEK_SET); |
1079 | 1172 | |
1080 | - if (bfd_bread ((PTR) buf, 76, abfd) != 76) { return -1; } | |
1173 | + if (bfd_bread ((PTR) buf, 76, abfd) != 76) | |
1174 | + return -1; | |
1081 | 1175 | |
1082 | 1176 | header->tag1 = bfd_getb32 (buf); |
1083 | 1177 | header->tag2 = bfd_getb32 (buf + 4); |
@@ -1110,18 +1204,15 @@ bfd_pef_xlib_scan (abfd, header) | ||
1110 | 1204 | { |
1111 | 1205 | bfd_pef_xlib_data_struct *mdata = NULL; |
1112 | 1206 | |
1113 | - if ((header->tag1 != BFD_PEF_XLIB_TAG1) | |
1114 | - || ((header->tag2 != BFD_PEF_VLIB_TAG2) && (header->tag2 != BFD_PEF_BLIB_TAG2))) { | |
1207 | + mdata = ((bfd_pef_xlib_data_struct *) | |
1208 | + bfd_alloc (abfd, sizeof (bfd_pef_xlib_data_struct))); | |
1209 | + if (mdata == NULL) | |
1115 | 1210 | return -1; |
1116 | - } | |
1117 | 1211 | |
1118 | - mdata = ((bfd_pef_xlib_data_struct *) | |
1119 | - bfd_alloc (abfd, sizeof (bfd_pef_xlib_data_struct))); | |
1120 | - if (mdata == NULL) { return -1; } | |
1121 | - | |
1122 | 1212 | mdata->header = *header; |
1123 | 1213 | |
1124 | - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); | |
1214 | + abfd->flags = (abfd->xvec->object_flags | |
1215 | + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); | |
1125 | 1216 | |
1126 | 1217 | abfd->tdata.pef_xlib_data = mdata; |
1127 | 1218 |
@@ -1132,22 +1223,37 @@ static const bfd_target * | ||
1132 | 1223 | bfd_pef_xlib_object_p (abfd) |
1133 | 1224 | bfd *abfd; |
1134 | 1225 | { |
1226 | + struct bfd_preserve preserve; | |
1135 | 1227 | bfd_pef_xlib_header header; |
1136 | - | |
1137 | - abfd->tdata.pef_xlib_data = NULL; | |
1138 | 1228 | |
1139 | - if (bfd_pef_xlib_read_header (abfd, &header) != 0) { | |
1140 | - abfd->tdata.pef_xlib_data = NULL; | |
1141 | - bfd_set_error (bfd_error_wrong_format); | |
1142 | - return NULL; | |
1143 | - } | |
1229 | + if (bfd_pef_xlib_read_header (abfd, &header) != 0) | |
1230 | + { | |
1231 | + bfd_set_error (bfd_error_wrong_format); | |
1232 | + return NULL; | |
1233 | + } | |
1144 | 1234 | |
1145 | - if (bfd_pef_xlib_scan (abfd, &header) != 0) { | |
1146 | - abfd->tdata.pef_xlib_data = NULL; | |
1147 | - bfd_set_error (bfd_error_wrong_format); | |
1148 | - return NULL; | |
1149 | - } | |
1235 | + if ((header.tag1 != BFD_PEF_XLIB_TAG1) | |
1236 | + || ((header.tag2 != BFD_PEF_VLIB_TAG2) | |
1237 | + && (header.tag2 != BFD_PEF_BLIB_TAG2))) | |
1238 | + { | |
1239 | + bfd_set_error (bfd_error_wrong_format); | |
1240 | + return NULL; | |
1241 | + } | |
1150 | 1242 | |
1243 | + if (! bfd_preserve_save (abfd, &preserve)) | |
1244 | + { | |
1245 | + bfd_set_error (bfd_error_wrong_format); | |
1246 | + return NULL; | |
1247 | + } | |
1248 | + | |
1249 | + if (bfd_pef_xlib_scan (abfd, &header) != 0) | |
1250 | + { | |
1251 | + bfd_preserve_restore (abfd, &preserve); | |
1252 | + bfd_set_error (bfd_error_wrong_format); | |
1253 | + return NULL; | |
1254 | + } | |
1255 | + | |
1256 | + bfd_preserve_finish (abfd, &preserve); | |
1151 | 1257 | return abfd->xvec; |
1152 | 1258 | } |
1153 | 1259 |
@@ -1201,7 +1307,6 @@ const bfd_target pef_xlib_vec = | ||
1201 | 1307 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
1202 | 1308 | |
1203 | 1309 | NULL, |
1204 | - | |
1310 | + | |
1205 | 1311 | NULL |
1206 | 1312 | }; |
1207 | - |
@@ -15,7 +15,7 @@ | ||
15 | 15 | GNU General Public License for more details. |
16 | 16 | |
17 | 17 | You should have received a copy of the GNU General Public License |
18 | - along with this program; if not, write to the Free Software | |
18 | + along with this program; if not, write to the Free Software | |
19 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 | 20 | |
21 | 21 | #include "bfd.h" |
@@ -43,7 +43,7 @@ struct bfd_pef_loader_header | ||
43 | 43 | long main_section; |
44 | 44 | unsigned long main_offset; |
45 | 45 | long init_section; |
46 | - unsigned long init_offset; | |
46 | + unsigned long init_offset; | |
47 | 47 | long term_section; |
48 | 48 | unsigned long term_offset; |
49 | 49 | unsigned long imported_library_count; |
@@ -183,4 +183,4 @@ int bfd_pef_parse_imported_library PARAMS ((bfd *, unsigned char *, size_t, bfd | ||
183 | 183 | int bfd_pef_parse_imported_symbol PARAMS ((bfd *, unsigned char *, size_t, bfd_pef_imported_symbol *)); |
184 | 184 | int bfd_pef_scan_section PARAMS ((bfd *, bfd_pef_section *)); |
185 | 185 | int bfd_pef_scan_start_address PARAMS ((bfd *)); |
186 | -int bfd_pef_scan PARAMS ((bfd *, bfd_pef_header *)); | |
186 | +int bfd_pef_scan PARAMS ((bfd *, bfd_pef_header *, bfd_pef_data_struct *)); |
@@ -997,11 +997,8 @@ static const bfd_target * const _bfd_target_vector[] = { | ||
997 | 997 | &pc532machaout_vec, |
998 | 998 | &pc532netbsd_vec, |
999 | 999 | &pdp11_aout_vec, |
1000 | -#if 0 | |
1001 | - /* bfd_pef_object_p and bfd_pef_xlib_object_p are broken. */ | |
1002 | 1000 | &pef_vec, |
1003 | 1001 | &pef_xlib_vec, |
1004 | -#endif | |
1005 | 1002 | #if 0 |
1006 | 1003 | /* This has the same magic number as RS/6000. */ |
1007 | 1004 | &pmac_xcoff_vec, |
@@ -1031,10 +1028,7 @@ static const bfd_target * const _bfd_target_vector[] = { | ||
1031 | 1028 | &sparclynx_coff_vec, |
1032 | 1029 | &sparcnetbsd_vec, |
1033 | 1030 | &sunos_big_vec, |
1034 | -#if 0 | |
1035 | - /* bfd_sym_object_p is broken. */ | |
1036 | 1031 | &sym_vec, |
1037 | -#endif | |
1038 | 1032 | &tic30_aout_vec, |
1039 | 1033 | &tic30_coff_vec, |
1040 | 1034 | &tic54x_coff0_beh_vec, |
@@ -15,7 +15,7 @@ | ||
15 | 15 | GNU General Public License for more details. |
16 | 16 | |
17 | 17 | You should have received a copy of the GNU General Public License |
18 | - along with this program; if not, write to the Free Software | |
18 | + along with this program; if not, write to the Free Software | |
19 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 | 20 | |
21 | 21 | #include "xsym.h" |
@@ -116,7 +116,7 @@ bfd_sym_valid (abfd) | ||
116 | 116 | if (abfd == NULL || abfd->xvec == NULL) |
117 | 117 | return 0; |
118 | 118 | |
119 | - return (abfd->xvec == &sym_vec); | |
119 | + return abfd->xvec == &sym_vec; | |
120 | 120 | } |
121 | 121 | |
122 | 122 | unsigned char * |
@@ -128,19 +128,19 @@ bfd_sym_read_name_table (abfd, dshb) | ||
128 | 128 | long ret; |
129 | 129 | size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size; |
130 | 130 | size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size; |
131 | - | |
131 | + | |
132 | 132 | rstr = (unsigned char *) bfd_alloc (abfd, table_size); |
133 | 133 | if (rstr == NULL) |
134 | 134 | return rstr; |
135 | 135 | |
136 | 136 | bfd_seek (abfd, table_offset, SEEK_SET); |
137 | 137 | ret = bfd_bread (rstr, table_size, abfd); |
138 | - if ((ret < 0) || ((unsigned long) ret != table_size)) | |
138 | + if (ret < 0 || (unsigned long) ret != table_size) | |
139 | 139 | { |
140 | 140 | bfd_release (abfd, rstr); |
141 | 141 | return NULL; |
142 | 142 | } |
143 | - | |
143 | + | |
144 | 144 | return rstr; |
145 | 145 | } |
146 | 146 |
@@ -163,11 +163,11 @@ bfd_sym_parse_disk_table_v32 (buf, len, table) | ||
163 | 163 | bfd_sym_table_info *table; |
164 | 164 | { |
165 | 165 | BFD_ASSERT (len == 8); |
166 | - | |
166 | + | |
167 | 167 | table->dti_first_page = bfd_getb16 (buf); |
168 | 168 | table->dti_page_count = bfd_getb16 (buf + 2); |
169 | 169 | table->dti_object_count = bfd_getb32 (buf + 4); |
170 | -} | |
170 | +} | |
171 | 171 | |
172 | 172 | void |
173 | 173 | bfd_sym_parse_header_v32 (buf, len, header) |
@@ -176,13 +176,13 @@ bfd_sym_parse_header_v32 (buf, len, header) | ||
176 | 176 | bfd_sym_header_block *header; |
177 | 177 | { |
178 | 178 | BFD_ASSERT (len == 154); |
179 | - | |
179 | + | |
180 | 180 | memcpy (header->dshb_id, buf, 32); |
181 | 181 | header->dshb_page_size = bfd_getb16 (buf + 32); |
182 | 182 | header->dshb_hash_page = bfd_getb16 (buf + 34); |
183 | 183 | header->dshb_root_mte = bfd_getb16 (buf + 36); |
184 | 184 | header->dshb_mod_date = bfd_getb32 (buf + 38); |
185 | - | |
185 | + | |
186 | 186 | bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte); |
187 | 187 | bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte); |
188 | 188 | bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte); |
@@ -196,7 +196,7 @@ bfd_sym_parse_header_v32 (buf, len, header) | ||
196 | 196 | bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo); |
197 | 197 | bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite); |
198 | 198 | bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const); |
199 | - | |
199 | + | |
200 | 200 | memcpy (&header->dshb_file_creator, buf + 146, 4); |
201 | 201 | memcpy (&header->dshb_file_type, buf + 150, 4); |
202 | 202 | } |
@@ -208,13 +208,13 @@ bfd_sym_read_header_v32 (abfd, header) | ||
208 | 208 | { |
209 | 209 | unsigned char buf[154]; |
210 | 210 | long ret; |
211 | - | |
211 | + | |
212 | 212 | ret = bfd_bread (buf, 154, abfd); |
213 | 213 | if (ret != 154) |
214 | 214 | return -1; |
215 | - | |
215 | + | |
216 | 216 | bfd_sym_parse_header_v32 (buf, 154, header); |
217 | - | |
217 | + | |
218 | 218 | return 0; |
219 | 219 | } |
220 | 220 |
@@ -253,11 +253,11 @@ bfd_sym_read_version (abfd, version) | ||
253 | 253 | { |
254 | 254 | unsigned char version_string[32]; |
255 | 255 | long ret; |
256 | - | |
256 | + | |
257 | 257 | ret = bfd_bread (version_string, sizeof (version_string), abfd); |
258 | 258 | if (ret != sizeof (version_string)) |
259 | 259 | return -1; |
260 | - | |
260 | + | |
261 | 261 | if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0) |
262 | 262 | *version = BFD_SYM_VERSION_3_1; |
263 | 263 | else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0) |
@@ -270,7 +270,7 @@ bfd_sym_read_version (abfd, version) | ||
270 | 270 | *version = BFD_SYM_VERSION_3_5; |
271 | 271 | else |
272 | 272 | return -1; |
273 | - | |
273 | + | |
274 | 274 | return 0; |
275 | 275 | } |
276 | 276 |
@@ -302,10 +302,10 @@ bfd_sym_display_header (f, dshb) | ||
302 | 302 | |
303 | 303 | fprintf (f, " File Creator: %.4s Type: %.4s\n\n", |
304 | 304 | dshb->dshb_file_creator, dshb->dshb_file_type); |
305 | - | |
305 | + | |
306 | 306 | fprintf (f, "Table Name First Page Page Count Object Count\n"); |
307 | 307 | fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); |
308 | - | |
308 | + | |
309 | 309 | bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE"); |
310 | 310 | bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE"); |
311 | 311 | bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE"); |
@@ -319,7 +319,7 @@ bfd_sym_display_header (f, dshb) | ||
319 | 319 | bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO"); |
320 | 320 | bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE"); |
321 | 321 | bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST"); |
322 | - | |
322 | + | |
323 | 323 | fprintf (f, "\n"); |
324 | 324 | } |
325 | 325 |
@@ -371,7 +371,7 @@ bfd_sym_parse_file_references_table_entry_v32 (buf, len, entry) | ||
371 | 371 | bfd_sym_file_references_table_entry *entry; |
372 | 372 | { |
373 | 373 | unsigned int type; |
374 | - | |
374 | + | |
375 | 375 | BFD_ASSERT (len == 10); |
376 | 376 | |
377 | 377 | memset (entry, 0, sizeof (bfd_sym_file_references_table_entry)); |
@@ -407,7 +407,7 @@ bfd_sym_parse_contained_modules_table_entry_v32 (buf, len, entry) | ||
407 | 407 | |
408 | 408 | memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry)); |
409 | 409 | type = bfd_getb16 (buf); |
410 | - | |
410 | + | |
411 | 411 | switch (type) |
412 | 412 | { |
413 | 413 | case BFD_SYM_END_OF_LIST_3_2: |
@@ -428,7 +428,7 @@ bfd_sym_parse_contained_variables_table_entry_v32 (buf, len, entry) | ||
428 | 428 | bfd_sym_contained_variables_table_entry *entry; |
429 | 429 | { |
430 | 430 | unsigned int type; |
431 | - | |
431 | + | |
432 | 432 | BFD_ASSERT (len == 26); |
433 | 433 | |
434 | 434 | memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry)); |
@@ -483,7 +483,7 @@ bfd_sym_parse_contained_statements_table_entry_v32 (buf, len, entry) | ||
483 | 483 | |
484 | 484 | memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry)); |
485 | 485 | type = bfd_getb16 (buf); |
486 | - | |
486 | + | |
487 | 487 | switch (type) |
488 | 488 | { |
489 | 489 | case BFD_SYM_END_OF_LIST_3_2: |
@@ -515,7 +515,7 @@ bfd_sym_parse_contained_labels_table_entry_v32 (buf, len, entry) | ||
515 | 515 | |
516 | 516 | memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry)); |
517 | 517 | type = bfd_getb16 (buf); |
518 | - | |
518 | + | |
519 | 519 | switch (type) |
520 | 520 | { |
521 | 521 | case BFD_SYM_END_OF_LIST_3_2: |
@@ -544,7 +544,7 @@ bfd_sym_parse_type_table_entry_v32 (buf, len, entry) | ||
544 | 544 | bfd_sym_type_table_entry *entry; |
545 | 545 | { |
546 | 546 | BFD_ASSERT (len == 4); |
547 | - | |
547 | + | |
548 | 548 | *entry = bfd_getb32 (buf); |
549 | 549 | } |
550 | 550 |
@@ -554,12 +554,14 @@ bfd_sym_fetch_resources_table_entry (abfd, entry, index) | ||
554 | 554 | bfd_sym_resources_table_entry *entry; |
555 | 555 | unsigned long index; |
556 | 556 | { |
557 | - void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *) = NULL; | |
557 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
558 | + bfd_sym_resources_table_entry *)); | |
558 | 559 | unsigned long offset; |
559 | 560 | unsigned long entry_size; |
560 | 561 | unsigned char buf[18]; |
561 | 562 | bfd_sym_data_struct *sdata = NULL; |
562 | 563 | |
564 | + parser = NULL; | |
563 | 565 | BFD_ASSERT (bfd_sym_valid (abfd)); |
564 | 566 | sdata = abfd->tdata.sym_data; |
565 | 567 |
@@ -588,14 +590,14 @@ bfd_sym_fetch_resources_table_entry (abfd, entry, index) | ||
588 | 590 | offset = compute_offset (sdata->header.dshb_rte.dti_first_page, |
589 | 591 | sdata->header.dshb_page_size, |
590 | 592 | entry_size, index); |
591 | - | |
593 | + | |
592 | 594 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
593 | 595 | return -1; |
594 | 596 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
595 | 597 | return -1; |
596 | 598 | |
597 | 599 | (*parser) (buf, entry_size, entry); |
598 | - | |
600 | + | |
599 | 601 | return 0; |
600 | 602 | } |
601 | 603 |
@@ -605,12 +607,14 @@ bfd_sym_fetch_modules_table_entry (abfd, entry, index) | ||
605 | 607 | bfd_sym_modules_table_entry *entry; |
606 | 608 | unsigned long index; |
607 | 609 | { |
608 | - void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *) = NULL; | |
610 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
611 | + bfd_sym_modules_table_entry *)); | |
609 | 612 | unsigned long offset; |
610 | 613 | unsigned long entry_size; |
611 | 614 | unsigned char buf[46]; |
612 | 615 | bfd_sym_data_struct *sdata = NULL; |
613 | 616 | |
617 | + parser = NULL; | |
614 | 618 | BFD_ASSERT (bfd_sym_valid (abfd)); |
615 | 619 | sdata = abfd->tdata.sym_data; |
616 | 620 |
@@ -639,14 +643,14 @@ bfd_sym_fetch_modules_table_entry (abfd, entry, index) | ||
639 | 643 | offset = compute_offset (sdata->header.dshb_mte.dti_first_page, |
640 | 644 | sdata->header.dshb_page_size, |
641 | 645 | entry_size, index); |
642 | - | |
646 | + | |
643 | 647 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
644 | 648 | return -1; |
645 | 649 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
646 | 650 | return -1; |
647 | 651 | |
648 | 652 | (*parser) (buf, entry_size, entry); |
649 | - | |
653 | + | |
650 | 654 | return 0; |
651 | 655 | } |
652 | 656 |
@@ -656,12 +660,14 @@ bfd_sym_fetch_file_references_table_entry (abfd, entry, index) | ||
656 | 660 | bfd_sym_file_references_table_entry *entry; |
657 | 661 | unsigned long index; |
658 | 662 | { |
659 | - void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *) = NULL; | |
663 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
664 | + bfd_sym_file_references_table_entry *)); | |
660 | 665 | unsigned long offset; |
661 | 666 | unsigned long entry_size = 0; |
662 | 667 | unsigned char buf[8]; |
663 | 668 | bfd_sym_data_struct *sdata = NULL; |
664 | 669 | |
670 | + parser = NULL; | |
665 | 671 | BFD_ASSERT (bfd_sym_valid (abfd)); |
666 | 672 | sdata = abfd->tdata.sym_data; |
667 | 673 |
@@ -689,14 +695,14 @@ bfd_sym_fetch_file_references_table_entry (abfd, entry, index) | ||
689 | 695 | offset = compute_offset (sdata->header.dshb_frte.dti_first_page, |
690 | 696 | sdata->header.dshb_page_size, |
691 | 697 | entry_size, index); |
692 | - | |
698 | + | |
693 | 699 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
694 | 700 | return -1; |
695 | 701 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
696 | 702 | return -1; |
697 | 703 | |
698 | 704 | (*parser) (buf, entry_size, entry); |
699 | - | |
705 | + | |
700 | 706 | return 0; |
701 | 707 | } |
702 | 708 |
@@ -706,12 +712,14 @@ bfd_sym_fetch_contained_modules_table_entry (abfd, entry, index) | ||
706 | 712 | bfd_sym_contained_modules_table_entry *entry; |
707 | 713 | unsigned long index; |
708 | 714 | { |
709 | - void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *) = NULL; | |
715 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
716 | + bfd_sym_contained_modules_table_entry *)); | |
710 | 717 | unsigned long offset; |
711 | 718 | unsigned long entry_size = 0; |
712 | 719 | unsigned char buf[6]; |
713 | 720 | bfd_sym_data_struct *sdata = NULL; |
714 | 721 | |
722 | + parser = NULL; | |
715 | 723 | BFD_ASSERT (bfd_sym_valid (abfd)); |
716 | 724 | sdata = abfd->tdata.sym_data; |
717 | 725 |
@@ -739,14 +747,14 @@ bfd_sym_fetch_contained_modules_table_entry (abfd, entry, index) | ||
739 | 747 | offset = compute_offset (sdata->header.dshb_cmte.dti_first_page, |
740 | 748 | sdata->header.dshb_page_size, |
741 | 749 | entry_size, index); |
742 | - | |
750 | + | |
743 | 751 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
744 | 752 | return -1; |
745 | 753 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
746 | 754 | return -1; |
747 | 755 | |
748 | 756 | (*parser) (buf, entry_size, entry); |
749 | - | |
757 | + | |
750 | 758 | return 0; |
751 | 759 | } |
752 | 760 |
@@ -756,12 +764,14 @@ bfd_sym_fetch_contained_variables_table_entry (abfd, entry, index) | ||
756 | 764 | bfd_sym_contained_variables_table_entry *entry; |
757 | 765 | unsigned long index; |
758 | 766 | { |
759 | - void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *) = NULL; | |
767 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
768 | + bfd_sym_contained_variables_table_entry *)); | |
760 | 769 | unsigned long offset; |
761 | 770 | unsigned long entry_size = 0; |
762 | 771 | unsigned char buf[26]; |
763 | 772 | bfd_sym_data_struct *sdata = NULL; |
764 | 773 | |
774 | + parser = NULL; | |
765 | 775 | BFD_ASSERT (bfd_sym_valid (abfd)); |
766 | 776 | sdata = abfd->tdata.sym_data; |
767 | 777 |
@@ -789,14 +799,14 @@ bfd_sym_fetch_contained_variables_table_entry (abfd, entry, index) | ||
789 | 799 | offset = compute_offset (sdata->header.dshb_cvte.dti_first_page, |
790 | 800 | sdata->header.dshb_page_size, |
791 | 801 | entry_size, index); |
792 | - | |
802 | + | |
793 | 803 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
794 | 804 | return -1; |
795 | 805 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
796 | 806 | return -1; |
797 | 807 | |
798 | 808 | (*parser) (buf, entry_size, entry); |
799 | - | |
809 | + | |
800 | 810 | return 0; |
801 | 811 | } |
802 | 812 |
@@ -806,12 +816,14 @@ bfd_sym_fetch_contained_statements_table_entry (abfd, entry, index) | ||
806 | 816 | bfd_sym_contained_statements_table_entry *entry; |
807 | 817 | unsigned long index; |
808 | 818 | { |
809 | - void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *) = NULL; | |
819 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
820 | + bfd_sym_contained_statements_table_entry *)); | |
810 | 821 | unsigned long offset; |
811 | 822 | unsigned long entry_size = 0; |
812 | 823 | unsigned char buf[8]; |
813 | 824 | bfd_sym_data_struct *sdata = NULL; |
814 | 825 | |
826 | + parser = NULL; | |
815 | 827 | BFD_ASSERT (bfd_sym_valid (abfd)); |
816 | 828 | sdata = abfd->tdata.sym_data; |
817 | 829 |
@@ -839,14 +851,14 @@ bfd_sym_fetch_contained_statements_table_entry (abfd, entry, index) | ||
839 | 851 | offset = compute_offset (sdata->header.dshb_csnte.dti_first_page, |
840 | 852 | sdata->header.dshb_page_size, |
841 | 853 | entry_size, index); |
842 | - | |
854 | + | |
843 | 855 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
844 | 856 | return -1; |
845 | 857 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
846 | 858 | return -1; |
847 | 859 | |
848 | 860 | (*parser) (buf, entry_size, entry); |
849 | - | |
861 | + | |
850 | 862 | return 0; |
851 | 863 | } |
852 | 864 |
@@ -856,12 +868,14 @@ bfd_sym_fetch_contained_labels_table_entry (abfd, entry, index) | ||
856 | 868 | bfd_sym_contained_labels_table_entry *entry; |
857 | 869 | unsigned long index; |
858 | 870 | { |
859 | - void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *) = NULL; | |
871 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
872 | + bfd_sym_contained_labels_table_entry *)); | |
860 | 873 | unsigned long offset; |
861 | 874 | unsigned long entry_size = 0; |
862 | 875 | unsigned char buf[12]; |
863 | 876 | bfd_sym_data_struct *sdata = NULL; |
864 | 877 | |
878 | + parser = NULL; | |
865 | 879 | BFD_ASSERT (bfd_sym_valid (abfd)); |
866 | 880 | sdata = abfd->tdata.sym_data; |
867 | 881 |
@@ -889,14 +903,14 @@ bfd_sym_fetch_contained_labels_table_entry (abfd, entry, index) | ||
889 | 903 | offset = compute_offset (sdata->header.dshb_clte.dti_first_page, |
890 | 904 | sdata->header.dshb_page_size, |
891 | 905 | entry_size, index); |
892 | - | |
906 | + | |
893 | 907 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
894 | 908 | return -1; |
895 | 909 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
896 | 910 | return -1; |
897 | 911 | |
898 | 912 | (*parser) (buf, entry_size, entry); |
899 | - | |
913 | + | |
900 | 914 | return 0; |
901 | 915 | } |
902 | 916 |
@@ -906,12 +920,14 @@ bfd_sym_fetch_contained_types_table_entry (abfd, entry, index) | ||
906 | 920 | bfd_sym_contained_types_table_entry *entry; |
907 | 921 | unsigned long index; |
908 | 922 | { |
909 | - void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *) = NULL; | |
923 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
924 | + bfd_sym_contained_types_table_entry *)); | |
910 | 925 | unsigned long offset; |
911 | 926 | unsigned long entry_size = 0; |
912 | 927 | unsigned char buf[0]; |
913 | 928 | bfd_sym_data_struct *sdata = NULL; |
914 | 929 | |
930 | + parser = NULL; | |
915 | 931 | BFD_ASSERT (bfd_sym_valid (abfd)); |
916 | 932 | sdata = abfd->tdata.sym_data; |
917 | 933 |
@@ -939,14 +955,14 @@ bfd_sym_fetch_contained_types_table_entry (abfd, entry, index) | ||
939 | 955 | offset = compute_offset (sdata->header.dshb_ctte.dti_first_page, |
940 | 956 | sdata->header.dshb_page_size, |
941 | 957 | entry_size, index); |
942 | - | |
958 | + | |
943 | 959 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
944 | 960 | return -1; |
945 | 961 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
946 | 962 | return -1; |
947 | 963 | |
948 | 964 | (*parser) (buf, entry_size, entry); |
949 | - | |
965 | + | |
950 | 966 | return 0; |
951 | 967 | } |
952 | 968 |
@@ -956,12 +972,14 @@ bfd_sym_fetch_file_references_index_table_entry (abfd, entry, index) | ||
956 | 972 | bfd_sym_file_references_index_table_entry *entry; |
957 | 973 | unsigned long index; |
958 | 974 | { |
959 | - void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *) = NULL; | |
975 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
976 | + bfd_sym_file_references_index_table_entry *)); | |
960 | 977 | unsigned long offset; |
961 | 978 | unsigned long entry_size = 0; |
962 | 979 | unsigned char buf[0]; |
963 | 980 | bfd_sym_data_struct *sdata = NULL; |
964 | 981 | |
982 | + parser = NULL; | |
965 | 983 | BFD_ASSERT (bfd_sym_valid (abfd)); |
966 | 984 | sdata = abfd->tdata.sym_data; |
967 | 985 |
@@ -989,14 +1007,14 @@ bfd_sym_fetch_file_references_index_table_entry (abfd, entry, index) | ||
989 | 1007 | offset = compute_offset (sdata->header.dshb_fite.dti_first_page, |
990 | 1008 | sdata->header.dshb_page_size, |
991 | 1009 | entry_size, index); |
992 | - | |
1010 | + | |
993 | 1011 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
994 | 1012 | return -1; |
995 | 1013 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
996 | 1014 | return -1; |
997 | 1015 | |
998 | 1016 | (*parser) (buf, entry_size, entry); |
999 | - | |
1017 | + | |
1000 | 1018 | return 0; |
1001 | 1019 | } |
1002 | 1020 |
@@ -1006,12 +1024,14 @@ bfd_sym_fetch_constant_pool_entry (abfd, entry, index) | ||
1006 | 1024 | bfd_sym_constant_pool_entry *entry; |
1007 | 1025 | unsigned long index; |
1008 | 1026 | { |
1009 | - void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *) = NULL; | |
1027 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
1028 | + bfd_sym_constant_pool_entry *)); | |
1010 | 1029 | unsigned long offset; |
1011 | 1030 | unsigned long entry_size = 0; |
1012 | 1031 | unsigned char buf[0]; |
1013 | 1032 | bfd_sym_data_struct *sdata = NULL; |
1014 | 1033 | |
1034 | + parser = NULL; | |
1015 | 1035 | BFD_ASSERT (bfd_sym_valid (abfd)); |
1016 | 1036 | sdata = abfd->tdata.sym_data; |
1017 | 1037 |
@@ -1039,14 +1059,14 @@ bfd_sym_fetch_constant_pool_entry (abfd, entry, index) | ||
1039 | 1059 | offset = compute_offset (sdata->header.dshb_fite.dti_first_page, |
1040 | 1060 | sdata->header.dshb_page_size, |
1041 | 1061 | entry_size, index); |
1042 | - | |
1062 | + | |
1043 | 1063 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
1044 | 1064 | return -1; |
1045 | 1065 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
1046 | 1066 | return -1; |
1047 | 1067 | |
1048 | 1068 | (*parser) (buf, entry_size, entry); |
1049 | - | |
1069 | + | |
1050 | 1070 | return 0; |
1051 | 1071 | } |
1052 | 1072 |
@@ -1056,12 +1076,14 @@ bfd_sym_fetch_type_table_entry (abfd, entry, index) | ||
1056 | 1076 | bfd_sym_type_table_entry *entry; |
1057 | 1077 | unsigned long index; |
1058 | 1078 | { |
1059 | - void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *) = NULL; | |
1079 | + void (*parser) PARAMS ((unsigned char *, size_t, | |
1080 | + bfd_sym_type_table_entry *)); | |
1060 | 1081 | unsigned long offset; |
1061 | 1082 | unsigned long entry_size = 0; |
1062 | 1083 | unsigned char buf[4]; |
1063 | 1084 | bfd_sym_data_struct *sdata = NULL; |
1064 | 1085 | |
1086 | + parser = NULL; | |
1065 | 1087 | BFD_ASSERT (bfd_sym_valid (abfd)); |
1066 | 1088 | sdata = abfd->tdata.sym_data; |
1067 | 1089 |
@@ -1086,14 +1108,14 @@ bfd_sym_fetch_type_table_entry (abfd, entry, index) | ||
1086 | 1108 | offset = compute_offset (sdata->header.dshb_tte.dti_first_page, |
1087 | 1109 | sdata->header.dshb_page_size, |
1088 | 1110 | entry_size, index); |
1089 | - | |
1111 | + | |
1090 | 1112 | if (bfd_seek (abfd, offset, SEEK_SET) < 0) |
1091 | 1113 | return -1; |
1092 | 1114 | if (bfd_bread (buf, entry_size, abfd) != entry_size) |
1093 | 1115 | return -1; |
1094 | 1116 | |
1095 | 1117 | (*parser) (buf, entry_size, entry); |
1096 | - | |
1118 | + | |
1097 | 1119 | return 0; |
1098 | 1120 | } |
1099 | 1121 |
@@ -1118,11 +1140,11 @@ bfd_sym_fetch_type_information_table_entry (abfd, entry, offset) | ||
1118 | 1140 | if (bfd_bread (buf, 4, abfd) != 4) |
1119 | 1141 | return -1; |
1120 | 1142 | entry->nte_index = bfd_getb32 (buf); |
1121 | - | |
1143 | + | |
1122 | 1144 | if (bfd_bread (buf, 2, abfd) != 2) |
1123 | 1145 | return -1; |
1124 | 1146 | entry->physical_size = bfd_getb16 (buf); |
1125 | - | |
1147 | + | |
1126 | 1148 | if (entry->physical_size & 0x8000) |
1127 | 1149 | { |
1128 | 1150 | if (bfd_bread (buf, 4, abfd) != 4) |
@@ -1180,12 +1202,13 @@ bfd_sym_symbol_name (abfd, index) | ||
1180 | 1202 | |
1181 | 1203 | if (index == 0) |
1182 | 1204 | return ""; |
1183 | - | |
1205 | + | |
1184 | 1206 | index *= 2; |
1185 | - if ((index / sdata->header.dshb_page_size) > sdata->header.dshb_nte.dti_page_count) | |
1207 | + if ((index / sdata->header.dshb_page_size) | |
1208 | + > sdata->header.dshb_nte.dti_page_count) | |
1186 | 1209 | return "\009[INVALID]"; |
1187 | - | |
1188 | - return ((const unsigned char *) sdata->name_table + index); | |
1210 | + | |
1211 | + return (const unsigned char *) sdata->name_table + index; | |
1189 | 1212 | } |
1190 | 1213 | |
1191 | 1214 | const unsigned char * |
@@ -1194,7 +1217,7 @@ bfd_sym_module_name (abfd, index) | ||
1194 | 1217 | unsigned long index; |
1195 | 1218 | { |
1196 | 1219 | bfd_sym_modules_table_entry entry; |
1197 | - | |
1220 | + | |
1198 | 1221 | if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0) |
1199 | 1222 | return "\011[INVALID]"; |
1200 | 1223 |
@@ -1272,7 +1295,8 @@ bfd_sym_print_file_reference (abfd, f, entry) | ||
1272 | 1295 | bfd_sym_file_references_table_entry frtentry; |
1273 | 1296 | int ret; |
1274 | 1297 | |
1275 | - ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry, entry->fref_frte_index); | |
1298 | + ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry, | |
1299 | + entry->fref_frte_index); | |
1276 | 1300 | fprintf (f, "FILE "); |
1277 | 1301 | |
1278 | 1302 | if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX)) |
@@ -1296,7 +1320,7 @@ bfd_sym_print_resources_table_entry (abfd, f, entry) | ||
1296 | 1320 | &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1], |
1297 | 1321 | entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number, |
1298 | 1322 | entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last); |
1299 | -} | |
1323 | +} | |
1300 | 1324 | |
1301 | 1325 | void |
1302 | 1326 | bfd_sym_print_modules_table_entry (abfd, f, entry) |
@@ -1308,27 +1332,28 @@ bfd_sym_print_modules_table_entry (abfd, f, entry) | ||
1308 | 1332 | bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0], |
1309 | 1333 | &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1], |
1310 | 1334 | entry->mte_nte_index); |
1311 | - | |
1312 | - fprintf (f, "\n "); | |
1335 | + | |
1336 | + fprintf (f, "\n "); | |
1313 | 1337 | |
1314 | 1338 | bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref); |
1315 | - fprintf (f, " range %lu -- %lu", entry->mte_imp_fref.fref_offset, entry->mte_imp_end); | |
1339 | + fprintf (f, " range %lu -- %lu", | |
1340 | + entry->mte_imp_fref.fref_offset, entry->mte_imp_end); | |
1316 | 1341 | |
1317 | - fprintf (f, "\n "); | |
1342 | + fprintf (f, "\n "); | |
1318 | 1343 | |
1319 | 1344 | fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind)); |
1320 | 1345 | fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope)); |
1321 | - | |
1346 | + | |
1322 | 1347 | fprintf (f, ", RTE %lu, offset %lu, size %lu", |
1323 | 1348 | entry->mte_rte_index, entry->mte_res_offset, entry->mte_size); |
1324 | 1349 | |
1325 | - fprintf (f, "\n "); | |
1350 | + fprintf (f, "\n "); | |
1326 | 1351 | |
1327 | - fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu", | |
1352 | + fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu", | |
1328 | 1353 | entry->mte_cmte_index, entry->mte_cvte_index, |
1329 | 1354 | entry->mte_clte_index, entry->mte_ctte_index, |
1330 | 1355 | entry->mte_csnte_idx_1, entry->mte_csnte_idx_2); |
1331 | - | |
1356 | + | |
1332 | 1357 | if (entry->mte_parent != 0) |
1333 | 1358 | fprintf (f, ", parent %lu", entry->mte_parent); |
1334 | 1359 | else |
@@ -1364,7 +1389,7 @@ bfd_sym_print_file_references_table_entry (abfd, f, entry) | ||
1364 | 1389 | switch (entry->generic.type) |
1365 | 1390 | { |
1366 | 1391 | case BFD_SYM_FILE_NAME_INDEX: |
1367 | - fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ", | |
1392 | + fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ", | |
1368 | 1393 | bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0], |
1369 | 1394 | &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1], |
1370 | 1395 | entry->filename.nte_index); |
@@ -1421,19 +1446,19 @@ bfd_sym_print_contained_variables_table_entry (abfd, f, entry) | ||
1421 | 1446 | fprintf (f, "END"); |
1422 | 1447 | return; |
1423 | 1448 | } |
1424 | - | |
1449 | + | |
1425 | 1450 | if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) |
1426 | 1451 | { |
1427 | 1452 | bfd_sym_print_file_reference (abfd, f, &entry->file.fref); |
1428 | 1453 | fprintf (f, " offset %lu", entry->file.fref.fref_offset); |
1429 | 1454 | return; |
1430 | 1455 | } |
1431 | - | |
1456 | + | |
1432 | 1457 | fprintf (f, "\"%.*s\" (NTE %lu)", |
1433 | 1458 | bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0], |
1434 | 1459 | &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1], |
1435 | 1460 | entry->entry.nte_index); |
1436 | - | |
1461 | + | |
1437 | 1462 | fprintf (f, ", TTE %lu", entry->entry.tte_index); |
1438 | 1463 | fprintf (f, ", offset %lu", entry->entry.file_delta); |
1439 | 1464 | fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope)); |
@@ -1454,7 +1479,7 @@ bfd_sym_print_contained_variables_table_entry (abfd, f, entry) | ||
1454 | 1479 | } |
1455 | 1480 | else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA) |
1456 | 1481 | fprintf (f, ", bigla %lu, biglakind %u", |
1457 | - entry->entry.address.biglastruct.big_la, | |
1482 | + entry->entry.address.biglastruct.big_la, | |
1458 | 1483 | entry->entry.address.biglastruct.big_la_kind); |
1459 | 1484 | |
1460 | 1485 | else |
@@ -1472,7 +1497,7 @@ bfd_sym_print_contained_statements_table_entry (abfd, f, entry) | ||
1472 | 1497 | fprintf (f, "END"); |
1473 | 1498 | return; |
1474 | 1499 | } |
1475 | - | |
1500 | + | |
1476 | 1501 | if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) |
1477 | 1502 | { |
1478 | 1503 | bfd_sym_print_file_reference (abfd, f, &entry->file.fref); |
@@ -1661,9 +1686,9 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1661 | 1686 | |
1662 | 1687 | if (offsetptr != NULL) |
1663 | 1688 | *offsetptr = offset; |
1664 | - return; | |
1689 | + return; | |
1665 | 1690 | } |
1666 | - | |
1691 | + | |
1667 | 1692 | type = buf[offset]; |
1668 | 1693 | offset++; |
1669 | 1694 |
@@ -1688,7 +1713,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1688 | 1713 | long value; |
1689 | 1714 | bfd_sym_type_information_table_entry tinfo; |
1690 | 1715 | |
1691 | - bfd_sym_fetch_long (buf, len, offset, &offset, &value); | |
1716 | + bfd_sym_fetch_long (buf, len, offset, &offset, &value); | |
1692 | 1717 | if (value <= 0) |
1693 | 1718 | fprintf (f, "[INVALID]"); |
1694 | 1719 | else |
@@ -1696,7 +1721,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1696 | 1721 | if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0) |
1697 | 1722 | fprintf (f, "[INVALID]"); |
1698 | 1723 | else |
1699 | - fprintf (f, "\"%.*s\"", | |
1724 | + fprintf (f, "\"%.*s\"", | |
1700 | 1725 | bfd_sym_symbol_name (abfd, tinfo.nte_index)[0], |
1701 | 1726 | &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]); |
1702 | 1727 | } |
@@ -1719,7 +1744,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1719 | 1744 | fprintf (f, " (%lu)", value); |
1720 | 1745 | break; |
1721 | 1746 | } |
1722 | - | |
1747 | + | |
1723 | 1748 | case 5: |
1724 | 1749 | { |
1725 | 1750 | unsigned long lower, upper, nelem; |
@@ -1727,9 +1752,9 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1727 | 1752 | |
1728 | 1753 | fprintf (f, "enumeration (0x%x) of ", type); |
1729 | 1754 | bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); |
1730 | - bfd_sym_fetch_long (buf, len, offset, &offset, &lower); | |
1731 | - bfd_sym_fetch_long (buf, len, offset, &offset, &upper); | |
1732 | - bfd_sym_fetch_long (buf, len, offset, &offset, &nelem); | |
1755 | + bfd_sym_fetch_long (buf, len, offset, &offset, &lower); | |
1756 | + bfd_sym_fetch_long (buf, len, offset, &offset, &upper); | |
1757 | + bfd_sym_fetch_long (buf, len, offset, &offset, &nelem); | |
1733 | 1758 | fprintf (f, " from %lu to %lu with %lu elements: ", lower, upper, nelem); |
1734 | 1759 | |
1735 | 1760 | for (i = 0; i < nelem; i++) |
@@ -1757,15 +1782,15 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1757 | 1782 | fprintf (f, "record (0x%x) of ", type); |
1758 | 1783 | else |
1759 | 1784 | fprintf (f, "union (0x%x) of ", type); |
1760 | - | |
1761 | - bfd_sym_fetch_long (buf, len, offset, &offset, &nrec); | |
1762 | - fprintf (f, "%lu elements: ", nrec); | |
1785 | + | |
1786 | + bfd_sym_fetch_long (buf, len, offset, &offset, &nrec); | |
1787 | + fprintf (f, "%lu elements: ", nrec); | |
1763 | 1788 | |
1764 | 1789 | for (i = 0; i < nrec; i++) |
1765 | 1790 | { |
1766 | - bfd_sym_fetch_long (buf, len, offset, &offset, &eloff); | |
1791 | + bfd_sym_fetch_long (buf, len, offset, &offset, &eloff); | |
1767 | 1792 | fprintf (f, "\n "); |
1768 | - fprintf (f, "offset %lu: ", eloff); | |
1793 | + fprintf (f, "offset %lu: ", eloff); | |
1769 | 1794 | bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); |
1770 | 1795 | } |
1771 | 1796 | break; |
@@ -1785,11 +1810,11 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1785 | 1810 | long value; |
1786 | 1811 | |
1787 | 1812 | fprintf (f, "named type (0x%x) ", type); |
1788 | - bfd_sym_fetch_long (buf, len, offset, &offset, &value); | |
1813 | + bfd_sym_fetch_long (buf, len, offset, &offset, &value); | |
1789 | 1814 | if (value <= 0) |
1790 | 1815 | fprintf (f, "[INVALID]"); |
1791 | 1816 | else |
1792 | - fprintf (f, "\"%.*s\"", | |
1817 | + fprintf (f, "\"%.*s\"", | |
1793 | 1818 | bfd_sym_symbol_name (abfd, value)[0], |
1794 | 1819 | &bfd_sym_symbol_name (abfd, value)[1]); |
1795 | 1820 |
@@ -1802,7 +1827,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1802 | 1827 | fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type); |
1803 | 1828 | break; |
1804 | 1829 | } |
1805 | - | |
1830 | + | |
1806 | 1831 | if (type == (0x40 | 0x6)) |
1807 | 1832 | { |
1808 | 1833 | /* Vector. */ |
@@ -1810,14 +1835,14 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1810 | 1835 | long l; |
1811 | 1836 | long i; |
1812 | 1837 | |
1813 | - bfd_sym_fetch_long (buf, len, offset, &offset, &n); | |
1814 | - bfd_sym_fetch_long (buf, len, offset, &offset, &width); | |
1815 | - bfd_sym_fetch_long (buf, len, offset, &offset, &m); | |
1838 | + bfd_sym_fetch_long (buf, len, offset, &offset, &n); | |
1839 | + bfd_sym_fetch_long (buf, len, offset, &offset, &width); | |
1840 | + bfd_sym_fetch_long (buf, len, offset, &offset, &m); | |
1816 | 1841 | /* fprintf (f, "\n "); */ |
1817 | 1842 | fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m); |
1818 | 1843 | for (i = 0; i < m; i++) |
1819 | 1844 | { |
1820 | - bfd_sym_fetch_long (buf, len, offset, &offset, &l); | |
1845 | + bfd_sym_fetch_long (buf, len, offset, &offset, &l); | |
1821 | 1846 | if (i != 0) |
1822 | 1847 | fprintf (f, " "); |
1823 | 1848 | fprintf (f, "%ld", l); |
@@ -1828,8 +1853,8 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) | ||
1828 | 1853 | /* Other packed type. */ |
1829 | 1854 | long msb, lsb; |
1830 | 1855 | |
1831 | - bfd_sym_fetch_long (buf, len, offset, &offset, &msb); | |
1832 | - bfd_sym_fetch_long (buf, len, offset, &offset, &lsb); | |
1856 | + bfd_sym_fetch_long (buf, len, offset, &offset, &msb); | |
1857 | + bfd_sym_fetch_long (buf, len, offset, &offset, &lsb); | |
1833 | 1858 | /* fprintf (f, "\n "); */ |
1834 | 1859 | fprintf (f, " msb %ld, lsb %ld", msb, lsb); |
1835 | 1860 | } |
@@ -1856,7 +1881,7 @@ bfd_sym_print_type_information_table_entry (abfd, f, entry) | ||
1856 | 1881 | entry->nte_index, |
1857 | 1882 | entry->physical_size, entry->offset, entry->logical_size); |
1858 | 1883 | |
1859 | - fprintf (f, "\n "); | |
1884 | + fprintf (f, "\n "); | |
1860 | 1885 | |
1861 | 1886 | buf = alloca (entry->physical_size); |
1862 | 1887 | if (buf == NULL) |
@@ -1885,7 +1910,7 @@ bfd_sym_print_type_information_table_entry (abfd, f, entry) | ||
1885 | 1910 | } |
1886 | 1911 | |
1887 | 1912 | fprintf (f, "]"); |
1888 | - fprintf (f, "\n "); | |
1913 | + fprintf (f, "\n "); | |
1889 | 1914 | |
1890 | 1915 | bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset); |
1891 | 1916 |
@@ -1923,16 +1948,16 @@ bfd_sym_display_name_table_entry (abfd, f, entry) | ||
1923 | 1948 | BFD_ASSERT (bfd_sym_valid (abfd)); |
1924 | 1949 | sdata = abfd->tdata.sym_data; |
1925 | 1950 | index = (entry - sdata->name_table) / 2; |
1926 | - | |
1927 | - if ((sdata->version >= BFD_SYM_VERSION_3_4) && (entry[0] == 255) && (entry[1] == 0)) | |
1951 | + | |
1952 | + if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0) | |
1928 | 1953 | { |
1929 | - unsigned short length = bfd_getb16 (entry + 2); | |
1954 | + unsigned short length = bfd_getb16 (entry + 2); | |
1930 | 1955 | fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4); |
1931 | 1956 | offset = 2 + length + 1; |
1932 | 1957 | } |
1933 | 1958 | else |
1934 | 1959 | { |
1935 | - if (! ((entry[0] == 0) || ((entry[0] == 1) && (entry[1] == '\0')))) | |
1960 | + if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0'))) | |
1936 | 1961 | fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1); |
1937 | 1962 | |
1938 | 1963 | if (sdata->version >= BFD_SYM_VERSION_3_4) |
@@ -1959,9 +1984,9 @@ bfd_sym_display_name_table (abfd, f) | ||
1959 | 1984 | name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size; |
1960 | 1985 | name_table = sdata->name_table; |
1961 | 1986 | name_table_end = name_table + name_table_len; |
1962 | - | |
1987 | + | |
1963 | 1988 | fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len); |
1964 | - | |
1989 | + | |
1965 | 1990 | cur = name_table; |
1966 | 1991 | for (;;) |
1967 | 1992 | { |
@@ -1985,7 +2010,7 @@ bfd_sym_display_resources_table (abfd, f) | ||
1985 | 2010 | |
1986 | 2011 | fprintf (f, "resource table (RTE) contains %lu objects:\n\n", |
1987 | 2012 | sdata->header.dshb_rte.dti_object_count); |
1988 | - | |
2013 | + | |
1989 | 2014 | for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++) |
1990 | 2015 | { |
1991 | 2016 | if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0) |
@@ -2061,7 +2086,7 @@ bfd_sym_display_contained_modules_table (abfd, f) | ||
2061 | 2086 | FILE *f; |
2062 | 2087 | { |
2063 | 2088 | unsigned long i; |
2064 | - bfd_sym_contained_modules_table_entry entry; | |
2089 | + bfd_sym_contained_modules_table_entry entry; | |
2065 | 2090 | bfd_sym_data_struct *sdata = NULL; |
2066 | 2091 | |
2067 | 2092 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2069,7 +2094,7 @@ bfd_sym_display_contained_modules_table (abfd, f) | ||
2069 | 2094 | |
2070 | 2095 | fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n", |
2071 | 2096 | sdata->header.dshb_cmte.dti_object_count); |
2072 | - | |
2097 | + | |
2073 | 2098 | for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++) |
2074 | 2099 | { |
2075 | 2100 | if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0) |
@@ -2097,7 +2122,7 @@ bfd_sym_display_contained_variables_table (abfd, f) | ||
2097 | 2122 | |
2098 | 2123 | fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n", |
2099 | 2124 | sdata->header.dshb_cvte.dti_object_count); |
2100 | - | |
2125 | + | |
2101 | 2126 | for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++) |
2102 | 2127 | { |
2103 | 2128 | if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0) |
@@ -2119,7 +2144,7 @@ bfd_sym_display_contained_statements_table (abfd, f) | ||
2119 | 2144 | FILE *f; |
2120 | 2145 | { |
2121 | 2146 | unsigned long i; |
2122 | - bfd_sym_contained_statements_table_entry entry; | |
2147 | + bfd_sym_contained_statements_table_entry entry; | |
2123 | 2148 | bfd_sym_data_struct *sdata = NULL; |
2124 | 2149 | |
2125 | 2150 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2127,7 +2152,7 @@ bfd_sym_display_contained_statements_table (abfd, f) | ||
2127 | 2152 | |
2128 | 2153 | fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n", |
2129 | 2154 | sdata->header.dshb_csnte.dti_object_count); |
2130 | - | |
2155 | + | |
2131 | 2156 | for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++) |
2132 | 2157 | { |
2133 | 2158 | if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0) |
@@ -2155,7 +2180,7 @@ bfd_sym_display_contained_labels_table (abfd, f) | ||
2155 | 2180 | |
2156 | 2181 | fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n", |
2157 | 2182 | sdata->header.dshb_clte.dti_object_count); |
2158 | - | |
2183 | + | |
2159 | 2184 | for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++) |
2160 | 2185 | { |
2161 | 2186 | if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0) |
@@ -2175,7 +2200,7 @@ bfd_sym_display_contained_types_table (abfd, f) | ||
2175 | 2200 | FILE *f; |
2176 | 2201 | { |
2177 | 2202 | unsigned long i; |
2178 | - bfd_sym_contained_types_table_entry entry; | |
2203 | + bfd_sym_contained_types_table_entry entry; | |
2179 | 2204 | bfd_sym_data_struct *sdata = NULL; |
2180 | 2205 | |
2181 | 2206 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2183,7 +2208,7 @@ bfd_sym_display_contained_types_table (abfd, f) | ||
2183 | 2208 | |
2184 | 2209 | fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n", |
2185 | 2210 | sdata->header.dshb_ctte.dti_object_count); |
2186 | - | |
2211 | + | |
2187 | 2212 | for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++) |
2188 | 2213 | { |
2189 | 2214 | if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0) |
@@ -2203,7 +2228,7 @@ bfd_sym_display_file_references_index_table (abfd, f) | ||
2203 | 2228 | FILE *f; |
2204 | 2229 | { |
2205 | 2230 | unsigned long i; |
2206 | - bfd_sym_file_references_index_table_entry entry; | |
2231 | + bfd_sym_file_references_index_table_entry entry; | |
2207 | 2232 | bfd_sym_data_struct *sdata = NULL; |
2208 | 2233 | |
2209 | 2234 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2211,7 +2236,7 @@ bfd_sym_display_file_references_index_table (abfd, f) | ||
2211 | 2236 | |
2212 | 2237 | fprintf (f, "file references index table (FITE) contains %lu objects:\n\n", |
2213 | 2238 | sdata->header.dshb_fite.dti_object_count); |
2214 | - | |
2239 | + | |
2215 | 2240 | for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++) |
2216 | 2241 | { |
2217 | 2242 | if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0) |
@@ -2231,7 +2256,7 @@ bfd_sym_display_constant_pool (abfd, f) | ||
2231 | 2256 | FILE *f; |
2232 | 2257 | { |
2233 | 2258 | unsigned long i; |
2234 | - bfd_sym_constant_pool_entry entry; | |
2259 | + bfd_sym_constant_pool_entry entry; | |
2235 | 2260 | bfd_sym_data_struct *sdata = NULL; |
2236 | 2261 | |
2237 | 2262 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2239,7 +2264,7 @@ bfd_sym_display_constant_pool (abfd, f) | ||
2239 | 2264 | |
2240 | 2265 | fprintf (f, "constant pool (CONST) contains %lu objects:\n\n", |
2241 | 2266 | sdata->header.dshb_const.dti_object_count); |
2242 | - | |
2267 | + | |
2243 | 2268 | for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++) |
2244 | 2269 | { |
2245 | 2270 | if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0) |
@@ -2260,7 +2285,7 @@ bfd_sym_display_type_information_table (abfd, f) | ||
2260 | 2285 | { |
2261 | 2286 | unsigned long i; |
2262 | 2287 | bfd_sym_type_table_entry index; |
2263 | - bfd_sym_type_information_table_entry entry; | |
2288 | + bfd_sym_type_information_table_entry entry; | |
2264 | 2289 | bfd_sym_data_struct *sdata = NULL; |
2265 | 2290 | |
2266 | 2291 | BFD_ASSERT (bfd_sym_valid (abfd)); |
@@ -2274,7 +2299,7 @@ bfd_sym_display_type_information_table (abfd, f) | ||
2274 | 2299 | fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n"); |
2275 | 2300 | return; |
2276 | 2301 | } |
2277 | - | |
2302 | + | |
2278 | 2303 | for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++) |
2279 | 2304 | { |
2280 | 2305 | if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0) |
@@ -2293,65 +2318,75 @@ bfd_sym_display_type_information_table (abfd, f) | ||
2293 | 2318 | } |
2294 | 2319 | } |
2295 | 2320 | |
2296 | -const bfd_target * | |
2297 | -bfd_sym_object_p (abfd) | |
2321 | +int | |
2322 | +bfd_sym_scan (abfd, version, mdata) | |
2298 | 2323 | bfd *abfd; |
2324 | + bfd_sym_version version; | |
2325 | + bfd_sym_data_struct *mdata; | |
2299 | 2326 | { |
2300 | - bfd_sym_data_struct *mdata = NULL; | |
2301 | 2327 | asection *bfdsec; |
2302 | 2328 | const char *name = "symbols"; |
2303 | - | |
2304 | - mdata = ((bfd_sym_data_struct *) | |
2305 | - bfd_alloc (abfd, sizeof (bfd_sym_data_struct))); | |
2306 | - if (mdata == NULL) | |
2307 | - return NULL; | |
2308 | - | |
2309 | - abfd->tdata.sym_data = mdata; | |
2310 | 2329 | |
2311 | 2330 | mdata->name_table = 0; |
2312 | 2331 | mdata->sbfd = abfd; |
2332 | + mdata->version = version; | |
2313 | 2333 | |
2314 | 2334 | bfd_seek (abfd, 0, SEEK_SET); |
2315 | - if (bfd_sym_read_version (abfd, &mdata->version) != 0) | |
2316 | - { | |
2317 | - abfd->tdata.sym_data = NULL; | |
2318 | - bfd_set_error (bfd_error_wrong_format); | |
2319 | - return NULL; | |
2320 | - } | |
2321 | - | |
2322 | - bfd_seek (abfd, 0, SEEK_SET); | |
2323 | 2335 | if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0) |
2324 | - { | |
2325 | - abfd->tdata.sym_data = NULL; | |
2326 | - bfd_set_error (bfd_error_wrong_format); | |
2327 | - return NULL; | |
2328 | - } | |
2336 | + return -1; | |
2329 | 2337 | |
2330 | 2338 | mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header); |
2331 | 2339 | if (mdata->name_table == NULL) |
2332 | - { | |
2333 | - abfd->tdata.sym_data = NULL; | |
2334 | - bfd_set_error (bfd_error_wrong_format); | |
2335 | - return NULL; | |
2336 | - } | |
2340 | + return -1; | |
2337 | 2341 | |
2338 | 2342 | bfdsec = bfd_make_section_anyway (abfd, name); |
2339 | 2343 | if (bfdsec == NULL) |
2340 | - { | |
2341 | - abfd->tdata.sym_data = NULL; | |
2342 | - bfd_set_error (bfd_error_wrong_format); | |
2343 | - return NULL; | |
2344 | - } | |
2345 | - | |
2344 | + return -1; | |
2345 | + | |
2346 | 2346 | bfdsec->vma = 0; |
2347 | 2347 | bfdsec->lma = 0; |
2348 | 2348 | bfdsec->_raw_size = 0; |
2349 | 2349 | bfdsec->filepos = 0; |
2350 | 2350 | bfdsec->alignment_power = 0; |
2351 | - | |
2351 | + | |
2352 | 2352 | bfdsec->flags = SEC_HAS_CONTENTS; |
2353 | 2353 | |
2354 | + abfd->tdata.sym_data = mdata; | |
2355 | + | |
2356 | + return 0; | |
2357 | +} | |
2358 | + | |
2359 | +const bfd_target * | |
2360 | +bfd_sym_object_p (abfd) | |
2361 | + bfd *abfd; | |
2362 | +{ | |
2363 | + struct bfd_preserve preserve; | |
2364 | + bfd_sym_version version = -1; | |
2365 | + | |
2366 | + preserve.marker = NULL; | |
2367 | + bfd_seek (abfd, 0, SEEK_SET); | |
2368 | + if (bfd_sym_read_version (abfd, &version) != 0) | |
2369 | + goto wrong; | |
2370 | + | |
2371 | + preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct)); | |
2372 | + if (preserve.marker == NULL | |
2373 | + || ! bfd_preserve_save (abfd, &preserve)) | |
2374 | + goto fail; | |
2375 | + | |
2376 | + if (bfd_sym_scan (abfd, version, | |
2377 | + (bfd_sym_data_struct *) preserve.marker) != 0) | |
2378 | + goto wrong; | |
2379 | + | |
2380 | + bfd_preserve_finish (abfd, &preserve); | |
2354 | 2381 | return abfd->xvec; |
2382 | + | |
2383 | + wrong: | |
2384 | + bfd_set_error (bfd_error_wrong_format); | |
2385 | + | |
2386 | + fail: | |
2387 | + if (preserve.marker != NULL) | |
2388 | + bfd_preserve_restore (abfd, &preserve); | |
2389 | + return NULL; | |
2355 | 2390 | } |
2356 | 2391 | |
2357 | 2392 | asymbol * |
@@ -2443,7 +2478,7 @@ const bfd_target sym_vec = | ||
2443 | 2478 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
2444 | 2479 | |
2445 | 2480 | NULL, |
2446 | - | |
2481 | + | |
2447 | 2482 | NULL |
2448 | 2483 | }; |
2449 | 2484 |
@@ -15,7 +15,7 @@ | ||
15 | 15 | GNU General Public License for more details. |
16 | 16 | |
17 | 17 | You should have received a copy of the GNU General Public License |
18 | - along with this program; if not, write to the Free Software | |
18 | + along with this program; if not, write to the Free Software | |
19 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
20 | 20 | |
21 | 21 | #include "bfd.h" |
@@ -103,7 +103,7 @@ typedef struct bfd_sym_file_reference bfd_sym_file_reference; | ||
103 | 103 | /* NAME TABLE (NTE). */ |
104 | 104 | |
105 | 105 | /* RESOURCES TABLE (RTE) |
106 | - | |
106 | + | |
107 | 107 | All code and data is *defined* to reside in a resource. Even A5 |
108 | 108 | relative data is defined to reside in a dummy resource of ResType |
109 | 109 | 'gbld'. Code always resides in a resource. Because a code/data |
@@ -128,7 +128,7 @@ struct bfd_sym_resources_table_entry | ||
128 | 128 | typedef struct bfd_sym_resources_table_entry bfd_sym_resources_table_entry; |
129 | 129 | |
130 | 130 | /* MODULES TABLE (MTE) |
131 | - | |
131 | + | |
132 | 132 | Modules table entries are ordered by their appearance in a resource. |
133 | 133 | (Note that having a single module copied into two resources is not |
134 | 134 | possible). Modules map back to their resource via an index into the |
@@ -159,19 +159,19 @@ struct bfd_sym_modules_table_entry | ||
159 | 159 | unsigned long mte_ctte_index; /* Types contained in this. */ |
160 | 160 | unsigned long mte_csnte_idx_1; /* CSNTE index of mte_snbr_first. */ |
161 | 161 | unsigned long mte_csnte_idx_2; /* CSNTE index of mte_snbr_last. */ |
162 | -}; | |
162 | +}; | |
163 | 163 | typedef struct bfd_sym_modules_table_entry bfd_sym_modules_table_entry; |
164 | 164 | |
165 | 165 | /* FILE REFERENCES TABLE (FRTE) |
166 | - | |
166 | + | |
167 | 167 | The FILE REFERENCES TABLE maps from source file to module & offset. |
168 | 168 | The table is ordered by increasing file offset. Each new offset |
169 | 169 | references a module. |
170 | - | |
170 | + | |
171 | 171 | FRT = FILE_SOURCE_START |
172 | 172 | FILE_SOURCE_INCREMENT* |
173 | 173 | END_OF_LIST. |
174 | - | |
174 | + | |
175 | 175 | *** THIS MECHANISM IS VERY SLOW FOR FILE+STATEMENT_NUMBER TO |
176 | 176 | *** MODULE/CODE ADDRESS OPERATIONS. ANOTHER MECHANISM IS |
177 | 177 | *** REQUIRED!! */ |
@@ -193,7 +193,7 @@ union bfd_sym_file_references_table_entry | ||
193 | 193 | unsigned long mod_date; |
194 | 194 | } |
195 | 195 | filename; |
196 | - | |
196 | + | |
197 | 197 | struct |
198 | 198 | { |
199 | 199 | /* < FILE_NAME_INDEX. */ |
@@ -209,7 +209,7 @@ typedef union bfd_sym_file_references_table_entry bfd_sym_file_references_table_ | ||
209 | 209 | Contained Modules are lists of indices into the modules table. The |
210 | 210 | lists are terminated by an END_OF_LIST index. All entries are of the |
211 | 211 | same size, hence mapping an index into a CMTE list is simple. |
212 | - | |
212 | + | |
213 | 213 | CMT = MTE_INDEX* END_OF_LIST. */ |
214 | 214 | |
215 | 215 | union bfd_sym_contained_modules_table_entry |
@@ -220,7 +220,7 @@ union bfd_sym_contained_modules_table_entry | ||
220 | 220 | unsigned long type; |
221 | 221 | } |
222 | 222 | generic; |
223 | - | |
223 | + | |
224 | 224 | struct |
225 | 225 | { |
226 | 226 | unsigned long mte_index; /* Index into the Modules Table. */ |
@@ -231,7 +231,7 @@ union bfd_sym_contained_modules_table_entry | ||
231 | 231 | typedef union bfd_sym_contained_modules_table_entry bfd_sym_contained_modules_table_entry; |
232 | 232 | |
233 | 233 | /* CONTAINED VARIABLES TABLE (CVTE) |
234 | - | |
234 | + | |
235 | 235 | Contained Variables map into the module table, file table, name table, and type |
236 | 236 | table. Contained Variables are a contiguous list of source file change record, |
237 | 237 | giving the name of and offset into the source file corresponding to all variables |
@@ -240,25 +240,25 @@ typedef union bfd_sym_contained_modules_table_entry bfd_sym_contained_modules_ta | ||
240 | 240 | table giving the type of the variable, an increment added to the source file |
241 | 241 | offset giving the start of the implementation of the variable, and a storage |
242 | 242 | class address, giving information on variable's runtime address. |
243 | - | |
243 | + | |
244 | 244 | CVT = SOURCE_FILE_CHANGE SYMBOL_INFO* END_OF_LIST. |
245 | 245 | SYMBOL_INFO = SYMBOL_DEFINITION | SOURCE_FILE_CHANGE . |
246 | - | |
246 | + | |
247 | 247 | All entries are of the same size, making the fetching of data simple. The |
248 | 248 | variable entries in the list are in ALPHABETICAL ORDER to simplify the display of |
249 | 249 | available variables for several of the debugger's windows. */ |
250 | 250 | |
251 | 251 | /* 'la_size' determines the variant used below: |
252 | - | |
252 | + | |
253 | 253 | == BFD_SYM_CVTE_SCA |
254 | 254 | Traditional STORAGE_CLASS_ADDRESS; |
255 | - | |
255 | + | |
256 | 256 | <= BFD_SYM_CVTE_LA_MAX_SIZE |
257 | 257 | That many logical address bytes ("in-situ"); |
258 | - | |
258 | + | |
259 | 259 | == BFD_SYM_CVTE_BIG_LA |
260 | 260 | Logical address bytes in constant pool, at offset 'big_la'. */ |
261 | - | |
261 | + | |
262 | 262 | #define BFD_SYM_CVTE_SCA 0 /* Indicate SCA variant of CVTE. */ |
263 | 263 | #define BFD_SYM_CVTE_LA_MAX_SIZE 13 /* Max# of logical address bytes in a CVTE. */ |
264 | 264 | #define BFD_SYM_CVTE_BIG_LA 127 /* Indicates LA redirection to constant pool. */ |
@@ -322,7 +322,7 @@ union bfd_sym_contained_variables_table_entry | ||
322 | 322 | typedef union bfd_sym_contained_variables_table_entry bfd_sym_contained_variables_table_entry; |
323 | 323 | |
324 | 324 | /* CONTAINED STATEMENTS TABLE (CSNTE) |
325 | - | |
325 | + | |
326 | 326 | Contained Statements table. This table is similar to the Contained |
327 | 327 | Variables table except that instead of VARIABLE_DEFINITION entries, this |
328 | 328 | module contains STATEMENT_NUMBER_DEFINITION entries. A statement number |
@@ -332,7 +332,7 @@ typedef union bfd_sym_contained_variables_table_entry bfd_sym_contained_variable | ||
332 | 332 | All entries are of the same size, making the fetching of data simple. The |
333 | 333 | entries in the table are in order of increasing statement number within the |
334 | 334 | source file. |
335 | - | |
335 | + | |
336 | 336 | The Contained Statements table is indexed from two places. An MTE contains |
337 | 337 | an index to the first statement number within the module. An FRTE contains |
338 | 338 | an index to the first statement in the table (Possibly. This is slow.) Or |
@@ -367,7 +367,7 @@ union bfd_sym_contained_statements_table_entry | ||
367 | 367 | typedef union bfd_sym_contained_statements_table_entry bfd_sym_contained_statements_table_entry; |
368 | 368 | |
369 | 369 | /* CONTAINED LABELS TABLE (CLTE) |
370 | - | |
370 | + | |
371 | 371 | Contained Labels table names those labels local to the module. It is similar |
372 | 372 | to the Contained Statements table. */ |
373 | 373 |
@@ -402,7 +402,7 @@ union bfd_sym_contained_labels_table_entry | ||
402 | 402 | typedef union bfd_sym_contained_labels_table_entry bfd_sym_contained_labels_table_entry; |
403 | 403 | |
404 | 404 | /* CONTAINED TYPES TABLE (CTTE) |
405 | - | |
405 | + | |
406 | 406 | Contained Types define the named types that are in the module. It is used to |
407 | 407 | map name indices into type indices. The type entries in the table are in |
408 | 408 | alphabetical order by type name. */ |
@@ -427,7 +427,7 @@ union bfd_sym_contained_types_table_entry | ||
427 | 427 | struct |
428 | 428 | { |
429 | 429 | /* < SOURCE_FILE_CHANGE. */ |
430 | - unsigned long tte_index; | |
430 | + unsigned long tte_index; | |
431 | 431 | unsigned long nte_index; |
432 | 432 | unsigned long file_delta; /* From last file definition. */ |
433 | 433 | } |
@@ -451,7 +451,7 @@ struct bfd_sym_type_information_table_entry | ||
451 | 451 | typedef struct bfd_sym_type_information_table_entry bfd_sym_type_information_table_entry; |
452 | 452 | |
453 | 453 | /* FILE REFERENCES INDEX TABLE (FITE) |
454 | - | |
454 | + | |
455 | 455 | The FRTE INDEX TABLE indexes into the FILE REFERENCE TABLE above. The FRTE |
456 | 456 | at that index is the FILE_SOURCE_START for a series of files. The FRTEs are |
457 | 457 | indexed from 1. The list is terminated with an END_OF_LIST. */ |
@@ -463,7 +463,7 @@ union bfd_sym_file_references_index_table_entry | ||
463 | 463 | unsigned long type; |
464 | 464 | } |
465 | 465 | generic; |
466 | - | |
466 | + | |
467 | 467 | struct |
468 | 468 | { |
469 | 469 | unsigned long frte_index; /* Index into the FRTE table. */ |
@@ -474,15 +474,15 @@ union bfd_sym_file_references_index_table_entry | ||
474 | 474 | typedef union bfd_sym_file_references_index_table_entry bfd_sym_file_references_index_table_entry; |
475 | 475 | |
476 | 476 | /* CONSTANT POOL (CONST) |
477 | - | |
477 | + | |
478 | 478 | The CONSTANT_POOL consists of entries that start on word boundaries. The entries |
479 | 479 | are referenced by byte index into the constant pool, not by record number. |
480 | - | |
480 | + | |
481 | 481 | Each entry takes the form: |
482 | - | |
482 | + | |
483 | 483 | <16-bit size> |
484 | 484 | <that many bytes of stuff> |
485 | - | |
485 | + | |
486 | 486 | Entries do not cross page boundaries. */ |
487 | 487 | |
488 | 488 | typedef short bfd_sym_constant_pool_entry; |
@@ -493,7 +493,7 @@ typedef short bfd_sym_constant_pool_entry; | ||
493 | 493 | allocations. For the purposes of paging, the * file is considered |
494 | 494 | to be an array of dshb_page_size blocks, with block 0 (and * |
495 | 495 | possibly more) devoted to the DISK_SYMBOL_HEADER_BLOCK. |
496 | - | |
496 | + | |
497 | 497 | The dti_object_count field means that the allowed indices for that |
498 | 498 | type of object are 0 .. dti_object_count. An index of 0, although |
499 | 499 | allowed, is never done. However, an 0th entry is created in the |
@@ -510,7 +510,7 @@ struct bfd_sym_table_info | ||
510 | 510 | }; |
511 | 511 | typedef struct bfd_sym_table_info bfd_sym_table_info; |
512 | 512 | |
513 | -struct bfd_sym_header_block | |
513 | +struct bfd_sym_header_block | |
514 | 514 | { |
515 | 515 | unsigned char dshb_id[32]; /* Version information. */ |
516 | 516 | unsigned short dshb_page_size; /* Size of the pages/blocks. */ |
@@ -683,6 +683,8 @@ extern void bfd_sym_display_constant_pool | ||
683 | 683 | PARAMS ((bfd *, FILE *)); |
684 | 684 | extern void bfd_sym_display_type_information_table |
685 | 685 | PARAMS ((bfd *, FILE *)); |
686 | +extern int bfd_sym_scan | |
687 | + PARAMS ((bfd *, bfd_sym_version, bfd_sym_data_struct *)); | |
686 | 688 | extern const bfd_target * bfd_sym_object_p |
687 | 689 | PARAMS ((bfd *)); |
688 | 690 | extern asymbol * bfd_sym_make_empty_symbol |