Another try at correcting relocations against discarded
[deliverable/binutils-gdb.git] / bfd / section.c
index 3b5162983e2fc1e0d0fb5d75bcccafcf23b911a3..ef7a7e6fe2aa08ed8a47d3df62f1dbe508327e08 100644 (file)
@@ -165,10 +165,6 @@ CODE_FRAGMENT
 .     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
@@ -264,6 +260,14 @@ CODE_FRAGMENT
 .     sections.  *}
 .#define SEC_COFF_SHARED_LIBRARY 0x800
 .
+.  {* The section has GOT references.  This flag is only for the
+.     linker, and is currently only used by the elf32-hppa back end.
+.     It will be set if global offset table references were detected
+.     in this section, which indicate to the linker that the section
+.     contains PIC code, and must be handled specially when doing a
+.     static link.  *}
+.#define SEC_HAS_GOT_REF 0x4000
+.
 .  {* 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
@@ -363,6 +367,9 @@ CODE_FRAGMENT
 .  {* A mark flag used by some linker backends for garbage collection.  *}
 .  unsigned int gc_mark : 1;
 .
+.  {* Used by the ELF code to mark sections which have been allocated to segments.  *}
+.  unsigned int segment_mark : 1;
+.
 .  {* End of internal packed boolean fields.  *}
 .
 .  {*  The virtual memory address of the section - where it will be
@@ -460,6 +467,10 @@ 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.  *}
 .
@@ -549,17 +560,17 @@ static const asymbol global_syms[] =
   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, id,       index, next, flags, user_set_vma, reloc_done, */        \
-    { NAME,  -1-(IDX), 0,     NULL, FLAGS, 0,            0,            \
+#define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)                                \
+  const asymbol * const SYM = (asymbol *) &global_syms[IDX];           \
+  const asection SEC =                                                         \
+    /* name, id,  index, next, flags, user_set_vma, reloc_done,      */        \
+    { NAME,  IDX, 0,     NULL, FLAGS, 0,            0,                 \
                                                                        \
-    /* linker_mark, gc_mark, vma, lma, _cooked_size, _raw_size,      */        \
-       0,           0,       0,   0,   0,            0,                        \
+    /* linker_mark, gc_mark, segment_mark, vma, lma, _cooked_size,   */        \
+       0,           0,       0,            0,   0,   0,                \
                                                                        \
-    /* output_offset, output_section,      alignment_power,          */        \
-       0,             (struct sec *) &SEC, 0,                          \
+    /* _raw_size, output_offset, output_section,    alignment_power, */ \
+       0,         0,           (struct sec *) &SEC, 0,                 \
                                                                        \
     /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */        \
        NULL,       NULL,        0,           0,       0,               \
@@ -567,11 +578,11 @@ static const asymbol global_syms[] =
     /* line_filepos, userdata, contents, lineno, lineno_count,       */        \
        0,            NULL,     NULL,     NULL,   0,                    \
                                                                        \
-    /* comdat, moving_line_filepos, target_index, used_by_bfd,       */        \
-       NULL,   0,                   0,            NULL,                        \
+    /* comdat, kept_section, moving_line_filepos, target_index,      */        \
+       NULL,   NULL,         0,                   0,                   \
                                                                        \
-    /* constructor_chain, owner,                                     */        \
-       NULL,              NULL,                                                \
+    /* used_by_bfd, constructor_chain, owner,                        */        \
+       NULL,        NULL,              NULL,                           \
                                                                        \
     /* symbol,                                                       */        \
        (struct symbol_cache_entry *) &global_syms[IDX],                        \
@@ -632,6 +643,57 @@ bfd_get_section_by_name (abfd, name)
 }
 
 
+/*
+FUNCTION
+       bfd_get_unique_section_name
+
+SYNOPSIS
+       char *bfd_get_unique_section_name(bfd *abfd,
+                                         const char *templat,
+                                         int *count);
+
+DESCRIPTION
+       Invent a section name that is unique in @var{abfd} by tacking
+       a dot and a digit suffix onto the original @var{templat}.  If
+       @var{count} is non-NULL, then it specifies the first number
+       tried as a suffix to generate a unique name.  The value
+       pointed to by @var{count} will be incremented in this case.
+*/
+
+char *
+bfd_get_unique_section_name (abfd, templat, count)
+     bfd *abfd;
+     const char *templat;
+     int *count;
+{
+  int num;
+  unsigned int len;
+  char *sname;
+
+  len = strlen (templat);
+  sname = bfd_malloc (len + 8);
+  if (sname == NULL)
+    return NULL;
+  strcpy (sname, templat);
+  num = 1;
+  if (count != NULL)
+    num = *count;
+
+  do
+    {
+      /* If we have a million sections, something is badly wrong.  */
+      if (num > 999999)
+       abort ();
+      sprintf (sname + len, ".%d", num++);
+    }
+  while (bfd_get_section_by_name (abfd, sname) != NULL);
+
+  if (count != NULL)
+    *count = num;
+  return sname;
+}
+
+
 /*
 FUNCTION
        bfd_make_section_old_way
@@ -693,7 +755,7 @@ bfd_make_section_anyway (abfd, name)
      bfd *abfd;
      const char *name;
 {
-  static int section_id = 0;
+  static int section_id = 0x10;  /* id 0 to 3 used by STD_SECTION.  */
   asection *newsect;
   asection **prev = &abfd->sections;
   asection *sect = abfd->sections;
@@ -727,13 +789,17 @@ 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
      section.  */
   newsect->symbol = bfd_make_empty_symbol (abfd);
   if (newsect->symbol == NULL)
-    return NULL;
+    {
+      bfd_release (abfd, newsect);
+      return NULL;
+    }
   newsect->symbol->name = name;
   newsect->symbol->value = 0;
   newsect->symbol->section = newsect;
@@ -743,7 +809,7 @@ bfd_make_section_anyway (abfd, name)
 
   if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true)
     {
-      free (newsect);
+      bfd_release (abfd, newsect);
       return NULL;
     }
 
This page took 0.026758 seconds and 4 git commands to generate.