This lot mainly cleans up `comparison between signed and unsigned' gcc
[deliverable/binutils-gdb.git] / binutils / objcopy.c
index 194478af97352d1ac1e16bf9d39bd9edc5d8d255..37b12e7ba5190231fdbfe3a7d857cf63f58da696 100644 (file)
@@ -1,5 +1,5 @@
 /* objcopy.c -- copy object file from input to output, optionally massaging it.
-   Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
+   Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 1999
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 #include "budbg.h"
 #include <sys/stat.h>
 
-#include "elf/internal.h"
-#include "elf-bfd.h"
-
-#ifdef HAVE_GOOD_UTIME_H
-#include <utime.h>
-#else /* ! HAVE_GOOD_UTIME_H */
-#ifdef HAVE_UTIMES
-#include <sys/time.h>
-#endif /* HAVE_UTIMES */
-#endif /* ! HAVE_GOOD_UTIME_H */
-
 /* A list of symbols to explicitly strip out, or to keep.  A linked
    list is good enough for a small number from the command line, but
    this will slow things down a lot if many symbols are being
@@ -69,9 +58,6 @@ static void copy_object PARAMS ((bfd *, bfd *));
 static void copy_archive PARAMS ((bfd *, bfd *, const char *));
 static void copy_file
   PARAMS ((const char *, const char *, const char *, const char *));
-static int simple_copy PARAMS ((const char *, const char *));
-static int smart_rename PARAMS ((const char *, const char *));
-static void set_times PARAMS ((const char *, const struct stat *));
 static int strip_main PARAMS ((int, char **));
 static int copy_main PARAMS ((int, char **));
 
@@ -125,6 +111,7 @@ struct section_list
   const char *          name;      /* Section name.  */
   boolean               used;      /* Whether this entry was used.  */
   boolean               remove;    /* Whether to remove this section.  */
+  boolean              copy;      /* Whether to copy this section.  */
   enum change_action    change_vma;/* Whether to change or set VMA.  */
   bfd_vma              vma_val;   /* Amount to change by or set to.  */
   enum change_action    change_lma;/* Whether to change or set LMA.  */
@@ -135,6 +122,7 @@ struct section_list
 
 static struct section_list *change_sections;
 static boolean sections_removed;
+static boolean sections_copied;
 
 /* Changes to the start address.  */
 static bfd_vma change_start = 0;
@@ -260,6 +248,7 @@ static struct option copy_options[] =
   {"debugging", no_argument, 0, OPTION_DEBUGGING},
   {"discard-all", no_argument, 0, 'x'},
   {"discard-locals", no_argument, 0, 'X'},
+  {"only-section", required_argument, 0, 'j'},
   {"format", required_argument, 0, 'F'}, /* Obsolete */
   {"gap-fill", required_argument, 0, OPTION_GAP_FILL},
   {"help", no_argument, 0, 'h'},
@@ -304,29 +293,52 @@ copy_usage (stream, exit_status)
      FILE *stream;
      int exit_status;
 {
+  fprintf (stream, _("Usage: %s <switches> in-file [out-file]\n"), program_name);
+  fprintf (stream, _(" The switches are:\n"));
   fprintf (stream, _("\
-Usage: %s [-vVSpgxX] [-I bfdname] [-O bfdname] [-F bfdname] [-b byte]\n\
-       [-R section] [-i interleave] [--interleave=interleave] [--byte=byte]\n\
-       [--input-target=bfdname] [--output-target=bfdname] [--target=bfdname]\n\
-       [--strip-all] [--strip-debug] [--strip-unneeded] [--discard-all]\n\
-       [--discard-locals] [--debugging] [--remove-section=section]\n"),
-          program_name);
-  fprintf (stream, _("\
-       [--gap-fill=val] [--pad-to=address] [--preserve-dates]\n\
-       [--set-start=val] \n\
-       [--change-start=incr] [--change-addresses=incr] \n\
-       (--adjust-start   and  --adjust-vma are aliases for these two) \n\
-       [--change-section-address=section{=,+,-}val]\n\
-       (--adjust-section-vma is an alias for --change-section-address)\n\
-       [--change-section-lma=section{=,+,-}val]\n\
-       [--change-section-vma=section{=,+,-}val]\n\
-       [--adjust-warnings] [--no-adjust-warnings]\n\
-       [--change-warnings] [--no-change-warnings]\n\
-       [--set-section-flags=section=flags] [--add-section=sectionname=filename]\n\
-       [--keep-symbol symbol] [-K symbol] [--strip-symbol symbol] [-N symbol]\n\
-       [--localize-symbol symbol] [-L symbol] [--weaken-symbol symbol]\n\
-       [-W symbol] [--change-leading-char] [--remove-leading-char] [--weaken]\n\
-       [--verbose] [--version] [--help] in-file [out-file]\n"));
+  -I --input-target <bfdname>      Assume input file is in format <bfdname>\n\
+  -O --output-target <bfdname>     Create an output file in format <bfdname>\n\
+  -F --target <bfdname>            Set both input and output format to <bfdname>\n\
+     --debugging                   Convert debugging information, if possible\n\
+  -p --preserve-dates              Copy modified/access timestamps to the output\n\
+  -j --only-section <name>         Only copy section <name> into the output\n\
+  -R --remove-section <name>       Remove section <name> from the output\n\
+  -S --strip-all                   Remove all symbol and relocation information\n\
+  -g --strip-debug                 Remove all debugging symbols\n\
+     --strip-unneeded              Remove all symbols not needed by relocations\n\
+  -N --strip-symbol <name>         Do not copy symbol <name>\n\
+  -K --keep-symbol <name>          Only copy symbol <name>\n\
+  -L --localize-symbol <name>      Force symbol <name> to be marked as a local\n\
+  -W --weaken-symbol <name>        Force symbol <name> to be marked as a weak\n\
+     --weaken                      Force all global symbols to be marked as weak\n\
+  -x --discard-all                 Remove all non-global symbols\n\
+  -X --discard-locals              Remove any compiler-generated symbols\n\
+  -i --interleave <number>         Only copy one out of every <number> bytes\n\
+  -b --byte <num>                  Select byte <num> in every interleaved block\n\
+     --gap-fill <val>              Fill gaps between sections with <val>\n\
+     --pad-to <addr>               Pad the last section up to address <addr>\n\
+     --set-start <addr>            Set the start address to <addr>\n\
+    {--change-start|--adjust-start} <incr>\n\
+                                   Add <incr> to the start address\n\
+    {--change-addresses|--adjust-vma} <incr>\n\
+                                   Add <incr> to LMA, VMA and start addresses\n\
+    {--change-section-address|--adjust-section-vma} <name>{=|+|-}<val>\n\
+                                   Change LMA and VMA of section <name> by <val>\n\
+     --change-section-lma <name>{=|+|-}<val>\n\
+                                   Change the LMA of section <name> by <val>\n\
+     --change-section-vma <name>{=|+|-}<val>\n\
+                                   Change the VMA of section <name> by <val>\n\
+    {--[no-]change-warnings|--[no-]adjust-warnings}\n\
+                                   Warn if a named section does not exist\n\
+     --set-section-flags <name>=<flags>\n\
+                                   Set section <name>'s properties to <flags>\n\
+     --add-section <name>=<file>   Add section <name> found in <file> to output\n\
+     --change-leading-char         Force output format's leading character style\n\
+     --remove-leading-char         Remove leading character from global symbols\n\
+  -v --verbose                     List all object files modified\n\
+  -V --version                     Display this program's version number\n\
+  -h --help                        Display this output\n\
+"));
   list_supported_targets (program_name, stream);
   if (exit_status == 0)
     fprintf (stream, _("Report bugs to bug-gnu-utils@gnu.org\n"));
@@ -338,14 +350,27 @@ strip_usage (stream, exit_status)
      FILE *stream;
      int exit_status;
 {
+  fprintf (stream, _("Usage: %s <switches> in-file(s)\n"), program_name);
+  fprintf (stream, _(" The switches are:\n"));
   fprintf (stream, _("\
-Usage: %s [-vVsSpgxX] [-I bfdname] [-O bfdname] [-F bfdname] [-R section]\n\
-       [--input-target=bfdname] [--output-target=bfdname] [--target=bfdname]\n\
-       [--strip-all] [--strip-debug] [--strip-unneeded] [--discard-all]\n\
-       [--discard-locals] [--keep-symbol symbol] [-K symbol]\n\
-       [--strip-symbol symbol] [-N symbol] [--remove-section=section]\n\
-       [-o file] [--preserve-dates] [--verbose] [--version] [--help] file...\n"),
-          program_name);
+  -I --input-target <bfdname>      Assume input file is in format <bfdname>\n\
+  -O --output-target <bfdname>     Create an output file in format <bfdname>\n\
+  -F --target <bfdname>            Set both input and output format to <bfdname>\n\
+  -p --preserve-dates              Copy modified/access timestamps to the output\n\
+  -R --remove-section <name>       Remove section <name> from the output\n\
+  -s --strip-all                   Remove all symbol and relocation information\n\
+  -g -S --strip-debug              Remove all debugging symbols\n\
+     --strip-unneeded              Remove all symbols not needed by relocations\n\
+  -N --strip-symbol <name>         Do not copy symbol <name>\n\
+  -K --keep-symbol <name>          Only copy symbol <name>\n\
+  -x --discard-all                 Remove all non-global symbols\n\
+  -X --discard-locals              Remove any compiler-generated symbols\n\
+  -v --verbose                     List all object files modified\n\
+  -V --version                     Display this program's version number\n\
+  -h --help                        Display this output\n\
+  -o <file>                        Place stripped output into <file>\n\
+"));
+
   list_supported_targets (program_name, stream);
   if (exit_status == 0)
     fprintf (stream, _("Report bugs to bug-gnu-utils@gnu.org\n"));
@@ -381,10 +406,13 @@ parse_flags (s)
   else if (strncasecmp (fname, s, len) == 0) ret |= fval
       PARSE_FLAG ("alloc", SEC_ALLOC);
       PARSE_FLAG ("load", SEC_LOAD);
+      PARSE_FLAG ("noload", SEC_NEVER_LOAD);
       PARSE_FLAG ("readonly", SEC_READONLY);
+      PARSE_FLAG ("debug", SEC_DEBUGGING);
       PARSE_FLAG ("code", SEC_CODE);
       PARSE_FLAG ("data", SEC_DATA);
       PARSE_FLAG ("rom", SEC_ROM);
+      PARSE_FLAG ("share", SEC_SHARED);
       PARSE_FLAG ("contents", SEC_HAS_CONTENTS);
 #undef PARSE_FLAG
       else
@@ -395,7 +423,7 @@ parse_flags (s)
          strncpy (copy, s, len);
          copy[len] = '\0';
          non_fatal (_("unrecognized section flag `%s'"), copy);
