* Many files: Changes to avoid gcc warnings: Remove unused local
[deliverable/binutils-gdb.git] / bfd / section.c
index 469b0262e50ef2120b92dcd22c20ed2eb223ca79..3e0aa2b207907e559d225264f1d19b1109e4e22b 100644 (file)
@@ -1,5 +1,6 @@
 /* Object file "section" support for the BFD library.
-   Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+   Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -136,7 +137,7 @@ SUBSECTION
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
-
+#include "bfdlink.h"
 
 /*
 DOCDD
@@ -214,7 +215,7 @@ CODE_FRAGMENT
 .           standard data. *}
 .#define SEC_CONSTRUCTOR 0x100
 .
-.        {* The section is a constuctor, and should be placed at the
+.        {* The section is a constructor, and should be placed at the
 .          end of the text, data, or bss section(?). *}
 .#define SEC_CONSTRUCTOR_TEXT 0x1100
 .#define SEC_CONSTRUCTOR_DATA 0x2100
@@ -240,7 +241,7 @@ CODE_FRAGMENT
 .           sections. *}
 .#define SEC_COFF_SHARED_LIBRARY 0x800
 .
-.        {* The section is a common section (symbols may be defined
+.        {* The section contains common symbols (symbols may be defined
 .           multiple times, the value of a symbol is the amount of
 .           space it requires, and the largest symbol value is the one
 .           used).  Most targets have exactly one of these (which we
@@ -269,6 +270,47 @@ CODE_FRAGMENT
 .         table.  *}
 .#define SEC_SORT_ENTRIES 0x80000
 .
+.      {* When linking, duplicate sections of the same name should be
+.         discarded, rather than being combined into a single section as
+.         is usually done.  This is similar to how common symbols are
+.         handled.  See SEC_LINK_DUPLICATES below.  *}
+.#define SEC_LINK_ONCE 0x100000
+.
+.      {* If SEC_LINK_ONCE is set, this bitfield describes how the linker
+.         should handle duplicate sections.  *}
+.#define SEC_LINK_DUPLICATES 0x600000
+.
+.      {* This value for SEC_LINK_DUPLICATES means that duplicate
+.         sections with the same name should simply be discarded. *}
+.#define SEC_LINK_DUPLICATES_DISCARD 0x0
+.
+.      {* This value for SEC_LINK_DUPLICATES means that the linker
+.         should warn if there are any duplicate sections, although
+.         it should still only link one copy.  *}
+.#define SEC_LINK_DUPLICATES_ONE_ONLY 0x200000
+.
+.      {* This value for SEC_LINK_DUPLICATES means that the linker
+.         should warn if any duplicate sections are a different size.  *}
+.#define SEC_LINK_DUPLICATES_SAME_SIZE 0x400000
+.
+.      {* This value for SEC_LINK_DUPLICATES means that the linker
+.         should warn if any duplicate sections contain different
+.         contents.  *}
+.#define SEC_LINK_DUPLICATES_SAME_CONTENTS 0x600000
+.
+.      {* This section was created by the linker as part of dynamic
+.         relocation or other arcane processing.  It is skipped when
+.         going through the first-pass output, trusting that someone
+.         else up the line will take care of it later.  *}
+.#define SEC_LINKER_CREATED 0x800000
+.
+.      {* This section should not be subject to garbage collection.  *}
+.#define SEC_KEEP 0x1000000
+.
+.      {* This section contains "short" data, and should be placed
+.         "near" the GP.  *}
+.#define SEC_SHORT 0x2000000
+.
 .      {*  End of section flags.  *}
 .
 .      {* Some internal packed boolean fields.  *}
@@ -282,6 +324,9 @@ CODE_FRAGMENT
 .      {* A mark flag used by some of the linker backends.  *}
 .      unsigned int linker_mark : 1;
 .
+.      {* A mark flag used by some linker backends for garbage collection.  *}
+.      unsigned int gc_mark : 1;
+.
 .      {* End of internal packed boolean fields.  *}
 .
 .       {*  The virtual memory address of the section - where it will be
@@ -441,16 +486,20 @@ CODE_FRAGMENT
 static const asymbol global_syms[] =
 {
  /* the_bfd, name, value, attr, section [, udata] */
