Add arm-epoc-pe specific linker script
[deliverable/binutils-gdb.git] / bfd / section.c
index 564a51e5bdbbb732e6c8dbe262f8077ec9488fbf..e2ca4435fb5ead8c15689fcffdc4899c25e3a139 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
@@ -149,6 +150,27 @@ SUBSECTION
 
 CODE_FRAGMENT
 .
+. {* This structure is used for a comdat section, as in PE.  A comdat
+.    section is associated with a particular symbol.  When the linker
+.    sees a comdat section, it keeps only one of the sections with a
+.    given name and associated with a given symbol. *}
+.
+.struct bfd_comdat_info
+.{
+.  {* The name of the symbol associated with a comdat section.  *}
+.  const char *name;
+.
+.  {* The local symbol table index of the symbol associated with a
+.     comdat section.  This is only meaningful to the object file format
+.     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
 .{
 .        {* The name of the section; the name isn't a copy, the pointer is
@@ -214,7 +236,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
@@ -303,6 +325,17 @@ CODE_FRAGMENT
 .         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_SMALL_DATA 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.  *}
@@ -316,6 +349,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
@@ -406,6 +442,10 @@ CODE_FRAGMENT
 .
 .   unsigned int lineno_count;
 .
+.       {* Optional information about a COMDAT entry; NULL if not COMDAT *}
+.
+.   struct bfd_comdat_info *comdat;
+.
 .        {* When a section is being output, this value changes as more
 .           linenumbers are written out *}
 .
@@ -470,23 +510,53 @@ 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, \
-      0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, \
-      (asymbol *) &global_syms[IDX], (asymbol **) &SYM, 0, 0 }
+    /* name, index, next, flags, set_vma, reloc_done, linker_mark, gc_mark */ \
+    { NAME,  0,     0,    FLAGS, 0,       0,          0,           0,        \
+                                                                             \
+    /* vma, lma, _cooked_size, _raw_size, output_offset, output_section, */   \
+       0,   0,   0,            0,         0,             (struct sec *) &SEC, \
+                                                                             \
+    /* alig..., reloc..., orel..., reloc_count, filepos, rel_..., line_... */ \
+       0,       0,        0,       0,           0,       0,       0,         \
+                                                                             \
+    /* userdata, contents, lineno, lineno_count */                           \
+       0,        0,        0,      0,                                        \
+                                                                             \
+    /* comdat_info, moving_line_filepos, target_index, used_by_bfd,  */       \
+       NULL,        0,                   0,            0,                    \
+                                                                             \
+    /* cons..., owner, symbol */                                             \
+       0,       0,     (struct symbol_cache_entry *) &global_syms[IDX],       \
+                                                                             \
+    /* symbol_ptr_ptr,                      link_order_head, ..._tail */      \
+       (struct symbol_cache_entry **) &SYM, 0,               0                \
+    }
 
 STD_SECTION (bfd_com_section, SEC_IS_COMMON, bfd_com_symbol,
             BFD_COM_SECTION_NAME, 0);
@@ -558,7 +628,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.
 
 */
 
@@ -590,7 +660,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
@@ -629,6 +699,7 @@ bfd_make_section_anyway (abfd, name)
   newsect->reloc_count = 0;
   newsect->line_filepos = 0;
   newsect->owner = abfd;
+  newsect->comdat = 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
@@ -726,7 +797,7 @@ DESCRIPTION
 /*ARGSUSED*/
 boolean
 bfd_set_section_flags (abfd, section, flags)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      sec_ptr section;
      flagword flags;
 {
@@ -1019,3 +1090,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.0249 seconds and 4 git commands to generate.