-         fatal (_("supported flags: alloc, load, readonly, code, data, rom, contents"));
+         fatal (_("supported flags: alloc, load, noload, readonly, debug, code, data, rom, share, contents"));
        }
 
       s = snext;
@@ -425,6 +453,7 @@ find_section_list (name, add)
   p->name = name;
   p->used = false;
   p->remove = false;
+  p->copy = false;
   p->change_vma = CHANGE_IGNORE;
   p->change_lma = CHANGE_IGNORE;
   p->vma_val = 0;
@@ -475,7 +504,7 @@ is_specified_symbol (name, list)
 
 static boolean
 is_strip_section (abfd, sec)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      asection *sec;
 {
   struct section_list *p;
@@ -488,10 +517,15 @@ is_strip_section (abfd, sec)
          || convert_debugging))
     return true;
 
-  if (! sections_removed)
+  if (! sections_removed && ! sections_copied)
     return false;
+
   p = find_section_list (bfd_get_section_name (abfd, sec), false);
-  return p != NULL && p->remove ? true : false;
+  if (sections_removed && p != NULL && p->remove)
+    return true;
+  if (sections_copied && (p == NULL || ! p->copy))
+    return true;
+  return false;
 }
 
 /* Choose which symbol entries to copy; put the result in OSYMS.
@@ -545,7 +579,12 @@ filter_symbols (abfd, obfd, osyms, isyms, symcount)
          && name[0] == bfd_get_symbol_leading_char (abfd))
        name = bfd_asymbol_name (sym) = name + 1;
 
-      if ((flags & BSF_KEEP) != 0)             /* Used in relocation.  */
+      if (strip_symbols == STRIP_ALL)
+       keep = 0;
+      else if ((flags & BSF_KEEP) != 0         /* Used in relocation.  */
+              || ((flags & BSF_SECTION_SYM) != 0
+                  && ((*bfd_get_section (sym)->symbol_ptr_ptr)->flags
+                      & BSF_KEEP) != 0))
        keep = 1;
       else if ((flags & BSF_GLOBAL) != 0       /* Global symbol.  */
               || (flags & BSF_WEAK) != 0
@@ -603,7 +642,10 @@ filter_bytes (memhunk, size)
 
   for (; from < end; from += interleave)
     *to++ = *from;
-  *size /= interleave;
+  if (*size % interleave > (bfd_size_type) copy_byte)
+    *size = (*size / interleave) + 1;
+  else
+    *size /= interleave;
 }
 
 /* Copy object file IBFD onto OBFD.  */
