* addr2line.c (usage): Update bug-gnu-utils address.
[binutils-gdb.git] / binutils / objcopy.c
index 3483f200cbedde60c2a24f9d0d63d3f276e65514..a7e804118931c6c53117b547dba09a8fe88f50ff 100644 (file)
@@ -1,5 +1,6 @@
 /* objcopy.c -- copy object file from input to output, optionally massaging it.
-   Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
+   Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
 
@@ -15,7 +16,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
 \f
 #include "bfd.h"
 #include "progress.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
+   deleted. */
+
+struct symlist
+{
+  const char *name;
+  struct symlist *next;
+};
+
 static void copy_usage PARAMS ((FILE *, int));
 static void strip_usage PARAMS ((FILE *, int));
 static flagword parse_flags PARAMS ((const char *));
@@ -41,8 +54,8 @@ static void setup_section PARAMS ((bfd *, asection *, PTR));
 static void copy_section PARAMS ((bfd *, asection *, PTR));
 static void get_sections PARAMS ((bfd *, asection *, PTR));
 static int compare_section_vma PARAMS ((const PTR, const PTR));
-static void add_strip_symbol PARAMS ((const char *));
-static boolean is_strip_symbol PARAMS ((const char *));
+static void add_specific_symbol PARAMS ((const char *, struct symlist **));
+static boolean is_specified_symbol PARAMS ((const char *, struct symlist *));
 static boolean is_strip_section PARAMS ((bfd *, asection *));
 static unsigned int filter_symbols
   PARAMS ((bfd *, bfd *, asymbol **, asymbol **, long));
@@ -166,6 +179,17 @@ static boolean change_leading_char = false;
 
 static boolean remove_leading_char = false;
 
+/* List of symbols to strip, keep, localize, and weaken.  */
+
+static struct symlist *strip_specific_list = NULL;
+static struct symlist *keep_specific_list = NULL;
+static struct symlist *localize_specific_list = NULL;
+static struct symlist *weaken_specific_list = NULL;
+
+/* If this is true, we weaken global symbols (set BSF_WEAK).  */
+
+static boolean weaken = false;
+
 /* 150 isn't special; it's just an arbitrary non-ASCII char value.  */
 
 #define OPTION_ADD_SECTION 150
@@ -285,7 +309,7 @@ Usage: %s [-vVSpgxX] [-I bfdname] [-O bfdname] [-F bfdname] [-b byte]\n\
        [--verbose] [--version] [--help] in-file [out-file]\n");
   list_supported_targets (program_name, stream);
   if (exit_status == 0)
-    fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
+    fprintf (stream, "Report bugs to bug-gnu-utils@gnu.org\n");
   exit (exit_status);
 }
 
@@ -304,7 +328,7 @@ Usage: %s [-vVsSpgxX] [-I bfdname] [-O bfdname] [-F bfdname] [-R section]\n\
           program_name);
   list_supported_targets (program_name, stream);
   if (exit_status == 0)
-    fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n");
+    fprintf (stream, "Report bugs to bug-gnu-utils@gnu.org\n");
   exit (exit_status);
 }
 
@@ -332,14 +356,31 @@ parse_flags (s)
          ++snext;
        }
 
-#define PARSE_FLAG(fname,fval) if (strncmp (fname, s, len) == 0) ret |= fval;
+      if (0) ;
+#define PARSE_FLAG(fname,fval) \
+  else if (strncasecmp (fname, s, len) == 0) ret |= fval
       PARSE_FLAG ("alloc", SEC_ALLOC);
       PARSE_FLAG ("load", SEC_LOAD);
       PARSE_FLAG ("readonly", SEC_READONLY);
       PARSE_FLAG ("code", SEC_CODE);
       PARSE_FLAG ("data", SEC_DATA);
       PARSE_FLAG ("rom", SEC_ROM);
+      PARSE_FLAG ("contents", SEC_HAS_CONTENTS);
 #undef PARSE_FLAG
+      else
+       {
+         char *copy;
+
+         copy = xmalloc (len + 1);
+         strncpy (copy, s, len);
+         copy[len] = '\0';
+         fprintf (stderr, "%s: unrecognized section flag `%s'\n",
+                  program_name, copy);
+         fprintf (stderr,
+                  "%s: supported flags: alloc, load, readonly, code, data, rom, contents\n",
+                  program_name);
+         exit (1);
+       }
 
       s = snext;
     }
@@ -379,28 +420,6 @@ find_section_list (name, add)
   return p;
 }
 
-/* Make 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 deleted. */
-
-struct symlist
-{
-  const char *name;
-  struct symlist *next;
-};
-
-/* List of symbols to strip, keep, localize, and weaken.  */
-
-static struct symlist *strip_specific_list = NULL;
-static struct symlist *keep_specific_list = NULL;
-static struct symlist *localize_specific_list = NULL;
-static struct symlist *weaken_specific_list = NULL;
-
-/* If this is true, we weaken global symbols (set BSF_WEAK).  */
-
-static boolean weaken = false;
-
 /* Add a symbol to strip_specific_list.  */
 
 static void 
@@ -919,7 +938,11 @@ copy_archive (ibfd, obfd, output_target)
   char *dir = make_tempname (bfd_get_filename (obfd));
 
   /* Make a temp directory to hold the contents.  */
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+  if (mkdir (dir) != 0)
+#else
   if (mkdir (dir, 0700) != 0)
+#endif
     {
       fatal ("cannot mkdir %s for archive copying (error: %s)",
             dir, strerror (errno));
@@ -1272,6 +1295,22 @@ copy_section (ibfd, isection, obfdarg)
        }
       free (memhunk);
     }
+  else if (p != NULL && p->set_flags && (p->flags & SEC_HAS_CONTENTS) != 0)
+    {
+      PTR memhunk = (PTR) xmalloc ((unsigned) size);
+
+      /* We don't permit the user to turn off the SEC_HAS_CONTENTS
+        flag--they can just remove the section entirely and add it
+        back again.  However, we do permit them to turn on the
+        SEC_HAS_CONTENTS flag, and take it to mean that the section
+        contents should be zeroed out.  */
+
+      memset (memhunk, 0, size);
+      if (! bfd_set_section_contents (obfd, osection, memhunk, (file_ptr) 0,
+                                     size))
+       nonfatal (bfd_get_filename (obfd));
+      free (memhunk);
+    }
 }
 
 /* Get all the sections.  This is used when --gap-fill or --pad-to is
@@ -1521,6 +1560,24 @@ smart_rename (from, to)
   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. */
+      int saved = errno;
+      fprintf (stderr, "%s: %s: ", program_name, to);
+      errno = saved;
+      perror ("rename");
+      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)
@@ -1565,6 +1622,8 @@ smart_rename (from, to)
        }
       unlink (from);
     }
+#endif /* _WIN32 && !__CYGWIN32__ */
+
   return ret;
 }