📄 bout.c
字号:
}static int DEFUN(b_out_sizeof_headers,(ignore_abfd, ignore), bfd *ignore_abfd AND boolean ignore){ return sizeof(struct internal_exec);}/************************************************************************/static bfd_vma DEFUN(get_value,(reloc, seclet), arelent *reloc AND bfd_seclet_type *seclet){ bfd_vma value; asymbol *symbol = *(reloc->sym_ptr_ptr); /* A symbol holds a pointer to a section, and an offset from the base of the section. To relocate, we find where the section will live in the output and add that in */ if (symbol->section == &bfd_und_section) { /* Ouch, this is an undefined symbol.. */ bfd_error_vector.undefined_symbol(reloc, seclet); value = symbol->value; } else { value = symbol->value + symbol->section->output_offset + symbol->section->output_section->vma; } /* Add the value contained in the relocation */ value += (short)((reloc->addend) & 0xffff); return value;}static voidDEFUN(perform_slip,(s, slip, input_section, value), asymbol **s AND unsigned int slip AND asection *input_section AND bfd_vma value){ /* Find all symbols past this point, and make them know what's happened */ while (*s) { asymbol *p = *s; if (p->section == input_section) { /* This was pointing into this section, so mangle it */ if (p->value > value) { p->value -=slip; } } s++; } }#if 1/* This routine works out if the thing we want to get to can be reached with a 24bit offset instead of a 32 bit one. If it can, then it changes the amode */static int DEFUN(abs32code,(input_section, symbols, r, shrink), asection *input_section AND asymbol **symbols AND arelent *r AND unsigned int shrink) { bfd_vma value = get_value(r,0); bfd_vma dot = input_section->output_section->vma + input_section->output_offset + r->address; bfd_vma gap; /* See if the address we're looking at within 2^23 bytes of where we are, if so then we can use a small branch rather than the jump we were going to */ gap = value - (dot - shrink); if (-1<<23 < (long)gap && (long)gap < 1<<23 ) { /* Change the reloc type from 32bitcode possible 24, to 24bit possible 32 */ r->howto = &howto_reloc_abs32codeshrunk; /* The place to relc moves back by four bytes */ r->address -=4; /* This will be four bytes smaller in the long run */ shrink += 4 ; perform_slip(symbols, 4, input_section, r->address-shrink +4); } return shrink; }static int DEFUN(aligncode,(input_section, symbols, r, shrink), asection *input_section AND asymbol **symbols AND arelent *r AND unsigned int shrink) { bfd_vma dot = input_section->output_section->vma + input_section->output_offset + r->address; bfd_vma gap; bfd_vma old_end; bfd_vma new_end; int shrink_delta; int size = r->howto->size; /* Reduce the size of the alignment so that it's still aligned but smaller - the current size is already the same size as or bigger than the alignment required. */ /* calculate the first byte following the padding before we optimize */ old_end = ((dot + size ) & ~size) + size+1; /* work out where the new end will be - remember that we're smaller than we used to be */ new_end = ((dot - shrink + size) & ~size); /* This is the new end */ gap = old_end - ((dot + size) & ~size); shrink_delta = (old_end - new_end) - shrink; if (shrink_delta) { /* Change the reloc so that it knows how far to align to */ r->howto = howto_done_align_table + (r->howto - howto_align_table); /* Encode the stuff into the addend - for future use we need to know how big the reloc used to be */ r->addend = old_end ; /* This will be N bytes smaller in the long run, adjust all the symbols */ perform_slip(symbols, shrink_delta, input_section, r->address - shrink ); shrink += shrink_delta; } return shrink; }static boolean DEFUN(b_out_relax_section,(abfd, i, symbols), bfd *abfd AND asection *i AND asymbol **symbols){ /* Get enough memory to hold the stuff */ bfd *input_bfd = i->owner; asection *input_section = i; int shrink = 0 ; boolean new = false; bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd, input_section); arelent **reloc_vector = (arelent **)alloca(reloc_size); /* Get the relocs and think about them */ if (bfd_canonicalize_reloc(input_bfd, input_section, reloc_vector, symbols)) { arelent **parent; for (parent = reloc_vector; *parent; parent++) { arelent *r = *parent; switch (r->howto->type) { case ALIGNER: /* An alignment reloc */ shrink = aligncode(input_section, symbols, r,shrink); new=true; break; case ABS32CODE: /* A 32bit reloc in an addressing mode */ shrink = abs32code(input_section, symbols, r,shrink); new=true; break; case ABS32CODE_SHRUNK: shrink+=4; break; } } } input_section->_cooked_size = input_section->_raw_size - shrink; return new;}#endifstatic bfd_byte *DEFUN(b_out_get_relocated_section_contents,(in_abfd, seclet, data), bfd *in_abfd AND bfd_seclet_type *seclet AND bfd_byte *data){ /* Get enough memory to hold the stuff */ bfd *input_bfd = seclet->u.indirect.section->owner; asection *input_section = seclet->u.indirect.section; bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd, input_section); arelent **reloc_vector = (arelent **)alloca(reloc_size); /* read in the section */ bfd_get_section_contents(input_bfd, input_section, data, 0, input_section->_raw_size); if (bfd_canonicalize_reloc(input_bfd, input_section, reloc_vector, seclet->u.indirect.symbols) ) { arelent **parent = reloc_vector; arelent *reloc ; unsigned int dst_address = 0; unsigned int src_address = 0; unsigned int run; unsigned int idx; /* Find how long a run we can do */ while (dst_address < seclet->size) { reloc = *parent; if (reloc) { /* Note that the relaxing didn't tie up the addresses in the relocation, so we use the original address to work out the run of non-relocated data */ run = reloc->address - src_address; parent++; } else { run = seclet->size - dst_address; } /* Copy the bytes */ for (idx = 0; idx < run; idx++) { data[dst_address++] = data[src_address++]; } /* Now do the relocation */ if (reloc) { switch (reloc->howto->type) { case ABS32CODE: calljx_callback(in_abfd, reloc, src_address + data, dst_address+data, input_section); src_address+=4; dst_address+=4; break; case ABS32: bfd_put_32(in_abfd, get_value(reloc, seclet), data+dst_address); src_address+=4; dst_address+=4; break; case CALLJ: callj_callback(in_abfd, reloc ,data,src_address,dst_address,input_section); src_address+=4; dst_address+=4; break; case ALIGNDONE: src_address = reloc->addend; dst_address = (dst_address + reloc->howto->size) & ~reloc->howto->size; break; case ABS32CODE_SHRUNK: /* This used to be a callx, but we've found out that a callj will reach, so do the right thing */ callj_callback(in_abfd, reloc,data,src_address+4, dst_address,input_section); dst_address+=4; src_address+=8; break; case PCREL24: { long int word = bfd_get_32(in_abfd, data+src_address); asymbol *symbol = *(reloc->sym_ptr_ptr); word = (word & ~BAL_MASK) | (((word & BAL_MASK) + symbol->section->output_offset + symbol->section->output_section->vma+ symbol->value + reloc->addend - dst_address - ( input_section->output_section->vma + input_section->output_offset)) & BAL_MASK); bfd_put_32(in_abfd,word, data+dst_address); dst_address+=4; src_address+=4; } break; case PCREL13: { long int word = bfd_get_32(in_abfd, data+src_address); asymbol *symbol = *(reloc->sym_ptr_ptr); word = (word & ~PCREL13_MASK) | (((word & PCREL13_MASK) + symbol->section->output_offset + symbol->section->output_section->vma+ symbol->value + reloc->addend - dst_address - ( input_section->output_section->vma + input_section->output_offset)) & PCREL13_MASK); bfd_put_32(in_abfd,word, data+dst_address); dst_address+=4; src_address+=4; } break; default: abort(); } } } } return data;}/***********************************************************************//* Build the transfer vectors for Big and Little-Endian B.OUT files. *//* We don't have core files. */#define aout_32_core_file_failing_command _bfd_dummy_core_file_failing_command#define aout_32_core_file_failing_signal _bfd_dummy_core_file_failing_signal#define aout_32_core_file_matches_executable_p \ _bfd_dummy_core_file_matches_executable_p/* We use BSD-Unix generic archive files. */#define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file#define aout_32_generic_stat_arch_elt bfd_generic_stat_arch_elt#define aout_32_slurp_armap bfd_slurp_bsd_armap#define aout_32_slurp_extended_name_table bfd_true#define aout_32_write_armap bsd_write_armap#define aout_32_truncate_arname bfd_bsd_truncate_arname/* We override these routines from the usual a.out file routines. */#define aout_32_canonicalize_reloc b_out_canonicalize_reloc#define aout_32_get_reloc_upper_bound b_out_get_reloc_upper_bound#define aout_32_set_section_contents b_out_set_section_contents#define aout_32_set_arch_mach b_out_set_arch_mach#define aout_32_sizeof_headers b_out_sizeof_headers#define aout_32_bfd_debug_info_start bfd_void#define aout_32_bfd_debug_info_end bfd_void#define aout_32_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void#define aout_32_bfd_get_relocated_section_contents b_out_get_relocated_section_contents#define aout_32_bfd_relax_section b_out_relax_sectionbfd_target b_out_vec_big_host ={ "b.out.big", /* name */ bfd_target_aout_flavour, false, /* data byte order is little */ true, /* hdr byte order is big */ (HAS_RELOC | EXEC_P | /* object flags */ HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ '_', /* symbol leading char */ ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 2, /* minumum alignment power */ _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */ _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */ {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */ bfd_generic_archive_p, _bfd_dummy_target}, {bfd_false, b_out_mkobject, /* bfd_set_format */ _bfd_generic_mkarchive, bfd_false}, {bfd_false, b_out_write_object_contents, /* bfd_write_contents */ _bfd_write_archive_contents, bfd_false}, JUMP_TABLE(aout_32), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */ b_out_reloc_type_lookup,};bfd_target b_out_vec_little_host ={ "b.out.little", /* name */ bfd_target_aout_flavour, false, /* data byte order is little */ false, /* header byte order is little */ (HAS_RELOC | EXEC_P | /* object flags */ HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT ), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ '_', /* symbol leading char */ ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 2, /* minum align */_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */_do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */ {_bfd_dummy_target, b_out_object_p, /* bfd_check_format */ bfd_generic_archive_p, _bfd_dummy_target}, {bfd_false, b_out_mkobject, /* bfd_set_format */ _bfd_generic_mkarchive, bfd_false}, {bfd_false, b_out_write_object_contents, /* bfd_write_contents */ _bfd_write_archive_contents, bfd_false}, JUMP_TABLE(aout_32), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* COFF stuff?! */ b_out_reloc_type_lookup,};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -