From cd9782e8fd31f32bb976b676249eeefec916c956 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 21 Oct 1994 23:43:29 +0000 Subject: [PATCH] * targets.c (BFD_JUMP_TABLE_ARCHIVE): Add case for _construct_extended_name_table. (bfd_target): Add _bfd_construct_extended_name_table. * archive.c (_bfd_archive_bsd_construct_extended_name_table): New function. (_bfd_archive_coff_construct_extended_name_table): New function. (_bfd_construct_extended_name_table): Renamed by adding a leading underscore, and made externally visible. Added trailing_slash argument, and used it instead of elf_style. Changed type of tablen to bfd_size_type *. (_bfd_write_archive_contents): Use BFD_SEND to call construct_extended_name_table. Use the returned name. * libbfd-in.h (_bfd_construct_extended_name_table): Declare. (_bfd_noarchive_construct_extended_name_table): Define. (_bfd_archive_bsd_construct_extended_name_table): Declare. (_bfd_archive_coff_construct_extended_name_table): Declare. * bfd-in2.h: Rebuild. * libbfd.h: Rebuild. * som.c (som_construct_extended_name_table): New static function. * aout-target.h (MY_construct_extended_name_table): Define. * coff-rs6000.c (rs6000coff_construct_extended_name_table): Define. * ieee.c (ieee_construct_extended_name_table): Define. * libecoff.h (_bfd_ecoff_construct_extended_name_table): Define. * oasys.c (oasys_construct_extended_name_table): Define. --- bfd/ChangeLog | 26 +++++++++++ bfd/archive.c | 119 +++++++++++++++++++++++++++++++++----------------- bfd/targets.c | 3 ++ 3 files changed, 108 insertions(+), 40 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6b5a3e3acd1..8b598d266e2 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,31 @@ Fri Oct 21 17:13:07 1994 Ian Lance Taylor + * targets.c (BFD_JUMP_TABLE_ARCHIVE): Add case for + _construct_extended_name_table. + (bfd_target): Add _bfd_construct_extended_name_table. + * archive.c (_bfd_archive_bsd_construct_extended_name_table): New + function. + (_bfd_archive_coff_construct_extended_name_table): New function. + (_bfd_construct_extended_name_table): Renamed by adding a leading + underscore, and made externally visible. Added trailing_slash + argument, and used it instead of elf_style. Changed type of + tablen to bfd_size_type *. + (_bfd_write_archive_contents): Use BFD_SEND to call + construct_extended_name_table. Use the returned name. + * libbfd-in.h (_bfd_construct_extended_name_table): Declare. + (_bfd_noarchive_construct_extended_name_table): Define. + (_bfd_archive_bsd_construct_extended_name_table): Declare. + (_bfd_archive_coff_construct_extended_name_table): Declare. + * bfd-in2.h: Rebuild. + * libbfd.h: Rebuild. + * som.c (som_construct_extended_name_table): New static function. + * aout-target.h (MY_construct_extended_name_table): Define. + * coff-rs6000.c (rs6000coff_construct_extended_name_table): + Define. + * ieee.c (ieee_construct_extended_name_table): Define. + * libecoff.h (_bfd_ecoff_construct_extended_name_table): Define. + * oasys.c (oasys_construct_extended_name_table): Define. + Fix the ELF linker to not require an interpreter if no dynamic objects were seen, even when linking PIC code. * libelf.h (ELF_LINK_HASH_NEEDS_PLT): Define. diff --git a/bfd/archive.c b/bfd/archive.c index 70a0d47d9e0..090c141fe73 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -176,9 +176,6 @@ static char *get_extended_arelt_filename PARAMS ((bfd *arch, 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, @@ -1155,6 +1152,32 @@ normalize (file) } #endif +/* Build a BFD style extended name table. */ + +boolean +_bfd_archive_bsd_construct_extended_name_table (abfd, tabloc, tablen, name) + bfd *abfd; + char **tabloc; + bfd_size_type *tablen; + const char **name; +{ + *name = "ARFILENAMES/"; + return _bfd_construct_extended_name_table (abfd, false, tabloc, tablen); +} + +/* Build an SVR4 style extended name table. */ + +boolean +_bfd_archive_coff_construct_extended_name_table (abfd, tabloc, tablen, name) + bfd *abfd; + char **tabloc; + bfd_size_type *tablen; + const char **name; +{ + *name = "//"; + return _bfd_construct_extended_name_table (abfd, true, tabloc, tablen); +} + /* Follows archive_head and produces an extended name table if necessary. Returns (in tabloc) a pointer to an extended name table, and in tablen the length of the table. If it makes an entry @@ -1163,11 +1186,12 @@ normalize (file) something went wrong. A successful return may still involve a zero-length tablen! */ -static boolean -bfd_construct_extended_name_table (abfd, tabloc, tablen) +boolean +_bfd_construct_extended_name_table (abfd, trailing_slash, tabloc, tablen) bfd *abfd; + boolean trailing_slash; char **tabloc; - unsigned int *tablen; + bfd_size_type *tablen; { unsigned int maxname = abfd->xvec->ar_max_namelen; unsigned int total_namelen = 0; @@ -1189,7 +1213,15 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen) } thislen = strlen (normal); if (thislen > maxname) - total_namelen += thislen + 1; /* leave room for \n */ + { + /* Add one to leave room for \n. */ + total_namelen += thislen + 1; + if (trailing_slash) + { + /* Leave room for trailing slash. */ + ++total_namelen; + } + } } if (total_namelen == 0) @@ -1224,7 +1256,13 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen) generalise this hack. */ struct ar_hdr *hdr = arch_hdr (current); strcpy (strptr, normal); - strptr[thislen] = '\012'; + if (! trailing_slash) + strptr[thislen] = '\012'; + else + { + strptr[thislen] = '/'; + strptr[thislen + 1] = '\012'; + } hdr->ar_name[0] = ar_padchar (current); /* We know there will always be enough room (one of the few cases where you may safely use sprintf). */ @@ -1238,6 +1276,8 @@ bfd_construct_extended_name_table (abfd, tabloc, tablen) *temp = ' '; } strptr += thislen + 1; + if (trailing_slash) + ++strptr; } } @@ -1459,7 +1499,8 @@ _bfd_write_archive_contents (arch) { bfd *current; char *etable = NULL; - unsigned int elength = 0; + bfd_size_type elength = 0; + const char *ename = NULL; boolean makemap = bfd_has_map (arch); boolean hasobjects = false; /* if no .o's, don't bother to make a map */ bfd_size_type wrote; @@ -1500,7 +1541,8 @@ _bfd_write_archive_contents (arch) } } - if (!bfd_construct_extended_name_table (arch, &etable, &elength)) + if (!BFD_SEND (arch, _bfd_construct_extended_name_table, + (arch, &etable, &elength, &ename))) return false; if (bfd_seek (arch, (file_ptr) 0, SEEK_SET) != 0) @@ -1524,10 +1566,7 @@ _bfd_write_archive_contents (arch) struct ar_hdr hdr; memset ((char *) (&hdr), 0, sizeof (struct ar_hdr)); - if (ar_padchar (arch) == '/') - sprintf (&(hdr.ar_name[0]), "//"); - else - sprintf (&(hdr.ar_name[0]), "ARFILENAMES/"); + strcpy (hdr.ar_name, ename); sprintf (&(hdr.ar_size[0]), "%-10d", (int) elength); strncpy (hdr.ar_fmag, ARFMAG, 2); for (i = 0; i < sizeof (struct ar_hdr); i++) @@ -1578,23 +1617,24 @@ _bfd_write_archive_contents (arch) } } - /* Verify the timestamp in the archive file. If it would not be - accepted by the linker, rewrite it until it would be. If - anything odd happens, break out and just return. (The Berkeley - linker checks the timestamp and refuses to read the - table-of-contents if it is >60 seconds less than the file's - modified-time. That painful hack requires this painful hack. */ - - tries = 1; - do + if (makemap && hasobjects) { - if (bfd_update_armap_timestamp (arch) == true) /* FIXME!!! Vector it */ - break; - if (tries > 0) - fprintf (stderr, - "Warning: writing archive was slow: rewriting timestamp\n"); + /* Verify the timestamp in the archive file. If it would not be + accepted by the linker, rewrite it until it would be. If + anything odd happens, break out and just return. (The + Berkeley linker checks the timestamp and refuses to read the + table-of-contents if it is >60 seconds less than the file's + modified-time. That painful hack requires this painful hack. */ + tries = 1; + do + { + if (bfd_update_armap_timestamp (arch)) + break; + fprintf (stderr, + "Warning: writing archive was slow: rewriting timestamp\n"); + } + while (++tries < 6); } - while (++tries < 6); return true; } @@ -1759,14 +1799,14 @@ bsd_write_armap (arch, elength, map, orl_count, stridx) int stridx; { int padit = stridx & 1; - unsigned int ranlibsize = orl_count * sizeof (struct ranlib); + unsigned int ranlibsize = orl_count * BSD_SYMDEF_SIZE; unsigned int stringsize = stridx + padit; /* Include 8 bytes to store ranlibsize and stringsize in output. */ unsigned int mapsize = ranlibsize + stringsize + 8; file_ptr firstreal; bfd *current = arch->archive_head; bfd *last_elt = current; /* last element arch seen */ - int temp; + bfd_byte temp[4]; int count; struct ar_hdr hdr; struct stat statbuf; @@ -1792,14 +1832,13 @@ bsd_write_armap (arch, elength, map, orl_count, stridx) if (bfd_write ((char *) &hdr, 1, sizeof (struct ar_hdr), arch) != sizeof (struct ar_hdr)) return false; - bfd_h_put_32 (arch, (bfd_vma) ranlibsize, (PTR) &temp); - if (bfd_write (&temp, 1, sizeof (temp), arch) != sizeof (temp)) + bfd_h_put_32 (arch, (bfd_vma) ranlibsize, temp); + if (bfd_write (temp, 1, sizeof (temp), arch) != sizeof (temp)) return false; for (count = 0; count < orl_count; count++) { - struct symdef outs; - struct symdef *outp = &outs; + bfd_byte buf[BSD_SYMDEF_SIZE]; if (((bfd *) (map[count]).pos) != last_elt) { @@ -1813,15 +1852,15 @@ bsd_write_armap (arch, elength, map, orl_count, stridx) } /* if new archive element */ last_elt = current; - bfd_h_put_32 (arch, ((map[count]).namidx), (PTR) &outs.s.string_offset); - bfd_h_put_32 (arch, firstreal, (PTR) &outs.file_offset); - if (bfd_write ((char *) outp, 1, sizeof (outs), arch) != sizeof (outs)) + bfd_h_put_32 (arch, map[count].namidx, buf); + bfd_h_put_32 (arch, firstreal, buf + BSD_SYMDEF_OFFSET_SIZE); + if (bfd_write (buf, BSD_SYMDEF_SIZE, 1, arch) != BSD_SYMDEF_SIZE) return false; } /* now write the strings themselves */ - bfd_h_put_32 (arch, stringsize, (PTR) &temp); - if (bfd_write ((PTR) &temp, 1, sizeof (temp), arch) != sizeof (temp)) + bfd_h_put_32 (arch, stringsize, temp); + if (bfd_write (temp, 1, sizeof (temp), arch) != sizeof (temp)) return false; for (count = 0; count < orl_count; count++) { diff --git a/bfd/targets.c b/bfd/targets.c index 085028d8327..61018a512bf 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -283,6 +283,7 @@ The general target vector. .#define BFD_JUMP_TABLE_ARCHIVE(NAME)\ .CAT(NAME,_slurp_armap),\ .CAT(NAME,_slurp_extended_name_table),\ +.CAT(NAME,_construct_extended_name_table),\ .CAT(NAME,_truncate_arname),\ .CAT(NAME,_write_armap),\ .CAT(NAME,_openr_next_archived_file),\ @@ -290,6 +291,8 @@ The general target vector. .CAT(NAME,_update_armap_timestamp) . boolean (*_bfd_slurp_armap) PARAMS ((bfd *)); . boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *)); +. boolean (*_bfd_construct_extended_name_table) +. PARAMS ((bfd *, char **, bfd_size_type *, const char **)); . void (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *)); . boolean (*write_armap) PARAMS ((bfd *arch, . unsigned int elength, -- 2.30.2