Don't abort for invalid input, print an error message instead.
[deliverable/binutils-gdb.git] / bfd / section.c
index 6064924b4308cf979ad4900e6163059683372b08..13e10d30f67536aff91177671dbe9f41d30cc2f2 100644 (file)
@@ -111,7 +111,6 @@ SUBSECTION
 |     size            0x103   |
 |     output_section  --------|
 
-
 SUBSECTION
        Link orders
 
@@ -133,7 +132,6 @@ SUBSECTION
 
 */
 
-
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
@@ -165,10 +163,6 @@ CODE_FRAGMENT
 .     specific code; it is not an index into the list returned by
 .     bfd_canonicalize_symtab.  *}
 .  long symbol;
-.
-.  {* If this section is being discarded, the linker uses this field
-.     to point to the input section which is being kept.  *}
-.  struct sec *sec;
 .};
 .
 .typedef struct sec
@@ -471,6 +465,10 @@ CODE_FRAGMENT
 .
 .  struct bfd_comdat_info *comdat;
 .
+.  {* Points to the kept section if this section is a link-once section,
+.     and is discarded.  *}
+.  struct sec *kept_section;
+.
 .  {* When a section is being output, this value changes as more
 .     linenumbers are written out.  *}
 .
@@ -567,7 +565,7 @@ static const asymbol global_syms[] =
     { NAME,  IDX, 0,     NULL, FLAGS, 0,            0,                 \
                                                                        \
     /* linker_mark, gc_mark, segment_mark, vma, lma, _cooked_size,   */        \
-       0,           0,       0,            0,   0,   0,                \
+       0,           1,       0,            0,   0,   0,                \
                                                                        \
     /* _raw_size, output_offset, output_section,    alignment_power, */ \
        0,         0,           (struct sec *) &SEC, 0,                 \
@@ -578,11 +576,11 @@ static const asymbol global_syms[] =
     /* line_filepos, userdata, contents, lineno, lineno_count,       */        \
        0,            NULL,     NULL,     NULL,   0,                    \
                                                                        \
-    /* comdat, moving_line_filepos, target_index, used_by_bfd,       */        \
-       NULL,   0,                   0,            NULL,                        \
+    /* comdat, kept_section, moving_line_filepos, target_index,      */        \
+       NULL,   NULL,         0,                   0,                   \
                                                                        \
-    /* constructor_chain, owner,                                     */        \
-       NULL,              NULL,                                                \
+    /* used_by_bfd, constructor_chain, owner,                        */        \
+       NULL,        NULL,              NULL,                           \
                                                                        \
     /* symbol,                                                       */        \
        (struct symbol_cache_entry *) &global_syms[IDX],                        \
@@ -642,7 +640,6 @@ bfd_get_section_by_name (abfd, name)
   return NULL;
 }
 
-
 /*
 FUNCTION
        bfd_get_unique_section_name
@@ -654,10 +651,10 @@ SYNOPSIS
 
 DESCRIPTION
        Invent a section name that is unique in @var{abfd} by tacking
-       a digit suffix onto the original @var{templat}.  If @var{count}
-       is non-NULL, then it specifies the first number tried as a
-       suffix to generate a unique name.  The value pointed to by
-       @var{count} will be incremented in this case.
+       a dot and a digit suffix onto the original @var{templat}.  If
+       @var{count} is non-NULL, then it specifies the first number
+       tried as a suffix to generate a unique name.  The value
+       pointed to by @var{count} will be incremented in this case.
 */
 
 char *
@@ -671,7 +668,9 @@ bfd_get_unique_section_name (abfd, templat, count)
   char *sname;
 
   len = strlen (templat);
-  sname = bfd_malloc (len + 7);
+  sname = bfd_malloc (len + 8);
+  if (sname == NULL)
+    return NULL;
   strcpy (sname, templat);
   num = 1;
   if (count != NULL)
@@ -682,7 +681,7 @@ bfd_get_unique_section_name (abfd, templat, count)
       /* If we have a million sections, something is badly wrong.  */
       if (num > 999999)
        abort ();
