aoutx.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 2,130 行 · 第 1/5 页
H
2,130 行
static booleanaout_get_external_symbols (abfd) bfd *abfd;{ if (obj_aout_external_syms (abfd) == (struct external_nlist *) NULL) { bfd_size_type count; struct external_nlist *syms; count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;#ifdef USE_MMAP if (bfd_get_file_window (abfd, obj_sym_filepos (abfd), exec_hdr (abfd)->a_syms, &obj_aout_sym_window (abfd), true) == false) return false; syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;#else /* We allocate using malloc to make the values easy to free later on. If we put them on the objalloc it might not be possible to free them. */ syms = ((struct external_nlist *) bfd_malloc ((size_t) count * EXTERNAL_NLIST_SIZE)); if (syms == (struct external_nlist *) NULL && count != 0) return false; if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 || (bfd_read (syms, 1, exec_hdr (abfd)->a_syms, abfd) != exec_hdr (abfd)->a_syms)) { free (syms); return false; }#endif obj_aout_external_syms (abfd) = syms; obj_aout_external_sym_count (abfd) = count; } if (obj_aout_external_strings (abfd) == NULL && exec_hdr (abfd)->a_syms != 0) { unsigned char string_chars[BYTES_IN_WORD]; bfd_size_type stringsize; char *strings; /* Get the size of the strings. */ if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0 || (bfd_read ((PTR) string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD)) return false; stringsize = GET_WORD (abfd, string_chars);#ifdef USE_MMAP if (bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize, &obj_aout_string_window (abfd), true) == false) return false; strings = (char *) obj_aout_string_window (abfd).data;#else strings = (char *) bfd_malloc ((size_t) stringsize + 1); if (strings == NULL) return false; /* Skip space for the string count in the buffer for convenience when using indexes. */ if (bfd_read (strings + BYTES_IN_WORD, 1, stringsize - BYTES_IN_WORD, abfd) != stringsize - BYTES_IN_WORD) { free (strings); return false; }#endif /* Ensure that a zero index yields an empty string. */ strings[0] = '\0'; strings[stringsize - 1] = 0; obj_aout_external_strings (abfd) = strings; obj_aout_external_string_size (abfd) = stringsize; } return true;}/* Translate an a.out symbol into a BFD symbol. The desc, other, type and symbol->value fields of CACHE_PTR will be set from the a.out nlist structure. This function is responsible for setting symbol->flags and symbol->section, and adjusting symbol->value. */static booleantranslate_from_native_sym_flags (abfd, cache_ptr) bfd *abfd; aout_symbol_type *cache_ptr;{ flagword visible; if ((cache_ptr->type & N_STAB) != 0 || cache_ptr->type == N_FN) { asection *sec; /* This is a debugging symbol. */ cache_ptr->symbol.flags = BSF_DEBUGGING; /* Work out the symbol section. */ switch (cache_ptr->type & N_TYPE) { case N_TEXT: case N_FN: sec = obj_textsec (abfd); break; case N_DATA: sec = obj_datasec (abfd); break; case N_BSS: sec = obj_bsssec (abfd); break; default: case N_ABS: sec = bfd_abs_section_ptr; break; } cache_ptr->symbol.section = sec; cache_ptr->symbol.value -= sec->vma; return true; } /* Get the default visibility. This does not apply to all types, so we just hold it in a local variable to use if wanted. */ if ((cache_ptr->type & N_EXT) == 0) visible = BSF_LOCAL; else visible = BSF_GLOBAL; switch (cache_ptr->type) { default: case N_ABS: case N_ABS | N_EXT: cache_ptr->symbol.section = bfd_abs_section_ptr; cache_ptr->symbol.flags = visible; break; case N_UNDF | N_EXT: if (cache_ptr->symbol.value != 0) { /* This is a common symbol. */ cache_ptr->symbol.flags = BSF_GLOBAL; cache_ptr->symbol.section = bfd_com_section_ptr; } else { cache_ptr->symbol.flags = 0; cache_ptr->symbol.section = bfd_und_section_ptr; } break; case N_TEXT: case N_TEXT | N_EXT: cache_ptr->symbol.section = obj_textsec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = visible; break; /* N_SETV symbols used to represent set vectors placed in the data section. They are no longer generated. Theoretically, it was possible to extract the entries and combine them with new ones, although I don't know if that was ever actually done. Unless that feature is restored, treat them as data symbols. */ case N_SETV: case N_SETV | N_EXT: case N_DATA: case N_DATA | N_EXT: cache_ptr->symbol.section = obj_datasec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = visible; break; case N_BSS: case N_BSS | N_EXT: cache_ptr->symbol.section = obj_bsssec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = visible; break; case N_SETA: case N_SETA | N_EXT: case N_SETT: case N_SETT | N_EXT: case N_SETD: case N_SETD | N_EXT: case N_SETB: case N_SETB | N_EXT: { /* This code is no longer needed. It used to be used to make the linker handle set symbols, but they are now handled in the add_symbols routine instead. */#if 0 asection *section; arelent_chain *reloc; asection *into_section; /* This is a set symbol. The name of the symbol is the name of the set (e.g., __CTOR_LIST__). The value of the symbol is the value to add to the set. We create a section with the same name as the symbol, and add a reloc to insert the appropriate value into the section. This action is actually obsolete; it used to make the linker do the right thing, but the linker no longer uses this function. */ section = bfd_get_section_by_name (abfd, cache_ptr->symbol.name); if (section == NULL) { char *copy; copy = bfd_alloc (abfd, strlen (cache_ptr->symbol.name) + 1); if (copy == NULL) return false; strcpy (copy, cache_ptr->symbol.name); section = bfd_make_section (abfd, copy); if (section == NULL) return false; } reloc = (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain)); if (reloc == NULL) return false; /* Build a relocation entry for the constructor. */ switch (cache_ptr->type & N_TYPE) { case N_SETA: into_section = bfd_abs_section_ptr; cache_ptr->type = N_ABS; break; case N_SETT: into_section = obj_textsec (abfd); cache_ptr->type = N_TEXT; break; case N_SETD: into_section = obj_datasec (abfd); cache_ptr->type = N_DATA; break; case N_SETB: into_section = obj_bsssec (abfd); cache_ptr->type = N_BSS; break; } /* Build a relocation pointing into the constructor section pointing at the symbol in the set vector specified. */ reloc->relent.addend = cache_ptr->symbol.value; cache_ptr->symbol.section = into_section; reloc->relent.sym_ptr_ptr = into_section->symbol_ptr_ptr; /* We modify the symbol to belong to a section depending upon the name of the symbol, and add to the size of the section to contain a pointer to the symbol. Build a reloc entry to relocate to this symbol attached to this section. */ section->flags = SEC_CONSTRUCTOR | SEC_RELOC; section->reloc_count++; section->alignment_power = 2; reloc->next = section->constructor_chain; section->constructor_chain = reloc; reloc->relent.address = section->_raw_size; section->_raw_size += BYTES_IN_WORD; reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO(abfd);#endif /* 0 */ switch (cache_ptr->type & N_TYPE) { case N_SETA: cache_ptr->symbol.section = bfd_abs_section_ptr; break; case N_SETT: cache_ptr->symbol.section = obj_textsec (abfd); break; case N_SETD: cache_ptr->symbol.section = obj_datasec (abfd); break; case N_SETB: cache_ptr->symbol.section = obj_bsssec (abfd); break; } cache_ptr->symbol.flags |= BSF_CONSTRUCTOR; } break; case N_WARNING: /* This symbol is the text of a warning message. The next symbol is the symbol to associate the warning with. If a reference is made to that symbol, a warning is issued. */ cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING; cache_ptr->symbol.section = bfd_abs_section_ptr; break; case N_INDR: case N_INDR | N_EXT: /* An indirect symbol. This consists of two symbols in a row. The first symbol is the name of the indirection. The second symbol is the name of the target. A reference to the first symbol becomes a reference to the second. */ cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT | visible; cache_ptr->symbol.section = bfd_ind_section_ptr; break; case N_WEAKU: cache_ptr->symbol.section = bfd_und_section_ptr; cache_ptr->symbol.flags = BSF_WEAK; break; case N_WEAKA: cache_ptr->symbol.section = bfd_abs_section_ptr; cache_ptr->symbol.flags = BSF_WEAK; break; case N_WEAKT: cache_ptr->symbol.section = obj_textsec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = BSF_WEAK; break; case N_WEAKD: cache_ptr->symbol.section = obj_datasec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = BSF_WEAK; break; case N_WEAKB: cache_ptr->symbol.section = obj_bsssec (abfd); cache_ptr->symbol.value -= cache_ptr->symbol.section->vma; cache_ptr->symbol.flags = BSF_WEAK; break; } return true;}/* Set the fields of SYM_POINTER according to CACHE_PTR. */static booleantranslate_to_native_sym_flags (abfd, cache_ptr, sym_pointer) bfd *abfd; asymbol *cache_ptr; struct external_nlist *sym_pointer;{ bfd_vma value = cache_ptr->value; asection *sec; bfd_vma off; /* Mask out any existing type bits in case copying from one section to another. */ sym_pointer->e_type[0] &= ~N_TYPE; sec = bfd_get_section (cache_ptr); off = 0; if (sec == NULL) { /* This case occurs, e.g., for the *DEBUG* section of a COFF file. */ (*_bfd_error_handler) (_("%s: can not represent section for symbol `%s' in a.out object file format"), bfd_get_filename (abfd), cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*")); bfd_set_error (bfd_error_nonrepresentable_section); return false; } if (sec->output_section != NULL) { off = sec->output_offset; sec = sec->output_section; } if (bfd_is_abs_section (sec)) sym_pointer->e_type[0] |= N_ABS; else if (sec == obj_textsec (abfd)) sym_pointer->e_type[0] |= N_TEXT; else if (sec == obj_datasec (abfd)) sym_pointer->e_type[0] |= N_DATA; else if (sec == obj_bsssec (abfd)) sym_pointer->e_type[0] |= N_BSS; else if (bfd_is_und_section (sec)) sym_pointer->e_type[0] = N_UNDF | N_EXT; else if (bfd_is_ind_section (sec)) sym_pointer->e_type[0] = N_INDR; else if (bfd_is_com_section (sec)) sym_pointer->e_type[0] = N_UNDF | N_EXT; else { (*_bfd_error_handler) (_("%s: can not represent section `%s' in a.out object file format"), bfd_get_filename (abfd), bfd_get_section_name (abfd, sec)); bfd_set_error (bfd_error_nonrepresentable_section); return false; } /* Turn the symbol from section relative to absolute again */ value += sec->vma + off; if ((cache_ptr->flags & BSF_WARNING) != 0) sym_pointer->e_type[0] = N_WARNING; if ((cache_ptr->flags & BSF_DEBUGGING) != 0) sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type; else if ((cache_ptr->flags & BSF_GLOBAL) != 0) sym_pointer->e_type[0] |= N_EXT; else if ((cache_ptr->flags & BSF_LOCAL) != 0) sym_pointer->e_type[0] &= ~N_EXT; if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0) { int type = ((aout_symbol_type *) cache_ptr)->type; switch (type) { case N_ABS: type = N_SETA; break; case N_TEXT: type = N_SETT; break; case N_DATA: type = N_SETD; break; case N_BSS: type = N_SETB; break; } sym_pointer->e_type[0] = type;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?