From b59f0276facbc819889ed96d1343ee804f4f761d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 3 Jan 1994 18:05:19 +0000 Subject: [PATCH] * libbfd-in.h (struct artdata): Added tdata field. (_bfd_add_bfd_to_archive_cache): Declare. (_bfd_snarf_ar_hdr): Renamed from snarf_ar_hdr. * libbfd.h: Rebuilt. * archive.c: Cleaned up some more. (_bfd_generic_mkarchive, bfd_generic_archive_p): Initialize pointer elements of artdata. (_bfd_add_bfd_to_archive_cache): Renamed from add_bfd_to_cache. (_bfd_snarf_ar_hdr): Renamed from snarf_ar_hdr. (get_extended_arelt_filename, get_elt_at_filepos, bfd_construct_extended_name_table, bfd_ar_hdr_from_filesystem, compute_and_write_armap): Made static. * ecoff.c: Some comment changes. (ecoff_slurp_armap): Handle rename of snarf_ar_hdr. Set ardata->tdata to raw_armap. (ecoff_archive_p): Initialize pointer elements of artdata. * coff-rs6000.c (rs6000coff_get_elt_at_filepos): Handle rename of add_bfd_to_cache. --- bfd/ChangeLog | 19 ++++++ bfd/archive.c | 206 +++++++++++++++++++++++++++++++------------------------- bfd/ecoff.c | 23 ++++--- bfd/libbfd-in.h | 4 +- bfd/libbfd.h | 4 +- 5 files changed, 154 insertions(+), 102 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 035c25f..ec30ad5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,24 @@ Mon Jan 3 11:41:45 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) + * libbfd-in.h (struct artdata): Added tdata field. + (_bfd_add_bfd_to_archive_cache): Declare. + (_bfd_snarf_ar_hdr): Renamed from snarf_ar_hdr. + * libbfd.h: Rebuilt. + * archive.c: Cleaned up some more. + (_bfd_generic_mkarchive, bfd_generic_archive_p): Initialize + pointer elements of artdata. + (_bfd_add_bfd_to_archive_cache): Renamed from add_bfd_to_cache. + (_bfd_snarf_ar_hdr): Renamed from snarf_ar_hdr. + (get_extended_arelt_filename, get_elt_at_filepos, + bfd_construct_extended_name_table, bfd_ar_hdr_from_filesystem, + compute_and_write_armap): Made static. + * ecoff.c: Some comment changes. + (ecoff_slurp_armap): Handle rename of snarf_ar_hdr. Set + ardata->tdata to raw_armap. + (ecoff_archive_p): Initialize pointer elements of artdata. + * coff-rs6000.c (rs6000coff_get_elt_at_filepos): Handle rename of + add_bfd_to_cache. + * hash.c: Added some documentation. Mon Jan 3 11:09:28 1994 Jim Kingdon (kingdon@lioth.cygnus.com) diff --git a/bfd/archive.c b/bfd/archive.c index 8cfdb14..9795340 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -170,28 +170,40 @@ struct ar_cache { #define arch_eltdata(bfd) ((struct areltdata *)((bfd)->arelt_data)) #define arch_hdr(bfd) ((struct ar_hdr *)arch_eltdata(bfd)->arch_header) -/* Forward declarations of functions */ - -boolean -compute_and_write_armap PARAMS ((bfd *arch, unsigned int elength)); - -static boolean -bsd_update_armap_timestamp PARAMS ((bfd *arch)); - - +static char *get_extended_arelt_filename PARAMS ((bfd *arch, + const char *name)); +static bfd *get_elt_at_filepos PARAMS ((bfd *archive, file_ptr filepos)); +static boolean do_slurp_bsd_armap PARAMS ((bfd *abfd)); +static boolean do_slurp_coff_armap PARAMS ((bfd *abfd)); +static const char *normalize PARAMS ((const char *file)); +static boolean bfd_construct_extended_name_table PARAMS ((bfd *abfd, + char **tabloc, + unsigned int *)); +static struct areltdata *bfd_ar_hdr_from_filesystem PARAMS ((bfd *abfd, + const char *)); +static boolean compute_and_write_armap PARAMS ((bfd *arch, + unsigned int elength)); +static boolean bsd_update_armap_timestamp PARAMS ((bfd *arch)); boolean _bfd_generic_mkarchive (abfd) bfd *abfd; { - abfd->tdata.aout_ar_data = (struct artdata *)bfd_zalloc(abfd, - sizeof (struct artdata)); + abfd->tdata.aout_ar_data = ((struct artdata *) + bfd_zalloc (abfd, sizeof (struct artdata))); - if (bfd_ardata (abfd) == NULL) { + if (bfd_ardata (abfd) == NULL) + { bfd_error = no_memory; return false; } - bfd_ardata(abfd)->cache = 0; + + bfd_ardata (abfd)->cache = NULL; + bfd_ardata (abfd)->archive_head = NULL; + bfd_ardata (abfd)->symdefs = NULL; + bfd_ardata (abfd)->extended_names = NULL; + bfd_ardata (abfd)->tdata = NULL; + return true; } @@ -217,10 +229,10 @@ DESCRIPTION */ symindex -DEFUN(bfd_get_next_mapent,(abfd, prev, entry), - bfd *abfd AND - symindex prev AND - carsym **entry) +bfd_get_next_mapent (abfd, prev, entry) + bfd *abfd; + symindex prev; + carsym **entry; { if (!bfd_has_map (abfd)) { bfd_error = invalid_operation; @@ -265,9 +277,9 @@ DESCRIPTION */ boolean -DEFUN(bfd_set_archive_head,(output_archive, new_head), - bfd *output_archive AND - bfd *new_head) +bfd_set_archive_head (output_archive, new_head) + bfd *output_archive; + bfd *new_head; { output_archive->archive_head = new_head; @@ -290,7 +302,7 @@ look_for_bfd_in_cache (arch_bfd, filepos) /* Kind of stupid to call cons for each one, but we don't do too many */ boolean -add_bfd_to_cache (arch_bfd, filepos, new_elt) +_bfd_add_bfd_to_archive_cache (arch_bfd, filepos, new_elt) bfd *arch_bfd, *new_elt; file_ptr filepos; { @@ -317,15 +329,14 @@ add_bfd_to_cache (arch_bfd, filepos, new_elt) return true; } - - /* The name begins with space. Hence the rest of the name is an index into the string table. */ -char * + +static char * get_extended_arelt_filename (arch, name) bfd *arch; - char *name; + const char *name; { unsigned long index = 0; @@ -352,7 +363,7 @@ get_extended_arelt_filename (arch, name) */ struct areltdata * -snarf_ar_hdr (abfd) +_bfd_snarf_ar_hdr (abfd) bfd *abfd; { #ifndef errno @@ -475,7 +486,7 @@ snarf_ar_hdr (abfd) element, since it handles the bookkeeping so nicely for us. */ -bfd * +static bfd * get_elt_at_filepos (archive, filepos) bfd *archive; file_ptr filepos; @@ -493,7 +504,7 @@ get_elt_at_filepos (archive, filepos) return NULL; } - if ((new_areldata = snarf_ar_hdr (archive)) == NULL) + if ((new_areldata = _bfd_snarf_ar_hdr (archive)) == NULL) return NULL; n_nfd = _bfd_create_empty_archive_element_shell (archive); @@ -507,7 +518,7 @@ get_elt_at_filepos (archive, filepos) n_nfd->arelt_data = (PTR) new_areldata; n_nfd->filename = new_areldata->filename; - if (add_bfd_to_cache (archive, filepos, n_nfd)) + if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_nfd)) return n_nfd; /* huh? */ @@ -530,9 +541,9 @@ DESCRIPTION */ bfd * -DEFUN(bfd_get_elt_at_index,(abfd, index), - bfd *abfd AND - int index) +bfd_get_elt_at_index (abfd, index) + bfd *abfd; + int index; { bfd *result = get_elt_at_filepos @@ -603,50 +614,60 @@ bfd_generic_archive_p (abfd) { char armag[SARMAG+1]; - if (bfd_read ((PTR)armag, 1, SARMAG, abfd) != SARMAG) { - bfd_error = wrong_format; - return 0; - } + if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG) + { + bfd_error = wrong_format; + return NULL; + } #ifdef GNU960 - if (strncmp (armag, BFD_GNU960_ARMAG(abfd), SARMAG)) return 0; + if (strncmp (armag, BFD_GNU960_ARMAG(abfd), SARMAG) != 0) + return 0; #else - if (strncmp (armag, ARMAG, SARMAG) && - strncmp (armag, ARMAGB, SARMAG)) return 0; + if (strncmp (armag, ARMAG, SARMAG) != 0 && + strncmp (armag, ARMAGB, SARMAG) != 0) + return 0; #endif - - /* 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)); + abfd->tdata.aout_ar_data = ((struct artdata *) + bfd_zalloc (abfd, sizeof (struct artdata))); - if (bfd_ardata (abfd) == NULL) { - bfd_error = no_memory; - return 0; - } + if (bfd_ardata (abfd) == NULL) + { + bfd_error = no_memory; + return NULL; + } bfd_ardata (abfd)->first_file_filepos = SARMAG; + bfd_ardata (abfd)->cache = NULL; + bfd_ardata (abfd)->archive_head = NULL; + bfd_ardata (abfd)->symdefs = NULL; + bfd_ardata (abfd)->extended_names = NULL; + bfd_ardata (abfd)->tdata = NULL; - if (!BFD_SEND (abfd, _bfd_slurp_armap, (abfd))) { - bfd_release(abfd, bfd_ardata (abfd)); - abfd->tdata.aout_ar_data = NULL; - return 0; - } + if (! BFD_SEND (abfd, _bfd_slurp_armap, (abfd))) + { + bfd_release(abfd, bfd_ardata (abfd)); + abfd->tdata.aout_ar_data = NULL; + return NULL; + } - if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) { - bfd_release(abfd, bfd_ardata (abfd)); - abfd->tdata.aout_ar_data = NULL; - return 0; - } + if (! BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) + { + bfd_release(abfd, bfd_ardata (abfd)); + abfd->tdata.aout_ar_data = NULL; + return NULL; + } return abfd->xvec; } /* Returns false on error, true otherwise */ static boolean -DEFUN (do_slurp_bsd_armap, (abfd), - bfd *abfd) +do_slurp_bsd_armap (abfd) + bfd *abfd; { struct areltdata *mapdata; unsigned int counter = 0; @@ -655,8 +676,9 @@ DEFUN (do_slurp_bsd_armap, (abfd), char *stringbase; unsigned int parsed_size; - mapdata = snarf_ar_hdr (abfd); - if (mapdata == NULL) return false; + mapdata = _bfd_snarf_ar_hdr (abfd); + if (mapdata == NULL) + return false; parsed_size = mapdata->parsed_size; bfd_release (abfd, (PTR)mapdata); /* Don't need it any more. */ @@ -708,8 +730,8 @@ DEFUN (do_slurp_bsd_armap, (abfd), /* Returns false on error, true otherwise */ static boolean -DEFUN (do_slurp_coff_armap, (abfd), - bfd *abfd) +do_slurp_coff_armap (abfd) + bfd *abfd; { struct areltdata *mapdata; int *raw_armap, *rawptr; @@ -724,8 +746,9 @@ DEFUN (do_slurp_coff_armap, (abfd), char int_buf[sizeof(long)]; unsigned int carsym_size, ptrsize, i; - mapdata = snarf_ar_hdr (abfd); - if (mapdata == NULL) return false; + mapdata = _bfd_snarf_ar_hdr (abfd); + if (mapdata == NULL) + return false; parsed_size = mapdata->parsed_size; bfd_release (abfd, (PTR)mapdata); /* Don't need it any more. */ @@ -865,8 +888,9 @@ bfd_slurp_bsd_armap_f2 (abfd) return true; } - mapdata = snarf_ar_hdr (abfd); - if (mapdata == NULL) return false; + mapdata = _bfd_snarf_ar_hdr (abfd); + if (mapdata == NULL) + return false; raw_armap = (int *) bfd_zalloc(abfd,mapdata->parsed_size); if (raw_armap == NULL) @@ -952,8 +976,9 @@ _bfd_slurp_extended_name_table (abfd) return true; } - namedata = snarf_ar_hdr (abfd); - if (namedata == NULL) return false; + namedata = _bfd_snarf_ar_hdr (abfd); + if (namedata == NULL) + return false; bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size); if (bfd_ardata (abfd)->extended_names == NULL) { @@ -999,9 +1024,9 @@ _bfd_slurp_extended_name_table (abfd) /* Return a copy of the stuff in the filename between any :]> and a semicolon */ -static CONST char * -DEFUN(normalize,(file), - CONST char *file) +static const char * +normalize (file) + const char *file; { CONST char *first; CONST char *last; @@ -1031,9 +1056,9 @@ DEFUN(normalize,(file), } #else -static CONST char * -DEFUN (normalize, (file), - CONST char *file) +static const char * +normalize (file) + const char *file; { CONST char * filename = strrchr(file, '/'); @@ -1053,11 +1078,11 @@ DEFUN (normalize, (file), Returns true if it ran successfully, false if something went wrong. A successful return may still involve a zero-length tablen! */ -boolean -DEFUN (bfd_construct_extended_name_table, (abfd, tabloc, tablen), - bfd *abfd AND - char **tabloc AND - unsigned int *tablen) +static boolean +bfd_construct_extended_name_table (abfd, tabloc, tablen) + bfd *abfd; + char **tabloc; + unsigned int *tablen; { unsigned int maxname = abfd->xvec->ar_max_namelen; unsigned int total_namelen = 0; @@ -1118,17 +1143,16 @@ DEFUN (bfd_construct_extended_name_table, (abfd, tabloc, tablen), The filename field of the ar_hdr will NOT be initialized */ -struct areltdata * -DEFUN(bfd_ar_hdr_from_filesystem, (abfd,filename), - bfd* abfd AND - CONST char *filename) +static struct areltdata * +bfd_ar_hdr_from_filesystem (abfd,filename) + bfd* abfd; + const char *filename; { struct stat status; struct areltdata *ared; struct ar_hdr *hdr; char *temp, *temp1; - if (stat (filename, &status) != 0) { bfd_error = system_call_error; return NULL; @@ -1175,9 +1199,9 @@ DEFUN(bfd_ar_hdr_from_filesystem, (abfd,filename), */ struct ar_hdr * -DEFUN(bfd_special_undocumented_glue, (abfd, filename), - bfd *abfd AND - char *filename) +bfd_special_undocumented_glue (abfd, filename) + bfd *abfd; + char *filename; { struct areltdata *ar_elt = bfd_ar_hdr_from_filesystem (abfd, filename); if (ar_elt == NULL) @@ -1269,7 +1293,8 @@ bfd_bsd_truncate_arname (abfd, pathname, arhdr) length = maxlen; } - if (length < maxlen) (hdr->ar_name)[length] = ar_padchar (abfd); + if (length < maxlen) + (hdr->ar_name)[length] = ar_padchar (abfd); } /* Store name into ar header. Truncates the name to fit. @@ -1309,7 +1334,8 @@ bfd_gnu_truncate_arname (abfd, pathname, arhdr) length = maxlen; } - if (length < 16) (hdr->ar_name)[length] = ar_padchar (abfd); + if (length < 16) + (hdr->ar_name)[length] = ar_padchar (abfd); } @@ -1455,7 +1481,7 @@ _bfd_write_archive_contents (arch) /* Note that the namidx for the first symbol is 0 */ -boolean +static boolean compute_and_write_armap (arch, elength) bfd *arch; unsigned int elength; diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 511ab59..fb4960a 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -1147,7 +1147,7 @@ ecoff_get_symtab_upper_bound (abfd) return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *)); } -/* Get the canonicals symbols. */ +/* Get the canonical symbols. */ unsigned int ecoff_get_symtab (abfd, alocation) @@ -2811,10 +2811,10 @@ ecoff_write_object_contents (abfd) } /* Archive handling. ECOFF uses what appears to be a unique type of - archive header (which I call an armap). The byte ordering of the - armap and the contents are encoded in the name of the armap itself. - At least for now, we only support archives with the same byte - ordering in the armap and the contents. + archive header (armap). The byte ordering of the armap and the + contents are encoded in the name of the armap itself. At least for + now, we only support archives with the same byte ordering in the + armap and the contents. The first four bytes in the armap are the number of symbol definitions. This is always a power of two. @@ -2830,10 +2830,6 @@ ecoff_write_object_contents (abfd) The symbols are hashed into the armap with a closed hashing scheme. See the functions below for the details of the algorithm. - We could use the hash table when looking up symbols in a library. - This would require a new BFD target entry point to replace the - bfd_get_next_mapent function used by the linker. - After the symbol definitions comes four bytes holding the size of the string table, followed by the string table itself. */ @@ -2942,7 +2938,7 @@ ecoff_slurp_armap (abfd) /* Read in the armap. */ ardata = bfd_ardata (abfd); - mapdata = snarf_ar_hdr (abfd); + mapdata = _bfd_snarf_ar_hdr (abfd); if (mapdata == (struct areltdata *) NULL) return false; parsed_size = mapdata->parsed_size; @@ -2962,6 +2958,8 @@ ecoff_slurp_armap (abfd) return false; } + ardata->tdata = (PTR) raw_armap; + count = bfd_h_get_32 (abfd, (PTR) raw_armap); ardata->symdef_count = 0; @@ -3232,6 +3230,11 @@ ecoff_archive_p (abfd) } bfd_ardata (abfd)->first_file_filepos = SARMAG; + bfd_ardata (abfd)->cache = NULL; + bfd_ardata (abfd)->archive_head = NULL; + bfd_ardata (abfd)->symdefs = NULL; + bfd_ardata (abfd)->extended_names = NULL; + bfd_ardata (abfd)->tdata = NULL; if (ecoff_slurp_armap (abfd) == false || ecoff_slurp_extended_name_table (abfd) == false) diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 5ba73fe..6e172e7 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -59,6 +59,7 @@ struct artdata { archive. */ file_ptr armap_datepos; /* Position within archive to seek to rewrite the date field. */ + PTR tdata; /* Backend specific information. */ }; #define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data) @@ -100,8 +101,9 @@ int bfd_stat PARAMS ((bfd *abfd, struct stat *)); bfd * _bfd_create_empty_archive_element_shell PARAMS ((bfd *obfd)); bfd * look_for_bfd_in_cache PARAMS ((bfd *arch_bfd, file_ptr index)); +boolean _bfd_add_bfd_to_archive_cache PARAMS ((bfd *, file_ptr, bfd *)); boolean _bfd_generic_mkarchive PARAMS ((bfd *abfd)); -struct areltdata * snarf_ar_hdr PARAMS ((bfd *abfd)); +struct areltdata * _bfd_snarf_ar_hdr PARAMS ((bfd *abfd)); bfd_target * bfd_generic_archive_p PARAMS ((bfd *abfd)); boolean bfd_slurp_armap PARAMS ((bfd *abfd)); boolean bfd_slurp_bsd_armap_f2 PARAMS ((bfd *abfd)); diff --git a/bfd/libbfd.h b/bfd/libbfd.h index d80c71f..458f803 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -59,6 +59,7 @@ struct artdata { archive. */ file_ptr armap_datepos; /* Position within archive to seek to rewrite the date field. */ + PTR tdata; /* Backend specific information. */ }; #define bfd_ardata(bfd) ((bfd)->tdata.aout_ar_data) @@ -100,8 +101,9 @@ int bfd_stat PARAMS ((bfd *abfd, struct stat *)); bfd * _bfd_create_empty_archive_element_shell PARAMS ((bfd *obfd)); bfd * look_for_bfd_in_cache PARAMS ((bfd *arch_bfd, file_ptr index)); +boolean _bfd_add_bfd_to_archive_cache PARAMS ((bfd *, file_ptr, bfd *)); boolean _bfd_generic_mkarchive PARAMS ((bfd *abfd)); -struct areltdata * snarf_ar_hdr PARAMS ((bfd *abfd)); +struct areltdata * _bfd_snarf_ar_hdr PARAMS ((bfd *abfd)); bfd_target * bfd_generic_archive_p PARAMS ((bfd *abfd)); boolean bfd_slurp_armap PARAMS ((bfd *abfd)); boolean bfd_slurp_bsd_armap_f2 PARAMS ((bfd *abfd)); -- 2.7.4