1999-08-08 Mark Elbrecht <snowball3@bigfoot.com>
[deliverable/binutils-gdb.git] / bfd / section.c
index 55a09f9a2b714dfdfa62a148950fdc009e3fa8a7..654ce231b88788ab76785cbbd98dab5e27ec67d9 100644 (file)
@@ -1,5 +1,5 @@
 /* Object file "section" support for the BFD library.
-   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997
+   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -137,7 +137,7 @@ SUBSECTION
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
-
+#include "bfdlink.h"
 
 /*
 DOCDD
@@ -307,6 +307,14 @@ CODE_FRAGMENT
 .      {* 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
+.
+.      {* This section contains data which may be shared with other
+.         executables or shared objects.  *}
+.#define SEC_SHARED 0x4000000
+.
 .      {*  End of section flags.  *}
 .
 .      {* Some internal packed boolean fields.  *}
@@ -477,21 +485,33 @@ CODE_FRAGMENT
 .     ((section->reloc_done) ? (section)->_cooked_size: (abort(),1))
 */
 
+/* We use a macro to initialize the static asymbol structures because
+   traditional C does not permit us to initialize a union member while
+   gcc warns if we don't initialize it.  */
+ /* the_bfd, name, value, attr, section [, udata] */
+#ifdef __STDC__
+#define GLOBAL_SYM_INIT(NAME, SECTION) \
+  { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION, { 0 }}
+#else
+#define GLOBAL_SYM_INIT(NAME, SECTION) \
+  { 0, NAME, 0, BSF_SECTION_SYM, (asection *) SECTION }
+#endif
+
 /* These symbols are global, not specific to any BFD.  Therefore, anything
    that tries to change them is broken, and should be repaired.  */
+
 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},
+  GLOBAL_SYM_INIT (BFD_COM_SECTION_NAME, &bfd_com_section),
+  GLOBAL_SYM_INIT (BFD_UND_SECTION_NAME, &bfd_und_section),
+  GLOBAL_SYM_INIT (BFD_ABS_SECTION_NAME, &bfd_abs_section),
+  GLOBAL_SYM_INIT (BFD_IND_SECTION_NAME, &bfd_ind_section)
 };
 
 #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 }
 
@@ -733,7 +753,7 @@ DESCRIPTION
 /*ARGSUSED*/
 boolean
 bfd_set_section_flags (abfd, section, flags)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      sec_ptr section;
      flagword flags;
 {
@@ -1026,3 +1046,52 @@ DESCRIPTION
 .     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.025761 seconds and 4 git commands to generate.