@@ -618,6 +660,9 @@ copy_object (ibfd, obfd)
   asection **osections = NULL;
   bfd_size_type *gaps = NULL;
   bfd_size_type max_gap = 0;
+  long symsize;
+  PTR dhandle;
+
 
   if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
     RETURN_NONFATAL (bfd_get_filename (obfd));
@@ -797,63 +842,56 @@ copy_object (ibfd, obfd)
 
   /* Symbol filtering must happen after the output sections have
      been created, but before their contents are set.  */
-  if (strip_symbols == STRIP_ALL)
+  dhandle = NULL;
+  symsize = bfd_get_symtab_upper_bound (ibfd);
+  if (symsize < 0)
+    RETURN_NONFATAL (bfd_get_filename (ibfd));
+  
+  osympp = isympp = (asymbol **) xmalloc (symsize);
+  symcount = bfd_canonicalize_symtab (ibfd, isympp);
+  if (symcount < 0)
+    RETURN_NONFATAL (bfd_get_filename (ibfd));
+  
+  if (convert_debugging)
+    dhandle = read_debugging_info (ibfd, isympp, symcount);
+  
+  if (strip_symbols == STRIP_DEBUG 
+      || strip_symbols == STRIP_ALL
+      || strip_symbols == STRIP_UNNEEDED
+      || discard_locals != LOCALS_UNDEF
+      || strip_specific_list != NULL
+      || keep_specific_list != NULL
+      || localize_specific_list != NULL
+      || weaken_specific_list != NULL
+      || sections_removed
+      || sections_copied
+      || convert_debugging
+      || change_leading_char
+      || remove_leading_char
+      || weaken)
     {
-      osympp = isympp = NULL;
-      symcount = 0;
+      /* Mark symbols used in output relocations so that they
+        are kept, even if they are local labels or static symbols.
+        
+        Note we iterate over the input sections examining their
+        relocations since the relocations for the output sections
+        haven't been set yet.  mark_symbols_used_in_relocations will
+        ignore input sections which have no corresponding output
+        section.  */
+      if (strip_symbols != STRIP_ALL)
+       bfd_map_over_sections (ibfd,
+                              mark_symbols_used_in_relocations,
+                              (PTR)isympp);
+      osympp = (asymbol **) xmalloc ((symcount + 1) * sizeof (asymbol *));
+      symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
     }
