aout-tic30.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,065 行 · 第 1/3 页
C
1,065 行
of the section. */ arch_align_power = bfd_get_arch_info (abfd)->section_align_power; arch_align = 1 << arch_align_power; if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align) == obj_textsec (abfd)->_raw_size) && (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align) == obj_datasec (abfd)->_raw_size) && (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align) == obj_bsssec (abfd)->_raw_size)) { obj_textsec (abfd)->alignment_power = arch_align_power; obj_datasec (abfd)->alignment_power = arch_align_power; obj_bsssec (abfd)->alignment_power = arch_align_power; } return abfd->xvec;}static bfd_reloc_status_typetic30_aout_final_link_relocate (howto, input_bfd, input_section, contents, address, value, addend) reloc_howto_type *howto; bfd *input_bfd; asection *input_section; bfd_byte *contents; bfd_vma address; bfd_vma value; bfd_vma addend;{ bfd_vma relocation; if (address > input_section->_raw_size) return bfd_reloc_outofrange; relocation = value + addend; if (howto->pc_relative) { relocation -= (input_section->output_section->vma + input_section->output_offset); if (howto->pcrel_offset) relocation -= address; } return tic30_aout_relocate_contents (howto, input_bfd, relocation, contents + address);}bfd_reloc_status_typetic30_aout_relocate_contents (howto, input_bfd, relocation, location) reloc_howto_type *howto; bfd *input_bfd; bfd_vma relocation; bfd_byte *location;{ bfd_vma x; boolean overflow; if (howto->size < 0) relocation = -relocation; switch (howto->size) { default: case 0: abort (); break; case 1: x = bfd_get_16 (input_bfd, location); break; case 2: x = bfd_getb_24 (input_bfd, location); break; case 3: x = bfd_get_8 (input_bfd, location); break; case 4: x = bfd_get_32 (input_bfd, location); break; } overflow = false; if (howto->complain_on_overflow != complain_overflow_dont) { bfd_vma check; bfd_signed_vma signed_check; bfd_vma add; bfd_signed_vma signed_add; if (howto->rightshift == 0) { check = relocation; signed_check = (bfd_signed_vma) relocation; } else { check = relocation >> howto->rightshift; if ((bfd_signed_vma) relocation >= 0) signed_check = check; else signed_check = (check | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->rightshift))); } add = x & howto->src_mask; signed_add = add; if ((add & (((~howto->src_mask) >> 1) & howto->src_mask)) != 0) signed_add -= (((~howto->src_mask) >> 1) & howto->src_mask) << 1; if (howto->bitpos == 0) { check += add; signed_check += signed_add; } else { check += add >> howto->bitpos; if (signed_add >= 0) signed_check += add >> howto->bitpos; else signed_check += ((add >> howto->bitpos) | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->bitpos))); } switch (howto->complain_on_overflow) { case complain_overflow_signed: { bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; bfd_signed_vma reloc_signed_min = ~reloc_signed_max; if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) overflow = true; } break; case complain_overflow_unsigned: { bfd_vma reloc_unsigned_max = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1; if (check > reloc_unsigned_max) overflow = true; } break; case complain_overflow_bitfield: { bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1; if ((check & ~reloc_bits) != 0 && (((bfd_vma) signed_check & ~reloc_bits) != (-1 & ~reloc_bits))) overflow = true; } break; default: abort (); } } relocation >>= (bfd_vma) howto->rightshift; relocation <<= (bfd_vma) howto->bitpos; x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask)); switch (howto->size) { default: case 0: abort (); break; case 1: bfd_put_16 (input_bfd, x, location); break; case 2: bfd_putb_24 (input_bfd, x, location); break; case 3: bfd_put_8 (input_bfd, x, location); break; case 4: bfd_put_32 (input_bfd, x, location); break; } return overflow ? bfd_reloc_overflow : bfd_reloc_ok;}/* Finish up the reading of an a.out file header */static const bfd_target *tic30_aout_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; }#ifdef SWAP_MAGIC exec.a_info = SWAP_MAGIC (exec_bytes.e_info);#else exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);#endif /* SWAP_MAGIC */ 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);#ifdef SWAP_MAGIC /* swap_exec_header_in read in a_info with the wrong byte order */ exec.a_info = SWAP_MAGIC (exec_bytes.e_info);#endif /* SWAP_MAGIC */ target = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);#ifdef ENTRY_CAN_BE_ZERO /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage) * means that it isn't obvious if EXEC_P should be set. * All of the following must be true for an executable: * There must be no relocations, the bfd can be neither an * archive nor an archive element, and the file must be executable. */ if (exec.a_trsize + exec.a_drsize == 0 && bfd_get_format (abfd) == bfd_object && abfd->my_archive == NULL) { struct stat buf;#ifndef S_IXUSR#define S_IXUSR 0100 /* Execute by owner. */#endif if (stat (abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR)) abfd->flags |= EXEC_P; }#endif /* ENTRY_CAN_BE_ZERO */ return target;}/* Copy private section data. This actually does nothing with the sections. It copies the subformat field. We copy it here, because we need to know whether this is a QMAGIC file before we set the section contents, and copy_private_bfd_data is not called until after the section contents have been set. */static booleanMY_bfd_copy_private_section_data (ibfd, isec, obfd, osec) bfd *ibfd; asection *isec ATTRIBUTE_UNUSED; bfd *obfd; asection *osec ATTRIBUTE_UNUSED;{ if (bfd_get_flavour (obfd) == bfd_target_aout_flavour) obj_aout_subformat (obfd) = obj_aout_subformat (ibfd); return true;}/* Write an object file. Section contents have already been written. We write the file header, symbols, and relocation. */static booleantic30_aout_write_object_contents (abfd) bfd *abfd;{ struct external_exec exec_bytes; struct internal_exec *execp = exec_hdr (abfd); obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; { bfd_size_type text_size; /* dummy vars */ file_ptr text_end; if (adata (abfd).magic == undecided_magic) NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end); execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE; execp->a_entry = bfd_get_start_address (abfd); execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * obj_reloc_entry_size (abfd)); execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * obj_reloc_entry_size (abfd)); NAME (aout, swap_exec_header_out) (abfd, execp, &exec_bytes); if (adata (abfd).exec_bytes_size > 0) { if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) return false; if (bfd_write ((PTR) & exec_bytes, 1, adata (abfd).exec_bytes_size, abfd) != adata (abfd).exec_bytes_size) return false; } /* Now write out reloc info, followed by syms and strings */ if (bfd_get_outsymbols (abfd) != (asymbol **) NULL && bfd_get_symcount (abfd) != 0) { if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*execp)), SEEK_SET) != 0) return false; if (!NAME (aout, write_syms) (abfd)) return false; } if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0) return false; if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd))) return false; if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0) return false; if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd))) return false; } return true;}static booleantic30_aout_set_sizes (abfd) bfd *abfd;{ adata (abfd).page_size = TARGET_PAGE_SIZE;#ifdef SEGMENT_SIZE adata (abfd).segment_size = SEGMENT_SIZE;#else adata (abfd).segment_size = TARGET_PAGE_SIZE;#endif#ifdef ZMAGIC_DISK_BLOCK_SIZE adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;#else adata (abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;#endif adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return true;}#ifndef MY_final_link_callback/* Callback for the final_link routine to set the section offsets. */static void MY_final_link_callback PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));static voidMY_final_link_callback (abfd, ptreloff, pdreloff, psymoff) bfd *abfd; file_ptr *ptreloff; file_ptr *pdreloff; file_ptr *psymoff;{ struct internal_exec *execp = exec_hdr (abfd); *ptreloff = obj_datasec (abfd)->filepos + execp->a_data; *pdreloff = *ptreloff + execp->a_trsize; *psymoff = *pdreloff + execp->a_drsize;;}#endif#ifndef MY_bfd_final_link/* Final link routine. We need to use a call back to get the correct
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?