-      sprintf (sname + len, "%d", num++);
+      sprintf (sname + len, ".%d", num++);
     }
   while (bfd_get_section_by_name (abfd, sname) != NULL);
 
@@ -691,7 +690,6 @@ bfd_get_unique_section_name (abfd, templat, count)
   return sname;
 }
 
-
 /*
 FUNCTION
        bfd_make_section_old_way
@@ -717,7 +715,6 @@ DESCRIPTION
 
 */
 
-
 asection *
 bfd_make_section_old_way (abfd, name)
      bfd *abfd;
@@ -787,13 +784,17 @@ bfd_make_section_anyway (abfd, name)
   newsect->line_filepos = 0;
   newsect->owner = abfd;
   newsect->comdat = NULL;
+  newsect->kept_section = NULL;
 
   /* Create a symbol whos only job is to point to this section. This is
      useful for things like relocs which are relative to the base of a
      section.  */
   newsect->symbol = bfd_make_empty_symbol (abfd);
   if (newsect->symbol == NULL)
-    return NULL;
+    {
+      bfd_release (abfd, newsect);
+      return NULL;
+    }
   newsect->symbol->name = name;
   newsect->symbol->value = 0;
   newsect->symbol->section = newsect;
@@ -803,7 +804,7 @@ bfd_make_section_anyway (abfd, name)
 
   if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true)
     {
-      free (newsect);
+      bfd_release (abfd, newsect);
       return NULL;
     }
 
@@ -861,7 +862,6 @@ bfd_make_section (abfd, name)
   return bfd_make_section_anyway (abfd, name);
 }
 
-
 /*
 FUNCTION
        bfd_set_section_flags
@@ -905,14 +905,13 @@ bfd_set_section_flags (abfd, section, flags)
   return true;
 }
 
-
 /*
 FUNCTION
        bfd_map_over_sections
 
 SYNOPSIS
        void bfd_map_over_sections(bfd *abfd,
-                                  void (*func)(bfd *abfd,
+                                  void (*func) (bfd *abfd,
                                                asection *sect,
                                                PTR obj),
                                   PTR obj);
@@ -931,7 +930,6 @@ DESCRIPTION
 |         for (p = abfd->sections; p != NULL; p = p->next)
 |            func(abfd, p, ...)
 
-
 */
 
 /*VARARGS2*/
@@ -951,7 +949,6 @@ bfd_map_over_sections (abfd, operation, user_storage)
     abort ();
 }
 
-
 /*
 FUNCTION
        bfd_set_section_size
@@ -976,7 +973,7 @@ bfd_set_section_size (abfd, ptr, val)
      bfd_size_type val;
 {
   /* Once you've started writing to any section you cannot create or change
-     the size of any others. */
+     the size of any others.  */
 
   if (abfd->output_has_begun)
     {
@@ -1002,15 +999,12 @@ SYNOPSIS
          file_ptr offset,
          bfd_size_type count);
 
-
 DESCRIPTION
        Sets the contents of the section @var{section} in BFD
        @var{abfd} to the data starting in memory at @var{data}. The
        data is written to the output section starting at offset
        @var{offset} for @var{count} octets.
 
-
-
        Normally <<true>> is returned, else <<false>>. Possible error
        returns are:
        o <<bfd_error_no_contents>> -
@@ -1021,7 +1015,6 @@ DESCRIPTION
        This routine is front end to the back end function
        <<_bfd_set_section_contents>>.
 
-
 */
 
 #define bfd_get_section_size_now(abfd,sec) \
@@ -1075,6 +1068,11 @@ bfd_set_section_contents (abfd, section, location, offset, count)
       break;
     }
 
+  /* Record a copy of the data in memory if desired.  */
+  if (section->contents
+      && location != section->contents + offset)
+    memcpy (section->contents + offset, location, count);
+
   if (BFD_SEND (abfd, _bfd_set_section_contents,
                (abfd, section, location, offset, count)))
     {
@@ -1106,8 +1104,6 @@ DESCRIPTION
        with zeroes. If no errors occur, <<true>> is returned, else
        <<false>>.
 
-
-
 */
 boolean
 bfd_get_section_contents (abfd, section, location, offset, count)
This page took 0.042103 seconds and 4 git commands to generate.