-  else
-    {
-      long symsize;
-      PTR dhandle = NULL;
-
-      symsize = bfd_get_symtab_upper_bound (ibfd);
-      if (symsize < 0)
-       RETURN_NONFATAL (bfd_get_filename (ibfd));
-
-      osympp = isympp = (asymbol **) xmalloc (symsize);
-      symcount = bfd_canonicalize_symtab (ibfd, isympp);
-      if (symcount < 0)
-       RETURN_NONFATAL (bfd_get_filename (ibfd));
-
-      if (convert_debugging)
-       dhandle = read_debugging_info (ibfd, isympp, symcount);
 
-      if (strip_symbols == STRIP_DEBUG 
-         || strip_symbols == STRIP_UNNEEDED
-         || discard_locals != LOCALS_UNDEF
-         || strip_specific_list != NULL
-         || keep_specific_list != NULL
-         || localize_specific_list != NULL
-         || weaken_specific_list != NULL
-         || sections_removed
-         || convert_debugging
-         || change_leading_char
-         || remove_leading_char
-         || weaken)
-       {
-         /* Mark symbols used in output relocations so that they
-            are kept, even if they are local labels or static symbols.
-
-            Note we iterate over the input sections examining their
-            relocations since the relocations for the output sections
-            haven't been set yet.  mark_symbols_used_in_relocations will
-            ignore input sections which have no corresponding output
-            section.  */
-         bfd_map_over_sections (ibfd,
-                                mark_symbols_used_in_relocations,
-                                (PTR)isympp);
-         osympp = (asymbol **) xmalloc ((symcount + 1) * sizeof (asymbol *));
-         symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
-       }
-
-      if (convert_debugging && dhandle != NULL)
+  if (convert_debugging && dhandle != NULL)
+    {
+      if (! write_debugging_info (obfd, dhandle, &symcount, &osympp))
        {
-         if (! write_debugging_info (obfd, dhandle, &symcount, &osympp))
-           {
-             status = 1;
-             return;
-           }
+         status = 1;
+         return;
        }
     }
 
@@ -973,6 +1011,16 @@ copy_archive (ibfd, obfd, output_target)
                                  (char *) NULL);
       bfd *output_bfd = bfd_openw (output_name, output_target);
       bfd *last_element;
