static bfd_boolean nlm_alpha_backend_object_p (bfd *abfd) { struct nlm32_alpha_external_prefix_header s; file_ptr size; if (bfd_bread (&s, (bfd_size_type) sizeof s, abfd) != sizeof s) return FALSE; if (H_GET_32 (abfd, s.magic) != NLM32_ALPHA_MAGIC) return FALSE; /* FIXME: Should we check the format number? */ /* Skip to the end of the header. */ size = H_GET_32 (abfd, s.size); if (bfd_seek (abfd, size, SEEK_SET) != 0) return FALSE; return TRUE; }
static bfd_boolean nlm_powerpc_backend_object_p (bfd *abfd) { struct nlm32_powerpc_external_prefix_header s; if (bfd_bread (& s, (bfd_size_type) sizeof s, abfd) != sizeof s) return FALSE; if (memcmp (s.signature, NLM32_POWERPC_SIGNATURE, sizeof s.signature) != 0 || H_GET_32 (abfd, s.headerVersion) != NLM32_POWERPC_HEADER_VERSION) return FALSE; return TRUE; }
/* Swaps the information in an executable header taken from a raw byte stream memory image, into the internal exec_header structure. */ static bfd_boolean os9k_swap_exec_header_in (bfd *abfd, mh_com *raw_bytes, struct internal_exec *execp) { mh_com *bytes = (mh_com *) raw_bytes; unsigned int dload, dmemsize, dmemstart; /* Now fill in fields in the execp, from the bytes in the raw data. */ execp->a_info = H_GET_16 (abfd, bytes->m_sync); execp->a_syms = 0; execp->a_entry = H_GET_32 (abfd, bytes->m_exec); execp->a_talign = 2; execp->a_dalign = 2; execp->a_balign = 2; dload = H_GET_32 (abfd, bytes->m_idata); execp->a_data = dload + 8; if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0 || (bfd_bread (&dmemstart, (bfd_size_type) sizeof (dmemstart), abfd) != sizeof (dmemstart)) || (bfd_bread (&dmemsize, (bfd_size_type) sizeof (dmemsize), abfd) != sizeof (dmemsize))) return FALSE; execp->a_tload = 0; execp->a_dload = H_GET_32 (abfd, (unsigned char *) &dmemstart); execp->a_text = dload - execp->a_tload; execp->a_data = H_GET_32 (abfd, (unsigned char *) &dmemsize); execp->a_bss = H_GET_32 (abfd, bytes->m_data) - execp->a_data; execp->a_trsize = 0; execp->a_drsize = 0; return TRUE; }
static void aout_adobe_swap_exec_header_in (bfd *abfd, struct external_exec *bytes, struct internal_exec *execp) { /* Now fill in fields in the execp, from the bytes in the raw data. */ execp->a_info = H_GET_32 (abfd, bytes->e_info); execp->a_text = GET_WORD (abfd, bytes->e_text); execp->a_data = GET_WORD (abfd, bytes->e_data); execp->a_bss = GET_WORD (abfd, bytes->e_bss); execp->a_syms = GET_WORD (abfd, bytes->e_syms); execp->a_entry = GET_WORD (abfd, bytes->e_entry); execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); }
static const bfd_target * aout_adobe_object_p (bfd *abfd) { struct internal_exec anexec; struct external_exec exec_bytes; char *targ; bfd_size_type amt = EXEC_BYTES_SIZE; if (bfd_bread (& exec_bytes, amt, abfd) != amt) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } anexec.a_info = H_GET_32 (abfd, exec_bytes.e_info); /* Normally we just compare for the magic number. However, a bunch of Adobe tools aren't fixed up yet; they generate files using ZMAGIC(!). If the environment variable GNUTARGET is set to "a.out.adobe", we will take just about any a.out file as an Adobe a.out file. FIXME! */ if (N_BADMAG (anexec)) { targ = getenv ("GNUTARGET"); if (targ && !strcmp (targ, a_out_adobe_vec.name)) /* Just continue anyway, if specifically set to this format. */ ; else { bfd_set_error (bfd_error_wrong_format); return NULL; } } aout_adobe_swap_exec_header_in (abfd, &exec_bytes, &anexec); return aout_32_some_aout_object_p (abfd, &anexec, aout_adobe_callback); }
static void mips_ecoff_swap_reloc_in (bfd * abfd, void * ext_ptr, struct internal_reloc *intern) { const RELOC *ext = (RELOC *) ext_ptr; intern->r_vaddr = H_GET_32 (abfd, ext->r_vaddr); if (bfd_header_big_endian (abfd)) { intern->r_symndx = (((int) ext->r_bits[0] << RELOC_BITS0_SYMNDX_SH_LEFT_BIG) | ((int) ext->r_bits[1] << RELOC_BITS1_SYMNDX_SH_LEFT_BIG) | ((int) ext->r_bits[2] << RELOC_BITS2_SYMNDX_SH_LEFT_BIG)); intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG) >> RELOC_BITS3_TYPE_SH_BIG); intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0; } else {
void i386dynix_32_swap_exec_header_in (bfd *abfd, struct external_exec *raw_bytes, struct internal_exec *execp) { struct external_exec *bytes = (struct external_exec *)raw_bytes; /* The internal_exec structure has some fields that are unused in this configuration (IE for i960), so ensure that all such uninitialized fields are zero'd out. There are places where two of these structs are memcmp'd, and thus the contents do matter. */ memset (execp, 0, sizeof (struct internal_exec)); /* Now fill in fields in the execp, from the bytes in the raw data. */ execp->a_info = H_GET_32 (abfd, bytes->e_info); execp->a_text = GET_WORD (abfd, bytes->e_text); execp->a_data = GET_WORD (abfd, bytes->e_data); execp->a_bss = GET_WORD (abfd, bytes->e_bss); execp->a_syms = GET_WORD (abfd, bytes->e_syms); execp->a_entry = GET_WORD (abfd, bytes->e_entry); execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); execp->a_drsize = GET_WORD (abfd, bytes->e_drsize); execp->a_shdata = GET_WORD (abfd, bytes->e_shdata); execp->a_shdrsize = GET_WORD (abfd, bytes->e_shdrsize); }
static const bfd_target * aout_adobe_callback (bfd *abfd) { struct internal_exec *execp = exec_hdr (abfd); asection *sect; struct external_segdesc ext[1]; char *section_name; char try_again[30]; /* Name and number. */ char *newname; int trynum; flagword flags; /* Architecture and machine type -- unknown in this format. */ bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L); /* The positions of the string table and symbol table. */ obj_str_filepos (abfd) = N_STROFF (*execp); obj_sym_filepos (abfd) = N_SYMOFF (*execp); /* Suck up the section information from the file, one section at a time. */ for (;;) { bfd_size_type amt = sizeof (*ext); if (bfd_bread ( ext, amt, abfd) != amt) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } switch (ext->e_type[0]) { case N_TEXT: section_name = ".text"; flags = SEC_CODE | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS; break; case N_DATA: section_name = ".data"; flags = SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS; break; case N_BSS: section_name = ".bss"; flags = SEC_DATA | SEC_HAS_CONTENTS; break; case 0: goto no_more_sections; default: (*_bfd_error_handler) (_("%B: Unknown section type in a.out.adobe file: %x\n"), abfd, ext->e_type[0]); goto no_more_sections; } /* First one is called ".text" or whatever; subsequent ones are ".text1", ".text2", ... */ bfd_set_error (bfd_error_no_error); sect = bfd_make_section_with_flags (abfd, section_name, flags); trynum = 0; while (!sect) { if (bfd_get_error () != bfd_error_no_error) /* Some other error -- slide into the sunset. */ return NULL; sprintf (try_again, "%s%d", section_name, ++trynum); sect = bfd_make_section_with_flags (abfd, try_again, flags); } /* Fix the name, if it is a sprintf'd name. */ if (sect->name == try_again) { amt = strlen (sect->name); newname = bfd_zalloc (abfd, amt); if (newname == NULL) return NULL; strcpy (newname, sect->name); sect->name = newname; } /* Assumed big-endian. */ sect->size = ((ext->e_size[0] << 8) | ext->e_size[1] << 8 | ext->e_size[2]); sect->vma = H_GET_32 (abfd, ext->e_virtbase); sect->filepos = H_GET_32 (abfd, ext->e_filebase); /* FIXME XXX alignment? */ /* Set relocation information for first section of each type. */ if (trynum == 0) switch (ext->e_type[0]) { case N_TEXT: sect->rel_filepos = N_TRELOFF (*execp); sect->reloc_count = execp->a_trsize; break; case N_DATA: sect->rel_filepos = N_DRELOFF (*execp); sect->reloc_count = execp->a_drsize; break; default: break; } } no_more_sections: adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external); adata (abfd).symbol_entry_size = sizeof (struct external_nlist); adata (abfd).page_size = 1; /* Not applicable. */ adata (abfd).segment_size = 1; /* Not applicable. */ adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return abfd->xvec; }
static bfd_boolean oasys_slurp_symbol_table (bfd *const abfd) { oasys_record_union_type record; oasys_data_type *data = OASYS_DATA (abfd); bfd_boolean loop = TRUE; asymbol *dest_defined; asymbol *dest; char *string_ptr; bfd_size_type amt; if (data->symbols != NULL) return TRUE; /* Buy enough memory for all the symbols and all the names. */ amt = abfd->symcount; amt *= sizeof (asymbol); data->symbols = bfd_alloc (abfd, amt); amt = data->symbol_string_length; #ifdef UNDERSCORE_HACK /* Buy 1 more char for each symbol to keep the underscore in. */ amt += abfd->symcount; #endif data->strings = bfd_alloc (abfd, amt); if (!data->symbols || !data->strings) return FALSE; dest_defined = data->symbols + abfd->symcount - 1; string_ptr = data->strings; if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) return FALSE; while (loop) { if (! oasys_read_record (abfd, &record)) return FALSE; switch (record.header.type) { case oasys_record_is_header_enum: break; case oasys_record_is_local_enum: case oasys_record_is_symbol_enum: { int flag = record.header.type == (int) oasys_record_is_local_enum ? (BSF_LOCAL) : (BSF_GLOBAL | BSF_EXPORT); size_t length = oasys_string_length (&record); switch (record.symbol.relb & RELOCATION_TYPE_BITS) { case RELOCATION_TYPE_ABS: dest = dest_defined--; dest->section = bfd_abs_section_ptr; dest->flags = 0; break; case RELOCATION_TYPE_REL: dest = dest_defined--; dest->section = OASYS_DATA (abfd)->sections[record.symbol.relb & RELOCATION_SECT_BITS]; if (record.header.type == (int) oasys_record_is_local_enum) { dest->flags = BSF_LOCAL; if (dest->section == (asection *) (~0)) { /* It seems that sometimes internal symbols are tied up, but still get output, even though there is no section */ dest->section = 0; } } else dest->flags = flag; break; case RELOCATION_TYPE_UND: dest = data->symbols + H_GET_16 (abfd, record.symbol.refno); dest->section = bfd_und_section_ptr; break; case RELOCATION_TYPE_COM: dest = dest_defined--; dest->name = string_ptr; dest->the_bfd = abfd; dest->section = bfd_com_section_ptr; break; default: dest = dest_defined--; BFD_ASSERT (FALSE); break; } dest->name = string_ptr; dest->the_bfd = abfd; dest->udata.p = NULL; dest->value = H_GET_32 (abfd, record.symbol.value); #ifdef UNDERSCORE_HACK if (record.symbol.name[0] != '_') { string_ptr[0] = '_'; string_ptr++; } #endif memcpy (string_ptr, record.symbol.name, length); string_ptr[length] = 0; string_ptr += length + 1; } break; default: loop = FALSE; } } return TRUE; }
static bfd_boolean oasys_slurp_section_data (bfd *const abfd) { oasys_record_union_type record; oasys_data_type *data = OASYS_DATA (abfd); bfd_boolean loop = TRUE; oasys_per_section_type *per; asection *s; bfd_size_type amt; /* See if the data has been slurped already. */ for (s = abfd->sections; s != NULL; s = s->next) { per = oasys_per_section (s); if (per->initialized) return TRUE; } if (data->first_data_record == 0) return TRUE; if (bfd_seek (abfd, data->first_data_record, SEEK_SET) != 0) return FALSE; while (loop) { if (! oasys_read_record (abfd, &record)) return FALSE; switch (record.header.type) { case oasys_record_is_header_enum: break; case oasys_record_is_data_enum: { bfd_byte *src = record.data.data; bfd_byte *end_src = ((bfd_byte *) & record) + record.header.length; bfd_byte *dst_ptr; bfd_byte *dst_base_ptr; unsigned int relbit; unsigned int count; asection *section = data->sections[record.data.relb & RELOCATION_SECT_BITS]; bfd_vma dst_offset; per = oasys_per_section (section); if (! per->initialized) { arelent **relpp; per->data = bfd_zalloc (abfd, section->size); if (!per->data) return FALSE; relpp = §ion->relocation; per->reloc_tail_ptr = (oasys_reloc_type **) relpp; per->had_vma = FALSE; per->initialized = TRUE; section->reloc_count = 0; section->flags = SEC_ALLOC; } dst_offset = H_GET_32 (abfd, record.data.addr); if (! per->had_vma) { /* Take the first vma we see as the base. */ section->vma = dst_offset; per->had_vma = TRUE; } dst_offset -= section->vma; dst_base_ptr = oasys_per_section (section)->data; dst_ptr = oasys_per_section (section)->data + dst_offset; if (src < end_src) section->flags |= SEC_LOAD | SEC_HAS_CONTENTS; while (src < end_src) { unsigned char mod_byte = *src++; size_t gap = end_src - src; count = 8; if (mod_byte == 0 && gap >= 8) { dst_ptr[0] = src[0]; dst_ptr[1] = src[1]; dst_ptr[2] = src[2]; dst_ptr[3] = src[3]; dst_ptr[4] = src[4]; dst_ptr[5] = src[5]; dst_ptr[6] = src[6]; dst_ptr[7] = src[7]; dst_ptr += 8; src += 8; } else { for (relbit = 1; count-- != 0 && src < end_src; relbit <<= 1) { if (relbit & mod_byte) { unsigned char reloc = *src; /* This item needs to be relocated. */ switch (reloc & RELOCATION_TYPE_BITS) { case RELOCATION_TYPE_ABS: break; case RELOCATION_TYPE_REL: { /* Relocate the item relative to the section. */ oasys_reloc_type *r; amt = sizeof (oasys_reloc_type); r = bfd_alloc (abfd, amt); if (!r) return FALSE; *(per->reloc_tail_ptr) = r; per->reloc_tail_ptr = &r->next; r->next = NULL; /* Reference to undefined symbol. */ src++; /* There is no symbol. */ r->symbol = 0; /* Work out the howto. */ abort (); r->relent.address = dst_ptr - dst_base_ptr; r->relent.howto = &howto_table[reloc >> 6]; r->relent.sym_ptr_ptr = NULL; section->reloc_count++; /* Fake up the data to look like it's got the -ve pc in it, this makes it much easier to convert into other formats. This is done by hitting the addend. */ if (r->relent.howto->pc_relative) r->relent.addend -= dst_ptr - dst_base_ptr; } break; case RELOCATION_TYPE_UND: { oasys_reloc_type *r; amt = sizeof (oasys_reloc_type); r = bfd_alloc (abfd, amt); if (!r) return FALSE; *(per->reloc_tail_ptr) = r; per->reloc_tail_ptr = &r->next; r->next = NULL; /* Reference to undefined symbol. */ src++; /* Get symbol number. */ r->symbol = (src[0] << 8) | src[1]; /* Work out the howto. */ abort (); r->relent.addend = 0; r->relent.address = dst_ptr - dst_base_ptr; r->relent.howto = &howto_table[reloc >> 6]; r->relent.sym_ptr_ptr = NULL; section->reloc_count++; src += 2; /* Fake up the data to look like it's got the -ve pc in it, this makes it much easier to convert into other formats. This is done by hitting the addend. */ if (r->relent.howto->pc_relative) r->relent.addend -= dst_ptr - dst_base_ptr; } break; case RELOCATION_TYPE_COM: BFD_FAIL (); } } *dst_ptr++ = *src++; } } } } break; case oasys_record_is_local_enum: case oasys_record_is_symbol_enum: case oasys_record_is_section_enum: break; default: loop = FALSE; } }
static const bfd_target * oasys_archive_p (bfd *abfd) { oasys_archive_header_type header; oasys_extarchive_header_type header_ext; unsigned int i; file_ptr filepos; bfd_size_type amt; amt = sizeof (header_ext); if (bfd_seek (abfd, (file_ptr) 0, 0) != 0 || bfd_bread ((void *) &header_ext, amt, abfd) != amt) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } header.version = H_GET_32 (abfd, header_ext.version); header.mod_count = H_GET_32 (abfd, header_ext.mod_count); header.mod_tbl_offset = H_GET_32 (abfd, header_ext.mod_tbl_offset); header.sym_tbl_size = H_GET_32 (abfd, header_ext.sym_tbl_size); header.sym_count = H_GET_32 (abfd, header_ext.sym_count); header.sym_tbl_offset = H_GET_32 (abfd, header_ext.sym_tbl_offset); header.xref_count = H_GET_32 (abfd, header_ext.xref_count); header.xref_lst_offset = H_GET_32 (abfd, header_ext.xref_lst_offset); /* There isn't a magic number in an Oasys archive, so the best we can do to verify reasonableness is to make sure that the values in the header are too weird. */ if (header.version > 10000 || header.mod_count > 10000 || header.sym_count > 100000 || header.xref_count > 100000) return NULL; /* That all worked, let's buy the space for the header and read in the headers. */ { oasys_ar_data_type *ar; oasys_module_info_type *module; oasys_module_table_type record; amt = sizeof (oasys_ar_data_type); ar = bfd_alloc (abfd, amt); amt = header.mod_count; amt *= sizeof (oasys_module_info_type); module = bfd_alloc (abfd, amt); if (!ar || !module) return NULL; abfd->tdata.oasys_ar_data = ar; ar->module = module; ar->module_count = header.mod_count; filepos = header.mod_tbl_offset; for (i = 0; i < header.mod_count; i++) { if (bfd_seek (abfd, filepos, SEEK_SET) != 0) return NULL; /* There are two ways of specifying the archive header. */ { oasys_extmodule_table_type_b_type record_ext; amt = sizeof (record_ext); if (bfd_bread ((void *) &record_ext, amt, abfd) != amt) return NULL; record.mod_size = H_GET_32 (abfd, record_ext.mod_size); record.file_offset = H_GET_32 (abfd, record_ext.file_offset); record.dep_count = H_GET_32 (abfd, record_ext.dep_count); record.depee_count = H_GET_32 (abfd, record_ext.depee_count); record.sect_count = H_GET_32 (abfd, record_ext.sect_count); record.module_name_size = H_GET_32 (abfd, record_ext.mod_name_length); amt = record.module_name_size; module[i].name = bfd_alloc (abfd, amt + 1); if (!module[i].name) return NULL; if (bfd_bread ((void *) module[i].name, amt, abfd) != amt) return NULL; module[i].name[record.module_name_size] = 0; filepos += (sizeof (record_ext) + record.dep_count * 4 + record.module_name_size + 1); } module[i].size = record.mod_size; module[i].pos = record.file_offset; module[i].abfd = 0; } } return abfd->xvec; }