-  {0, BFD_COM_SECTION_NAME, 0, BSF_SECTION_SYM, (asection *) &bfd_com_section},
-  {0, BFD_UND_SECTION_NAME, 0, BSF_SECTION_SYM, (asection *) &bfd_und_section},
-  {0, BFD_ABS_SECTION_NAME, 0, BSF_SECTION_SYM, (asection *) &bfd_abs_section},
-  {0, BFD_IND_SECTION_NAME, 0, BSF_SECTION_SYM, (asection *) &bfd_ind_section},
+  {0, BFD_COM_SECTION_NAME, 0, BSF_SECTION_SYM,
+   (asection *) &bfd_com_section, { 0 }},
+  {0, BFD_UND_SECTION_NAME, 0, BSF_SECTION_SYM,
+   (asection *) &bfd_und_section, { 0 }},
+  {0, BFD_ABS_SECTION_NAME, 0, BSF_SECTION_SYM,
+   (asection *) &bfd_abs_section, { 0 }},
+  {0, BFD_IND_SECTION_NAME, 0, BSF_SECTION_SYM,
+   (asection *) &bfd_ind_section, { 0 }},
 };
 
 #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)        \
   const asymbol * const SYM = (asymbol *) &global_syms[IDX]; \
   const asection SEC = \
-    { NAME, 0, 0, FLAGS, 0, 0, 0, 0, 0, 0, 0, 0, (asection *) &SEC, \
+    { NAME, 0, 0, FLAGS, 0, 0, 0, 0, 0, 0, 0, 0, 0, (asection *) &SEC, \
       0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, \
       (asymbol *) &global_syms[IDX], (asymbol **) &SYM, 0, 0 }
 
@@ -524,7 +573,7 @@ DESCRIPTION
        o <<bfd_error_invalid_operation>> -
        If output has already started for this BFD.
        o <<bfd_error_no_memory>> -
-       If obstack alloc fails.
+       If memory allocation fails.
 
 */
 
@@ -556,7 +605,7 @@ DESCRIPTION
 
    Return <<NULL>> and set <<bfd_error>> on error; possible errors are:
    o <<bfd_error_invalid_operation>> - If output has already started for @var{abfd}.
-   o <<bfd_error_no_memory>> - If obstack alloc fails.
+   o <<bfd_error_no_memory>> - If memory allocation fails.
 */
 
 sec_ptr
@@ -692,7 +741,7 @@ DESCRIPTION
 /*ARGSUSED*/
 boolean
 bfd_set_section_flags (abfd, section, flags)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      sec_ptr section;
      flagword flags;
 {
@@ -982,6 +1031,55 @@ DESCRIPTION
        Not enough memory exists to create private data for @var{osec}.
 
 .#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
-.     BFD_SEND (ibfd, _bfd_copy_private_section_data, \
+.     BFD_SEND (obfd, _bfd_copy_private_section_data, \
 .              (ibfd, isection, obfd, osection))
 */
+
+/*
+FUNCTION
+       _bfd_strip_section_from_output
+
+SYNOPSIS
+       void _bfd_strip_section_from_output
+       (asection *section);
+
+DESCRIPTION
+       Remove @var{section} from the output.  If the output section becomes
+       empty, remove it from the output bfd.
+*/
+void
+_bfd_strip_section_from_output (s)
+     asection *s;
+{
+  asection **spp, *os;
+  struct bfd_link_order *p, *pp;
+
+  /* Excise the input section from the link order.  */
+  os = s->output_section;
+  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)
+      {
+       if (pp)
+         pp->next = p->next;
+       else
+         os->link_order_head = p->next;
+       if (!p->next)
+         os->link_order_tail = pp;
+       break;
+      }
+
+  /* If the output section is empty, remove it too.  Careful about sections
+     that have been discarded in the link script -- they are mapped to 
+     bfd_abs_section, which has no owner.  */
+  if (!os->link_order_head && os->owner)
+    {
+      for (spp = &os->owner->sections; *spp; spp = &(*spp)->next)
+       if (*spp == os)
+         {
+           *spp = os->next;
+           os->owner->section_count--;
+           break;
+         }
+    }
+}
This page took 0.026288 seconds and 4 git commands to generate.