+      struct stat buf;
+      int stat_status = 0;
+
+      if (preserve_dates)
+       {
+         stat_status = bfd_stat_arch_elt (this_element, &buf);
+         if (stat_status != 0)
+           non_fatal (_("internal stat error on %s"),
+                      bfd_get_filename (this_element));
+       }
 
       l = (struct name_list *) xmalloc (sizeof (struct name_list));
       l->name = output_name;
@@ -995,6 +1043,9 @@ copy_archive (ibfd, obfd, output_target)
          status = 1;
        }
 
+      if (preserve_dates && stat_status == 0)
+       set_times (output_name, &buf);
+
       /* Open the newly output file and attach to our list.  */
       output_bfd = bfd_openr (output_name, output_target);
 
@@ -1125,7 +1176,9 @@ setup_section (ibfd, isection, obfdarg)
   if (p != NULL)
     p->used = true;
 
-  if (p != NULL && p->remove)
+  if (sections_removed && p != NULL && p->remove)
+    return;
+  if (sections_copied && (p == NULL || ! p->copy))
     return;
 
   osection = bfd_make_section_anyway (obfd, bfd_section_name (ibfd, isection));
@@ -1235,6 +1288,7 @@ copy_section (ibfd, isection, obfdarg)
   long relcount;
   sec_ptr osection;
   bfd_size_type size;
+  long relsize;
 
   /* If we have already failed earlier on, do not keep on generating
      complaints now.  */
@@ -1253,7 +1307,9 @@ copy_section (ibfd, isection, obfdarg)
 
   p = find_section_list (bfd_section_name (ibfd, isection), false);
 
