2001-10-05 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / bfd / section.c
index 9918b012628b469d455e20a011d1cbc946178b78..f3bd381a4cca198fd4e277d2cf140ab0cd95f841 100644 (file)
@@ -1,6 +1,6 @@
 /* Object file "section" support for the BFD library.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000
+   2000, 2001
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -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
@@ -372,6 +374,10 @@ CODE_FRAGMENT
 .  {* A mark flag used by some of the linker backends.  *}
 .  unsigned int linker_mark : 1;
 .
+.  {* Another mark flag used by some of the linker backends.  Set for
+.     output sections that have a input section.  *}
+.  unsigned int linker_has_input : 1;
+.
 .  {* A mark flag used by some linker backends for garbage collection.  *}
 .  unsigned int gc_mark : 1;
 .
@@ -479,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.  *}
 .
@@ -578,11 +580,14 @@ static const asymbol global_syms[] =
     /* name, id,  index, next, flags, user_set_vma, reloc_done,      */        \
     { NAME,  IDX, 0,     NULL, FLAGS, 0,            0,                 \
                                                                        \
-    /* linker_mark, gc_mark, segment_mark, vma, lma, _cooked_size,   */        \
-       0,           1,       0,            0,   0,   0,                \
+    /* linker_mark, linker_has_input, gc_mark, segment_mark,         */        \
+       0,           0,                1,       0,                      \
+                                                                       \
+    /* vma, lma, _cooked_size, _raw_size,                            */        \
+       0,   0,   0,            0,                                      \
                                                                        \
-    /* _raw_size, output_offset, output_section,    alignment_power, */ \
-       0,         0,           (struct sec *) &SEC, 0,                 \
+    /* output_offset, output_section,      alignment_power,          */        \
+       0,             (struct sec *) &SEC, 0,                          \
                                                                        \
     /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */        \
        NULL,       NULL,        0,           0,       0,               \
@@ -590,11 +595,11 @@ static const asymbol global_syms[] =
     /* line_filepos, userdata, contents, lineno, lineno_count,       */        \
        0,            NULL,     NULL,     NULL,   0,                    \
                                                                        \
-    /* comdat, kept_section, moving_line_filepos, target_index,      */        \
-       NULL,   NULL,         0,                   0,                   \
+    /* entsize, comdat, moving_line_filepos,                         */        \
+       0,       NULL,   0,                                             \
                                                                        \
-    /* used_by_bfd, constructor_chain, owner,                        */        \
-       NULL,        NULL,              NULL,                           \
+    /* target_index, used_by_bfd, constructor_chain, owner,          */        \
+       0,            NULL,        NULL,              NULL,             \
                                                                        \
     /* symbol,                                                       */        \
        (struct symbol_cache_entry *) &global_syms[IDX],                        \
@@ -682,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);
@@ -781,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;
 
@@ -798,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
@@ -1006,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
@@ -1052,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)
     {
@@ -1085,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)))
@@ -1102,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}
@@ -1131,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.  */
@@ -1153,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;
     }
 
@@ -1172,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
@@ -1217,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.039683 seconds and 4 git commands to generate.