diff options
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 27 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 21 | ||||
-rw-r--r-- | bfd/bfd.c | 130 | ||||
-rw-r--r-- | bfd/elfcode.h | 59 | ||||
-rw-r--r-- | bfd/mach-o.c | 196 | ||||
-rw-r--r-- | bfd/mach-o.h | 32 | ||||
-rw-r--r-- | bfd/pef.c | 863 | ||||
-rw-r--r-- | bfd/pef.h | 6 | ||||
-rw-r--r-- | bfd/targets.c | 6 | ||||
-rw-r--r-- | bfd/xsym.c | 359 | ||||
-rw-r--r-- | bfd/xsym.h | 62 |
11 files changed, 1038 insertions, 723 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2ce4cfc..95e638f 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,30 @@ +2002-11-13 Klee Dienes <kdienes@apple.com> + Alan Modra <amodra@bigpond.net.au> + + * 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. + 2002-11-12 Nick Clifton <nickc@redhat.com> * po/da.po: Updated Danish translation. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index b58e7f5..8f4a48b 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -3739,6 +3739,27 @@ extern bfd_byte *bfd_get_relocated_section_contents boolean bfd_alt_mach_code PARAMS ((bfd *abfd, int alternative)); +struct bfd_preserve +{ + PTR marker; + PTR tdata; + flagword flags; + const struct bfd_arch_info *arch_info; + struct sec *sections; + struct sec **section_tail; + unsigned int section_count; + struct bfd_hash_table section_htab; +}; + +boolean +bfd_preserve_save PARAMS ((bfd *, struct bfd_preserve *)); + +void +bfd_preserve_restore PARAMS ((bfd *, struct bfd_preserve *)); + +void +bfd_preserve_finish PARAMS ((bfd *, struct bfd_preserve *)); + /* Extracted from archive.c. */ symindex bfd_get_next_mapent PARAMS ((bfd *abfd, symindex previous, carsym **sym)); @@ -1392,3 +1392,133 @@ bfd_alt_mach_code (abfd, alternative) return false; } + +/* +CODE_FRAGMENT + +.struct bfd_preserve +.{ +. PTR marker; +. PTR tdata; +. flagword flags; +. const struct bfd_arch_info *arch_info; +. struct sec *sections; +. struct sec **section_tail; +. unsigned int section_count; +. struct bfd_hash_table section_htab; +.}; +. +*/ + +/* +FUNCTION + bfd_preserve_save + +SYNOPSIS + boolean bfd_preserve_save (bfd *, struct bfd_preserve *); + +DESCRIPTION + When testing an object for compatibility with a particular + target back-end, the back-end object_p function needs to set + up certain fields in the bfd on successfully recognizing the + object. This typically happens in a piecemeal fashion, with + failures possible at many points. On failure, the bfd is + supposed to be restored to its initial state, which is + virtually impossible. However, restoring a subset of the bfd + state works in practice. This function stores the subset and + reinitializes the bfd. + +*/ + +boolean +bfd_preserve_save (abfd, preserve) + bfd *abfd; + struct bfd_preserve *preserve; +{ + preserve->tdata = abfd->tdata.any; + preserve->arch_info = abfd->arch_info; + preserve->flags = abfd->flags; + + preserve->sections = abfd->sections; + preserve->section_tail = abfd->section_tail; + preserve->section_count = abfd->section_count; + preserve->section_htab = abfd->section_htab; + + if (! bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc)) + return false; + + abfd->tdata.any = NULL; + abfd->arch_info = &bfd_default_arch_struct; + abfd->flags = 0; + + abfd->sections = NULL; + abfd->section_tail = &abfd->sections; + abfd->section_count = 0; + + return true; +} + +/* +FUNCTION + bfd_preserve_restore + +SYNOPSIS + void bfd_preserve_restore (bfd *, struct bfd_preserve *); + +DESCRIPTION + This function restores bfd state saved by bfd_preserve_save. + If MARKER is non-NULL in struct bfd_preserve then that block + and all subsequently bfd_alloc'd memory is freed. + +*/ + +void +bfd_preserve_restore (abfd, preserve) + bfd *abfd; + struct bfd_preserve *preserve; +{ + bfd_hash_table_free (&abfd->section_htab); + + abfd->tdata.any = preserve->tdata; + abfd->arch_info = preserve->arch_info; + abfd->flags = preserve->flags; + + abfd->section_htab = preserve->section_htab; + abfd->sections = preserve->sections; + abfd->section_tail = preserve->section_tail; + abfd->section_count = preserve->section_count; + + /* bfd_release frees all memory more recently bfd_alloc'd than + its arg, as well as its arg. */ + if (preserve->marker != NULL) + { + bfd_release (abfd, preserve->marker); + preserve->marker = NULL; + } +} + +/* +FUNCTION + bfd_preserve_finish + +SYNOPSIS + void bfd_preserve_finish (bfd *, struct bfd_preserve *); + +DESCRIPTION + This function should be called when the bfd state saved by + bfd_preserve_save is no longer needed. ie. when the back-end + object_p function returns with success. + +*/ + +void +bfd_preserve_finish (abfd, preserve) + bfd *abfd ATTRIBUTE_UNUSED; + struct bfd_preserve *preserve; +{ + /* It would be nice to be able to free more memory here, eg. old + tdata, but that's not possible since these blocks are sitting + inside bfd_alloc'd memory. The section hash is on a separate + objalloc. */ + bfd_hash_table_free (&preserve->section_htab); +} diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 4f54cd3..35c99f0 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -505,16 +505,6 @@ elf_file_p (x_ehdrp) && (x_ehdrp->e_ident[EI_MAG3] == ELFMAG3)); } -struct bfd_preserve -{ - const struct bfd_arch_info *arch_info; - struct elf_obj_tdata *tdata; - struct bfd_hash_table section_htab; - struct sec *sections; - struct sec **section_tail; - unsigned int section_count; -}; - /* Check to see if the file associated with ABFD matches the target vector that ABFD points to. @@ -536,11 +526,10 @@ elf_object_p (abfd) char *shstrtab; /* Internal copy of section header stringtab */ struct elf_backend_data *ebd; struct bfd_preserve preserve; - struct elf_obj_tdata *new_tdata = NULL; asection *s; bfd_size_type amt; - preserve.arch_info = abfd->arch_info; + preserve.marker = NULL; /* Read in the ELF header in external format. */ @@ -584,24 +573,14 @@ elf_object_p (abfd) the tdata pointer in the bfd. */ amt = sizeof (struct elf_obj_tdata); - new_tdata = (struct elf_obj_tdata *) bfd_zalloc (abfd, amt); - if (new_tdata == NULL) + preserve.marker = bfd_zalloc (abfd, amt); + if (preserve.marker == NULL) goto got_no_match; - preserve.tdata = elf_tdata (abfd); - elf_tdata (abfd) = new_tdata; - - /* Clear section information, since there might be a recognized bfd that - we now check if we can replace, and we don't want to append to it. */ - preserve.sections = abfd->sections; - preserve.section_tail = abfd->section_tail; - preserve.section_count = abfd->section_count; - preserve.section_htab = abfd->section_htab; - abfd->sections = NULL; - abfd->section_tail = &abfd->sections; - abfd->section_count = 0; - if (!bfd_hash_table_init (&abfd->section_htab, bfd_section_hash_newfunc)) + if (!bfd_preserve_save (abfd, &preserve)) goto got_no_match; + elf_tdata (abfd) = preserve.marker; + /* Now that we know the byte order, swap in the rest of the header */ i_ehdrp = elf_elfheader (abfd); elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp); @@ -633,8 +612,10 @@ elf_object_p (abfd) /* Check that the ELF e_machine field matches what this particular BFD format expects. */ if (ebd->elf_machine_code != i_ehdrp->e_machine - && (ebd->elf_machine_alt1 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt1) - && (ebd->elf_machine_alt2 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt2)) + && (ebd->elf_machine_alt1 == 0 + || i_ehdrp->e_machine != ebd->elf_machine_alt1) + && (ebd->elf_machine_alt2 == 0 + || i_ehdrp->e_machine != ebd->elf_machine_alt2)) { const bfd_target * const *target_ptr; @@ -844,11 +825,8 @@ elf_object_p (abfd) } } - /* It would be nice to be able to free more memory here, eg. old - elf_elfsections, old tdata, but that's not possible since these - blocks are sitting inside obj_alloc'd memory. */ - bfd_hash_table_free (&preserve.section_htab); - return (abfd->xvec); + bfd_preserve_finish (abfd, &preserve); + return abfd->xvec; got_wrong_format_error: /* There is way too much undoing of half-known state here. The caller, @@ -864,17 +842,8 @@ elf_object_p (abfd) got_no_match: abfd->arch_info = preserve.arch_info; - if (new_tdata != NULL) - { - /* bfd_release frees all memory more recently bfd_alloc'd than - its arg, as well as its arg. */ - bfd_release (abfd, new_tdata); - elf_tdata (abfd) = preserve.tdata; - abfd->section_htab = preserve.section_htab; - abfd->sections = preserve.sections; - abfd->section_tail = preserve.section_tail; - abfd->section_count = preserve.section_count; - } + if (preserve.marker != NULL) + bfd_preserve_restore (abfd, &preserve); return NULL; } diff --git a/bfd/mach-o.c b/bfd/mach-o.c index 4c3551e..1daaf98 100644 --- a/bfd/mach-o.c +++ b/bfd/mach-o.c @@ -691,7 +691,7 @@ bfd_mach_o_scan_read_symtab_symbol (abfd, sym, s, i) unsigned char type = -1; unsigned char section = -1; short desc = -1; - long value = -1; + unsigned long value = -1; unsigned long stroff = -1; unsigned int symtype = -1; @@ -1374,7 +1374,8 @@ bfd_mach_o_scan_read_segment (abfd, command) { bfd_vma segoff = command->offset + 48 + 8 + (i * 68); - if (bfd_mach_o_scan_read_section (abfd, &seg->sections[i], segoff) != 0) + if (bfd_mach_o_scan_read_section (abfd, &seg->sections[i], + segoff) != 0) return -1; } } @@ -1455,7 +1456,8 @@ bfd_mach_o_scan_read_command (abfd, command) return -1; command->type = (bfd_h_get_32 (abfd, buf) & ~BFD_MACH_O_LC_REQ_DYLD); - command->type_required = (bfd_h_get_32 (abfd, buf) & BFD_MACH_O_LC_REQ_DYLD) ? 1 : 0; + command->type_required = (bfd_h_get_32 (abfd, buf) & BFD_MACH_O_LC_REQ_DYLD + ? 1 : 0); command->len = bfd_h_get_32 (abfd, buf + 4); switch (command->type) @@ -1531,20 +1533,24 @@ bfd_mach_o_flatten_sections (abfd) { if (mdata->commands[i].type == BFD_MACH_O_LC_SEGMENT) { - bfd_mach_o_segment_command *seg = &mdata->commands[i].command.segment; + bfd_mach_o_segment_command *seg; + + seg = &mdata->commands[i].command.segment; mdata->nsects += seg->nsects; } } - mdata->sections = bfd_alloc (abfd, mdata->nsects * sizeof (bfd_mach_o_section *)); + mdata->sections = bfd_alloc (abfd, + mdata->nsects * sizeof (bfd_mach_o_section *)); csect = 0; for (i = 0; i < mdata->header.ncmds; i++) { if (mdata->commands[i].type == BFD_MACH_O_LC_SEGMENT) { - bfd_mach_o_segment_command *seg = &mdata->commands[i].command.segment; + bfd_mach_o_segment_command *seg; + seg = &mdata->commands[i].command.segment; BFD_ASSERT (csect + seg->nsects <= mdata->nsects); for (j = 0; j < seg->nsects; j++) @@ -1579,7 +1585,8 @@ bfd_mach_o_scan_start_address (abfd) for (i = 0; i < cmd->nflavours; i++) { if ((mdata->header.cputype == BFD_MACH_O_CPU_TYPE_I386) - && (cmd->flavours[i].flavour == (unsigned long) BFD_MACH_O_i386_THREAD_STATE)) + && (cmd->flavours[i].flavour + == (unsigned long) BFD_MACH_O_i386_THREAD_STATE)) { unsigned char buf[4]; @@ -1608,27 +1615,24 @@ bfd_mach_o_scan_start_address (abfd) } int -bfd_mach_o_scan (abfd, header) +bfd_mach_o_scan (abfd, header, mdata) bfd *abfd; bfd_mach_o_header *header; + bfd_mach_o_data_struct *mdata; { unsigned int i; - bfd_mach_o_data_struct *mdata = NULL; enum bfd_architecture cputype; unsigned long cpusubtype; - mdata = ((bfd_mach_o_data_struct *) - bfd_alloc (abfd, sizeof (bfd_mach_o_data_struct))); - if (mdata == NULL) - return -1; - mdata->header = *header; mdata->symbols = NULL; - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); + abfd->flags = (abfd->xvec->object_flags + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); abfd->tdata.mach_o_data = mdata; - bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype, &cputype, &cpusubtype); + bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype, + &cputype, &cpusubtype); if (cputype == bfd_arch_unknown) { fprintf (stderr, "bfd_mach_o_scan: unknown architecture 0x%lx/0x%lx\n", @@ -1712,84 +1716,99 @@ const bfd_target * bfd_mach_o_object_p (abfd) bfd *abfd; { + struct bfd_preserve preserve; bfd_mach_o_header header; + preserve.marker = NULL; if (bfd_mach_o_read_header (abfd, &header) != 0) - { - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + goto wrong; - if (! ((header.byteorder == BFD_ENDIAN_BIG) - || (header.byteorder == BFD_ENDIAN_LITTLE))) + if (! (header.byteorder == BFD_ENDIAN_BIG + || header.byteorder == BFD_ENDIAN_LITTLE)) { - fprintf (stderr, "unknown header byte-order value 0x%lx\n", (long) header.byteorder); - bfd_set_error (bfd_error_wrong_format); - return NULL; + fprintf (stderr, "unknown header byte-order value 0x%lx\n", + (long) header.byteorder); + goto wrong; } - if (! (((header.byteorder == BFD_ENDIAN_BIG) - && (abfd->xvec->byteorder == BFD_ENDIAN_BIG) - && (abfd->xvec->header_byteorder == BFD_ENDIAN_BIG)) - || - ((header.byteorder == BFD_ENDIAN_LITTLE) - && (abfd->xvec->byteorder == BFD_ENDIAN_LITTLE) - && (abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE)))) - { - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + if (! ((header.byteorder == BFD_ENDIAN_BIG + && abfd->xvec->byteorder == BFD_ENDIAN_BIG + && abfd->xvec->header_byteorder == BFD_ENDIAN_BIG) + || (header.byteorder == BFD_ENDIAN_LITTLE + && abfd->xvec->byteorder == BFD_ENDIAN_LITTLE + && abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE))) + goto wrong; - abfd->tdata.mach_o_data = NULL; + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct)); + if (preserve.marker == NULL + || !bfd_preserve_save (abfd, &preserve)) + goto fail; - if (bfd_mach_o_scan (abfd, &header) != 0) - { - abfd->tdata.mach_o_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + if (bfd_mach_o_scan (abfd, &header, + (bfd_mach_o_data_struct *) preserve.marker) != 0) + goto wrong; + bfd_preserve_finish (abfd, &preserve); return abfd->xvec; + + wrong: + bfd_set_error (bfd_error_wrong_format); + + fail: + if (preserve.marker != NULL) + bfd_preserve_restore (abfd, &preserve); + return NULL; } const bfd_target * bfd_mach_o_core_p (abfd) bfd *abfd; { + struct bfd_preserve preserve; bfd_mach_o_header header; - bfd_set_error (bfd_error_wrong_format); - + preserve.marker = NULL; if (bfd_mach_o_read_header (abfd, &header) != 0) - return NULL; + goto wrong; - if (! ((header.byteorder == BFD_ENDIAN_BIG) - || (header.byteorder == BFD_ENDIAN_LITTLE))) + if (! (header.byteorder == BFD_ENDIAN_BIG + || header.byteorder == BFD_ENDIAN_LITTLE)) { - fprintf (stderr, "unknown header byte-order value 0x%lx\n", (long) header.byteorder); + fprintf (stderr, "unknown header byte-order value 0x%lx\n", + (long) header.byteorder); abort (); } - if (! (((header.byteorder == BFD_ENDIAN_BIG) - && (abfd->xvec->byteorder == BFD_ENDIAN_BIG) - && (abfd->xvec->header_byteorder == BFD_ENDIAN_BIG)) - || - ((header.byteorder == BFD_ENDIAN_LITTLE) - && (abfd->xvec->byteorder == BFD_ENDIAN_LITTLE) - && (abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE)))) - return NULL; + if (! ((header.byteorder == BFD_ENDIAN_BIG + && abfd->xvec->byteorder == BFD_ENDIAN_BIG + && abfd->xvec->header_byteorder == BFD_ENDIAN_BIG) + || (header.byteorder == BFD_ENDIAN_LITTLE + && abfd->xvec->byteorder == BFD_ENDIAN_LITTLE + && abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE))) + goto wrong; if (header.filetype != BFD_MACH_O_MH_CORE) - return NULL; + goto wrong; - abfd->tdata.mach_o_data = NULL; - if (bfd_mach_o_scan (abfd, &header) != 0) - { - abfd->tdata.mach_o_data = NULL; - return NULL; - } + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_mach_o_data_struct)); + if (preserve.marker == NULL + || !bfd_preserve_save (abfd, &preserve)) + goto fail; + if (bfd_mach_o_scan (abfd, &header, + (bfd_mach_o_data_struct *) preserve.marker) != 0) + goto wrong; + + bfd_preserve_finish (abfd, &preserve); return abfd->xvec; + + wrong: + bfd_set_error (bfd_error_wrong_format); + + fail: + if (preserve.marker != NULL) + bfd_preserve_restore (abfd, &preserve); + return NULL; } typedef struct mach_o_fat_archentry @@ -1813,35 +1832,35 @@ const bfd_target * bfd_mach_o_archive_p (abfd) bfd *abfd; { - mach_o_fat_data_struct *adata; + mach_o_fat_data_struct *adata = NULL; unsigned char buf[20]; unsigned long i; bfd_seek (abfd, 0, SEEK_SET); if (bfd_bread ((PTR) buf, 8, abfd) != 8) - return NULL; + goto error; adata = (mach_o_fat_data_struct *) bfd_alloc (abfd, sizeof (mach_o_fat_data_struct)); if (adata == NULL) - return NULL; + goto error; adata->magic = bfd_getb32 (buf); adata->nfat_arch = bfd_getb32 (buf + 4); if (adata->magic != 0xcafebabe) - return NULL; + goto error; adata->archentries = (mach_o_fat_archentry *) bfd_alloc (abfd, adata->nfat_arch * sizeof (mach_o_fat_archentry)); if (adata->archentries == NULL) - return NULL; + goto error; for (i = 0; i < adata->nfat_arch; i++) { bfd_seek (abfd, 8 + 20 * i, SEEK_SET); if (bfd_bread ((PTR) buf, 20, abfd) != 20) - return NULL; + goto error; adata->archentries[i].cputype = bfd_getb32 (buf); adata->archentries[i].cpusubtype = bfd_getb32 (buf + 4); adata->archentries[i].offset = bfd_getb32 (buf + 8); @@ -1852,6 +1871,12 @@ bfd_mach_o_archive_p (abfd) abfd->tdata.mach_o_fat_data = adata; return abfd->xvec; + + error: + if (adata != NULL) + bfd_release (abfd, adata); + bfd_set_error (bfd_error_wrong_format); + return NULL; } bfd * @@ -1859,10 +1884,11 @@ bfd_mach_o_openr_next_archived_file (archive, prev) bfd *archive; bfd *prev; { - mach_o_fat_data_struct *adata = (mach_o_fat_data_struct *) archive->tdata.mach_o_fat_data; + mach_o_fat_data_struct *adata; mach_o_fat_archentry *entry = NULL; unsigned long i; + adata = (mach_o_fat_data_struct *) archive->tdata.mach_o_fat_data; BFD_ASSERT (adata != NULL); /* Find index of previous entry. */ @@ -1913,9 +1939,12 @@ bfd_mach_o_openr_next_archived_file (archive, prev) return entry->abfd; } -int bfd_mach_o_lookup_section - (bfd *abfd, asection *section, - bfd_mach_o_load_command **mcommand, bfd_mach_o_section **msection) +int +bfd_mach_o_lookup_section (abfd, section, mcommand, msection) + bfd *abfd; + asection *section; + bfd_mach_o_load_command **mcommand; + bfd_mach_o_section **msection; { struct mach_o_data_struct *md = abfd->tdata.mach_o_data; unsigned int i, j, num; @@ -1962,9 +1991,10 @@ int bfd_mach_o_lookup_section } int -bfd_mach_o_lookup_command - (bfd *abfd, bfd_mach_o_load_command_type type, - bfd_mach_o_load_command **mcommand) +bfd_mach_o_lookup_command (abfd, type, mcommand) + bfd *abfd; + bfd_mach_o_load_command_type type; + bfd_mach_o_load_command **mcommand; { struct mach_o_data_struct *md = NULL; bfd_mach_o_load_command *ncmd = NULL; @@ -2011,7 +2041,7 @@ bfd_mach_o_stack_addr (type) case BFD_MACH_O_CPU_TYPE_I860: return 0; case BFD_MACH_O_CPU_TYPE_HPPA: - return (0xc0000000-0x04000000); + return 0xc0000000 - 0x04000000; default: return 0; } @@ -2063,8 +2093,9 @@ bfd_mach_o_core_fetch_environment (abfd, rbuf, rlen) for (offset = 4; offset <= size; offset += 4) { - unsigned long val = *((unsigned long *) (buf + size - offset)); + unsigned long val; + val = *((unsigned long *) (buf + size - offset)); if (! found_nonnull) { if (val != 0) @@ -2072,9 +2103,11 @@ bfd_mach_o_core_fetch_environment (abfd, rbuf, rlen) } else if (val == 0x0) { - unsigned long bottom = seg->fileoff + seg->filesize - offset; - unsigned long top = seg->fileoff + seg->filesize - 4; + unsigned long bottom; + unsigned long top; + bottom = seg->fileoff + seg->filesize - offset; + top = seg->fileoff + seg->filesize - 4; *rbuf = bfd_malloc (top - bottom); *rlen = top - bottom; @@ -2159,4 +2192,3 @@ bfd_mach_o_core_file_matches_executable_p (core_bfd, exec_bfd) #undef TARGET_STRING #undef TARGET_BIG_ENDIAN #undef TARGET_ARCHIVE - diff --git a/bfd/mach-o.h b/bfd/mach-o.h index c368c1e..f780273 100644 --- a/bfd/mach-o.h +++ b/bfd/mach-o.h @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _BFD_MACH_O_H_ @@ -127,13 +127,13 @@ bfd_mach_o_filetype; typedef enum bfd_mach_o_section_type { /* Regular section. */ - BFD_MACH_O_S_REGULAR = 0x0, + BFD_MACH_O_S_REGULAR = 0x0, /* Zero fill on demand section. */ BFD_MACH_O_S_ZEROFILL = 0x1, /* Section with only literal C strings. */ - BFD_MACH_O_S_CSTRING_LITERALS = 0x2, + BFD_MACH_O_S_CSTRING_LITERALS = 0x2, /* Section with only 4 byte literals. */ BFD_MACH_O_S_4BYTE_LITERALS = 0x3, @@ -159,13 +159,13 @@ typedef enum bfd_mach_o_section_type /* Section with only non-lazy symbol pointers. */ BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS = 0x6, - + /* Section with only lazy symbol pointers. */ BFD_MACH_O_S_LAZY_SYMBOL_POINTERS = 0x7, - + /* Section with only symbol stubs, byte size of stub in the reserved2 field. */ BFD_MACH_O_S_SYMBOL_STUBS = 0x8, - + /* Section with only function pointers for initialization. */ BFD_MACH_O_S_MOD_INIT_FUNC_POINTERS = 0x9 } @@ -232,7 +232,7 @@ bfd_mach_o_symtab_command; /* This is the second set of the symbolic information which is used to support the data structures for the dynamicly link editor. - + The original set of symbolic information in the symtab_command which contains the symbol and string tables must also be present when this load command is present. When this load command is present the symbol table is organized @@ -242,7 +242,7 @@ bfd_mach_o_symtab_command; undefined external symbols (sorted by name) In this load command there are offsets and counts to each of the three groups of symbols. - + This load command contains a the offsets and sizes of the following new symbolic information tables: table of contents @@ -258,7 +258,7 @@ bfd_mach_o_symtab_command; module table - the file contains only one module so everything in the file is part of the module. reference symbol table - is the defined and undefined external symbols - + For dynamicly linked shared library files this load command also contains offsets and sizes to the pool of relocation entries for all sections separated into two groups: @@ -274,11 +274,11 @@ typedef struct bfd_mach_o_dysymtab_command local symbols (further grouped by the module they are from) defined external symbols (further grouped by the module they are from) undefined symbols - + The local symbols are used only for debugging. The dynamic binding process may have to use them to indicate to the debugger the local symbols for a module that is being bound. - + The last two groups are used by the dynamic binding process to do the binding (indirectly through the module table and the reference symbol table when this is a dynamicly linked shared library file). */ @@ -368,11 +368,11 @@ typedef struct bfd_mach_o_dysymtab_command unsigned long locreloff; /* Offset to local relocation entries. */ unsigned long nlocrel; /* Number of local relocation entries. */ } -bfd_mach_o_dysymtab_command; +bfd_mach_o_dysymtab_command; -/* An indirect symbol table entry is simply a 32bit index into the symbol table +/* An indirect symbol table entry is simply a 32bit index into the symbol table to the symbol that the pointer or stub is refering to. Unless it is for a - non-lazy symbol pointer section for a defined symbol which strip(1) as + non-lazy symbol pointer section for a defined symbol which strip(1) as removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. */ @@ -390,7 +390,7 @@ bfd_mach_o_thread_flavour; typedef struct bfd_mach_o_thread_command { unsigned long nflavours; - bfd_mach_o_thread_flavour *flavours; + bfd_mach_o_thread_flavour *flavours; asection *section; } bfd_mach_o_thread_command; @@ -469,7 +469,7 @@ int bfd_mach_o_scan_read_symtab_strtab PARAMS ((bfd *, bfd_mach int bfd_mach_o_scan_read_symtab_symbols PARAMS ((bfd *, bfd_mach_o_symtab_command *)); int bfd_mach_o_scan_read_dysymtab_symbol PARAMS ((bfd *, bfd_mach_o_dysymtab_command *, bfd_mach_o_symtab_command *, asymbol *, unsigned long)); int bfd_mach_o_scan_start_address PARAMS ((bfd *)); -int bfd_mach_o_scan PARAMS ((bfd *, bfd_mach_o_header *)); +int bfd_mach_o_scan PARAMS ((bfd *, bfd_mach_o_header *, bfd_mach_o_data_struct *)); boolean bfd_mach_o_mkobject PARAMS ((bfd *)); const bfd_target * bfd_mach_o_object_p PARAMS ((bfd *)); const bfd_target * bfd_mach_o_core_p PARAMS ((bfd *)); @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <ctype.h> @@ -70,7 +70,7 @@ static void bfd_pef_print_symbol PARAMS ((bfd *abfd, PTR afile, asymbol *symbol, bfd_print_symbol_type how)); static void bfd_pef_convert_architecture -PARAMS ((unsigned long architecture, +PARAMS ((unsigned long architecture, enum bfd_architecture *type, unsigned long *subtype)); static boolean bfd_pef_mkobject PARAMS ((bfd *abfd)); static int bfd_pef_parse_traceback_table @@ -78,7 +78,8 @@ PARAMS ((bfd *abfd, asection *section, unsigned char *buf, size_t len, size_t pos, asymbol *sym, FILE *file)); static const char *bfd_pef_section_name PARAMS ((bfd_pef_section *section)); static unsigned long bfd_pef_section_flags PARAMS ((bfd_pef_section *section)); -static asection *bfd_pef_make_bfd_section PARAMS ((bfd *abfd, bfd_pef_section *section)); +static asection *bfd_pef_make_bfd_section +PARAMS ((bfd *abfd, bfd_pef_section *section)); static int bfd_pef_read_header PARAMS ((bfd *abfd, bfd_pef_header *header)); static const bfd_target *bfd_pef_object_p PARAMS ((bfd *)); static int bfd_pef_parse_traceback_tables @@ -86,9 +87,10 @@ PARAMS ((bfd *abfd, asection *sec, unsigned char *buf, size_t len, long *nsym, asymbol **csym)); static int bfd_pef_parse_function_stub PARAMS ((bfd *abfd, unsigned char *buf, size_t len, unsigned long *offset)); -static int bfd_pef_parse_function_stubs +static int bfd_pef_parse_function_stubs PARAMS ((bfd *abfd, asection *codesec, unsigned char *codebuf, size_t codelen, - unsigned char *loaderbuf, size_t loaderlen, unsigned long *nsym, asymbol **csym)); + unsigned char *loaderbuf, size_t loaderlen, unsigned long *nsym, + asymbol **csym)); static long bfd_pef_parse_symbols PARAMS ((bfd *abfd, asymbol **csym)); static long bfd_pef_count_symbols PARAMS ((bfd *abfd)); static long bfd_pef_get_symtab_upper_bound PARAMS ((bfd *)); @@ -97,7 +99,8 @@ static asymbol *bfd_pef_make_empty_symbol PARAMS ((bfd *)); static void bfd_pef_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *)); static int bfd_pef_sizeof_headers PARAMS ((bfd *, boolean)); -static int bfd_pef_xlib_read_header PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); +static int bfd_pef_xlib_read_header +PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); static int bfd_pef_xlib_scan PARAMS ((bfd *abfd, bfd_pef_xlib_header *header)); static const bfd_target *bfd_pef_xlib_object_p PARAMS ((bfd *abfd)); @@ -109,29 +112,32 @@ bfd_pef_print_symbol (abfd, afile, symbol, how) bfd_print_symbol_type how; { FILE *file = (FILE *) afile; - switch (how) { - case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); - break; - default: - bfd_print_symbol_vandf (abfd, (PTR) file, symbol); - fprintf (file, " %-5s %s", symbol->section->name, symbol->name); - if (strncmp (symbol->name, "__traceback_", strlen ("__traceback_")) == 0) { - char *buf = alloca (symbol->udata.i); - size_t offset = symbol->value + 4; - size_t len = symbol->udata.i; - int ret; - - bfd_get_section_contents (abfd, symbol->section, buf, offset, len); - ret = bfd_pef_parse_traceback_table (abfd, symbol->section, buf, len, 0, NULL, file); - if (ret < 0) { - fprintf (file, " [ERROR]"); - } + switch (how) + { + case bfd_print_symbol_name: + fprintf (file, "%s", symbol->name); + break; + default: + bfd_print_symbol_vandf (abfd, (PTR) file, symbol); + fprintf (file, " %-5s %s", symbol->section->name, symbol->name); + if (strncmp (symbol->name, "__traceback_", strlen ("__traceback_")) == 0) + { + char *buf = alloca (symbol->udata.i); + size_t offset = symbol->value + 4; + size_t len = symbol->udata.i; + int ret; + + bfd_get_section_contents (abfd, symbol->section, buf, offset, len); + ret = bfd_pef_parse_traceback_table (abfd, symbol->section, buf, + len, 0, NULL, file); + if (ret < 0) + fprintf (file, " [ERROR]"); + } } - } } -static void bfd_pef_convert_architecture (architecture, type, subtype) +static void +bfd_pef_convert_architecture (architecture, type, subtype) unsigned long architecture; enum bfd_architecture *type; unsigned long *subtype; @@ -141,7 +147,7 @@ static void bfd_pef_convert_architecture (architecture, type, subtype) const unsigned long ARCH_POWERPC = 0x70777063; /* 'pwpc' */ const unsigned long ARCH_M68K = 0x6d36386b; /* 'm68k' */ - + if (architecture == ARCH_POWERPC) *type = bfd_arch_powerpc; else if (architecture == ARCH_M68K) @@ -169,8 +175,9 @@ bfd_pef_parse_traceback_table (abfd, section, buf, len, pos, sym, file) size_t offset; const char *s; asymbol tmpsymbol; - - if (sym == NULL) { sym = &tmpsymbol; } + + if (sym == NULL) + sym = &tmpsymbol; sym->name = NULL; sym->value = 0; @@ -181,150 +188,150 @@ bfd_pef_parse_traceback_table (abfd, section, buf, len, pos, sym, file) /* memcpy is fine since all fields are unsigned char */ - if ((pos + 8) > len) { return -1; } + if ((pos + 8) > len) + return -1; memcpy (&table, buf + pos, 8); - - /* calling code relies on returned symbols having a name and correct offset */ - if ((table.lang != TB_C) && (table.lang != TB_CPLUSPLUS)) { + /* calling code relies on returned symbols having a name and + correct offset */ + + if ((table.lang != TB_C) && (table.lang != TB_CPLUSPLUS)) return -1; - } - if (! (table.flags2 & TB_NAME_PRESENT)) { + + if (! (table.flags2 & TB_NAME_PRESENT)) return -1; - } - if (! table.flags1 & TB_HAS_TBOFF) { + + if (! table.flags1 & TB_HAS_TBOFF) return -1; - } offset = 8; - if ((table.flags5 & TB_FLOATPARAMS) || (table.fixedparams)) { - offset += 4; - } + if ((table.flags5 & TB_FLOATPARAMS) || (table.fixedparams)) + offset += 4; - if (table.flags1 & TB_HAS_TBOFF) { + if (table.flags1 & TB_HAS_TBOFF) + { + struct traceback_table_tboff off; - struct traceback_table_tboff off; - - if ((pos + offset + 4) > len) { return -1; } - off.tb_offset = bfd_getb32 (buf + pos + offset); - offset += 4; + if ((pos + offset + 4) > len) + return -1; + off.tb_offset = bfd_getb32 (buf + pos + offset); + offset += 4; - /* need to subtract 4 because the offset includes the 0x0L - preceding the table */ + /* need to subtract 4 because the offset includes the 0x0L + preceding the table */ - if (file != NULL) { - fprintf (file, " [offset = 0x%lx]", off.tb_offset); - } + if (file != NULL) + fprintf (file, " [offset = 0x%lx]", off.tb_offset); - if ((file == NULL) && ((off.tb_offset + 4) > (pos + offset))) { - return -1; + if ((file == NULL) && ((off.tb_offset + 4) > (pos + offset))) + return -1; + + sym->value = pos - off.tb_offset - 4; } - sym->value = pos - off.tb_offset - 4; - } - if (table.flags2 & TB_INT_HNDL) { + if (table.flags2 & TB_INT_HNDL) offset += 4; - } - if (table.flags1 & TB_HAS_CTL) { + if (table.flags1 & TB_HAS_CTL) + { + struct traceback_table_anchors anchors; - struct traceback_table_anchors anchors; + if ((pos + offset + 4) > len) + return -1; + anchors.ctl_info = bfd_getb32 (buf + pos + offset); + offset += 4; - if ((pos + offset + 4) > len) { return -1; } - anchors.ctl_info = bfd_getb32 (buf + pos + offset); - offset += 4; + if (anchors.ctl_info > 1024) + return -1; - if (anchors.ctl_info > 1024) { - return -1; + offset += anchors.ctl_info * 4; } - offset += anchors.ctl_info * 4; - } + if (table.flags2 & TB_NAME_PRESENT) + { + struct traceback_table_routine name; + char *namebuf; - if (table.flags2 & TB_NAME_PRESENT) { + if ((pos + offset + 2) > len) + return -1; + name.name_len = bfd_getb16 (buf + pos + offset); + offset += 2; - struct traceback_table_routine name; - char *namebuf; + if (name.name_len > 4096) + return -1; - if ((pos + offset + 2) > len) { return -1; } - name.name_len = bfd_getb16 (buf + pos + offset); - offset += 2; + if ((pos + offset + name.name_len) > len) + return -1; - if (name.name_len > 4096) { return -1; } + namebuf = (char *) bfd_alloc (abfd, name.name_len + 1); + if (namebuf == NULL) + return -1; - if ((pos + offset + name.name_len) > len) { return -1; } + memcpy (namebuf, buf + pos + offset, name.name_len); + namebuf[name.name_len] = '\0'; - namebuf = (char *) bfd_alloc (abfd, name.name_len + 1); - if (namebuf == NULL) { return -1; } + /* strip leading period inserted by compiler */ + if (namebuf[0] == '.') + memmove (namebuf, namebuf + 1, name.name_len + 1); - memcpy (namebuf, buf + pos + offset, name.name_len); - namebuf[name.name_len] = '\0'; - - /* strip leading period inserted by compiler */ - if (namebuf[0] == '.') { - memmove (namebuf, namebuf + 1, name.name_len + 1); - } + sym->name = namebuf; - sym->name = namebuf; + for (s = sym->name; (*s != '\0'); s++) + if (! isprint (*s)) + return -1; - for (s = sym->name; (*s != '\0'); s++) { - if (! isprint (*s)) { - return -1; - } + offset += name.name_len; } - offset += name.name_len; - } - - if (table.flags2 & TB_USES_ALLOCA) { + if (table.flags2 & TB_USES_ALLOCA) offset += 4; - } - if (table.flags4 & TB_HAS_VEC_INFO) { + if (table.flags4 & TB_HAS_VEC_INFO) offset += 4; - } - if (file != NULL) { + if (file != NULL) fprintf (file, " [length = 0x%lx]", (long) offset); - } + return offset; } static const char *bfd_pef_section_name (section) bfd_pef_section *section; { - switch (section->section_kind) { - case BFD_PEF_SECTION_CODE: return "code"; - case BFD_PEF_SECTION_UNPACKED_DATA: return "unpacked-data"; - case BFD_PEF_SECTION_PACKED_DATA: return "packed-data"; - case BFD_PEF_SECTION_CONSTANT: return "constant"; - case BFD_PEF_SECTION_LOADER: return "loader"; - case BFD_PEF_SECTION_DEBUG: return "debug"; - case BFD_PEF_SECTION_EXEC_DATA: return "exec-data"; - case BFD_PEF_SECTION_EXCEPTION: return "exception"; - case BFD_PEF_SECTION_TRACEBACK: return "traceback"; - default: return "unknown"; - } + switch (section->section_kind) + { + case BFD_PEF_SECTION_CODE: return "code"; + case BFD_PEF_SECTION_UNPACKED_DATA: return "unpacked-data"; + case BFD_PEF_SECTION_PACKED_DATA: return "packed-data"; + case BFD_PEF_SECTION_CONSTANT: return "constant"; + case BFD_PEF_SECTION_LOADER: return "loader"; + case BFD_PEF_SECTION_DEBUG: return "debug"; + case BFD_PEF_SECTION_EXEC_DATA: return "exec-data"; + case BFD_PEF_SECTION_EXCEPTION: return "exception"; + case BFD_PEF_SECTION_TRACEBACK: return "traceback"; + default: return "unknown"; + } } static unsigned long bfd_pef_section_flags (section) bfd_pef_section *section; { - switch (section->section_kind) { - case BFD_PEF_SECTION_CODE: - return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_CODE; - case BFD_PEF_SECTION_UNPACKED_DATA: - case BFD_PEF_SECTION_PACKED_DATA: - case BFD_PEF_SECTION_CONSTANT: - case BFD_PEF_SECTION_LOADER: - case BFD_PEF_SECTION_DEBUG: - case BFD_PEF_SECTION_EXEC_DATA: - case BFD_PEF_SECTION_EXCEPTION: - case BFD_PEF_SECTION_TRACEBACK: - default: - return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; - } + switch (section->section_kind) + { + case BFD_PEF_SECTION_CODE: + return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_CODE; + case BFD_PEF_SECTION_UNPACKED_DATA: + case BFD_PEF_SECTION_PACKED_DATA: + case BFD_PEF_SECTION_CONSTANT: + case BFD_PEF_SECTION_LOADER: + case BFD_PEF_SECTION_DEBUG: + case BFD_PEF_SECTION_EXEC_DATA: + case BFD_PEF_SECTION_EXCEPTION: + case BFD_PEF_SECTION_TRACEBACK: + default: + return SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; + } } static asection * @@ -336,8 +343,9 @@ bfd_pef_make_bfd_section (abfd, section) const char *name = bfd_pef_section_name (section); bfdsec = bfd_make_section_anyway (abfd, name); - if (bfdsec == NULL) { return NULL; } - + if (bfdsec == NULL) + return NULL; + bfdsec->vma = section->default_address + section->container_offset; bfdsec->lma = section->default_address + section->container_offset; bfdsec->_raw_size = section->container_length; @@ -417,9 +425,10 @@ int bfd_pef_scan_section (abfd, section) bfd_pef_section *section; { unsigned char buf[28]; - + bfd_seek (abfd, section->header_offset, SEEK_SET); - if (bfd_bread ((PTR) buf, 28, abfd) != 28) { return -1; } + if (bfd_bread ((PTR) buf, 28, abfd) != 28) + return -1; section->name_offset = bfd_h_get_32 (abfd, buf); section->default_address = bfd_h_get_32 (abfd, buf + 4); @@ -433,7 +442,8 @@ int bfd_pef_scan_section (abfd, section) section->reserved = buf[27]; section->bfd_section = bfd_pef_make_bfd_section (abfd, section); - if (section->bfd_section == NULL) { return -1; } + if (section->bfd_section == NULL) + return -1; return 0; } @@ -450,14 +460,19 @@ bfd_pef_print_loader_header (abfd, header, file) fprintf (file, "init_offset: %lu\n", header->init_offset); fprintf (file, "term_section: %ld\n", header->term_section); fprintf (file, "term_offset: %lu\n", header->term_offset); - fprintf (file, "imported_library_count: %lu\n", header->imported_library_count); - fprintf (file, "total_imported_symbol_count: %lu\n", header->total_imported_symbol_count); + fprintf (file, "imported_library_count: %lu\n", + header->imported_library_count); + fprintf (file, "total_imported_symbol_count: %lu\n", + header->total_imported_symbol_count); fprintf (file, "reloc_section_count: %lu\n", header->reloc_section_count); fprintf (file, "reloc_instr_offset: %lu\n", header->reloc_instr_offset); - fprintf (file, "loader_strings_offset: %lu\n", header->loader_strings_offset); + fprintf (file, "loader_strings_offset: %lu\n", + header->loader_strings_offset); fprintf (file, "export_hash_offset: %lu\n", header->export_hash_offset); - fprintf (file, "export_hash_table_power: %lu\n", header->export_hash_table_power); - fprintf (file, "exported_symbol_count: %lu\n", header->exported_symbol_count); + fprintf (file, "export_hash_table_power: %lu\n", + header->export_hash_table_power); + fprintf (file, "exported_symbol_count: %lu\n", + header->exported_symbol_count); } int @@ -472,18 +487,33 @@ bfd_pef_print_loader_section (abfd, file) int ret; loadersec = bfd_get_section_by_name (abfd, "loader"); - if (loadersec == NULL) { return -1; } - + if (loadersec == NULL) + return -1; + loaderlen = bfd_section_size (abfd, loadersec); loaderbuf = (unsigned char *) bfd_malloc (loaderlen); if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) - { free (loaderbuf); return -1; } + { + free (loaderbuf); + return -1; + } if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) - { free (loaderbuf); return -1; } + { + free (loaderbuf); + return -1; + } - if (loaderlen < 56) { free (loaderbuf); return -1; } + if (loaderlen < 56) + { + free (loaderbuf); + return -1; + } ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); - if (ret < 0) { free (loaderbuf); return -1; } + if (ret < 0) + { + free (loaderbuf); + return -1; + } bfd_pef_print_loader_header (abfd, &header, file); return 0; @@ -502,89 +532,97 @@ bfd_pef_scan_start_address (abfd) int ret; loadersec = bfd_get_section_by_name (abfd, "loader"); - if (loadersec == NULL) { goto end; } - + if (loadersec == NULL) + goto end; + loaderlen = bfd_section_size (abfd, loadersec); loaderbuf = (unsigned char *) bfd_malloc (loaderlen); - if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) { goto error; } - if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) { goto error; } + if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) + goto error; + if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) + goto error; - if (loaderlen < 56) { goto error; } + if (loaderlen < 56) + goto error; ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); - if (ret < 0) { goto error; } + if (ret < 0) + goto error; + + if (header.main_section < 0) + goto end; + + for (section = abfd->sections; section != NULL; section = section->next) + if ((section->index + 1) == header.main_section) + break; - if (header.main_section < 0) { goto end; } + if (section == NULL) + goto error; - for (section = abfd->sections; section != NULL; section = section->next) { - if ((section->index + 1) == header.main_section) { break; } - } - - if (section == NULL) { goto error; } - abfd->start_address = section->vma + header.main_offset; end: - if (loaderbuf != NULL) { free (loaderbuf); } + if (loaderbuf != NULL) + free (loaderbuf); return 0; error: - if (loaderbuf != NULL) { free (loaderbuf); } + if (loaderbuf != NULL) + free (loaderbuf); return -1; } int -bfd_pef_scan (abfd, header) +bfd_pef_scan (abfd, header, mdata) bfd *abfd; bfd_pef_header *header; + bfd_pef_data_struct *mdata; { unsigned int i; - bfd_pef_data_struct *mdata = NULL; enum bfd_architecture cputype; unsigned long cpusubtype; - if ((header->tag1 != BFD_PEF_TAG1) || (header->tag2 != BFD_PEF_TAG2)) { - return -1; - } + mdata->header = *header; - mdata = ((bfd_pef_data_struct *) - bfd_alloc (abfd, sizeof (bfd_pef_data_struct))); - if (mdata == NULL) { return -1; } - bfd_pef_convert_architecture (header->architecture, &cputype, &cpusubtype); - if (cputype == bfd_arch_unknown) { - fprintf (stderr, "bfd_pef_scan: unknown architecture 0x%lx\n", header->architecture); - return -1; - } + if (cputype == bfd_arch_unknown) + { + fprintf (stderr, "bfd_pef_scan: unknown architecture 0x%lx\n", + header->architecture); + return -1; + } bfd_set_arch_mach (abfd, cputype, cpusubtype); mdata->header = *header; - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); + abfd->flags = (abfd->xvec->object_flags + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); - if (header->section_count != 0) { - - mdata->sections = - ((bfd_pef_section *) - bfd_alloc (abfd, header->section_count * sizeof (bfd_pef_section))); - if (mdata->sections == NULL) { return -1; } + if (header->section_count != 0) + { + mdata->sections = + ((bfd_pef_section *) + bfd_alloc (abfd, header->section_count * sizeof (bfd_pef_section))); - for (i = 0; i < header->section_count; i++) { - bfd_pef_section *cur = &mdata->sections[i]; - cur->header_offset = 40 + (i * 28); - if (bfd_pef_scan_section (abfd, cur) < 0) { + if (mdata->sections == NULL) return -1; - } + + for (i = 0; i < header->section_count; i++) + { + bfd_pef_section *cur = &mdata->sections[i]; + cur->header_offset = 40 + (i * 28); + if (bfd_pef_scan_section (abfd, cur) < 0) + return -1; + } } - } - if (bfd_pef_scan_start_address (abfd) < 0) { + if (bfd_pef_scan_start_address (abfd) < 0) + { #if 0 - fprintf (stderr, "bfd_pef_scan: unable to scan start address: %s\n", - bfd_errmsg (bfd_get_error ())); - abfd->tdata.pef_data = NULL; - return -1; + fprintf (stderr, "bfd_pef_scan: unable to scan start address: %s\n", + bfd_errmsg (bfd_get_error ())); + return -1; #endif - } + } abfd->tdata.pef_data = mdata; @@ -600,7 +638,8 @@ bfd_pef_read_header (abfd, header) bfd_seek (abfd, 0, SEEK_SET); - if (bfd_bread ((PTR) buf, 40, abfd) != 40) { return -1; } + if (bfd_bread ((PTR) buf, 40, abfd) != 40) + return -1; header->tag1 = bfd_getb32 (buf); header->tag2 = bfd_getb32 (buf + 4); @@ -621,23 +660,35 @@ static const bfd_target * bfd_pef_object_p (abfd) bfd *abfd; { + struct bfd_preserve preserve; bfd_pef_header header; - - abfd->tdata.pef_data = NULL; - if (bfd_pef_read_header (abfd, &header) != 0) { - abfd->tdata.pef_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + preserve.marker = NULL; + if (bfd_pef_read_header (abfd, &header) != 0) + goto wrong; - if (bfd_pef_scan (abfd, &header) != 0) { - abfd->tdata.pef_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2) + goto wrong; + + preserve.marker = bfd_zalloc (abfd, sizeof (bfd_pef_data_struct)); + if (preserve.marker == NULL + || !bfd_preserve_save (abfd, &preserve)) + goto fail; + if (bfd_pef_scan (abfd, &header, + (bfd_pef_data_struct *) preserve.marker) != 0) + goto wrong; + + bfd_preserve_finish (abfd, &preserve); return abfd->xvec; + + wrong: + bfd_set_error (bfd_error_wrong_format); + + fail: + if (preserve.marker != NULL) + bfd_preserve_restore (abfd, &preserve); + return NULL; } 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) unsigned long count = 0; int ret; - for (;;) { - - /* we're reading symbols two at a time */ + for (;;) + { + /* we're reading symbols two at a time */ - if (csym && ((csym[count] == NULL) || (csym[count + 1] == NULL))) { - break; - } + if (csym && ((csym[count] == NULL) || (csym[count + 1] == NULL))) + break; - pos += 3; - pos -= (pos % 4); + pos += 3; + pos -= (pos % 4); - while ((pos + 4) <= len) { - if (bfd_getb32 (buf + pos) == 0) { - break; - } - pos += 4; - } + while ((pos + 4) <= len) + { + if (bfd_getb32 (buf + pos) == 0) + break; + pos += 4; + } - if ((pos + 4) > len) { - break; - } - - ret = bfd_pef_parse_traceback_table (abfd, sec, buf, len, pos + 4, &function, 0); - if (ret < 0) { - /* skip over 0x0L to advance to next possible traceback table */ - pos += 4; - continue; - } - - BFD_ASSERT (function.name != NULL); + if ((pos + 4) > len) + break; - /* Don't bother to compute the name if we are just - counting symbols */ + ret = bfd_pef_parse_traceback_table (abfd, sec, buf, len, pos + 4, + &function, 0); + if (ret < 0) + { + /* skip over 0x0L to advance to next possible traceback table */ + pos += 4; + continue; + } - if (csym) - { - tbnamelen = strlen (tbprefix) + strlen (function.name); - name = bfd_alloc (abfd, tbnamelen + 1); - if (name == NULL) { - bfd_release (abfd, (PTR) function.name); - function.name = NULL; - break; + BFD_ASSERT (function.name != NULL); + + /* Don't bother to compute the name if we are just + counting symbols */ + + if (csym) + { + tbnamelen = strlen (tbprefix) + strlen (function.name); + name = bfd_alloc (abfd, tbnamelen + 1); + if (name == NULL) + { + bfd_release (abfd, (PTR) function.name); + function.name = NULL; + break; + } + snprintf (name, tbnamelen + 1, "%s%s", tbprefix, function.name); + traceback.name = name; + traceback.value = pos; + traceback.the_bfd = abfd; + traceback.section = sec; + traceback.flags = 0; + traceback.udata.i = ret; + + *(csym[count]) = function; + *(csym[count + 1]) = traceback; } - snprintf (name, tbnamelen + 1, "%s%s", tbprefix, function.name); - traceback.name = name; - traceback.value = pos; - traceback.the_bfd = abfd; - traceback.section = sec; - traceback.flags = 0; - traceback.udata.i = ret; - - *(csym[count]) = function; - *(csym[count + 1]) = traceback; - } - pos += ret; - count += 2; - } + pos += ret; + count += 2; + } *nsym = count; return 0; @@ -731,21 +783,27 @@ static int bfd_pef_parse_function_stub (abfd, buf, len, offset) { BFD_ASSERT (len == 24); - if ((bfd_getb32 (buf) & 0xffff0000) != 0x81820000) { return -1; } - if (bfd_getb32 (buf + 4) != 0x90410014) { return -1; } - if (bfd_getb32 (buf + 8) != 0x800c0000) { return -1; } - if (bfd_getb32 (buf + 12) != 0x804c0004) { return -1; } - if (bfd_getb32 (buf + 16) != 0x7c0903a6) { return -1; } - if (bfd_getb32 (buf + 20) != 0x4e800420) { return -1; } - - if (offset != NULL) { + if ((bfd_getb32 (buf) & 0xffff0000) != 0x81820000) + return -1; + if (bfd_getb32 (buf + 4) != 0x90410014) + return -1; + if (bfd_getb32 (buf + 8) != 0x800c0000) + return -1; + if (bfd_getb32 (buf + 12) != 0x804c0004) + return -1; + if (bfd_getb32 (buf + 16) != 0x7c0903a6) + return -1; + if (bfd_getb32 (buf + 20) != 0x4e800420) + return -1; + + if (offset != NULL) *offset = (bfd_getb32 (buf) & 0x0000ffff) / 4; - } return 0; } -static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, loaderbuf, loaderlen, nsym, csym) +static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, + loaderbuf, loaderlen, nsym, csym) bfd *abfd; asection *codesec; unsigned char *codebuf; @@ -767,113 +825,142 @@ static int bfd_pef_parse_function_stubs (abfd, codesec, codebuf, codelen, loader unsigned long i; int ret; - if (loaderlen < 56) { goto error; } + if (loaderlen < 56) + goto error; ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header); - if (ret < 0) { goto error; } + if (ret < 0) + goto error; libraries = (bfd_pef_imported_library *) bfd_malloc (header.imported_library_count * sizeof (bfd_pef_imported_library)); imports = (bfd_pef_imported_symbol *) bfd_malloc (header.total_imported_symbol_count * sizeof (bfd_pef_imported_symbol)); - - if (loaderlen < (56 + (header.imported_library_count * 24))) { goto error; } - for (i = 0; i < header.imported_library_count; i++) { - ret = bfd_pef_parse_imported_library - (abfd, loaderbuf + 56 + (i * 24), 24, &libraries[i]); - if (ret < 0) { goto error; } - } - - if (loaderlen < (56 + (header.imported_library_count * 24) + (header.total_imported_symbol_count * 4))) - { goto error; } - for (i = 0; i < header.total_imported_symbol_count; i++) { - ret = bfd_pef_parse_imported_symbol - (abfd, loaderbuf + 56 + (header.imported_library_count * 24) + (i * 4), 4, &imports[i]); - if (ret < 0) { goto error; } - } - + + if (loaderlen < (56 + (header.imported_library_count * 24))) + goto error; + for (i = 0; i < header.imported_library_count; i++) + { + ret = bfd_pef_parse_imported_library + (abfd, loaderbuf + 56 + (i * 24), 24, &libraries[i]); + if (ret < 0) + goto error; + } + + if (loaderlen < (56 + (header.imported_library_count * 24) + + (header.total_imported_symbol_count * 4))) + goto error; + for (i = 0; i < header.total_imported_symbol_count; i++) + { + ret = (bfd_pef_parse_imported_symbol + (abfd, + loaderbuf + 56 + (header.imported_library_count * 24) + (i * 4), + 4, &imports[i])); + if (ret < 0) + goto error; + } + codepos = 0; - for (;;) { + for (;;) + { + asymbol sym; + const char *symname; + char *name; + unsigned long index; + int ret; - asymbol sym; - const char *symname; - char *name; - unsigned long index; - int ret; + if (csym && (csym[count] == NULL)) + break; - if (csym && (csym[count] == NULL)) { break; } + codepos += 3; + codepos -= (codepos % 4); - codepos += 3; - codepos -= (codepos % 4); + while ((codepos + 4) <= codelen) + { + if ((bfd_getb32 (codebuf + codepos) & 0xffff0000) == 0x81820000) + break; + codepos += 4; + } - while ((codepos + 4) <= codelen) { - if ((bfd_getb32 (codebuf + codepos) & 0xffff0000) == 0x81820000) { + if ((codepos + 4) > codelen) break; - } - codepos += 4; - } - if ((codepos + 4) > codelen) { - break; - } + ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &index); + if (ret < 0) + { + codepos += 24; + continue; + } - ret = bfd_pef_parse_function_stub (abfd, codebuf + codepos, 24, &index); - if (ret < 0) { codepos += 24; continue; } - - if (index >= header.total_imported_symbol_count) { codepos += 24; continue; } + if (index >= header.total_imported_symbol_count) + { + codepos += 24; + continue; + } - { - size_t max, namelen; - const char *s; - - if (loaderlen < (header.loader_strings_offset + imports[index].name)) { goto error; } - - max = loaderlen - (header.loader_strings_offset + imports[index].name); - symname = loaderbuf + header.loader_strings_offset + imports[index].name; - namelen = 0; - for (s = symname; s < (symname + max); s++) { - if (*s == '\0') { break; } - if (! isprint (*s)) { goto error; } - namelen++; - } - if (*s != '\0') { goto error; } + { + size_t max, namelen; + const char *s; + + if (loaderlen < (header.loader_strings_offset + imports[index].name)) + goto error; + + max = loaderlen - (header.loader_strings_offset + imports[index].name); + symname = loaderbuf + header.loader_strings_offset + imports[index].name; + namelen = 0; + for (s = symname; s < (symname + max); s++) + { + if (*s == '\0') + break; + if (! isprint (*s)) + goto error; + namelen++; + } + if (*s != '\0') + goto error; + + name = bfd_alloc (abfd, strlen (sprefix) + namelen + 1); + if (name == NULL) + break; - name = bfd_alloc (abfd, strlen (sprefix) + namelen + 1); - if (name == NULL) { break; } + snprintf (name, strlen (sprefix) + namelen + 1, "%s%s", + sprefix, symname); + sym.name = name; + } - snprintf (name, strlen (sprefix) + namelen + 1, "%s%s", sprefix, symname); - sym.name = name; - } + sym.value = codepos; + sym.the_bfd = abfd; + sym.section = codesec; + sym.flags = 0; + sym.udata.i = 0; - sym.value = codepos; - sym.the_bfd = abfd; - sym.section = codesec; - sym.flags = 0; - sym.udata.i = 0; + codepos += 24; - codepos += 24; + if (csym != NULL) + *(csym[count]) = sym; - if (csym != NULL) { - *(csym[count]) = sym; + count++; } - count++; - } goto end; end: - if (libraries != NULL) { free (libraries); } - if (imports != NULL) { free (imports); } + if (libraries != NULL) + free (libraries); + if (imports != NULL) + free (imports); *nsym = count; return 0; error: - if (libraries != NULL) { free (libraries); } - if (imports != NULL) { free (imports); } + if (libraries != NULL) + free (libraries); + if (imports != NULL) + free (imports); *nsym = count; return -1; -} +} static long bfd_pef_parse_symbols (abfd, csym) bfd *abfd; @@ -894,8 +981,10 @@ static long bfd_pef_parse_symbols (abfd, csym) { codelen = bfd_section_size (abfd, codesec); codebuf = (unsigned char *) bfd_malloc (codelen); - if (bfd_seek (abfd, codesec->filepos, SEEK_SET) < 0) { goto end; } - if (bfd_bread ((PTR) codebuf, codelen, abfd) != codelen) { goto end; } + if (bfd_seek (abfd, codesec->filepos, SEEK_SET) < 0) + goto end; + if (bfd_bread ((PTR) codebuf, codelen, abfd) != codelen) + goto end; } loadersec = bfd_get_section_by_name (abfd, "loader"); @@ -903,15 +992,18 @@ static long bfd_pef_parse_symbols (abfd, csym) { loaderlen = bfd_section_size (abfd, loadersec); loaderbuf = (unsigned char *) bfd_malloc (loaderlen); - if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) { goto end; } - if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) { goto end; } + if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) < 0) + goto end; + if (bfd_bread ((PTR) loaderbuf, loaderlen, abfd) != loaderlen) + goto end; } - + count = 0; if (codesec != NULL) { unsigned long ncount = 0; - bfd_pef_parse_traceback_tables (abfd, codesec, codebuf, codelen, &ncount, csym); + bfd_pef_parse_traceback_tables (abfd, codesec, codebuf, codelen, + &ncount, csym); count += ncount; } @@ -923,18 +1015,17 @@ static long bfd_pef_parse_symbols (abfd, csym) (csym != NULL) ? (csym + count) : NULL); count += ncount; } - - if (csym != NULL) { + + if (csym != NULL) csym[count] = NULL; - } - + end: - if (codebuf != NULL) + if (codebuf != NULL) free (codebuf); - if (loaderbuf != NULL) - free (loaderbuf); - + if (loaderbuf != NULL) + free (loaderbuf); + return count; } @@ -950,7 +1041,8 @@ bfd_pef_get_symtab_upper_bound (abfd) bfd *abfd; { long nsyms = bfd_pef_count_symbols (abfd); - if (nsyms < 0) { return nsyms; } + if (nsyms < 0) + return nsyms; return ((nsyms + 1) * sizeof (asymbol *)); } @@ -964,20 +1056,21 @@ bfd_pef_get_symtab (abfd, alocation) long ret; long nsyms = bfd_pef_count_symbols (abfd); - if (nsyms < 0) { return nsyms; } + if (nsyms < 0) + return nsyms; syms = bfd_alloc (abfd, nsyms * sizeof (asymbol)); - if (syms == NULL) { return -1; } + if (syms == NULL) + return -1; - for (i = 0; i < nsyms; i++) { + for (i = 0; i < nsyms; i++) alocation[i] = &syms[i]; - } + alocation[nsyms] = NULL; ret = bfd_pef_parse_symbols (abfd, alocation); - if (ret != nsyms) { + if (ret != nsyms) return 0; - } return ret; } @@ -1056,7 +1149,7 @@ const bfd_target pef_vec = BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), NULL, - + NULL }; @@ -1077,7 +1170,8 @@ bfd_pef_xlib_read_header (abfd, header) bfd_seek (abfd, 0, SEEK_SET); - if (bfd_bread ((PTR) buf, 76, abfd) != 76) { return -1; } + if (bfd_bread ((PTR) buf, 76, abfd) != 76) + return -1; header->tag1 = bfd_getb32 (buf); header->tag2 = bfd_getb32 (buf + 4); @@ -1110,18 +1204,15 @@ bfd_pef_xlib_scan (abfd, header) { bfd_pef_xlib_data_struct *mdata = NULL; - if ((header->tag1 != BFD_PEF_XLIB_TAG1) - || ((header->tag2 != BFD_PEF_VLIB_TAG2) && (header->tag2 != BFD_PEF_BLIB_TAG2))) { + mdata = ((bfd_pef_xlib_data_struct *) + bfd_alloc (abfd, sizeof (bfd_pef_xlib_data_struct))); + if (mdata == NULL) return -1; - } - mdata = ((bfd_pef_xlib_data_struct *) - bfd_alloc (abfd, sizeof (bfd_pef_xlib_data_struct))); - if (mdata == NULL) { return -1; } - mdata->header = *header; - abfd->flags = abfd->xvec->object_flags | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS)); + abfd->flags = (abfd->xvec->object_flags + | (abfd->flags & (BFD_IN_MEMORY | BFD_IO_FUNCS))); abfd->tdata.pef_xlib_data = mdata; @@ -1132,22 +1223,37 @@ static const bfd_target * bfd_pef_xlib_object_p (abfd) bfd *abfd; { + struct bfd_preserve preserve; bfd_pef_xlib_header header; - - abfd->tdata.pef_xlib_data = NULL; - if (bfd_pef_xlib_read_header (abfd, &header) != 0) { - abfd->tdata.pef_xlib_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + if (bfd_pef_xlib_read_header (abfd, &header) != 0) + { + bfd_set_error (bfd_error_wrong_format); + return NULL; + } - if (bfd_pef_xlib_scan (abfd, &header) != 0) { - abfd->tdata.pef_xlib_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + if ((header.tag1 != BFD_PEF_XLIB_TAG1) + || ((header.tag2 != BFD_PEF_VLIB_TAG2) + && (header.tag2 != BFD_PEF_BLIB_TAG2))) + { + bfd_set_error (bfd_error_wrong_format); + return NULL; + } + if (! bfd_preserve_save (abfd, &preserve)) + { + bfd_set_error (bfd_error_wrong_format); + return NULL; + } + + if (bfd_pef_xlib_scan (abfd, &header) != 0) + { + bfd_preserve_restore (abfd, &preserve); + bfd_set_error (bfd_error_wrong_format); + return NULL; + } + + bfd_preserve_finish (abfd, &preserve); return abfd->xvec; } @@ -1201,7 +1307,6 @@ const bfd_target pef_xlib_vec = BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), NULL, - + NULL }; - @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" @@ -43,7 +43,7 @@ struct bfd_pef_loader_header long main_section; unsigned long main_offset; long init_section; - unsigned long init_offset; + unsigned long init_offset; long term_section; unsigned long term_offset; unsigned long imported_library_count; @@ -183,4 +183,4 @@ int bfd_pef_parse_imported_library PARAMS ((bfd *, unsigned char *, size_t, bfd int bfd_pef_parse_imported_symbol PARAMS ((bfd *, unsigned char *, size_t, bfd_pef_imported_symbol *)); int bfd_pef_scan_section PARAMS ((bfd *, bfd_pef_section *)); int bfd_pef_scan_start_address PARAMS ((bfd *)); -int bfd_pef_scan PARAMS ((bfd *, bfd_pef_header *)); +int bfd_pef_scan PARAMS ((bfd *, bfd_pef_header *, bfd_pef_data_struct *)); diff --git a/bfd/targets.c b/bfd/targets.c index 6f74471..6a68eaa 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -997,11 +997,8 @@ static const bfd_target * const _bfd_target_vector[] = { &pc532machaout_vec, &pc532netbsd_vec, &pdp11_aout_vec, -#if 0 - /* bfd_pef_object_p and bfd_pef_xlib_object_p are broken. */ &pef_vec, &pef_xlib_vec, -#endif #if 0 /* This has the same magic number as RS/6000. */ &pmac_xcoff_vec, @@ -1031,10 +1028,7 @@ static const bfd_target * const _bfd_target_vector[] = { &sparclynx_coff_vec, &sparcnetbsd_vec, &sunos_big_vec, -#if 0 - /* bfd_sym_object_p is broken. */ &sym_vec, -#endif &tic30_aout_vec, &tic30_coff_vec, &tic54x_coff0_beh_vec, @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "xsym.h" @@ -116,7 +116,7 @@ bfd_sym_valid (abfd) if (abfd == NULL || abfd->xvec == NULL) return 0; - return (abfd->xvec == &sym_vec); + return abfd->xvec == &sym_vec; } unsigned char * @@ -128,19 +128,19 @@ bfd_sym_read_name_table (abfd, dshb) long ret; size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size; size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size; - + rstr = (unsigned char *) bfd_alloc (abfd, table_size); if (rstr == NULL) return rstr; bfd_seek (abfd, table_offset, SEEK_SET); ret = bfd_bread (rstr, table_size, abfd); - if ((ret < 0) || ((unsigned long) ret != table_size)) + if (ret < 0 || (unsigned long) ret != table_size) { bfd_release (abfd, rstr); return NULL; } - + return rstr; } @@ -163,11 +163,11 @@ bfd_sym_parse_disk_table_v32 (buf, len, table) bfd_sym_table_info *table; { BFD_ASSERT (len == 8); - + table->dti_first_page = bfd_getb16 (buf); table->dti_page_count = bfd_getb16 (buf + 2); table->dti_object_count = bfd_getb32 (buf + 4); -} +} void bfd_sym_parse_header_v32 (buf, len, header) @@ -176,13 +176,13 @@ bfd_sym_parse_header_v32 (buf, len, header) bfd_sym_header_block *header; { BFD_ASSERT (len == 154); - + memcpy (header->dshb_id, buf, 32); header->dshb_page_size = bfd_getb16 (buf + 32); header->dshb_hash_page = bfd_getb16 (buf + 34); header->dshb_root_mte = bfd_getb16 (buf + 36); header->dshb_mod_date = bfd_getb32 (buf + 38); - + bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte); bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte); bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte); @@ -196,7 +196,7 @@ bfd_sym_parse_header_v32 (buf, len, header) bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo); bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite); bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const); - + memcpy (&header->dshb_file_creator, buf + 146, 4); memcpy (&header->dshb_file_type, buf + 150, 4); } @@ -208,13 +208,13 @@ bfd_sym_read_header_v32 (abfd, header) { unsigned char buf[154]; long ret; - + ret = bfd_bread (buf, 154, abfd); if (ret != 154) return -1; - + bfd_sym_parse_header_v32 (buf, 154, header); - + return 0; } @@ -253,11 +253,11 @@ bfd_sym_read_version (abfd, version) { unsigned char version_string[32]; long ret; - + ret = bfd_bread (version_string, sizeof (version_string), abfd); if (ret != sizeof (version_string)) return -1; - + if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0) *version = BFD_SYM_VERSION_3_1; else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0) @@ -270,7 +270,7 @@ bfd_sym_read_version (abfd, version) *version = BFD_SYM_VERSION_3_5; else return -1; - + return 0; } @@ -302,10 +302,10 @@ bfd_sym_display_header (f, dshb) fprintf (f, " File Creator: %.4s Type: %.4s\n\n", dshb->dshb_file_creator, dshb->dshb_file_type); - + fprintf (f, "Table Name First Page Page Count Object Count\n"); fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); - + bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE"); bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE"); bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE"); @@ -319,7 +319,7 @@ bfd_sym_display_header (f, dshb) bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO"); bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE"); bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST"); - + fprintf (f, "\n"); } @@ -371,7 +371,7 @@ bfd_sym_parse_file_references_table_entry_v32 (buf, len, entry) bfd_sym_file_references_table_entry *entry; { unsigned int type; - + BFD_ASSERT (len == 10); 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) memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry)); type = bfd_getb16 (buf); - + switch (type) { case BFD_SYM_END_OF_LIST_3_2: @@ -428,7 +428,7 @@ bfd_sym_parse_contained_variables_table_entry_v32 (buf, len, entry) bfd_sym_contained_variables_table_entry *entry; { unsigned int type; - + BFD_ASSERT (len == 26); 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) memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry)); type = bfd_getb16 (buf); - + switch (type) { case BFD_SYM_END_OF_LIST_3_2: @@ -515,7 +515,7 @@ bfd_sym_parse_contained_labels_table_entry_v32 (buf, len, entry) memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry)); type = bfd_getb16 (buf); - + switch (type) { case BFD_SYM_END_OF_LIST_3_2: @@ -544,7 +544,7 @@ bfd_sym_parse_type_table_entry_v32 (buf, len, entry) bfd_sym_type_table_entry *entry; { BFD_ASSERT (len == 4); - + *entry = bfd_getb32 (buf); } @@ -554,12 +554,14 @@ bfd_sym_fetch_resources_table_entry (abfd, entry, index) bfd_sym_resources_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_resources_table_entry *)); unsigned long offset; unsigned long entry_size; unsigned char buf[18]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -588,14 +590,14 @@ bfd_sym_fetch_resources_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_rte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -605,12 +607,14 @@ bfd_sym_fetch_modules_table_entry (abfd, entry, index) bfd_sym_modules_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_modules_table_entry *)); unsigned long offset; unsigned long entry_size; unsigned char buf[46]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -639,14 +643,14 @@ bfd_sym_fetch_modules_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_mte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -656,12 +660,14 @@ bfd_sym_fetch_file_references_table_entry (abfd, entry, index) bfd_sym_file_references_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_file_references_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[8]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -689,14 +695,14 @@ bfd_sym_fetch_file_references_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_frte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -706,12 +712,14 @@ bfd_sym_fetch_contained_modules_table_entry (abfd, entry, index) bfd_sym_contained_modules_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_contained_modules_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[6]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -739,14 +747,14 @@ bfd_sym_fetch_contained_modules_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_cmte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -756,12 +764,14 @@ bfd_sym_fetch_contained_variables_table_entry (abfd, entry, index) bfd_sym_contained_variables_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_contained_variables_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[26]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -789,14 +799,14 @@ bfd_sym_fetch_contained_variables_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_cvte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -806,12 +816,14 @@ bfd_sym_fetch_contained_statements_table_entry (abfd, entry, index) bfd_sym_contained_statements_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_contained_statements_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[8]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -839,14 +851,14 @@ bfd_sym_fetch_contained_statements_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_csnte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -856,12 +868,14 @@ bfd_sym_fetch_contained_labels_table_entry (abfd, entry, index) bfd_sym_contained_labels_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_contained_labels_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[12]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -889,14 +903,14 @@ bfd_sym_fetch_contained_labels_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_clte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -906,12 +920,14 @@ bfd_sym_fetch_contained_types_table_entry (abfd, entry, index) bfd_sym_contained_types_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_contained_types_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[0]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -939,14 +955,14 @@ bfd_sym_fetch_contained_types_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_ctte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -956,12 +972,14 @@ bfd_sym_fetch_file_references_index_table_entry (abfd, entry, index) bfd_sym_file_references_index_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_file_references_index_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[0]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -989,14 +1007,14 @@ bfd_sym_fetch_file_references_index_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_fite.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -1006,12 +1024,14 @@ bfd_sym_fetch_constant_pool_entry (abfd, entry, index) bfd_sym_constant_pool_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_constant_pool_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[0]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -1039,14 +1059,14 @@ bfd_sym_fetch_constant_pool_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_fite.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -1056,12 +1076,14 @@ bfd_sym_fetch_type_table_entry (abfd, entry, index) bfd_sym_type_table_entry *entry; unsigned long index; { - void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *) = NULL; + void (*parser) PARAMS ((unsigned char *, size_t, + bfd_sym_type_table_entry *)); unsigned long offset; unsigned long entry_size = 0; unsigned char buf[4]; bfd_sym_data_struct *sdata = NULL; + parser = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; @@ -1086,14 +1108,14 @@ bfd_sym_fetch_type_table_entry (abfd, entry, index) offset = compute_offset (sdata->header.dshb_tte.dti_first_page, sdata->header.dshb_page_size, entry_size, index); - + if (bfd_seek (abfd, offset, SEEK_SET) < 0) return -1; if (bfd_bread (buf, entry_size, abfd) != entry_size) return -1; (*parser) (buf, entry_size, entry); - + return 0; } @@ -1118,11 +1140,11 @@ bfd_sym_fetch_type_information_table_entry (abfd, entry, offset) if (bfd_bread (buf, 4, abfd) != 4) return -1; entry->nte_index = bfd_getb32 (buf); - + if (bfd_bread (buf, 2, abfd) != 2) return -1; entry->physical_size = bfd_getb16 (buf); - + if (entry->physical_size & 0x8000) { if (bfd_bread (buf, 4, abfd) != 4) @@ -1180,12 +1202,13 @@ bfd_sym_symbol_name (abfd, index) if (index == 0) return ""; - + index *= 2; - if ((index / sdata->header.dshb_page_size) > sdata->header.dshb_nte.dti_page_count) + if ((index / sdata->header.dshb_page_size) + > sdata->header.dshb_nte.dti_page_count) return "\009[INVALID]"; - - return ((const unsigned char *) sdata->name_table + index); + + return (const unsigned char *) sdata->name_table + index; } const unsigned char * @@ -1194,7 +1217,7 @@ bfd_sym_module_name (abfd, index) unsigned long index; { bfd_sym_modules_table_entry entry; - + if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0) return "\011[INVALID]"; @@ -1272,7 +1295,8 @@ bfd_sym_print_file_reference (abfd, f, entry) bfd_sym_file_references_table_entry frtentry; int ret; - ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry, entry->fref_frte_index); + ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry, + entry->fref_frte_index); fprintf (f, "FILE "); if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX)) @@ -1296,7 +1320,7 @@ bfd_sym_print_resources_table_entry (abfd, f, entry) &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1], entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number, entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last); -} +} void bfd_sym_print_modules_table_entry (abfd, f, entry) @@ -1308,27 +1332,28 @@ bfd_sym_print_modules_table_entry (abfd, f, entry) bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0], &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1], entry->mte_nte_index); - - fprintf (f, "\n "); + + fprintf (f, "\n "); bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref); - fprintf (f, " range %lu -- %lu", entry->mte_imp_fref.fref_offset, entry->mte_imp_end); + fprintf (f, " range %lu -- %lu", + entry->mte_imp_fref.fref_offset, entry->mte_imp_end); - fprintf (f, "\n "); + fprintf (f, "\n "); fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind)); fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope)); - + fprintf (f, ", RTE %lu, offset %lu, size %lu", entry->mte_rte_index, entry->mte_res_offset, entry->mte_size); - fprintf (f, "\n "); + fprintf (f, "\n "); - fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu", + fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu", entry->mte_cmte_index, entry->mte_cvte_index, entry->mte_clte_index, entry->mte_ctte_index, entry->mte_csnte_idx_1, entry->mte_csnte_idx_2); - + if (entry->mte_parent != 0) fprintf (f, ", parent %lu", entry->mte_parent); else @@ -1364,7 +1389,7 @@ bfd_sym_print_file_references_table_entry (abfd, f, entry) switch (entry->generic.type) { case BFD_SYM_FILE_NAME_INDEX: - fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ", + fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ", bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0], &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1], entry->filename.nte_index); @@ -1421,19 +1446,19 @@ bfd_sym_print_contained_variables_table_entry (abfd, f, entry) fprintf (f, "END"); return; } - + if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) { bfd_sym_print_file_reference (abfd, f, &entry->file.fref); fprintf (f, " offset %lu", entry->file.fref.fref_offset); return; } - + fprintf (f, "\"%.*s\" (NTE %lu)", bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0], &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1], entry->entry.nte_index); - + fprintf (f, ", TTE %lu", entry->entry.tte_index); fprintf (f, ", offset %lu", entry->entry.file_delta); 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) } else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA) fprintf (f, ", bigla %lu, biglakind %u", - entry->entry.address.biglastruct.big_la, + entry->entry.address.biglastruct.big_la, entry->entry.address.biglastruct.big_la_kind); else @@ -1472,7 +1497,7 @@ bfd_sym_print_contained_statements_table_entry (abfd, f, entry) fprintf (f, "END"); return; } - + if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) { 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) if (offsetptr != NULL) *offsetptr = offset; - return; + return; } - + type = buf[offset]; offset++; @@ -1688,7 +1713,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) long value; bfd_sym_type_information_table_entry tinfo; - bfd_sym_fetch_long (buf, len, offset, &offset, &value); + bfd_sym_fetch_long (buf, len, offset, &offset, &value); if (value <= 0) fprintf (f, "[INVALID]"); else @@ -1696,7 +1721,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0) fprintf (f, "[INVALID]"); else - fprintf (f, "\"%.*s\"", + fprintf (f, "\"%.*s\"", bfd_sym_symbol_name (abfd, tinfo.nte_index)[0], &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]); } @@ -1719,7 +1744,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) fprintf (f, " (%lu)", value); break; } - + case 5: { unsigned long lower, upper, nelem; @@ -1727,9 +1752,9 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) fprintf (f, "enumeration (0x%x) of ", type); bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); - bfd_sym_fetch_long (buf, len, offset, &offset, &lower); - bfd_sym_fetch_long (buf, len, offset, &offset, &upper); - bfd_sym_fetch_long (buf, len, offset, &offset, &nelem); + bfd_sym_fetch_long (buf, len, offset, &offset, &lower); + bfd_sym_fetch_long (buf, len, offset, &offset, &upper); + bfd_sym_fetch_long (buf, len, offset, &offset, &nelem); fprintf (f, " from %lu to %lu with %lu elements: ", lower, upper, nelem); for (i = 0; i < nelem; i++) @@ -1757,15 +1782,15 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) fprintf (f, "record (0x%x) of ", type); else fprintf (f, "union (0x%x) of ", type); - - bfd_sym_fetch_long (buf, len, offset, &offset, &nrec); - fprintf (f, "%lu elements: ", nrec); + + bfd_sym_fetch_long (buf, len, offset, &offset, &nrec); + fprintf (f, "%lu elements: ", nrec); for (i = 0; i < nrec; i++) { - bfd_sym_fetch_long (buf, len, offset, &offset, &eloff); + bfd_sym_fetch_long (buf, len, offset, &offset, &eloff); fprintf (f, "\n "); - fprintf (f, "offset %lu: ", eloff); + fprintf (f, "offset %lu: ", eloff); bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); } break; @@ -1785,11 +1810,11 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) long value; fprintf (f, "named type (0x%x) ", type); - bfd_sym_fetch_long (buf, len, offset, &offset, &value); + bfd_sym_fetch_long (buf, len, offset, &offset, &value); if (value <= 0) fprintf (f, "[INVALID]"); else - fprintf (f, "\"%.*s\"", + fprintf (f, "\"%.*s\"", bfd_sym_symbol_name (abfd, value)[0], &bfd_sym_symbol_name (abfd, value)[1]); @@ -1802,7 +1827,7 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type); break; } - + if (type == (0x40 | 0x6)) { /* Vector. */ @@ -1810,14 +1835,14 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) long l; long i; - bfd_sym_fetch_long (buf, len, offset, &offset, &n); - bfd_sym_fetch_long (buf, len, offset, &offset, &width); - bfd_sym_fetch_long (buf, len, offset, &offset, &m); + bfd_sym_fetch_long (buf, len, offset, &offset, &n); + bfd_sym_fetch_long (buf, len, offset, &offset, &width); + bfd_sym_fetch_long (buf, len, offset, &offset, &m); /* fprintf (f, "\n "); */ fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m); for (i = 0; i < m; i++) { - bfd_sym_fetch_long (buf, len, offset, &offset, &l); + bfd_sym_fetch_long (buf, len, offset, &offset, &l); if (i != 0) fprintf (f, " "); fprintf (f, "%ld", l); @@ -1828,8 +1853,8 @@ bfd_sym_print_type_information (abfd, f, buf, len, offset, offsetptr) /* Other packed type. */ long msb, lsb; - bfd_sym_fetch_long (buf, len, offset, &offset, &msb); - bfd_sym_fetch_long (buf, len, offset, &offset, &lsb); + bfd_sym_fetch_long (buf, len, offset, &offset, &msb); + bfd_sym_fetch_long (buf, len, offset, &offset, &lsb); /* fprintf (f, "\n "); */ fprintf (f, " msb %ld, lsb %ld", msb, lsb); } @@ -1856,7 +1881,7 @@ bfd_sym_print_type_information_table_entry (abfd, f, entry) entry->nte_index, entry->physical_size, entry->offset, entry->logical_size); - fprintf (f, "\n "); + fprintf (f, "\n "); buf = alloca (entry->physical_size); if (buf == NULL) @@ -1885,7 +1910,7 @@ bfd_sym_print_type_information_table_entry (abfd, f, entry) } fprintf (f, "]"); - fprintf (f, "\n "); + fprintf (f, "\n "); bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset); @@ -1923,16 +1948,16 @@ bfd_sym_display_name_table_entry (abfd, f, entry) BFD_ASSERT (bfd_sym_valid (abfd)); sdata = abfd->tdata.sym_data; index = (entry - sdata->name_table) / 2; - - if ((sdata->version >= BFD_SYM_VERSION_3_4) && (entry[0] == 255) && (entry[1] == 0)) + + if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0) { - unsigned short length = bfd_getb16 (entry + 2); + unsigned short length = bfd_getb16 (entry + 2); fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4); offset = 2 + length + 1; } else { - if (! ((entry[0] == 0) || ((entry[0] == 1) && (entry[1] == '\0')))) + if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0'))) fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1); if (sdata->version >= BFD_SYM_VERSION_3_4) @@ -1959,9 +1984,9 @@ bfd_sym_display_name_table (abfd, f) name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size; name_table = sdata->name_table; name_table_end = name_table + name_table_len; - + fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len); - + cur = name_table; for (;;) { @@ -1985,7 +2010,7 @@ bfd_sym_display_resources_table (abfd, f) fprintf (f, "resource table (RTE) contains %lu objects:\n\n", sdata->header.dshb_rte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++) { if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0) @@ -2061,7 +2086,7 @@ bfd_sym_display_contained_modules_table (abfd, f) FILE *f; { unsigned long i; - bfd_sym_contained_modules_table_entry entry; + bfd_sym_contained_modules_table_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2069,7 +2094,7 @@ bfd_sym_display_contained_modules_table (abfd, f) fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n", sdata->header.dshb_cmte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++) { if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0) @@ -2097,7 +2122,7 @@ bfd_sym_display_contained_variables_table (abfd, f) fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n", sdata->header.dshb_cvte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++) { if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0) @@ -2119,7 +2144,7 @@ bfd_sym_display_contained_statements_table (abfd, f) FILE *f; { unsigned long i; - bfd_sym_contained_statements_table_entry entry; + bfd_sym_contained_statements_table_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2127,7 +2152,7 @@ bfd_sym_display_contained_statements_table (abfd, f) fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n", sdata->header.dshb_csnte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++) { if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0) @@ -2155,7 +2180,7 @@ bfd_sym_display_contained_labels_table (abfd, f) fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n", sdata->header.dshb_clte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++) { if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0) @@ -2175,7 +2200,7 @@ bfd_sym_display_contained_types_table (abfd, f) FILE *f; { unsigned long i; - bfd_sym_contained_types_table_entry entry; + bfd_sym_contained_types_table_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2183,7 +2208,7 @@ bfd_sym_display_contained_types_table (abfd, f) fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n", sdata->header.dshb_ctte.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++) { 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) FILE *f; { unsigned long i; - bfd_sym_file_references_index_table_entry entry; + bfd_sym_file_references_index_table_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2211,7 +2236,7 @@ bfd_sym_display_file_references_index_table (abfd, f) fprintf (f, "file references index table (FITE) contains %lu objects:\n\n", sdata->header.dshb_fite.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++) { if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0) @@ -2231,7 +2256,7 @@ bfd_sym_display_constant_pool (abfd, f) FILE *f; { unsigned long i; - bfd_sym_constant_pool_entry entry; + bfd_sym_constant_pool_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2239,7 +2264,7 @@ bfd_sym_display_constant_pool (abfd, f) fprintf (f, "constant pool (CONST) contains %lu objects:\n\n", sdata->header.dshb_const.dti_object_count); - + for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++) { if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0) @@ -2260,7 +2285,7 @@ bfd_sym_display_type_information_table (abfd, f) { unsigned long i; bfd_sym_type_table_entry index; - bfd_sym_type_information_table_entry entry; + bfd_sym_type_information_table_entry entry; bfd_sym_data_struct *sdata = NULL; BFD_ASSERT (bfd_sym_valid (abfd)); @@ -2274,7 +2299,7 @@ bfd_sym_display_type_information_table (abfd, f) fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n"); return; } - + for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++) { if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0) @@ -2293,65 +2318,75 @@ bfd_sym_display_type_information_table (abfd, f) } } -const bfd_target * -bfd_sym_object_p (abfd) +int +bfd_sym_scan (abfd, version, mdata) bfd *abfd; + bfd_sym_version version; + bfd_sym_data_struct *mdata; { - bfd_sym_data_struct *mdata = NULL; asection *bfdsec; const char *name = "symbols"; - - mdata = ((bfd_sym_data_struct *) - bfd_alloc (abfd, sizeof (bfd_sym_data_struct))); - if (mdata == NULL) - return NULL; - - abfd->tdata.sym_data = mdata; mdata->name_table = 0; mdata->sbfd = abfd; + mdata->version = version; bfd_seek (abfd, 0, SEEK_SET); - if (bfd_sym_read_version (abfd, &mdata->version) != 0) - { - abfd->tdata.sym_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } - - bfd_seek (abfd, 0, SEEK_SET); if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0) - { - abfd->tdata.sym_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + return -1; mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header); if (mdata->name_table == NULL) - { - abfd->tdata.sym_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } + return -1; bfdsec = bfd_make_section_anyway (abfd, name); if (bfdsec == NULL) - { - abfd->tdata.sym_data = NULL; - bfd_set_error (bfd_error_wrong_format); - return NULL; - } - + return -1; + bfdsec->vma = 0; bfdsec->lma = 0; bfdsec->_raw_size = 0; bfdsec->filepos = 0; bfdsec->alignment_power = 0; - + bfdsec->flags = SEC_HAS_CONTENTS; + abfd->tdata.sym_data = mdata; + + return 0; +} + +const bfd_target * +bfd_sym_object_p (abfd) + bfd *abfd; +{ + struct bfd_preserve preserve; + bfd_sym_version version = -1; + + preserve.marker = NULL; + bfd_seek (abfd, 0, SEEK_SET); + if (bfd_sym_read_version (abfd, &version) != 0) + goto wrong; + + preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct)); + if (preserve.marker == NULL + || ! bfd_preserve_save (abfd, &preserve)) + goto fail; + + if (bfd_sym_scan (abfd, version, + (bfd_sym_data_struct *) preserve.marker) != 0) + goto wrong; + + bfd_preserve_finish (abfd, &preserve); return abfd->xvec; + + wrong: + bfd_set_error (bfd_error_wrong_format); + + fail: + if (preserve.marker != NULL) + bfd_preserve_restore (abfd, &preserve); + return NULL; } asymbol * @@ -2443,7 +2478,7 @@ const bfd_target sym_vec = BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), NULL, - + NULL }; @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" @@ -103,7 +103,7 @@ typedef struct bfd_sym_file_reference bfd_sym_file_reference; /* NAME TABLE (NTE). */ /* RESOURCES TABLE (RTE) - + All code and data is *defined* to reside in a resource. Even A5 relative data is defined to reside in a dummy resource of ResType 'gbld'. Code always resides in a resource. Because a code/data @@ -128,7 +128,7 @@ struct bfd_sym_resources_table_entry typedef struct bfd_sym_resources_table_entry bfd_sym_resources_table_entry; /* MODULES TABLE (MTE) - + Modules table entries are ordered by their appearance in a resource. (Note that having a single module copied into two resources is not possible). Modules map back to their resource via an index into the @@ -159,19 +159,19 @@ struct bfd_sym_modules_table_entry unsigned long mte_ctte_index; /* Types contained in this. */ unsigned long mte_csnte_idx_1; /* CSNTE index of mte_snbr_first. */ unsigned long mte_csnte_idx_2; /* CSNTE index of mte_snbr_last. */ -}; +}; typedef struct bfd_sym_modules_table_entry bfd_sym_modules_table_entry; /* FILE REFERENCES TABLE (FRTE) - + The FILE REFERENCES TABLE maps from source file to module & offset. The table is ordered by increasing file offset. Each new offset references a module. - + FRT = FILE_SOURCE_START FILE_SOURCE_INCREMENT* END_OF_LIST. - + *** THIS MECHANISM IS VERY SLOW FOR FILE+STATEMENT_NUMBER TO *** MODULE/CODE ADDRESS OPERATIONS. ANOTHER MECHANISM IS *** REQUIRED!! */ @@ -193,7 +193,7 @@ union bfd_sym_file_references_table_entry unsigned long mod_date; } filename; - + struct { /* < FILE_NAME_INDEX. */ @@ -209,7 +209,7 @@ typedef union bfd_sym_file_references_table_entry bfd_sym_file_references_table_ Contained Modules are lists of indices into the modules table. The lists are terminated by an END_OF_LIST index. All entries are of the same size, hence mapping an index into a CMTE list is simple. - + CMT = MTE_INDEX* END_OF_LIST. */ union bfd_sym_contained_modules_table_entry @@ -220,7 +220,7 @@ union bfd_sym_contained_modules_table_entry unsigned long type; } generic; - + struct { unsigned long mte_index; /* Index into the Modules Table. */ @@ -231,7 +231,7 @@ union bfd_sym_contained_modules_table_entry typedef union bfd_sym_contained_modules_table_entry bfd_sym_contained_modules_table_entry; /* CONTAINED VARIABLES TABLE (CVTE) - + Contained Variables map into the module table, file table, name table, and type table. Contained Variables are a contiguous list of source file change record, 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 table giving the type of the variable, an increment added to the source file offset giving the start of the implementation of the variable, and a storage class address, giving information on variable's runtime address. - + CVT = SOURCE_FILE_CHANGE SYMBOL_INFO* END_OF_LIST. SYMBOL_INFO = SYMBOL_DEFINITION | SOURCE_FILE_CHANGE . - + All entries are of the same size, making the fetching of data simple. The variable entries in the list are in ALPHABETICAL ORDER to simplify the display of available variables for several of the debugger's windows. */ /* 'la_size' determines the variant used below: - + == BFD_SYM_CVTE_SCA Traditional STORAGE_CLASS_ADDRESS; - + <= BFD_SYM_CVTE_LA_MAX_SIZE That many logical address bytes ("in-situ"); - + == BFD_SYM_CVTE_BIG_LA Logical address bytes in constant pool, at offset 'big_la'. */ - + #define BFD_SYM_CVTE_SCA 0 /* Indicate SCA variant of CVTE. */ #define BFD_SYM_CVTE_LA_MAX_SIZE 13 /* Max# of logical address bytes in a CVTE. */ #define BFD_SYM_CVTE_BIG_LA 127 /* Indicates LA redirection to constant pool. */ @@ -322,7 +322,7 @@ union bfd_sym_contained_variables_table_entry typedef union bfd_sym_contained_variables_table_entry bfd_sym_contained_variables_table_entry; /* CONTAINED STATEMENTS TABLE (CSNTE) - + Contained Statements table. This table is similar to the Contained Variables table except that instead of VARIABLE_DEFINITION entries, this 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 All entries are of the same size, making the fetching of data simple. The entries in the table are in order of increasing statement number within the source file. - + The Contained Statements table is indexed from two places. An MTE contains an index to the first statement number within the module. An FRTE contains 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 typedef union bfd_sym_contained_statements_table_entry bfd_sym_contained_statements_table_entry; /* CONTAINED LABELS TABLE (CLTE) - + Contained Labels table names those labels local to the module. It is similar to the Contained Statements table. */ @@ -402,7 +402,7 @@ union bfd_sym_contained_labels_table_entry typedef union bfd_sym_contained_labels_table_entry bfd_sym_contained_labels_table_entry; /* CONTAINED TYPES TABLE (CTTE) - + Contained Types define the named types that are in the module. It is used to map name indices into type indices. The type entries in the table are in alphabetical order by type name. */ @@ -427,7 +427,7 @@ union bfd_sym_contained_types_table_entry struct { /* < SOURCE_FILE_CHANGE. */ - unsigned long tte_index; + unsigned long tte_index; unsigned long nte_index; unsigned long file_delta; /* From last file definition. */ } @@ -451,7 +451,7 @@ struct bfd_sym_type_information_table_entry typedef struct bfd_sym_type_information_table_entry bfd_sym_type_information_table_entry; /* FILE REFERENCES INDEX TABLE (FITE) - + The FRTE INDEX TABLE indexes into the FILE REFERENCE TABLE above. The FRTE at that index is the FILE_SOURCE_START for a series of files. The FRTEs are indexed from 1. The list is terminated with an END_OF_LIST. */ @@ -463,7 +463,7 @@ union bfd_sym_file_references_index_table_entry unsigned long type; } generic; - + struct { unsigned long frte_index; /* Index into the FRTE table. */ @@ -474,15 +474,15 @@ union bfd_sym_file_references_index_table_entry typedef union bfd_sym_file_references_index_table_entry bfd_sym_file_references_index_table_entry; /* CONSTANT POOL (CONST) - + The CONSTANT_POOL consists of entries that start on word boundaries. The entries are referenced by byte index into the constant pool, not by record number. - + Each entry takes the form: - + <16-bit size> <that many bytes of stuff> - + Entries do not cross page boundaries. */ typedef short bfd_sym_constant_pool_entry; @@ -493,7 +493,7 @@ typedef short bfd_sym_constant_pool_entry; allocations. For the purposes of paging, the * file is considered to be an array of dshb_page_size blocks, with block 0 (and * possibly more) devoted to the DISK_SYMBOL_HEADER_BLOCK. - + The dti_object_count field means that the allowed indices for that type of object are 0 .. dti_object_count. An index of 0, although allowed, is never done. However, an 0th entry is created in the @@ -510,7 +510,7 @@ struct bfd_sym_table_info }; typedef struct bfd_sym_table_info bfd_sym_table_info; -struct bfd_sym_header_block +struct bfd_sym_header_block { unsigned char dshb_id[32]; /* Version information. */ unsigned short dshb_page_size; /* Size of the pages/blocks. */ @@ -683,6 +683,8 @@ extern void bfd_sym_display_constant_pool PARAMS ((bfd *, FILE *)); extern void bfd_sym_display_type_information_table PARAMS ((bfd *, FILE *)); +extern int bfd_sym_scan + PARAMS ((bfd *, bfd_sym_version, bfd_sym_data_struct *)); extern const bfd_target * bfd_sym_object_p PARAMS ((bfd *)); extern asymbol * bfd_sym_make_empty_symbol |