📄 coffcode.h
字号:
bfd_write((PTR) (q->name), 1, name_length + 1, abfd); } } } else { /* We would normally not write anything here, but we'll write out 4 so that any stupid coff reader which tries to read the string table even when there isn't one won't croak. */ uint32e_type size = 4; size = size; bfd_write((PTR)&size, 1, sizeof(size), abfd); }}/*SUBSUBSECTION Writing Relocations To write relocations, all the back end does is step though the canonical relocation table, and create an @code{internal_reloc}. The symbol index to use is removed from the @code{offset} field in the symbol table supplied, the address comes directly from the sum of the section base address and the relocation offset and the type is dug directly from the howto field. Then the @code{internal_reloc} is swapped into the shape of an @code{external_reloc} and written out to disk. */static voidDEFUN(coff_write_relocs,(abfd), bfd *abfd){ asection *s; for (s = abfd->sections; s != (asection *) NULL; s = s->next) { unsigned int i; struct external_reloc dst; arelent **p = s->orelocation; bfd_seek(abfd, s->rel_filepos, SEEK_SET); for (i = 0; i < s->reloc_count; i++) { struct internal_reloc n; arelent *q = p[i]; memset((PTR)&n, 0, sizeof(n)); n.r_vaddr = q->address + s->vma; /* The 29k const/consth reloc pair is a real kludge - the consth part doesn't have a symbol - it has an offset. So rebuilt that here */#ifdef R_IHCONST if (q->howto->type == R_IHCONST) n.r_symndx = q->addend; else#endif if (q->sym_ptr_ptr) { n.r_symndx = get_index((*(q->sym_ptr_ptr))); /* Take notice if the symbol reloc points to a symbol we don't have in our symbol table. What should we do for this?? */ if (n.r_symndx > obj_conv_table_size (abfd)) abort (); }#ifdef SELECT_RELOC /* Work out reloc type from what is required */ SELECT_RELOC(n.r_type, q->howto);#else n.r_type = q->howto->type;#endif coff_swap_reloc_out(abfd, &n, &dst); bfd_write((PTR) &dst, 1, RELSZ, abfd); } }}#endif /* NO_COFF_SYMBOLS */#ifndef NO_COFF_LINENOSstatic voidDEFUN(coff_write_linenumbers,(abfd), bfd *abfd){ asection *s; for (s = abfd->sections; s != (asection *) NULL; s = s->next) { if (s->lineno_count) { asymbol **q = abfd->outsymbols; bfd_seek(abfd, s->line_filepos, SEEK_SET); /* Find all the linenumbers in this section */ while (*q) { asymbol *p = *q; alent *l = BFD_SEND(p->the_bfd, _get_lineno, (p->the_bfd, p)); if (l) { /* Found a linenumber entry, output */ struct internal_lineno out; LINENO buff; memset( (PTR)&out, 0, sizeof(out)); out.l_lnno = 0; out.l_addr.l_symndx = l->u.offset; coff_swap_lineno_out(abfd, &out, &buff); bfd_write((PTR) &buff, 1, LINESZ, abfd); l++; while (l->line_number) { out.l_lnno = l->line_number; out.l_addr.l_symndx = l->u.offset; coff_swap_lineno_out(abfd, &out, &buff); bfd_write((PTR) &buff, 1, LINESZ, abfd); l++; } } q++; } } }}static alent *DEFUN(coff_get_lineno,(ignore_abfd, symbol), bfd *ignore_abfd AND asymbol *symbol){ return coffsymbol(symbol)->lineno;}#endif /* NO_COFF_LINENOS */static asymbol *coff_make_empty_symbol(abfd)bfd *abfd;{ coff_symbol_type *new = (coff_symbol_type *) bfd_alloc(abfd, sizeof(coff_symbol_type)); if (new == NULL) { bfd_error = no_memory; return (NULL); } /* on error */ new->symbol.section = 0; new->native = 0; new->lineno = (alent *) NULL; new->done_lineno = false; new->symbol.the_bfd = abfd; return &new->symbol;}#ifndef NO_COFF_SYMBOLSstatic asymbol *DEFUN (coff_make_debug_symbol, (abfd, ptr, sz), bfd *abfd AND PTR ptr AND unsigned long sz){ coff_symbol_type *new = (coff_symbol_type *) bfd_alloc(abfd, sizeof(coff_symbol_type)); if (new == NULL) { bfd_error = no_memory; return (NULL); } /* on error */ /* @@ This shouldn't be using a constant multiplier. */ new->native = (combined_entry_type *) bfd_zalloc (abfd, sizeof (combined_entry_type) * 10); new->symbol.section = &bfd_debug_section; new->lineno = (alent *) NULL; new->done_lineno = false; new->symbol.the_bfd = abfd; return &new->symbol;}static voidDEFUN(coff_print_symbol,(ignore_abfd, filep, symbol, how), bfd *ignore_abfd AND PTR filep AND asymbol *symbol AND bfd_print_symbol_type how){ FILE *file = (FILE *)filep; switch (how) { case bfd_print_symbol_name: fprintf(file, "%s", symbol->name); break; case bfd_print_symbol_more: fprintf(file, "coff %lx %lx", (unsigned long) coffsymbol(symbol)->native, (unsigned long) coffsymbol(symbol)->lineno); break; case bfd_print_symbol_nm: { CONST char *section_name = symbol->section->name; bfd_print_symbol_vandf((PTR) file, symbol); fprintf(file, " %-5s %s %s %s", section_name, coffsymbol(symbol)->native ? "n" : "g", coffsymbol(symbol)->lineno ? "l" : " ", symbol->name); } break; case bfd_print_symbol_all: /* Print out the symbols in a reasonable way */ { CONST char *section_name = symbol->section->name; if (coffsymbol(symbol)->native) { unsigned int aux; combined_entry_type *combined = coffsymbol(symbol)->native; combined_entry_type *root = obj_raw_syments(ignore_abfd); fprintf(file,"[%3d]", combined - root); fprintf(file, "(sc %2d)(fl%4x)(ty%3x)(sc%3d) nx(%d) %08x %s", combined->u.syment.n_scnum, combined->u.syment.n_flags, combined->u.syment.n_type, combined->u.syment.n_sclass, combined->u.syment.n_numaux, combined->u.syment.n_value, symbol->name ); for (aux = 0; aux < combined->u.syment.n_numaux; aux++) { fprintf(file,"\n"); switch (combined->u.syment.n_sclass) { case C_FILE: fprintf(file, "File "); break; default: fprintf(file, "AUX lnno %x size %x tagndx %x", combined[aux+1].u.auxent.x_sym.x_misc.x_lnsz.x_lnno, combined[aux+1].u.auxent.x_sym.x_misc.x_lnsz.x_size, combined[aux+1].u.auxent.x_sym.x_tagndx.l); break; } } { struct lineno_cache_entry *l = coffsymbol(symbol)->lineno; if (l) { printf("\n%s :", l->u.sym->name); l++; while (l->line_number) { printf("\n%4d : %x", l->line_number, l->u.offset); l++; } } } } else { bfd_print_symbol_vandf((PTR) file, symbol); fprintf(file, " %-5s %s %s %s", section_name, coffsymbol(symbol)->native ? "n" : "g", coffsymbol(symbol)->lineno ? "l" : " ", symbol->name); } } }}#endif /* NO_COFF_SYMBOLS *//* Set flags and magic number of a coff file from architecture and machine type. Result is true if we can represent the arch&type, false if not. */static booleanDEFUN(coff_set_flags,(abfd, magicp, flagsp), bfd *abfd AND unsigned *magicp AND unsigned short *flagsp){ switch (bfd_get_arch(abfd)) {#ifdef Z8KMAGIC case bfd_arch_z8k: *magicp = Z8KMAGIC; switch (bfd_get_mach(abfd)) { case bfd_mach_z8001: *flagsp = F_Z8001; break; case bfd_mach_z8002: *flagsp = F_Z8002; break; default: return false; } return true;#endif#ifdef I960ROMAGIC case bfd_arch_i960: { unsigned flags; *magicp = I960ROMAGIC; /* ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC : I960RWMAGIC); FIXME??? */ switch (bfd_get_mach(abfd)) { case bfd_mach_i960_core: flags = F_I960CORE; break; case bfd_mach_i960_kb_sb: flags = F_I960KB; break; case bfd_mach_i960_mc: flags = F_I960MC; break; case bfd_mach_i960_xa: flags = F_I960XA; break; case bfd_mach_i960_ca: flags = F_I960CA; break; case bfd_mach_i960_ka_sa: flags = F_I960KA; break; default: return false; } *flagsp = flags; return true; } break;#endif#ifdef MIPS case bfd_arch_mips: *magicp = MIPS_MAGIC_2; return true; break;#endif#ifdef I386MAGIC case bfd_arch_i386: *magicp = I386MAGIC; return true; break;#endif#ifdef MC68MAGIC case bfd_arch_m68k: *magicp = MC68MAGIC; return true; break;#endif#ifdef MC88MAGIC case bfd_arch_m88k: *magicp = MC88OMAGIC; return true; break;#endif#ifdef H8300MAGIC case bfd_arch_h8300: *magicp = H8300MAGIC; return true; break;#endif#ifdef A29K_MAGIC_BIG case bfd_arch_a29k: if (abfd->xvec->byteorder_big_p) *magicp = A29K_MAGIC_BIG; else *magicp = A29K_MAGIC_LITTLE; return true; break;#endif#ifdef WE32KMAGIC case bfd_arch_we32k: *magicp = WE32KMAGIC; return true; break;#endif#ifdef U802TOCMAGIC case bfd_arch_rs6000: *magicp = U802TOCMAGIC; return true; break;#endif default: /* Unknown architecture */ /* return false; -- fall through to "return false" below, to avoid "statement never reached" errors on the one below. */ break; } return false;}static booleanDEFUN(coff_set_arch_mach,(abfd, arch, machine), bfd *abfd AND enum bfd_architecture arch AND unsigned long machine){ unsigned dummy1; unsigned short dummy2; bfd_default_set_arch_mach(abfd, arch, machine); if (arch != bfd_arch_unknown && coff_set_flags(abfd, &dummy1, &dummy2) != true) return false; /* We can't represent this type */ return true; /* We're easy ... */}/* Calculate the file position for each section. */static voidDEFUN(coff_compute_section_file_positions,(abfd), bfd *abfd){ asection *current; asection *previous = (asection *)NULL; file_ptr sofar = FILHSZ; file_ptr old_sofar; if (bfd_get_start_address(abfd)) { /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -