(display_debug_lines, case DW_LNS_const_add_pc): Multiply adv by info.li_min_insn_length.
[deliverable/binutils-gdb.git] / binutils / objcopy.c
index 5fd77775d701a6c2af2e65eb2d8a5f7cc04e3d2f..6137f1139b1ea0499ea98404dca5c2b8bea5c4ca 100644 (file)
@@ -111,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.  */
@@ -121,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;
@@ -246,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'},
@@ -292,10 +295,12 @@ copy_usage (stream, exit_status)
 {
   fprintf (stream, _("\
 Usage: %s [-vVSpgxX] [-I bfdname] [-O bfdname] [-F bfdname] [-b byte]\n\
-       [-R section] [-i interleave] [--interleave=interleave] [--byte=byte]\n\
+       [-j section] [-R section]\n\
+       [-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"),
+       [--discard-locals] [--debugging]\n\
+       [--only-section=section] [--remove-section=section]\n"),
           program_name);
   fprintf (stream, _("\
        [--gap-fill=val] [--pad-to=address] [--preserve-dates]\n\
@@ -411,6 +416,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;
@@ -461,7 +467,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;
@@ -474,10 +480,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.
@@ -594,7 +605,7 @@ filter_bytes (memhunk, size)
 
   for (; from < end; from += interleave)
     *to++ = *from;
-  if (*size % interleave > copy_byte)
+  if (*size % interleave > (bfd_size_type) copy_byte)
     *size = (*size / interleave) + 1;
   else
     *size /= interleave;
@@ -816,6 +827,7 @@ copy_object (ibfd, obfd)
       || localize_specific_list != NULL
       || weaken_specific_list != NULL
       || sections_removed
+      || sections_copied
       || convert_debugging
       || change_leading_char
       || remove_leading_char
@@ -962,6 +974,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;
@@ -984,6 +1006,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);
 
@@ -1114,7 +1139,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));
@@ -1243,7 +1270,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;
@@ -1331,7 +1360,7 @@ copy_section (ibfd, isection, obfdarg)
 
 static void
 get_sections (obfd, osection, secppparg)
-     bfd *obfd;
+     bfd *obfd ATTRIBUTE_UNUSED;
      asection *osection;
      PTR secppparg;
 {
@@ -1438,8 +1467,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);
@@ -1644,7 +1673,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)
@@ -1670,8 +1699,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;
@@ -1769,15 +1807,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, '=');
This page took 0.02537 seconds and 4 git commands to generate.