aoutx.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 2,130 行 · 第 1/5 页
H
2,130 行
return false; } /* Determine the size of a relocation entry */ switch (arch) { case bfd_arch_sparc: case bfd_arch_a29k: case bfd_arch_mips: obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE; break; default: obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; break; } return (*aout_backend_info(abfd)->set_sizes) (abfd);}static voidadjust_o_magic (abfd, execp) bfd *abfd; struct internal_exec *execp;{ file_ptr pos = adata (abfd).exec_bytes_size; bfd_vma vma = 0; int pad = 0; /* Text. */ obj_textsec(abfd)->filepos = pos; if (!obj_textsec(abfd)->user_set_vma) obj_textsec(abfd)->vma = vma; else vma = obj_textsec(abfd)->vma; pos += obj_textsec(abfd)->_raw_size; vma += obj_textsec(abfd)->_raw_size; /* Data. */ if (!obj_datasec(abfd)->user_set_vma) {#if 0 /* ?? Does alignment in the file image really matter? */ pad = align_power (vma, obj_datasec(abfd)->alignment_power) - vma;#endif obj_textsec(abfd)->_raw_size += pad; pos += pad; vma += pad; obj_datasec(abfd)->vma = vma; } else vma = obj_datasec(abfd)->vma; obj_datasec(abfd)->filepos = pos; pos += obj_datasec(abfd)->_raw_size; vma += obj_datasec(abfd)->_raw_size; /* BSS. */ if (!obj_bsssec(abfd)->user_set_vma) {#if 0 pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;#endif obj_datasec(abfd)->_raw_size += pad; pos += pad; vma += pad; obj_bsssec(abfd)->vma = vma; } else { /* The VMA of the .bss section is set by the the VMA of the .data section plus the size of the .data section. We may need to add padding bytes to make this true. */ pad = obj_bsssec (abfd)->vma - vma; if (pad > 0) { obj_datasec (abfd)->_raw_size += pad; pos += pad; } } obj_bsssec(abfd)->filepos = pos; /* Fix up the exec header. */ execp->a_text = obj_textsec(abfd)->_raw_size; execp->a_data = obj_datasec(abfd)->_raw_size; execp->a_bss = obj_bsssec(abfd)->_raw_size; N_SET_MAGIC (*execp, OMAGIC);}static voidadjust_z_magic (abfd, execp) bfd *abfd; struct internal_exec *execp;{ bfd_size_type data_pad, text_pad; file_ptr text_end; CONST struct aout_backend_data *abdp; int ztih; /* Nonzero if text includes exec header. */ abdp = aout_backend_info (abfd); /* Text. */ ztih = (abdp != NULL && (abdp->text_includes_header || obj_aout_subformat (abfd) == q_magic_format)); obj_textsec(abfd)->filepos = (ztih ? adata(abfd).exec_bytes_size : adata(abfd).zmagic_disk_block_size); if (! obj_textsec(abfd)->user_set_vma) { /* ?? Do we really need to check for relocs here? */ obj_textsec(abfd)->vma = ((abfd->flags & HAS_RELOC) ? 0 : (ztih ? (abdp->default_text_vma + adata(abfd).exec_bytes_size) : abdp->default_text_vma)); text_pad = 0; } else { /* The .text section is being loaded at an unusual address. We may need to pad it such that the .data section starts at a page boundary. */ if (ztih) text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma) & (adata (abfd).page_size - 1)); else text_pad = ((- obj_textsec (abfd)->vma) & (adata (abfd).page_size - 1)); } /* Find start of data. */ if (ztih) { text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->_raw_size; text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; } else { /* Note that if page_size == zmagic_disk_block_size, then filepos == page_size, and this case is the same as the ztih case. */ text_end = obj_textsec (abfd)->_raw_size; text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end; text_end += obj_textsec (abfd)->filepos; } obj_textsec(abfd)->_raw_size += text_pad; text_end += text_pad; /* Data. */ if (!obj_datasec(abfd)->user_set_vma) { bfd_vma vma; vma = obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size; obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size); } if (abdp && abdp->zmagic_mapped_contiguous) { text_pad = (obj_datasec(abfd)->vma - obj_textsec(abfd)->vma - obj_textsec(abfd)->_raw_size); obj_textsec(abfd)->_raw_size += text_pad; } obj_datasec(abfd)->filepos = (obj_textsec(abfd)->filepos + obj_textsec(abfd)->_raw_size); /* Fix up exec header while we're at it. */ execp->a_text = obj_textsec(abfd)->_raw_size; if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted))) execp->a_text += adata(abfd).exec_bytes_size; if (obj_aout_subformat (abfd) == q_magic_format) N_SET_MAGIC (*execp, QMAGIC); else N_SET_MAGIC (*execp, ZMAGIC); /* Spec says data section should be rounded up to page boundary. */ obj_datasec(abfd)->_raw_size = align_power (obj_datasec(abfd)->_raw_size, obj_bsssec(abfd)->alignment_power); execp->a_data = BFD_ALIGN (obj_datasec(abfd)->_raw_size, adata(abfd).page_size); data_pad = execp->a_data - obj_datasec(abfd)->_raw_size; /* BSS. */ if (!obj_bsssec(abfd)->user_set_vma) obj_bsssec(abfd)->vma = (obj_datasec(abfd)->vma + obj_datasec(abfd)->_raw_size); /* If the BSS immediately follows the data section and extra space in the page is left after the data section, fudge data in the header so that the bss section looks smaller by that amount. We'll start the bss section there, and lie to the OS. (Note that a linker script, as well as the above assignment, could have explicitly set the BSS vma to immediately follow the data section.) */ if (align_power (obj_bsssec(abfd)->vma, obj_bsssec(abfd)->alignment_power) == obj_datasec(abfd)->vma + obj_datasec(abfd)->_raw_size) execp->a_bss = (data_pad > obj_bsssec(abfd)->_raw_size) ? 0 : obj_bsssec(abfd)->_raw_size - data_pad; else execp->a_bss = obj_bsssec(abfd)->_raw_size;}static voidadjust_n_magic (abfd, execp) bfd *abfd; struct internal_exec *execp;{ file_ptr pos = adata(abfd).exec_bytes_size; bfd_vma vma = 0; int pad; /* Text. */ obj_textsec(abfd)->filepos = pos; if (!obj_textsec(abfd)->user_set_vma) obj_textsec(abfd)->vma = vma; else vma = obj_textsec(abfd)->vma; pos += obj_textsec(abfd)->_raw_size; vma += obj_textsec(abfd)->_raw_size; /* Data. */ obj_datasec(abfd)->filepos = pos; if (!obj_datasec(abfd)->user_set_vma) obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size); vma = obj_datasec(abfd)->vma; /* Since BSS follows data immediately, see if it needs alignment. */ vma += obj_datasec(abfd)->_raw_size; pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma; obj_datasec(abfd)->_raw_size += pad; pos += obj_datasec(abfd)->_raw_size; /* BSS. */ if (!obj_bsssec(abfd)->user_set_vma) obj_bsssec(abfd)->vma = vma; else vma = obj_bsssec(abfd)->vma; /* Fix up exec header. */ execp->a_text = obj_textsec(abfd)->_raw_size; execp->a_data = obj_datasec(abfd)->_raw_size; execp->a_bss = obj_bsssec(abfd)->_raw_size; N_SET_MAGIC (*execp, NMAGIC);}booleanNAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end) bfd *abfd; bfd_size_type *text_size; file_ptr *text_end ATTRIBUTE_UNUSED;{ struct internal_exec *execp = exec_hdr (abfd); if (! NAME(aout,make_sections) (abfd)) return false; if (adata(abfd).magic != undecided_magic) return true; obj_textsec(abfd)->_raw_size = align_power(obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->alignment_power); *text_size = obj_textsec (abfd)->_raw_size; /* Rule (heuristic) for when to pad to a new page. Note that there are (at least) two ways demand-paged (ZMAGIC) files have been handled. Most Berkeley-based systems start the text segment at (TARGET_PAGE_SIZE). However, newer versions of SUNOS start the text segment right after the exec header; the latter is counted in the text segment size, and is paged in by the kernel with the rest of the text. */ /* This perhaps isn't the right way to do this, but made it simpler for me to understand enough to implement it. Better would probably be to go right from BFD flags to alignment/positioning characteristics. But the old code was sloppy enough about handling the flags, and had enough other magic, that it was a little hard for me to understand. I think I understand it better now, but I haven't time to do the cleanup this minute. */ if (abfd->flags & D_PAGED) /* Whether or not WP_TEXT is set -- let D_PAGED override. */ adata(abfd).magic = z_magic; else if (abfd->flags & WP_TEXT) adata(abfd).magic = n_magic; else adata(abfd).magic = o_magic;#ifdef BFD_AOUT_DEBUG /* requires gcc2 */#if __GNUC__ >= 2 fprintf (stderr, "%s text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x,%x>\n", ({ char *str; switch (adata(abfd).magic) { case n_magic: str = "NMAGIC"; break; case o_magic: str = "OMAGIC"; break; case z_magic: str = "ZMAGIC"; break; default: abort (); } str; }), obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->alignment_power, obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->alignment_power, obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size, obj_bsssec(abfd)->alignment_power);#endif#endif switch (adata(abfd).magic) { case o_magic: adjust_o_magic (abfd, execp); break; case z_magic: adjust_z_magic (abfd, execp); break; case n_magic: adjust_n_magic (abfd, execp); break; default: abort (); }#ifdef BFD_AOUT_DEBUG fprintf (stderr, " text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n", obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->filepos, obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->filepos, obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size);#endif return true;}/*FUNCTION aout_@var{size}_new_section_hookSYNOPSIS boolean aout_@var{size}_new_section_hook, (bfd *abfd, asection *newsect));DESCRIPTION Called by the BFD in response to a @code{bfd_make_section} request.*/booleanNAME(aout,new_section_hook) (abfd, newsect) bfd *abfd; asection *newsect;{ /* align to double at least */ newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power; if (bfd_get_format (abfd) == bfd_object) { if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) { obj_textsec(abfd)= newsect; newsect->target_index = N_TEXT; return true; } if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) { obj_datasec(abfd) = newsect; newsect->target_index = N_DATA; return true; } if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) { obj_bsssec(abfd) = newsect; newsect->target_index = N_BSS; return true; } } /* We allow more than three sections internally */ return true;}booleanNAME(aout,set_section_contents) (abfd, section, location, offset, count) bfd *abfd; sec_ptr section; PTR location; file_ptr offset; bfd_size_type count;{ file_ptr text_end; bfd_size_type text_size; if (! abfd->output_has_begun) { if (! NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end)) return false; } if (section == obj_bsssec (abfd)) { bfd_set_error (bfd_error_no_contents); return false; } if (section != obj_textsec (abfd) && section != obj_datasec (abfd)) { (*_bfd_error_handler) (_("%s: can not represent section `%s' in a.out object file format"), bfd_get_filename (abfd), bfd_get_section_name (abfd, section)); bfd_set_error (bfd_error_nonrepresentable_section); return false; } if (count != 0) { if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 || bfd_write (location, 1, count, abfd) != count) return false; } return true;}/* Read the external symbols from an a.out file. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?