From: Ian Lance Taylor Date: Tue, 4 Jul 1995 20:28:29 +0000 (+0000) Subject: * ar.c (replace_members): In verbose messages, use 'r' when X-Git-Tag: gdb-4_18~11527 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52af6a44ad1f772d5bf3e714a8fef86783589ed4;p=platform%2Fupstream%2Fbinutils.git * ar.c (replace_members): In verbose messages, use 'r' when replacing a member, and 'a' when adding one. * ar.c (truncate): New static variable. (normalize): Change return type to const char *. Add abfd argument. Change all callers. If truncate, chop the filename to abfd->ar_max_namelen. (main): For the 'f' modifier, set truncate to true. Don't change quick_append to replace to truncate is true. (do_quick_append): If truncate, set BFD_TRADITIONAL_FORMAT. (write_archive): Likewise. * binutils.texi, ar.1: Document 'f' modifier. PR 6888. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 4e0025b..734ddab 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,5 +1,18 @@ Tue Jul 4 14:48:42 1995 Ian Lance Taylor + * ar.c (replace_members): In verbose messages, use 'r' when + replacing a member, and 'a' when adding one. + + * ar.c (truncate): New static variable. + (normalize): Change return type to const char *. Add abfd + argument. Change all callers. If truncate, chop the filename to + abfd->ar_max_namelen. + (main): For the 'f' modifier, set truncate to true. Don't change + quick_append to replace to truncate is true. + (do_quick_append): If truncate, set BFD_TRADITIONAL_FORMAT. + (write_archive): Likewise. + * binutils.texi, ar.1: Document 'f' modifier. + * objcopy.c (enum strip_action): Define strip_unneeded. (OPTION_STRIP_UNNEEDED): Define. (strip_options): Add "strip-unneeded". diff --git a/binutils/ar.1 b/binutils/ar.1 index 93d8777..fac6223 100644 --- a/binutils/ar.1 +++ b/binutils/ar.1 @@ -364,6 +364,18 @@ issued unless you specify in advance that you expect to create it, by using this modifier. .TP +.B f +Truncate names in the archive. +.B ar +will normally permit file names of any length. This will cause it to +create archives which are not compatible with the native +.B ar +program on some systems. If this is a concern, the +.B f +modifier may be used to truncate file names when putting them in the +archive. + +.TP .B i Insert new files \c .I before\c diff --git a/binutils/ar.c b/binutils/ar.c index 7a3a477..763f561 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -61,6 +61,9 @@ struct ar_hdr * /* Forward declarations */ +static const char * +normalize PARAMS ((const char *, bfd *)); + static void remove_output PARAMS ((void)); @@ -139,6 +142,9 @@ enum pos pos_default, pos_before, pos_after, pos_end } postype = pos_default; +/* Whether to truncate names of files stored in the archive. */ +static boolean truncate = false; + int interactive = 0; void @@ -231,19 +237,32 @@ Usage: %s [-vV] archive\n", program_name); /* Normalize a file name specified on the command line into a file name which we will use in an archive. */ -static char * -normalize (file) - char *file; +static const char * +normalize (file, abfd) + const char *file; + bfd *abfd; { - char *filename = strrchr (file, '/'); + const char *filename; + + filename = strrchr (file, '/'); if (filename != (char *) NULL) - { - filename++; - } + filename++; else + filename = file; + + if (truncate + && abfd != NULL + && strlen (filename) > abfd->xvec->ar_max_namelen) { - filename = file; + char *s; + + /* Space leak. */ + s = (char *) xmalloc (abfd->xvec->ar_max_namelen + 1); + memcpy (s, filename, abfd->xvec->ar_max_namelen); + s[abfd->xvec->ar_max_namelen] = '\0'; + filename = s; } + return filename; } @@ -420,11 +439,7 @@ main (argc, argv) mri_mode = 1; break; case 'f': - /* On HP/UX 9, the f modifier means to truncate names to 14 - characters when comparing them to existing names. We - always use an extended name table, so the truncation has - no purpose for us. We ignore the modifier for - compatibility with the AR_FLAGS definition in make. */ + truncate = true; break; default: fprintf (stderr, "%s: illegal option -- %c\n", program_name, c); @@ -478,13 +493,13 @@ main (argc, argv) rebuild the name table. Unfortunately, at this point we don't actually know the maximum name length permitted by this object file format. So, we guess. FIXME. */ - if (operation == quick_append) + if (operation == quick_append && ! truncate) { char **chk; for (chk = files; chk != NULL && *chk != '\0'; chk++) { - if (strlen (normalize (*chk)) > 14) + if (strlen (normalize (*chk, (bfd *) NULL)) > 14) { operation = replace; break; @@ -808,6 +823,9 @@ do_quick_append (archive_filename, files_to_append) program_name, archive_filename); } + if (truncate) + temp->flags |= BFD_TRADITIONAL_FORMAT; + /* assume it's an achive, go straight to the end, sans $200 */ fseek (ofile, 0, 2); @@ -883,6 +901,13 @@ write_archive (iarch) been explicitly requested not to. */ obfd->has_armap = write_armap >= 0; + if (truncate) + { + /* This should really use bfd_set_file_flags, but that rejects + archives. */ + obfd->flags |= BFD_TRADITIONAL_FORMAT; + } + if (bfd_set_archive_head (obfd, contents_head) != true) bfd_fatal (old_name); @@ -1004,7 +1029,8 @@ move_members (arch, files_to_move) while (*current_ptr_ptr) { bfd *current_ptr = *current_ptr_ptr; - if (strcmp (normalize (*files_to_move), current_ptr->filename) == 0) + if (strcmp (normalize (*files_to_move, arch), + current_ptr->filename) == 0) { /* Move this file to the end of the list - first cut from where it is. */ @@ -1053,8 +1079,8 @@ replace_members (arch, files_to_move) { current = *current_ptr; - if (!strcmp (normalize (*files_to_move), - normalize (current->filename))) + if (!strcmp (normalize (*files_to_move, arch), + normalize (current->filename, arch))) { if (newer_only) { @@ -1097,8 +1123,7 @@ replace_members (arch, files_to_move) if (verbose) { - printf ("%c - %s\n", (postype == pos_after ? 'r' : 'a'), - *files_to_move); + printf ("r - %s\n", *files_to_move); } goto next_file; } @@ -1116,7 +1141,7 @@ replace_members (arch, files_to_move) } if (verbose) { - printf ("c - %s\n", *files_to_move); + printf ("a - %s\n", *files_to_move); } (*after_bfd)->next = temp; diff --git a/binutils/binutils.texi b/binutils/binutils.texi index f31cdb5..ac9a91f 100644 --- a/binutils/binutils.texi +++ b/binutils/binutils.texi @@ -344,6 +344,13 @@ created if it did not exist, when you request an update. But a warning is issued unless you specify in advance that you expect to create it, by using this modifier. +@item f +Truncate names in the archive. GNU @code{ar} will normally permit file +names of any length. This will cause it to create archives which are +not compatible with the native @code{ar} program on some systems. If +this is a concern, the @samp{f} modifier may be used to truncate file +names when putting them in the archive. + @item i Insert new files @emph{before} an existing member of the archive. If you use the modifier @samp{i}, the name of an existing archive