2001-10-05 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / bfd / section.c
index ad9046285e60d54daa5dcb5a210a419b2996dea8..f3bd381a4cca198fd4e277d2cf140ab0cd95f841 100644 (file)
@@ -205,9 +205,11 @@ CODE_FRAGMENT
 .     some relocation information too.  *}
 .#define SEC_RELOC      0x004
 .
-.#if 0   {* Obsolete ? *}
-.#define SEC_BALIGN     0x008
-.#endif
+.  {* ELF reserves 4 processor specific bits and 8 operating system
+.     specific bits in sh_flags; at present we can get away with just
+.     one in communicating between the assembler and BFD, but this
+.     isn't a good long-term solution.  *}
+.#define SEC_ARCH_BIT_0 0x008
 .
 .  {* A signal to the OS that the section contains read only data.  *}
 .#define SEC_READONLY   0x010
@@ -483,10 +485,6 @@ 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.  *}
 .
@@ -597,8 +595,8 @@ static const asymbol global_syms[] =
     /* line_filepos, userdata, contents, lineno, lineno_count,       */        \
        0,            NULL,     NULL,     NULL,   0,                    \
                                                                        \
-    /* entsize, comdat, kept_section, moving_line_filepos,           */        \
-       0,       NULL,   NULL,         0,                               \
+    /* entsize, comdat, moving_line_filepos,                         */        \
+       0,       NULL,   0,                                             \
                                                                        \
     /* target_index, used_by_bfd, constructor_chain, owner,          */        \
        0,            NULL,        NULL,              NULL,             \
@@ -689,7 +687,7 @@ bfd_get_unique_section_name (abfd, templat, count)
   char *sname;
 
   len = strlen (templat);
-  sname = bfd_malloc (len + 8);
+  sname = bfd_malloc ((bfd_size_type) len + 8);
   if (sname == NULL)
     return NULL;
   strcpy (sname, templat);
@@ -788,7 +786,7 @@ bfd_make_section_anyway (abfd, name)
       sect = sect->next;
     }
 
-  newsect = (asection *) bfd_zalloc (abfd, sizeof (asection));
+  newsect = (asection *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asection));
   if (newsect == NULL)
     return NULL;
 
@@ -805,7 +803,6 @@ 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
@@ -1013,12 +1010,9 @@ FUNCTION
        bfd_set_section_contents
 
 SYNOPSIS
-       boolean bfd_set_section_contents
-         (bfd *abfd,
-         asection *section,
-         PTR data,
-         file_ptr offset,
-         bfd_size_type count);
+       boolean bfd_set_section_contents (bfd *abfd, asection *section,
+                                         PTR data, file_ptr offset,
+                                         bfd_size_type count);
 
 DESCRIPTION
        Sets the contents of the section @var{section} in BFD
@@ -1059,17 +1053,15 @@ bfd_set_section_contents (abfd, section, location, offset, count)
       return (false);
     }
 
-  if (offset < 0)
+  sz = bfd_get_section_size_now (abfd, section);
+  if ((bfd_size_type) offset > sz
+      || count > sz
+      || offset + count > sz
+      || count != (size_t) count)
     {
-    bad_val:
       bfd_set_error (bfd_error_bad_value);
       return false;
     }
-  sz = bfd_get_section_size_now (abfd, section);
-  if ((bfd_size_type) offset > sz
-      || count > sz
-      || offset + count > sz)
-    goto bad_val;
 
   switch (abfd->direction)
     {
@@ -1092,7 +1084,7 @@ bfd_set_section_contents (abfd, section, location, offset, count)
   /* Record a copy of the data in memory if desired.  */
   if (section->contents
       && location != section->contents + offset)
-    memcpy (section->contents + offset, location, count);
+    memcpy (section->contents + offset, location, (size_t) count);
 
   if (BFD_SEND (abfd, _bfd_set_section_contents,
                (abfd, section, location, offset, count)))
@@ -1109,9 +1101,9 @@ FUNCTION
        bfd_get_section_contents
 
 SYNOPSIS
-       boolean bfd_get_section_contents
-        (bfd *abfd, asection *section, PTR location,
-         file_ptr offset, bfd_size_type count);
+       boolean bfd_get_section_contents (bfd *abfd, asection *section,
+                                         PTR location, file_ptr offset,
+                                         bfd_size_type count);
 
 DESCRIPTION
        Read data from @var{section} in BFD @var{abfd}
@@ -1138,21 +1130,21 @@ bfd_get_section_contents (abfd, section, location, offset, count)
 
   if (section->flags & SEC_CONSTRUCTOR)
     {
-      memset (location, 0, (unsigned) count);
+      memset (location, 0, (size_t) count);
       return true;
     }
 
-  if (offset < 0)
+  /* Even if reloc_done is true, this function reads unrelocated
+     contents, so we want the raw size.  */
+  sz = section->_raw_size;
+  if ((bfd_size_type) offset > sz
+      || count > sz
+      || offset + count > sz
+      || count != (size_t) count)
     {
-    bad_val:
       bfd_set_error (bfd_error_bad_value);
       return false;
     }
-  /* Even if reloc_done is true, this function reads unrelocated
-     contents, so we want the raw size.  */
-  sz = section->_raw_size;
-  if ((bfd_size_type) offset > sz || count > sz || offset + count > sz)
-    goto bad_val;
 
   if (count == 0)
     /* Don't bother.  */
@@ -1160,7 +1152,7 @@ bfd_get_section_contents (abfd, section, location, offset, count)
 
   if ((section->flags & SEC_HAS_CONTENTS) == 0)
     {
-      memset (location, 0, (unsigned) count);
+      memset (location, 0, (size_t) count);
       return true;
     }
 
@@ -1179,7 +1171,8 @@ FUNCTION
        bfd_copy_private_section_data
 
 SYNOPSIS
-       boolean bfd_copy_private_section_data(bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
+       boolean bfd_copy_private_section_data (bfd *ibfd, asection *isec,
+                                              bfd *obfd, asection *osec);
 
 DESCRIPTION
        Copy private section information from @var{isec} in the BFD
@@ -1224,6 +1217,11 @@ _bfd_strip_section_from_output (info, s)
      orders have not yet been set up.  So why are we checking them? --
      Ian */
   os = s->output_section;
+
+  /* Handle a section that wasn't output.  */
+  if (os == NULL)
+    return;
+
   for (p = os->link_order_head, pp = NULL; p != NULL; pp = p, p = p->next)
     if (p->type == bfd_indirect_link_order
        && p->u.indirect.section == s)
This page took 0.026137 seconds and 4 git commands to generate.