BFD: Add BFD pointer member to `struct carsym' Replace the file offset with a union of one and a BFD pointer in `struct carsym', as a preparation to handle symbol maps built on the fly rather than fetched from a file. No functional change. NB there's a note on `struct carsym' being a type pun on `struct symdef' as in include/aout/ranlib.h (or `struct ranlib'; no idea where it comes from). It is possibly not true anymore, even more so with this code update in place, depending on the underlying type of `file_ptr'. This is not a problem however, because we always process `struct carsym' data by hand and only use it internally rather than reading/writing from/to a file. Therefore remove the note, as no longer applicable.
diff --git a/bfd/archive.c b/bfd/archive.c index c92ad51..c962bd2 100644 --- a/bfd/archive.c +++ b/bfd/archive.c
@@ -149,12 +149,19 @@ /* EXTERNAL +.{* Holds a file position or bfd* depending on context. *} +.typedef union ufile_ptr_or_bfd +.{ +. ufile_ptr file_offset; +. bfd *abfd; +.} +.ufile_ptr_or_bfd; +. .{* A canonical archive symbol. *} -.{* This is a type pun with struct symdef/struct ranlib on purpose! *} .typedef struct carsym .{ . const char *name; -. ufile_ptr file_offset; {* Look here to find the file. *} +. ufile_ptr_or_bfd u; {* bfd* or file position. *} .} .carsym; . @@ -804,7 +811,7 @@ carsym *entry; entry = bfd_ardata (abfd)->symdefs + sym_index; - return _bfd_get_elt_at_filepos (abfd, entry->file_offset, NULL); + return _bfd_get_elt_at_filepos (abfd, entry->u.file_offset, NULL); } bfd * @@ -1041,7 +1048,7 @@ goto release_armap; } set->name = stringbase + nameoff; - set->file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); + set->u.file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE); } ardata->first_file_filepos = bfd_tell (abfd); @@ -1142,7 +1149,7 @@ for (i = 0; i < nsymz; i++) { rawptr = raw_armap + i; - carsyms->file_offset = swap ((bfd_byte *) rawptr); + carsyms->u.file_offset = swap ((bfd_byte *) rawptr); carsyms->name = stringbase; stringbase += strlen (stringbase); if (stringbase != stringend)
diff --git a/bfd/archive64.c b/bfd/archive64.c index 2ea4f2f..4789bef 100644 --- a/bfd/archive64.c +++ b/bfd/archive64.c
@@ -129,7 +129,7 @@ *stringend = 0; for (i = 0; i < nsymz; i++) { - carsyms->file_offset = bfd_getb64 (raw_armap + i * 8); + carsyms->u.file_offset = bfd_getb64 (raw_armap + i * 8); carsyms->name = stringbase; stringbase += strlen (stringbase); if (stringbase != stringend)
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index b0eaafe..8f55c1e 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h
@@ -1273,12 +1273,19 @@ (ibfd, isymbol, obfd, osymbol)) /* Extracted from archive.c. */ +/* Holds a file position or bfd* depending on context. */ +typedef union ufile_ptr_or_bfd +{ + ufile_ptr file_offset; + bfd *abfd; +} +ufile_ptr_or_bfd; + /* A canonical archive symbol. */ -/* This is a type pun with struct symdef/struct ranlib on purpose! */ typedef struct carsym { const char *name; - ufile_ptr file_offset; /* Look here to find the file. */ + ufile_ptr_or_bfd u; /* bfd* or file position. */ } carsym;
diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c index 9e63256..f623e0a 100644 --- a/bfd/coff-alpha.c +++ b/bfd/coff-alpha.c
@@ -2240,7 +2240,7 @@ carsym *entry; entry = bfd_ardata (abfd)->symdefs + sym_index; - return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset, NULL); + return alpha_ecoff_get_elt_at_filepos (abfd, entry->u.file_offset, NULL); } static void
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 7f3a237..65dc831 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c
@@ -1411,7 +1411,7 @@ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4; i < c; ++i, ++arsym, p += 4) - arsym->file_offset = H_GET_32 (abfd, p); + arsym->u.file_offset = H_GET_32 (abfd, p); } else { @@ -1472,7 +1472,7 @@ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; i < c; ++i, ++arsym, p += 8) - arsym->file_offset = H_GET_64 (abfd, p); + arsym->u.file_offset = H_GET_64 (abfd, p); } /* After the file offsets come null terminated symbol names. */
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c index 65159cb..87e31b6 100644 --- a/bfd/coff64-rs6000.c +++ b/bfd/coff64-rs6000.c
@@ -1872,7 +1872,7 @@ for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; i < c; ++i, ++arsym, p += 8) - arsym->file_offset = H_GET_64 (abfd, p); + arsym->u.file_offset = H_GET_64 (abfd, p); /* After the file offsets come null terminated symbol names. */ cend = contents + sz;
diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 38c074b..f7767ee 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c
@@ -3065,7 +3065,7 @@ if (name_offset > stringsize) goto error_malformed; symdef_ptr->name = stringbase + name_offset; - symdef_ptr->file_offset = file_offset; + symdef_ptr->u.file_offset = file_offset; ++symdef_ptr; }
diff --git a/bfd/elflink.c b/bfd/elflink.c index 29ebe41..049ef75 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c
@@ -3708,7 +3708,7 @@ Elf_Internal_Sym *isymend; bool result; - abfd = _bfd_get_elt_at_filepos (abfd, symdef->file_offset, NULL); + abfd = _bfd_get_elt_at_filepos (abfd, symdef->u.file_offset, NULL); if (abfd == NULL) return false; @@ -6305,7 +6305,7 @@ if (included[i]) continue; - if (symdef->file_offset == last) + if (symdef->u.file_offset == last) { included[i] = true; continue; @@ -6390,7 +6390,7 @@ } /* We need to include this archive member. */ - element = _bfd_get_elt_at_filepos (abfd, symdef->file_offset, + element = _bfd_get_elt_at_filepos (abfd, symdef->u.file_offset, info); if (element == NULL) goto error_return; @@ -6426,11 +6426,11 @@ break; --mark; } - while (symdefs[mark].file_offset == symdef->file_offset); + while (symdefs[mark].u.file_offset == symdef->u.file_offset); /* We mark subsequent symbols from this object file as we go on through the loop. */ - last = symdef->file_offset; + last = symdef->u.file_offset; } } while (loop);
diff --git a/bfd/linker.c b/bfd/linker.c index b905749..3fac038 100644 --- a/bfd/linker.c +++ b/bfd/linker.c
@@ -974,7 +974,7 @@ if (included[indx]) continue; - if (needed && arsym->file_offset == last_ar_offset) + if (needed && arsym->u.file_offset == last_ar_offset) { included[indx] = 1; continue; @@ -1003,9 +1003,9 @@ continue; } - if (last_ar_offset != arsym->file_offset) + if (last_ar_offset != arsym->u.file_offset) { - last_ar_offset = arsym->file_offset; + last_ar_offset = arsym->u.file_offset; element = _bfd_get_elt_at_filepos (abfd, last_ar_offset, info); if (element == NULL @@ -1034,7 +1034,7 @@ break; --mark; } - while (arsyms[mark].file_offset == last_ar_offset); + while (arsyms[mark].u.file_offset == last_ar_offset); if (undefs_tail != info->hash->undefs_tail) loop = true;
diff --git a/bfd/som.c b/bfd/som.c index d256a66..9a4ccaa 100644 --- a/bfd/som.c +++ b/bfd/som.c
@@ -6042,7 +6042,7 @@ bfd_set_error (bfd_error_bad_value); goto error_return; } - set->file_offset + set->u.file_offset = bfd_getb32 (som_dict[ndx].location) - sizeof (struct ar_hdr); /* Go to the next symbol. */ @@ -6093,7 +6093,7 @@ bfd_set_error (bfd_error_bad_value); goto error_return; } - set->file_offset + set->u.file_offset = bfd_getb32 (som_dict[ndx].location) - sizeof (struct ar_hdr); /* Go on to the next symbol. */
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c index ca82f2a..995c7ec 100644 --- a/bfd/vms-lib.c +++ b/bfd/vms-lib.c
@@ -170,7 +170,7 @@ cs->idx = n; cs->realloced = true; } - cs->idx[cs->nbr].file_offset = (idx_vbn - 1) * VMS_BLOCK_SIZE + idx_off; + cs->idx[cs->nbr].u.file_offset = (idx_vbn - 1) * VMS_BLOCK_SIZE + idx_off; cs->idx[cs->nbr].name = name; cs->nbr++; return true; @@ -1385,7 +1385,7 @@ return tdata->cache[modidx]; /* Build it. */ - file_off = tdata->modules[modidx].file_offset; + file_off = tdata->modules[modidx].u.file_offset; if (tdata->type != LBR__C_TYP_IOBJ) { res = _bfd_create_empty_archive_element_shell (abfd); @@ -1485,12 +1485,12 @@ /* Check symidx. */ if (symidx > tdata->artdata.symdef_count) return NULL; - file_off = tdata->artdata.symdefs[symidx].file_offset; + file_off = tdata->artdata.symdefs[symidx].u.file_offset; /* Linear-scan. */ for (modidx = 0; modidx < tdata->nbr_modules; modidx++) { - if (tdata->modules[modidx].file_offset == file_off) + if (tdata->modules[modidx].u.file_offset == file_off) break; } if (modidx >= tdata->nbr_modules)