coff-rs6000.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,164 行 · 第 1/5 页
C
2,164 行
return &xcoff_howto_table[0]; case BFD_RELOC_64: return &xcoff_howto_table[0x1c]; default: return NULL; }}/* XCOFF archive support. The original version of this code was by Damon A. Permezel. It was enhanced to permit cross support, and writing archive files, by Ian Lance Taylor, Cygnus Support. XCOFF uses its own archive format. Everything is hooked together with file offset links, so it is possible to rapidly update an archive in place. Of course, we don't do that. An XCOFF archive has a real file header, not just an ARMAG string. The structure of the file header and of each archive header appear below. An XCOFF archive also has a member table, which is a list of elements in the archive (you can get that by looking through the linked list, but you have to read a lot more of the file). The member table has a normal archive header with an empty name. It is normally (and perhaps must be) the second to last entry in the archive. The member table data is almost printable ASCII. It starts with a 12 character decimal string which is the number of entries in the table. For each entry it has a 12 character decimal string which is the offset in the archive of that member. These entries are followed by a series of null terminated strings which are the member names for each entry. Finally, an XCOFF archive has a global symbol table, which is what we call the armap. The global symbol table has a normal archive header with an empty name. It is normally (and perhaps must be) the last entry in the archive. The contents start with a four byte binary number which is the number of entries. This is followed by a that many four byte binary numbers; each is the file offset of an entry in the archive. These numbers are followed by a series of null terminated strings, which are symbol names. AIX 4.3 introduced a new archive format which can handle larger files and also 32- and 64-bit objects in the same archive. The things said above remain true except that there is now more than one global symbol table. The one is used to index 32-bit objects, the other for 64-bit objects. The new archives (recognizable by the new ARMAG string) has larger field lengths so that we cannot really share any code. Also we have to take care that we are not generating the new form of archives on AIX 4.2 or earlier systems. *//* XCOFF archives use this as a magic string. Note that both strings have the same length. */#define XCOFFARMAG "<aiaff>\012"#define XCOFFARMAGBIG "<bigaf>\012"#define SXCOFFARMAG 8/* This terminates an XCOFF archive member name. */#define XCOFFARFMAG "`\012"#define SXCOFFARFMAG 2/* XCOFF archives start with this (printable) structure. */struct xcoff_ar_file_hdr{ /* Magic string. */ char magic[SXCOFFARMAG]; /* Offset of the member table (decimal ASCII string). */ char memoff[12]; /* Offset of the global symbol table (decimal ASCII string). */ char symoff[12]; /* Offset of the first member in the archive (decimal ASCII string). */ char firstmemoff[12]; /* Offset of the last member in the archive (decimal ASCII string). */ char lastmemoff[12]; /* Offset of the first member on the free list (decimal ASCII string). */ char freeoff[12];};#define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)/* This is the equivalent data structure for the big archive format. */struct xcoff_ar_file_hdr_big{ /* Magic string. */ char magic[SXCOFFARMAG]; /* Offset of the member table (decimal ASCII string). */ char memoff[20]; /* Offset of the global symbol table for 32-bit objects (decimal ASCII string). */ char symoff[20]; /* Offset of the global symbol table for 64-bit objects (decimal ASCII string). */ char symoff64[20]; /* Offset of the first member in the archive (decimal ASCII string). */ char firstmemoff[20]; /* Offset of the last member in the archive (decimal ASCII string). */ char lastmemoff[20]; /* Offset of the first member on the free list (decimal ASCII string). */ char freeoff[20];};#define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)/* Each XCOFF archive member starts with this (printable) structure. */struct xcoff_ar_hdr{ /* File size not including the header (decimal ASCII string). */ char size[12]; /* File offset of next archive member (decimal ASCII string). */ char nextoff[12]; /* File offset of previous archive member (decimal ASCII string). */ char prevoff[12]; /* File mtime (decimal ASCII string). */ char date[12]; /* File UID (decimal ASCII string). */ char uid[12]; /* File GID (decimal ASCII string). */ char gid[12]; /* File mode (octal ASCII string). */ char mode[12]; /* Length of file name (decimal ASCII string). */ char namlen[4]; /* This structure is followed by the file name. The length of the name is given in the namlen field. If the length of the name is odd, the name is followed by a null byte. The name and optional null byte are followed by XCOFFARFMAG, which is not included in namlen. The contents of the archive member follow; the number of bytes is given in the size field. */};#define SIZEOF_AR_HDR (7 * 12 + 4)/* The equivalent for the big archive format. */struct xcoff_ar_hdr_big{ /* File size not including the header (decimal ASCII string). */ char size[20]; /* File offset of next archive member (decimal ASCII string). */ char nextoff[20]; /* File offset of previous archive member (decimal ASCII string). */ char prevoff[20]; /* File mtime (decimal ASCII string). */ char date[12]; /* File UID (decimal ASCII string). */ char uid[12]; /* File GID (decimal ASCII string). */ char gid[12]; /* File mode (octal ASCII string). */ char mode[12]; /* Length of file name (decimal ASCII string). */ char namlen[4]; /* This structure is followed by the file name. The length of the name is given in the namlen field. If the length of the name is odd, the name is followed by a null byte. The name and optional null byte are followed by XCOFFARFMAG, which is not included in namlen. The contents of the archive member follow; the number of bytes is given in the size field. */};#define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)/* We often have to distinguish between the old and big file format. Make it a bit cleaner. We can use `xcoff_ardata' here because the `hdr' member has the same size and position in both formats. */#define xcoff_big_format_p(abfd) \ (xcoff_ardata (abfd)->magic[1] == 'b')/* We store a copy of the xcoff_ar_file_hdr in the tdata field of the artdata structure. Similar for the big archive. */#define xcoff_ardata(abfd) \ ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)#define xcoff_ardata_big(abfd) \ ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)/* We store a copy of the xcoff_ar_hdr in the arelt_data field of an archive element. Similar for the big archive. */#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))#define arch_xhdr(bfd) \ ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)#define arch_xhdr_big(bfd) \ ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)/* Read in the armap of an XCOFF archive. */boolean_bfd_xcoff_slurp_armap (abfd) bfd *abfd;{ file_ptr off; size_t namlen; bfd_size_type sz; bfd_byte *contents, *cend; bfd_vma c, i; carsym *arsym; bfd_byte *p; if (xcoff_ardata (abfd) == NULL) { bfd_has_map (abfd) = false; return true; } if (! xcoff_big_format_p (abfd)) { /* This is for the old format. */ struct xcoff_ar_hdr hdr; off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10); if (off == 0) { bfd_has_map (abfd) = false; return true; } if (bfd_seek (abfd, off, SEEK_SET) != 0) return false; /* The symbol table starts with a normal archive header. */ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR) return false; /* Skip the name (normally empty). */ namlen = strtol (hdr.namlen, (char **) NULL, 10); if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0) return false; sz = strtol (hdr.size, (char **) NULL, 10); /* Read in the entire symbol table. */ contents = (bfd_byte *) bfd_alloc (abfd, sz); if (contents == NULL) return false; if (bfd_read ((PTR) contents, 1, sz, abfd) != sz) return false; /* The symbol table starts with a four byte count. */ c = bfd_h_get_32 (abfd, contents); if (c * 4 >= sz) { bfd_set_error (bfd_error_bad_value); return false; } bfd_ardata (abfd)->symdefs = ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); if (bfd_ardata (abfd)->symdefs == NULL) return false; /* After the count comes a list of four byte file offsets. */ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4; i < c; ++i, ++arsym, p += 4) arsym->file_offset = bfd_h_get_32 (abfd, p); } else { /* This is for the new format. */ struct xcoff_ar_hdr_big hdr; off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10); if (off == 0) { bfd_has_map (abfd) = false; return true; } if (bfd_seek (abfd, off, SEEK_SET) != 0) return false; /* The symbol table starts with a normal archive header. */ if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG) return false; /* Skip the name (normally empty). */ namlen = strtol (hdr.namlen, (char **) NULL, 10); if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0) return false; /* XXX This actually has to be a call to strtoll (at least on 32-bit machines) since the field width is 20 and there numbers with more than 32 bits can be represented. */ sz = strtol (hdr.size, (char **) NULL, 10); /* Read in the entire symbol table. */ contents = (bfd_byte *) bfd_alloc (abfd, sz); if (contents == NULL) return false; if (bfd_read ((PTR) contents, 1, sz, abfd) != sz) return false; /* The symbol table starts with an eight byte count. */ c = bfd_h_get_64 (abfd, contents); if (c * 8 >= sz) { bfd_set_error (bfd_error_bad_value); return false; } bfd_ardata (abfd)->symdefs = ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); if (bfd_ardata (abfd)->symdefs == NULL) return false; /* After the count comes a list of eight byte file offsets. */ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; i < c; ++i, ++arsym, p += 8) arsym->file_offset = bfd_h_get_64 (abfd, p); } /* After the file offsets come null terminated symbol names. */ cend = contents + sz; for (i = 0, arsym = bfd_ardata (abfd)->symdefs; i < c; ++i, ++arsym, p += strlen ((char *) p) + 1) { if (p >= cend) { bfd_set_error (bfd_error_bad_value); return false; } arsym->name = (char *) p; } bfd_ardata (abfd)->symdef_count = c; bfd_has_map (abfd) = true; return true;}/* See if this is an XCOFF archive. */const bfd_target *_bfd_xcoff_archive_p (abfd) bfd *abfd;{ char magic[SXCOFFARMAG]; if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0) { bfd_set_error (bfd_error_wrong_format); return NULL; } /* We are setting bfd_ardata(abfd) here, but since bfd_ardata involves a cast, we can't do it as the left operand of assignment. */ abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata)); if (bfd_ardata (abfd) == (struct artdata *) NULL) return NULL; bfd_ardata (abfd)->cache = NULL; bfd_ardata (abfd)->archive_head = NULL; bfd_ardata (abfd)->symdefs = NULL; bfd_ardata (abfd)->extended_names = NULL; /* Now handle the two formats. */ if (magic[1] != 'b') { /* This is the old format. */ struct xcoff_ar_file_hdr hdr; /* Copy over the magic string. */ memcpy (hdr.magic, magic, SXCOFFARMAG); /* Now read the rest of the file header. */ if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1, abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff, (char **) NULL, 10); bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR); if (bfd_ardata (abfd)->tdata == NULL) return NULL; memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR); } else { /* This is the new format. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?