📄 riscix.c
字号:
check for that here */ if (bfd_is_com_section (output_section) || output_section == &bfd_abs_section || output_section == &bfd_und_section) { if (bfd_abs_section.symbol == sym) { /* Whoops, looked like an abs symbol, but is really an offset from the abs section */ r_index = 0; r_extern = 0; } else { /* Fill in symbol */ r_extern = 1; r_index = (*g->sym_ptr_ptr)->udata.i; } } else { /* Just an ordinary section */ r_extern = 0; r_index = output_section->target_index; } /* now the fun stuff */ if (bfd_header_big_endian (abfd)) { natptr->r_index[0] = r_index >> 16; natptr->r_index[1] = r_index >> 8; natptr->r_index[2] = r_index; natptr->r_type[0] = ( (r_extern ? RELOC_STD_BITS_EXTERN_BIG: 0) | (r_pcrel ? RELOC_STD_BITS_PCREL_BIG: 0) | (r_neg ? RELOC_STD_BITS_BASEREL_BIG: 0) | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG)); } else { natptr->r_index[2] = r_index >> 16; natptr->r_index[1] = r_index >> 8; natptr->r_index[0] = r_index; natptr->r_type[0] = ( (r_extern ? RELOC_STD_BITS_EXTERN_LITTLE: 0) | (r_pcrel ? RELOC_STD_BITS_PCREL_LITTLE: 0) | (r_neg ? RELOC_STD_BITS_BASEREL_LITTLE: 0) | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE)); }}booleanriscix_squirt_out_relocs (abfd, section) bfd *abfd; asection *section;{ arelent **generic; unsigned char *native, *natptr; size_t each_size; unsigned int count = section->reloc_count; size_t natsize; if (count == 0) return true; each_size = obj_reloc_entry_size (abfd); natsize = each_size * count; native = (unsigned char *) bfd_zalloc (abfd, natsize); if (!native) return false; generic = section->orelocation; for (natptr = native; count != 0; --count, natptr += each_size, ++generic) riscix_swap_std_reloc_out (abfd, *generic, (struct reloc_std_external *) natptr); if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { bfd_release(abfd, native); return false; } bfd_release (abfd, native); return true;}/* * This is just like the standard aoutx.h version but we need to do our * own mapping of external reloc type values to howto entries. */longMY(canonicalize_reloc) (abfd, section, relptr, symbols) bfd *abfd; sec_ptr section; arelent **relptr; asymbol **symbols;{ arelent *tblptr = section->relocation; unsigned int count, c; extern reloc_howto_type NAME(aout,std_howto_table)[]; /* If we have already read in the relocation table, return the values. */ if (section->flags & SEC_CONSTRUCTOR) { arelent_chain *chain = section->constructor_chain; for (count = 0; count < section->reloc_count; count++) { *relptr++ = &chain->relent; chain = chain->next; } *relptr = 0; return section->reloc_count; } if (tblptr && section->reloc_count) { for (count = 0; count++ < section->reloc_count;) *relptr++ = tblptr++; *relptr = 0; return section->reloc_count; } if (!NAME(aout,slurp_reloc_table) (abfd, section, symbols)) return -1; tblptr = section->relocation; /* fix up howto entries */ for (count = 0; count++ < section->reloc_count;) { c = tblptr->howto - NAME(aout,std_howto_table); BFD_ASSERT (c < RISCIX_TABLE_SIZE); tblptr->howto = &riscix_std_reloc_howto[c]; *relptr++ = tblptr++; } *relptr = 0; return section->reloc_count;}/* This is the same as NAME(aout,some_aout_object_p), but has different expansions of the macro definitions. */const bfd_target *riscix_some_aout_object_p (abfd, execp, callback_to_real_object_p) bfd *abfd; struct internal_exec *execp; const bfd_target *(*callback_to_real_object_p) PARAMS ((bfd *));{ struct aout_data_struct *rawptr, *oldrawptr; const bfd_target *result; rawptr = ((struct aout_data_struct *) bfd_zalloc (abfd, sizeof (struct aout_data_struct ))); if (rawptr == NULL) return 0; oldrawptr = abfd->tdata.aout_data; abfd->tdata.aout_data = rawptr; /* Copy the contents of the old tdata struct. In particular, we want the subformat, since for hpux it was set in hp300hpux.c:swap_exec_header_in and will be used in hp300hpux.c:callback. */ if (oldrawptr != NULL) *abfd->tdata.aout_data = *oldrawptr; abfd->tdata.aout_data->a.hdr = &rawptr->e; *(abfd->tdata.aout_data->a.hdr) = *execp; /* Copy in the internal_exec struct */ execp = abfd->tdata.aout_data->a.hdr; /* Set the file flags */ abfd->flags = BFD_NO_FLAGS; if (execp->a_drsize || execp->a_trsize) abfd->flags |= HAS_RELOC; /* Setting of EXEC_P has been deferred to the bottom of this function */ if (execp->a_syms) abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS; if (N_DYNAMIC(*execp)) abfd->flags |= DYNAMIC; if ((execp->a_info & MF_SQUEEZED) != 0) /* Squeezed files aren't supported (yet)! */ { bfd_set_error (bfd_error_wrong_format); return NULL; } else if ((execp->a_info & MF_IS_SL) != 0) /* Nor are shared libraries */ { bfd_set_error (bfd_error_wrong_format); return NULL; } else if (N_MAGIC (*execp) == ZMAGIC) { abfd->flags |= D_PAGED | WP_TEXT; adata (abfd).magic = z_magic; } else if (N_MAGIC (*execp) == NMAGIC) { abfd->flags |= WP_TEXT; adata (abfd).magic = n_magic; } else if (N_MAGIC (*execp) == OMAGIC) adata (abfd).magic = o_magic; else { /* Should have been checked with N_BADMAG before this routine was called. */ abort (); } bfd_get_start_address (abfd) = execp->a_entry; obj_aout_symbols (abfd) = (aout_symbol_type *)NULL; bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist); /* The default relocation entry size is that of traditional V7 Unix. */ obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; /* The default symbol entry size is that of traditional Unix. */ obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE; obj_aout_external_syms (abfd) = NULL; obj_aout_external_strings (abfd) = NULL; obj_aout_sym_hashes (abfd) = NULL; if (! NAME(aout,make_sections) (abfd)) return NULL; obj_datasec (abfd)->_raw_size = execp->a_data; obj_bsssec (abfd)->_raw_size = execp->a_bss; obj_textsec (abfd)->flags = (execp->a_trsize != 0 ? (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_RELOC) : (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)); obj_datasec (abfd)->flags = (execp->a_drsize != 0 ? (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS | SEC_RELOC) : (SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS)); obj_bsssec (abfd)->flags = SEC_ALLOC; result = (*callback_to_real_object_p) (abfd);#if defined(MACH) || defined(STAT_FOR_EXEC) /* The original heuristic doesn't work in some important cases. The * a.out file has no information about the text start address. For * files (like kernels) linked to non-standard addresses (ld -Ttext * nnn) the entry point may not be between the default text start * (obj_textsec(abfd)->vma) and (obj_textsec(abfd)->vma) + text size * This is not just a mach issue. Many kernels are loaded at non * standard addresses. */ { struct stat stat_buf; if (abfd->iostream != NULL && (abfd->flags & BFD_IN_MEMORY) == 0 && (fstat(fileno((FILE *) (abfd->iostream)), &stat_buf) == 0) && ((stat_buf.st_mode & 0111) != 0)) abfd->flags |= EXEC_P; }#else /* ! MACH */ /* Now that the segment addresses have been worked out, take a better guess at whether the file is executable. If the entry point is within the text segment, assume it is. (This makes files executable even if their entry point address is 0, as long as their text starts at zero.) At some point we should probably break down and stat the file and declare it executable if (one of) its 'x' bits are on... */ if ((execp->a_entry >= obj_textsec(abfd)->vma) && (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size)) abfd->flags |= EXEC_P;#endif /* MACH */ if (result) { } else { free (rawptr); abfd->tdata.aout_data = oldrawptr; } return result;}static const bfd_target *MY(object_p) (abfd) bfd *abfd;{ struct external_exec exec_bytes; /* Raw exec header from file */ struct internal_exec exec; /* Cleaned-up exec header */ const bfd_target *target; if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd) != EXEC_BYTES_SIZE) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return 0; } exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info); if (N_BADMAG (exec)) return 0;#ifdef MACHTYPE_OK if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;#endif NAME(aout,swap_exec_header_in) (abfd, &exec_bytes, &exec); target = riscix_some_aout_object_p (abfd, &exec, MY(callback)); return target;}#include "aout-target.h"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -