coff-rs6000.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,164 行 · 第 1/5 页
C
2,164 行
b = '\0'; if (bfd_write (&b, 1, 1, abfd) != 1) return false; } return true;}static booleanxcoff_write_armap_big (abfd, elength, map, orl_count, stridx) bfd *abfd; unsigned int elength ATTRIBUTE_UNUSED; struct orl *map; unsigned int orl_count; int stridx;{ unsigned int i; unsigned int orl_count_32, orl_count_64; unsigned int stridx_32, stridx_64; const bfd_arch_info_type *arch_info = NULL; bfd *object_bfd; /* First, we look through the symbols and work out which are from 32-bit objects and which from 64-bit ones. */ orl_count_32 = 0; orl_count_64 = 0; stridx_32 = 0; stridx_64 = 0; object_bfd = NULL; for (i = 0; i < orl_count; i++) { bfd *ob = (bfd *)map[i].pos; unsigned int len; if (ob != object_bfd) arch_info = bfd_get_arch_info (ob); len = strlen (*map[i].name) + 1; if (arch_info && arch_info->bits_per_address == 64) { orl_count_64++; stridx_64 += len; } else { orl_count_32++; stridx_32 += len; } object_bfd = ob; } /* A quick sanity check... */ BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count); BFD_ASSERT (stridx_64 + stridx_32 == stridx); /* Now write out each map. */ if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32, stridx_32, false, xcoff_ardata_big (abfd)->memoff, xcoff_ardata_big (abfd)->symoff)) return false; if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64, stridx_64, true, xcoff_ardata_big (abfd)->symoff, xcoff_ardata_big (abfd)->symoff64)) return false; return true;}boolean_bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx) bfd *abfd; unsigned int elength ATTRIBUTE_UNUSED; struct orl *map; unsigned int orl_count; int stridx;{ if (! xcoff_big_format_p (abfd)) return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx); else return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);}/* Write out an XCOFF archive. We always write an entire archive, rather than fussing with the freelist and so forth. */static booleanxcoff_write_archive_contents_old (abfd) bfd *abfd;{ struct xcoff_ar_file_hdr fhdr; size_t count; size_t total_namlen; file_ptr *offsets; boolean makemap; boolean hasobjects; file_ptr prevoff, nextoff; bfd *sub; unsigned int i; struct xcoff_ar_hdr ahdr; bfd_size_type size; char *p; char decbuf[13]; memset (&fhdr, 0, sizeof fhdr); strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG); sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR); sprintf (fhdr.freeoff, "%d", 0); count = 0; total_namlen = 0; for (sub = abfd->archive_head; sub != NULL; sub = sub->next) { ++count; total_namlen += strlen (normalize_filename (sub)) + 1; } offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); if (offsets == NULL) return false; if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0) return false; makemap = bfd_has_map (abfd); hasobjects = false; prevoff = 0; nextoff = SIZEOF_AR_FILE_HDR; for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) { const char *name; size_t namlen; struct xcoff_ar_hdr *ahdrp; bfd_size_type remaining; if (makemap && ! hasobjects) { if (bfd_check_format (sub, bfd_object)) hasobjects = true; } name = normalize_filename (sub); namlen = strlen (name); if (sub->arelt_data != NULL) ahdrp = arch_xhdr (sub); else ahdrp = NULL; if (ahdrp == NULL) { struct stat s; memset (&ahdr, 0, sizeof ahdr); ahdrp = &ahdr; if (stat (bfd_get_filename (sub), &s) != 0) { bfd_set_error (bfd_error_system_call); return false; } sprintf (ahdrp->size, "%ld", (long) s.st_size); sprintf (ahdrp->date, "%ld", (long) s.st_mtime); sprintf (ahdrp->uid, "%ld", (long) s.st_uid); sprintf (ahdrp->gid, "%ld", (long) s.st_gid); sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); if (sub->arelt_data == NULL) { sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata)); if (sub->arelt_data == NULL) return false; } arch_eltdata (sub)->parsed_size = s.st_size; } sprintf (ahdrp->prevoff, "%ld", (long) prevoff); sprintf (ahdrp->namlen, "%ld", (long) namlen); /* If the length of the name is odd, we write out the null byte after the name as well. */ namlen = (namlen + 1) &~ 1; remaining = arelt_size (sub); size = (SIZEOF_AR_HDR + namlen + SXCOFFARFMAG + remaining); BFD_ASSERT (nextoff == bfd_tell (abfd)); offsets[i] = nextoff; prevoff = nextoff; nextoff += size + (size & 1); sprintf (ahdrp->nextoff, "%ld", (long) nextoff); /* We need spaces, not null bytes, in the header. */ for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++) if (*p == '\0') *p = ' '; if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR || bfd_write ((PTR) name, 1, namlen, abfd) != namlen || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)) return false; if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0) return false; while (remaining != 0) { bfd_size_type amt; bfd_byte buffer[DEFAULT_BUFFERSIZE]; amt = sizeof buffer; if (amt > remaining) amt = remaining; if (bfd_read (buffer, 1, amt, sub) != amt || bfd_write (buffer, 1, amt, abfd) != amt) return false; remaining -= amt; } if ((size & 1) != 0) { bfd_byte b; b = '\0'; if (bfd_write (&b, 1, 1, abfd) != 1) return false; } } sprintf (fhdr.lastmemoff, "%ld", (long) prevoff); /* Write out the member table. */ BFD_ASSERT (nextoff == bfd_tell (abfd)); sprintf (fhdr.memoff, "%ld", (long) nextoff); memset (&ahdr, 0, sizeof ahdr); sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen)); sprintf (ahdr.prevoff, "%ld", (long) prevoff); sprintf (ahdr.date, "%d", 0); sprintf (ahdr.uid, "%d", 0); sprintf (ahdr.gid, "%d", 0); sprintf (ahdr.mode, "%d", 0); sprintf (ahdr.namlen, "%d", 0); size = (SIZEOF_AR_HDR + 12 + count * 12 + total_namlen + SXCOFFARFMAG); prevoff = nextoff; nextoff += size + (size & 1); if (makemap && hasobjects) sprintf (ahdr.nextoff, "%ld", (long) nextoff); else sprintf (ahdr.nextoff, "%d", 0); /* We need spaces, not null bytes, in the header. */ for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++) if (*p == '\0') *p = ' '; if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)) return false; sprintf (decbuf, "%-12ld", (long) count); if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) return false; for (i = 0; i < count; i++) { sprintf (decbuf, "%-12ld", (long) offsets[i]); if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) return false; } for (sub = abfd->archive_head; sub != NULL; sub = sub->next) { const char *name; size_t namlen; name = normalize_filename (sub); namlen = strlen (name); if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1) return false; } if ((size & 1) != 0) { bfd_byte b; b = '\0'; if (bfd_write ((PTR) &b, 1, 1, abfd) != 1) return false; } /* Write out the armap, if appropriate. */ if (! makemap || ! hasobjects) sprintf (fhdr.symoff, "%d", 0); else { BFD_ASSERT (nextoff == bfd_tell (abfd)); sprintf (fhdr.symoff, "%ld", (long) nextoff); bfd_ardata (abfd)->tdata = (PTR) &fhdr; if (! _bfd_compute_and_write_armap (abfd, 0)) return false; } /* Write out the archive file header. */ /* We need spaces, not null bytes, in the header. */ for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++) if (*p == '\0') *p = ' '; if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) != SIZEOF_AR_FILE_HDR)) return false; return true;}static booleanxcoff_write_archive_contents_big (abfd) bfd *abfd;{ struct xcoff_ar_file_hdr_big fhdr; size_t count; size_t total_namlen; file_ptr *offsets; boolean makemap; boolean hasobjects; file_ptr prevoff, nextoff; bfd *sub; unsigned int i; struct xcoff_ar_hdr_big ahdr; bfd_size_type size; char *p; char decbuf[13]; memset (&fhdr, 0, sizeof fhdr); strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG); sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG); sprintf (fhdr.freeoff, "%d", 0); count = 0; total_namlen = 0; for (sub = abfd->archive_head; sub != NULL; sub = sub->next) { ++count; total_namlen += strlen (normalize_filename (sub)) + 1; } offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); if (offsets == NULL) return false; if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0) return false; makemap = bfd_has_map (abfd); hasobjects = false; prevoff = 0; nextoff = SIZEOF_AR_FILE_HDR_BIG; for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) { const char *name; size_t namlen; struct xcoff_ar_hdr_big *ahdrp; bfd_size_type remaining; if (makemap && ! hasobjects) { if (bfd_check_format (sub, bfd_object)) hasobjects = true; } name = normalize_filename (sub); namlen = strlen (name); if (sub->arelt_data != NULL) ahdrp = arch_xhdr_big (sub); else ahdrp = NULL; if (ahdrp == NULL) { struct stat s; memset (&ahdr, 0, sizeof ahdr); ahdrp = &ahdr; /* XXX This should actually be a call to stat64 (at least on 32-bit machines). */ if (stat (bfd_get_filename (sub), &s) != 0) { bfd_set_error (bfd_error_system_call); return false; } /* XXX This call actually should use %lld (at least on 32-bit machines) since the fields's width is 20 and there numbers with more than 32 bits can be represented. */ sprintf (ahdrp->size, "%ld", (long) s.st_size); sprintf (ahdrp->date, "%ld", (long) s.st_mtime); sprintf (ahdrp->uid, "%ld", (long) s.st_uid); sprintf (ahdrp->gid, "%ld", (long) s.st_gid); sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); if (sub->arelt_data == NULL) { sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata)); if (sub->arelt_data == NULL) return false; } arch_eltdata (sub)->parsed_size = s.st_size; } /* XXX These calls actually should use %lld (at least on 32-bit machines) since the fields's width is 20 and there numbers with more than 32 bits can be represented. */ sprintf (ahdrp->prevoff, "%ld", (long) prevoff); sprintf (ahdrp->namlen, "%ld", (long) namlen); /* I
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?