-  if (p != NULL && p->remove)
+  if (sections_removed && p != NULL && p->remove)
+    return;
+  if (sections_copied && (p == NULL || ! p->copy))
     return;
 
   osection = isection->output_section;
@@ -1262,29 +1318,42 @@ copy_section (ibfd, isection, obfdarg)
   if (size == 0 || osection == 0)
     return;
 
-  if (strip_symbols == STRIP_ALL)
+
+  relsize = bfd_get_reloc_upper_bound (ibfd, isection);
+  if (relsize < 0)
+    RETURN_NONFATAL (bfd_get_filename (ibfd));
+  
+  if (relsize == 0)
     bfd_set_reloc (obfd, osection, (arelent **) NULL, 0);
   else
     {
-      long relsize;
-
-      relsize = bfd_get_reloc_upper_bound (ibfd, isection);
-      if (relsize < 0)
+      relpp = (arelent **) xmalloc (relsize);
+      relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
+      if (relcount < 0)
        RETURN_NONFATAL (bfd_get_filename (ibfd));
-
-      if (relsize == 0)
-       bfd_set_reloc (obfd, osection, (arelent **) NULL, 0);
-      else
+      
+      if (strip_symbols == STRIP_ALL)
        {
-         relpp = (arelent **) xmalloc (relsize);
-         relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
-         if (relcount < 0)
-           RETURN_NONFATAL (bfd_get_filename (ibfd));
-
-         bfd_set_reloc (obfd, osection, relpp, relcount);
+         /* Remove relocations which are not in
+            keep_strip_specific_list. */
+         arelent **temp_relpp;
+         long temp_relcount = 0;
+         long i;
+         
+         temp_relpp = (arelent **) xmalloc (relsize);
+         for (i = 0; i < relcount; i++)
+           if (is_specified_symbol
+               (bfd_asymbol_name (*relpp [i]->sym_ptr_ptr),
+                keep_specific_list))
+             temp_relpp [temp_relcount++] = relpp [i];
+         relcount = temp_relcount;
+         free (relpp);
+         relpp = temp_relpp;
        }
+      bfd_set_reloc (obfd, osection,
+                    (relcount == 0 ? (arelent **) NULL : relpp), relcount);
     }
-
+  
   isection->_cooked_size = isection->_raw_size;
   isection->reloc_done = true;
 
@@ -1328,7 +1397,7 @@ copy_section (ibfd, isection, obfdarg)
 
 static void
 get_sections (obfd, osection, secppparg)
-     bfd *obfd;
+     bfd *obfd ATTRIBUTE_UNUSED;
      asection *osection;
      PTR secppparg;
 {
@@ -1435,8 +1504,8 @@ static boolean
 write_debugging_info (obfd, dhandle, symcountp, symppp)
      bfd *obfd;
      PTR dhandle;
-     long *symcountp;
-     asymbol ***symppp;
+     long *symcountp ATTRIBUTE_UNUSED;
+     asymbol ***symppp ATTRIBUTE_UNUSED;
 {
   if (bfd_get_flavour (obfd) == bfd_target_ieee_flavour)
     return write_ieee_debugging_info (obfd, dhandle);
@@ -1499,178 +1568,6 @@ write_debugging_info (obfd, dhandle, symcountp, symppp)
   return false;
 }
 
-/* The number of bytes to copy at once.  */
-#define COPY_BUF 8192
-
-/* Copy file FROM to file TO, performing no translations.
-   Return 0 if ok, -1 if error.  */
-
-static int
-simple_copy (from, to)
-     const char *from;
-     const char *to;
-{
-  int fromfd, tofd, nread;
-  int saved;
-  char buf[COPY_BUF];
-
-  fromfd = open (from, O_RDONLY);
-  if (fromfd < 0)
-    return -1;
-  tofd = creat (to, 0777);
-  if (tofd < 0)
-    {
-      saved = errno;
-      close (fromfd);
-      errno = saved;
-      return -1;
-    }
-  while ((nread = read (fromfd, buf, sizeof buf)) > 0)
-    {
-      if (write (tofd, buf, nread) != nread)
-       {
-         saved = errno;
-         close (fromfd);
-         close (tofd);
-         errno = saved;
-         return -1;
-       }
-    }
-  saved = errno;
-  close (fromfd);
-  close (tofd);
-  if (nread < 0)
-    {
-      errno = saved;
-      return -1;
-    }
-  return 0;
-}
-
-#ifndef S_ISLNK
-#ifdef S_IFLNK
-#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
-#else
-#define S_ISLNK(m) 0
-#define lstat stat
-#endif
-#endif
-
-/* Rename FROM to TO, copying if TO is a link.
-   Assumes that TO already exists, because FROM is a temp file.
-   Return 0 if ok, -1 if error.  */
-
-static int
-smart_rename (from, to)
-     const char *from;
-     const char *to;
-{
-  struct stat s;
-  int ret = 0;
-
-  if (lstat (to, &s))
-    return -1;
-
-#if defined (_WIN32) && !defined (__CYGWIN32__)
-  /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but
-     fail instead.  Also, chown is not present.  */
-
-  if (stat (to, &s) == 0)
-    remove (to);
-
-  ret = rename (from, to);
-  if (ret != 0)
-    {
-      /* We have to clean up here. */
-      
-      non_fatal (_("%s: rename: %s"), to, strerror (errno));
-      unlink (from);
-    }
-#else
-  /* Use rename only if TO is not a symbolic link and has
-     only one hard link.  */
-  if (!S_ISLNK (s.st_mode) && s.st_nlink == 1)
-    {
-      ret = rename (from, to);
-      if (ret == 0)
-       {
-         /* Try to preserve the permission bits and ownership of TO.
-             First get the mode right except for the setuid bit.  Then
-             change the ownership.  Then fix the setuid bit.  We do
-             the chmod before the chown because if the chown succeeds,
-             and we are a normal user, we won't be able to do the
-             chmod afterward.  We don't bother to fix the setuid bit
-             first because that might introduce a fleeting security
-             problem, and because the chown will clear the setuid bit
-             anyhow.  We only fix the setuid bit if the chown
-             succeeds, because we don't want to introduce an
-             unexpected setuid file owned by the user running objcopy.  */
-         chmod (to, s.st_mode & 0777);
-         if (chown (to, s.st_uid, s.st_gid) >= 0)
-           chmod (to, s.st_mode & 07777);
-       }
-      else
-       {
-         /* We have to clean up here. */
-         non_fatal (_("%s: rename: %s"), to, strerror (errno));
-         unlink (from);
-       }
-    }
-  else
-    {
-      ret = simple_copy (from, to);
-      if (ret != 0)
-       non_fatal (_("%s: simple_copy: %s"), to, strerror (errno));
-
-      if (preserve_dates)
-       set_times (to, &s);
-      unlink (from);
-    }
-#endif /* _WIN32 && !__CYGWIN32__ */
-
-  return ret;
-}
-
-/* Set the times of the file DESTINATION to be the same as those in
-   STATBUF.  */
-
-static void
-set_times (destination, statbuf)
-     const char *destination;
-     const struct stat *statbuf;
-{
-  int result;
-
-  {
-#ifdef HAVE_GOOD_UTIME_H
-    struct utimbuf tb;
-
-    tb.actime = statbuf->st_atime;
-    tb.modtime = statbuf->st_mtime;
-    result = utime (destination, &tb);
-#else /* ! HAVE_GOOD_UTIME_H */
-#ifndef HAVE_UTIMES
-    long tb[2];
-
-    tb[0] = statbuf->st_atime;
-    tb[1] = statbuf->st_mtime;
-    result = utime (destination, tb);
-#else /* HAVE_UTIMES */
-    struct timeval tv[2];
-
-    tv[0].tv_sec = statbuf->st_atime;
-    tv[0].tv_usec = 0;
-    tv[1].tv_sec = statbuf->st_mtime;
-    tv[1].tv_usec = 0;
-    result = utimes (destination, tv);
-#endif /* HAVE_UTIMES */
-#endif /* ! HAVE_GOOD_UTIME_H */
-  }
-
-  if (result != 0)
-    non_fatal (_("%s: cannot set time: %s"), destination, strerror (errno));
-}
-
 static int
 strip_main (argc, argv)
      int argc;
@@ -1750,8 +1647,7 @@ strip_main (argc, argv)
   /* Default is to strip all symbols.  */
   if (strip_symbols == STRIP_UNDEF
       && discard_locals == LOCALS_UNDEF
-      && strip_specific_list == NULL
-      && keep_specific_list == NULL)
+      && strip_specific_list == NULL)
     strip_symbols = STRIP_ALL;
 
   if (output_target == (char *) NULL)
@@ -1789,7 +1685,7 @@ strip_main (argc, argv)
          if (preserve_dates)
            set_times (tmpname, &statbuf);
          if (output_file == NULL)
-           smart_rename (tmpname, argv[i]);
+           smart_rename (tmpname, argv[i], preserve_dates);
          status = hold_status;
        }
       else
@@ -1814,7 +1710,7 @@ copy_main (argc, argv)
   struct section_list *p;
   struct stat statbuf;
 
-  while ((c = getopt_long (argc, argv, "b:i:I:K:N:s:O:d:F:L:R:SpgxXVvW:",
+  while ((c = getopt_long (argc, argv, "b:i:I:j:K:N:s:O:d:F:L:R:SpgxXVvW:",
                           copy_options, (int *) 0)) != EOF)
     {
       switch (c)
@@ -1840,8 +1736,17 @@ copy_main (argc, argv)
        case 'F':
          input_target = output_target = optarg;
          break;
+       case 'j':
+         p = find_section_list (optarg, true);
+         if (p->remove)
+           fatal (_("%s both copied and removed"), optarg);
+         p->copy = true;
+         sections_copied = true;
+         break;
        case 'R':
          p = find_section_list (optarg, true);
+         if (p->copy)
+           fatal (_("%s both copied and removed"), optarg);
          p->remove = true;
          sections_removed = true;
          break;
@@ -1939,15 +1844,21 @@ copy_main (argc, argv)
            const char *s;
            int len;
            char *name;
-           char *option;
+           char *option = NULL;
            bfd_vma val;
-           enum change_action what;
+           enum change_action what = CHANGE_IGNORE;
            
            switch (c)
              {
-             case OPTION_CHANGE_SECTION_ADDRESS: option = "--change-section-address"; break;
-             case OPTION_CHANGE_SECTION_LMA: option = "--change-section-lma"; break;
-             case OPTION_CHANGE_SECTION_VMA: option = "--change-section-vma"; break;
+             case OPTION_CHANGE_SECTION_ADDRESS:
+               option = "--change-section-address";
+               break;
+             case OPTION_CHANGE_SECTION_LMA:
+               option = "--change-section-lma";
+               break;
+             case OPTION_CHANGE_SECTION_VMA:
+               option = "--change-section-vma";
+               break;
              }
            
            s = strchr (optarg, '=');
@@ -2110,7 +2021,7 @@ copy_main (argc, argv)
        {       
          if (preserve_dates)
            set_times (tmpname, &statbuf);
-         smart_rename (tmpname, input_filename);
+         smart_rename (tmpname, input_filename, preserve_dates);
        }
       else
        unlink (tmpname);
@@ -2165,7 +2076,7 @@ main (argc, argv)
      int argc;
      char *argv[];
 {
-#ifdef HAVE_SETLOCALE
+#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   setlocale (LC_MESSAGES, "");
 #endif
   bindtextdomain (PACKAGE, LOCALEDIR);
This page took 0.031951 seconds and 4 git commands to generate.