* elf32-arm.h (elf32_arm_final_link_relocate): Don't copy STN_UNDEF
[deliverable/binutils-gdb.git] / bfd / elf.c
index 30104185a434c681a8950f6397f8144c63d73a0b..7bffecdb40f9eb6419795addba3c6f8ffaaaae00 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -40,6 +40,7 @@ SECTION
 #include "libbfd.h"
 #define ARCH_SIZE 0
 #include "elf-bfd.h"
+#include "libiberty.h"
 
 static INLINE struct elf_segment_map *make_mapping
   PARAMS ((bfd *, asection **, unsigned int, unsigned int, boolean));
@@ -384,7 +385,7 @@ setup_group (abfd, hdr, newsect)
        }
 
       if (num_group == 0)
-       num_group = -1;
+       num_group = (unsigned) -1;
       elf_tdata (abfd)->num_group = num_group;
 
       if (num_group > 0)
@@ -402,7 +403,7 @@ setup_group (abfd, hdr, newsect)
              Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i];
              if (shdr->sh_type == SHT_GROUP && shdr->sh_size >= 8)
                {
-                 char *src;
+                 unsigned char *src;
                  Elf_Internal_Group *dest;
 
                  /* Add to list of sections.  */
@@ -466,7 +467,7 @@ setup_group (abfd, hdr, newsect)
          while (--n_elt != 0)
            if ((++idx)->shdr == hdr)
              {
-               asection *s;
+               asection *s = NULL;
 
                /* We are a member of this group.  Go looking through
                   other members to see if any others are linked via
@@ -502,7 +503,7 @@ setup_group (abfd, hdr, newsect)
                    pos = elf_tdata (abfd)->symtab_hdr.sh_offset;
                    pos += shdr->sh_info * bed->s->sizeof_sym;
                    if (bfd_seek (abfd, pos, SEEK_SET) != 0
-                       || bfd_bread (ename, 4, abfd) != 4)
+                       || bfd_bread (ename, (bfd_size_type) 4, abfd) != 4)
                      return false;
                    iname = H_GET_32 (abfd, ename);
                    gname = elf_string_from_elf_strtab (abfd, iname);
@@ -599,7 +600,7 @@ _bfd_elf_make_section_from_shdr (abfd, hdr, name)
     };
     int i;
 
-    for (i = sizeof (debug_sec_names) / sizeof (debug_sec_names[0]); i--;)
+    for (i = ARRAY_SIZE (debug_sec_names); i--;)
       if (strncmp (name, debug_sec_names[i], strlen (debug_sec_names[i])) == 0)
        break;
 
@@ -643,17 +644,30 @@ _bfd_elf_make_section_from_shdr (abfd, hdr, name)
          phdr = elf_tdata (abfd)->phdr;
          for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
            {
+             /* This section is part of this segment if its file
+                offset plus size lies within the segment's memory
+                span and, if the section is loaded, the extent of the
+                loaded data lies within the extent of the segment.  
+                If the p_paddr field is not set, we don't alter the 
+                LMA.  */
              if (phdr->p_type == PT_LOAD
-                 && phdr->p_vaddr != phdr->p_paddr
-                 && phdr->p_vaddr <= hdr->sh_addr
-                 && (phdr->p_vaddr + phdr->p_memsz
-                     >= hdr->sh_addr + hdr->sh_size)
+                 && phdr->p_paddr
+                 && (bfd_vma) hdr->sh_offset >= phdr->p_offset
+                 && (hdr->sh_offset + hdr->sh_size
+                     <= phdr->p_offset + phdr->p_memsz)
                  && ((flags & SEC_LOAD) == 0
-                     || (phdr->p_offset <= (bfd_vma) hdr->sh_offset
-                         && (phdr->p_offset + phdr->p_filesz
-                             >= hdr->sh_offset + hdr->sh_size))))
+                     || (phdr->p_offset + phdr->p_filesz
+                         >= hdr->sh_offset + hdr->sh_size)))
                {
-                 newsect->lma += phdr->p_paddr - phdr->p_vaddr;
+                 /* We used to do a relative adjustment here, but
+                    that doesn't work if the segment is packed with
+                    code from multiple VMAs.  Instead we calculate
+                    the LMA absoultely, based on the LMA of the
+                    segment (it is assumed that the segment will
+                    contain sections with contiguous LMAs, even if
+                    the VMAs are not).  */
+                 newsect->lma = phdr->p_paddr
+                   + hdr->sh_offset - phdr->p_offset;
                  break;
                }
            }
@@ -1193,7 +1207,7 @@ _bfd_elf_link_hash_copy_indirect (dir, ind)
        | ELF_LINK_HASH_REF_REGULAR_NONWEAK
        | ELF_LINK_NON_GOT_REF));
 
-  if (dir == ind->weakdef)
+  if (ind->root.type != bfd_link_hash_indirect)
     return;
 
   /* Copy over the global and procedure linkage table refcount entries.
@@ -1733,6 +1747,62 @@ bfd_section_from_shdr (abfd, shindex)
   return true;
 }
 
+/* Return the section for the local symbol specified by ABFD, R_SYMNDX.
+   Return SEC for sections that have no elf section, and NULL on error.  */
+
+asection *
+bfd_section_from_r_symndx (abfd, cache, sec, r_symndx)
+     bfd *abfd;
+     struct sym_sec_cache *cache;
+     asection *sec;
+     unsigned long r_symndx;
+{
+  unsigned char esym_shndx[2];
+  unsigned int isym_shndx;
+  Elf_Internal_Shdr *symtab_hdr;
+  file_ptr pos;
+  bfd_size_type amt;
+  unsigned int ent = r_symndx % LOCAL_SYM_CACHE_SIZE;
+
+  if (cache->abfd == abfd && cache->indx[ent] == r_symndx)
+    return cache->sec[ent];
+
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  pos = symtab_hdr->sh_offset;
+  if (get_elf_backend_data (abfd)->s->sizeof_sym
+      == sizeof (Elf64_External_Sym))
+    {
+      pos += r_symndx * sizeof (Elf64_External_Sym);
+      pos += offsetof (Elf64_External_Sym, st_shndx);
+    }
+  else
+    {
+      pos += r_symndx * sizeof (Elf32_External_Sym);
+      pos += offsetof (Elf32_External_Sym, st_shndx);
+    }
+  amt = sizeof (esym_shndx);
+  if (bfd_seek (abfd, pos, SEEK_SET) != 0
+      || bfd_bread ((PTR) esym_shndx, amt, abfd) != amt)
+    return NULL;
+  isym_shndx = H_GET_16 (abfd, esym_shndx);
+
+  if (cache->abfd != abfd)
+    {
+      memset (cache->indx, -1, sizeof (cache->indx));
+      cache->abfd = abfd;
+    }
+  cache->indx[ent] = r_symndx;
+  cache->sec[ent] = sec;
+  if (isym_shndx > 0 && isym_shndx < SHN_LORESERVE)
+    {
+      asection *s;
+      s = bfd_section_from_elf_index (abfd, isym_shndx);
+      if (s != NULL)
+       cache->sec[ent] = s;
+    }
+  return cache->sec[ent];
+}
+
 /* Given an ELF section number, retrieve the corresponding BFD
    section.  */
 
@@ -1925,8 +1995,8 @@ _bfd_elf_init_reloc_shdr (abfd, rel_hdr, asect, use_rela_p)
     return false;
   sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name);
   rel_hdr->sh_name =
-    (unsigned int) _bfd_stringtab_add (elf_shstrtab (abfd), name,
-                                      true, false);
+    (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name,
+                                       false);
   if (rel_hdr->sh_name == (unsigned int) -1)
     return false;
   rel_hdr->sh_type = use_rela_p ? SHT_RELA : SHT_REL;
@@ -1963,9 +2033,8 @@ elf_fake_sections (abfd, asect, failedptrarg)
 
   this_hdr = &elf_section_data (asect)->this_hdr;
 
-  this_hdr->sh_name = (unsigned long) _bfd_stringtab_add (elf_shstrtab (abfd),
-                                                         asect->name,
-                                                         true, false);
+  this_hdr->sh_name = (unsigned long) _bfd_elf_strtab_add (elf_shstrtab (abfd),
+                                                          asect->name, false);
   if (this_hdr->sh_name == (unsigned long) -1)
     {
       *failedptr = true;
@@ -2186,38 +2255,51 @@ assign_section_numbers (abfd)
 {
   struct elf_obj_tdata *t = elf_tdata (abfd);
   asection *sec;
-  unsigned int section_number;
+  unsigned int section_number, secn;
   Elf_Internal_Shdr **i_shdrp;
   bfd_size_type amt;
 
   section_number = 1;
 
+  _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
+
   for (sec = abfd->sections; sec; sec = sec->next)
     {
       struct bfd_elf_section_data *d = elf_section_data (sec);
 
       d->this_idx = section_number++;
+      _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
       if ((sec->flags & SEC_RELOC) == 0)
        d->rel_idx = 0;
       else
-       d->rel_idx = section_number++;
+       {
+         d->rel_idx = section_number++;
+         _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr.sh_name);
+       }
 
       if (d->rel_hdr2)
-       d->rel_idx2 = section_number++;
+       {
+         d->rel_idx2 = section_number++;
+         _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr2->sh_name);
+       }
       else
        d->rel_idx2 = 0;
     }
 
   t->shstrtab_section = section_number++;
+  _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->shstrtab_hdr.sh_name);
   elf_elfheader (abfd)->e_shstrndx = t->shstrtab_section;
-  t->shstrtab_hdr.sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
 
   if (bfd_get_symcount (abfd) > 0)
     {
       t->symtab_section = section_number++;
+      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
       t->strtab_section = section_number++;
+      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
     }
 
+  _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
+  t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
   elf_elfheader (abfd)->e_shnum = section_number;
 
   /* Set up the list of section header pointers, in agreement with the
@@ -2354,6 +2436,10 @@ assign_section_numbers (abfd)
        }
     }
 
+  for (secn = 1; secn < section_number; ++secn)
+    i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
+                                                    i_shdrp[secn]->sh_name);
+
   return true;
 }
 
@@ -2387,7 +2473,6 @@ elf_map_symbols (abfd)
   unsigned int num_locals2 = 0;
   unsigned int num_globals2 = 0;
   int max_index = 0;
-  unsigned int num_sections = 0;
   unsigned int idx;
   asection *asect;
   asymbol **new_syms;
@@ -2398,8 +2483,6 @@ elf_map_symbols (abfd)
   fflush (stderr);
 #endif
 
-  /* Add a section symbol for each BFD section.  FIXME: Is this really
-     necessary?  */
   for (asect = abfd->sections; asect; asect = asect->next)
     {
       if (max_index < asect->index)
@@ -2414,6 +2497,8 @@ elf_map_symbols (abfd)
   elf_section_syms (abfd) = sect_syms;
   elf_num_section_syms (abfd) = max_index;
 
+  /* Init sect_syms entries for any section symbols we have already
+     decided to output.  */
   for (idx = 0; idx < symcount; idx++)
     {
       asymbol *sym = syms[idx];
@@ -2434,15 +2519,16 @@ elf_map_symbols (abfd)
 
                  sec = sec->output_section;
 
-                 /* Empty sections in the input files may have had a section
-                    symbol created for them.  (See the comment near the end of
-                    _bfd_generic_link_output_symbols in linker.c).  If the linker
-                    script discards such sections then we will reach this point.
-                    Since we know that we cannot avoid this case, we detect it
-                    and skip the abort and the assignment to the sect_syms array.
-                    To reproduce this particular case try running the linker
-                    testsuite test ld-scripts/weak.exp for an ELF port that uses
-                    the generic linker.  */
+                 /* Empty sections in the input files may have had a
+                    section symbol created for them.  (See the comment
+                    near the end of _bfd_generic_link_output_symbols in
+                    linker.c).  If the linker script discards such
+                    sections then we will reach this point.  Since we know
+                    that we cannot avoid this case, we detect it and skip
+                    the abort and the assignment to the sect_syms array.
+                    To reproduce this particular case try running the
+                    linker testsuite test ld-scripts/weak.exp for an ELF
+                    port that uses the generic linker.  */
                  if (sec->owner == NULL)
                    continue;
 
@@ -2453,31 +2539,6 @@ elf_map_symbols (abfd)
        }
     }
 
-  for (asect = abfd->sections; asect; asect = asect->next)
-    {
-      asymbol *sym;
-
-      if (sect_syms[asect->index] != NULL)
-       continue;
-
-      sym = bfd_make_empty_symbol (abfd);
-      if (sym == NULL)
-       return false;
-      sym->the_bfd = abfd;
-      sym->name = asect->name;
-      sym->value = 0;
-      /* Set the flags to 0 to indicate that this one was newly added.  */
-      sym->flags = 0;
-      sym->section = asect;
-      sect_syms[asect->index] = sym;
-      num_sections++;
-#ifdef DEBUG
-      fprintf (stderr,
- _("creating section symbol, name = %s, value = 0x%.8lx, index = %d, section = 0x%.8lx\n"),
-              asect->name, (long) asect->vma, asect->index, (long) asect);
-#endif
-    }
-
   /* Classify all of the symbols.  */
   for (idx = 0; idx < symcount; idx++)
     {
@@ -2486,17 +2547,19 @@ elf_map_symbols (abfd)
       else
        num_globals++;
     }
+
+  /* We will be adding a section symbol for each BFD section.  Most normal
+     sections will already have a section symbol in outsymbols, but
+     eg. SHT_GROUP sections will not, and we need the section symbol mapped
+     at least in that case.  */
   for (asect = abfd->sections; asect; asect = asect->next)
     {
-      if (sect_syms[asect->index] != NULL
-         && sect_syms[asect->index]->flags == 0)
+      if (sect_syms[asect->index] == NULL)
        {
-         sect_syms[asect->index]->flags = BSF_SECTION_SYM;
-         if (!sym_is_global (abfd, sect_syms[asect->index]))
+         if (!sym_is_global (abfd, asect->symbol))
            num_locals++;
          else
            num_globals++;
-         sect_syms[asect->index]->flags = 0;
        }
     }
 
@@ -2521,13 +2584,12 @@ elf_map_symbols (abfd)
     }
   for (asect = abfd->sections; asect; asect = asect->next)
     {
-      if (sect_syms[asect->index] != NULL
-         && sect_syms[asect->index]->flags == 0)
+      if (sect_syms[asect->index] == NULL)
        {
-         asymbol *sym = sect_syms[asect->index];
+         asymbol *sym = asect->symbol;
          unsigned int i;
 
-         sym->flags = BSF_SECTION_SYM;
+         sect_syms[asect->index] = sym;
          if (!sym_is_global (abfd, sym))
            i = num_locals2++;
          else
@@ -2639,7 +2701,7 @@ _bfd_elf_compute_section_file_positions (abfd, link_info)
   shstrtab_hdr->sh_type = SHT_STRTAB;
   shstrtab_hdr->sh_flags = 0;
   shstrtab_hdr->sh_addr = 0;
-  shstrtab_hdr->sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
+  shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
   shstrtab_hdr->sh_entsize = 0;
   shstrtab_hdr->sh_link = 0;
   shstrtab_hdr->sh_info = 0;
@@ -3272,10 +3334,10 @@ assign_file_positions_for_segments (abfd)
 
          /* The section may have artificial alignment forced by a
             link script.  Notice this case by the gap between the
-            cumulative phdr vma and the section's vma.  */
-         if (p->p_vaddr + p->p_memsz < sec->vma)
+            cumulative phdr lma and the section's lma.  */
+         if (p->p_paddr + p->p_memsz < sec->lma)
            {
-             bfd_vma adjust = sec->vma - (p->p_vaddr + p->p_memsz);
+             bfd_vma adjust = sec->lma - (p->p_paddr + p->p_memsz);
 
              p->p_memsz += adjust;
              off += adjust;
@@ -3630,13 +3692,13 @@ prep_headers (abfd)
   Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */
   Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */
   int count;
-  struct bfd_strtab_hash *shstrtab;
+  struct elf_strtab_hash *shstrtab;
   struct elf_backend_data *bed = get_elf_backend_data (abfd);
 
   i_ehdrp = elf_elfheader (abfd);
   i_shdrp = elf_elfsections (abfd);
 
-  shstrtab = _bfd_elf_stringtab_init ();
+  shstrtab = _bfd_elf_strtab_init ();
   if (shstrtab == NULL)
     return false;
 
@@ -3722,11 +3784,11 @@ prep_headers (abfd)
     }
 
   elf_tdata (abfd)->symtab_hdr.sh_name =
-    (unsigned int) _bfd_stringtab_add (shstrtab, ".symtab", true, false);
+    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", false);
   elf_tdata (abfd)->strtab_hdr.sh_name =
-    (unsigned int) _bfd_stringtab_add (shstrtab, ".strtab", true, false);
+    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", false);
   elf_tdata (abfd)->shstrtab_hdr.sh_name =
-    (unsigned int) _bfd_stringtab_add (shstrtab, ".shstrtab", true, false);
+    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", false);
   if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
       || elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
       || elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1)
@@ -3805,7 +3867,7 @@ _bfd_elf_write_object_contents (abfd)
 
   /* Write out the section header names.  */
   if (bfd_seek (abfd, elf_tdata (abfd)->shstrtab_hdr.sh_offset, SEEK_SET) != 0
-      || ! _bfd_stringtab_emit (abfd, elf_shstrtab (abfd)))
+      || ! _bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd)))
     return false;
 
   if (bed->elf_backend_final_write_processing)
@@ -4004,16 +4066,19 @@ copy_private_bfd_data (ibfd, obfd)
 
   /* Decide if the given section should be included in the given segment.
      A section will be included if:
-       1. It is within the address space of the segment,
+       1. It is within the address space of the segment -- we use the LMA
+          if that is set for the segment and the VMA otherwise,
        2. It is an allocated segment,
        3. There is an output section associated with it,
        4. The section has not already been allocated to a previous segment.  */
-#define INCLUDE_SECTION_IN_SEGMENT(section, segment)   \
-  ((((IS_CONTAINED_BY_VMA (section, segment)           \
-      || IS_SOLARIS_PT_INTERP (segment, section))      \
-     && (section->flags & SEC_ALLOC) != 0)             \
-    || IS_COREFILE_NOTE (segment, section))            \
-   && section->output_section != NULL                  \
+#define INCLUDE_SECTION_IN_SEGMENT(section, segment)                   \
+  (((((segment->p_paddr                                                        \
+       ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)      \
+       : IS_CONTAINED_BY_VMA (section, segment))                       \
+      || IS_SOLARIS_PT_INTERP (segment, section))                      \
+     && (section->flags & SEC_ALLOC) != 0)                             \
+    || IS_COREFILE_NOTE (segment, section))                            \
+   && section->output_section != NULL                                  \
    && section->segment_mark == false)
 
   /* Returns true iff seg1 starts after the end of seg2.  */
@@ -4233,7 +4298,8 @@ copy_private_bfd_data (ibfd, obfd)
                                                 ? iehdr->e_ehsize
                                                 : 0)
                                              + (map->includes_phdrs
-                                                ? iehdr->e_phnum * iehdr->e_phentsize
+                                                ? (iehdr->e_phnum
+                                                   * iehdr->e_phentsize)
                                                 : 0))))
                map->p_paddr = segment->p_vaddr;
 
@@ -4358,9 +4424,11 @@ copy_private_bfd_data (ibfd, obfd)
                      /* If the gap between the end of the previous section
                         and the start of this section is more than
                         maxpagesize then we need to start a new segment.  */
-                     if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size, maxpagesize)
+                     if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size,
+                                     maxpagesize)
                          < BFD_ALIGN (output_section->lma, maxpagesize))
-                         || ((prev_sec->lma + prev_sec->_raw_size) > output_section->lma))
+                         || ((prev_sec->lma + prev_sec->_raw_size)
+                             > output_section->lma))
                        {
                          if (suggested_lma == 0)
                            suggested_lma = output_section->lma;
@@ -4592,223 +4660,225 @@ swap_out_syms (abfd, sttp, relocatable_p)
      struct bfd_strtab_hash **sttp;
      int relocatable_p;
 {
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  struct elf_backend_data *bed;
+  int symcount;
+  asymbol **syms;
+  struct bfd_strtab_hash *stt;
+  Elf_Internal_Shdr *symtab_hdr;
+  Elf_Internal_Shdr *symstrtab_hdr;
+  char *outbound_syms;
+  int idx;
+  bfd_size_type amt;
 
   if (!elf_map_symbols (abfd))
     return false;
 
   /* Dump out the symtabs.  */
-  {
-    int symcount = bfd_get_symcount (abfd);
-    asymbol **syms = bfd_get_outsymbols (abfd);
-    struct bfd_strtab_hash *stt;
-    Elf_Internal_Shdr *symtab_hdr;
-    Elf_Internal_Shdr *symstrtab_hdr;
-    char *outbound_syms;
-    int idx;
-    bfd_size_type amt;
-
-    stt = _bfd_elf_stringtab_init ();
-    if (stt == NULL)
-      return false;
-
-    symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-    symtab_hdr->sh_type = SHT_SYMTAB;
-    symtab_hdr->sh_entsize = bed->s->sizeof_sym;
-    symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1);
-    symtab_hdr->sh_info = elf_num_locals (abfd) + 1;
-    symtab_hdr->sh_addralign = bed->s->file_align;
+  stt = _bfd_elf_stringtab_init ();
+  if (stt == NULL)
+    return false;
 
-    symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
-    symstrtab_hdr->sh_type = SHT_STRTAB;
+  bed = get_elf_backend_data (abfd);
+  symcount = bfd_get_symcount (abfd);
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  symtab_hdr->sh_type = SHT_SYMTAB;
+  symtab_hdr->sh_entsize = bed->s->sizeof_sym;
+  symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1);
+  symtab_hdr->sh_info = elf_num_locals (abfd) + 1;
+  symtab_hdr->sh_addralign = bed->s->file_align;
+
+  symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
+  symstrtab_hdr->sh_type = SHT_STRTAB;
+
+  amt = (bfd_size_type) (1 + symcount) * bed->s->sizeof_sym;
+  outbound_syms = bfd_alloc (abfd, amt);
+  if (outbound_syms == NULL)
+    return false;
+  symtab_hdr->contents = (PTR) outbound_syms;
 
-    amt = (bfd_size_type) (1 + symcount) * bed->s->sizeof_sym;
-    outbound_syms = bfd_alloc (abfd, amt);
-    if (outbound_syms == NULL)
-      return false;
-    symtab_hdr->contents = (PTR) outbound_syms;
+  /* now generate the data (for "contents") */
+  {
+    /* Fill in zeroth symbol and swap it out.  */
+    Elf_Internal_Sym sym;
+    sym.st_name = 0;
+    sym.st_value = 0;
+    sym.st_size = 0;
+    sym.st_info = 0;
+    sym.st_other = 0;
+    sym.st_shndx = SHN_UNDEF;
+    bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
+    outbound_syms += bed->s->sizeof_sym;
+  }
 
-    /* now generate the data (for "contents") */
+  syms = bfd_get_outsymbols (abfd);
+  for (idx = 0; idx < symcount; idx++)
     {
-      /* Fill in zeroth symbol and swap it out.  */
       Elf_Internal_Sym sym;
-      sym.st_name = 0;
-      sym.st_value = 0;
-      sym.st_size = 0;
-      sym.st_info = 0;
-      sym.st_other = 0;
-      sym.st_shndx = SHN_UNDEF;
-      bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
-      outbound_syms += bed->s->sizeof_sym;
-    }
-    for (idx = 0; idx < symcount; idx++)
-      {
-       Elf_Internal_Sym sym;
-       bfd_vma value = syms[idx]->value;
-       elf_symbol_type *type_ptr;
-       flagword flags = syms[idx]->flags;
-       int type;
+      bfd_vma value = syms[idx]->value;
+      elf_symbol_type *type_ptr;
+      flagword flags = syms[idx]->flags;
+      int type;
 
-       if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
-         {
-           /* Local section symbols have no name.  */
-           sym.st_name = 0;
-         }
-       else
-         {
-           sym.st_name = (unsigned long) _bfd_stringtab_add (stt,
-                                                             syms[idx]->name,
-                                                             true, false);
-           if (sym.st_name == (unsigned long) -1)
-             return false;
-         }
+      if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
+       {
+         /* Local section symbols have no name.  */
+         sym.st_name = 0;
+       }
+      else
+       {
+         sym.st_name = (unsigned long) _bfd_stringtab_add (stt,
+                                                           syms[idx]->name,
+                                                           true, false);
+         if (sym.st_name == (unsigned long) -1)
+           return false;
+       }
 
-       type_ptr = elf_symbol_from (abfd, syms[idx]);
+      type_ptr = elf_symbol_from (abfd, syms[idx]);
 
-       if ((flags & BSF_SECTION_SYM) == 0
-           && bfd_is_com_section (syms[idx]->section))
-         {
-           /* ELF common symbols put the alignment into the `value' field,
-              and the size into the `size' field.  This is backwards from
-              how BFD handles it, so reverse it here.  */
-           sym.st_size = value;
-           if (type_ptr == NULL
-               || type_ptr->internal_elf_sym.st_value == 0)
-             sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value));
-           else
-             sym.st_value = type_ptr->internal_elf_sym.st_value;
-           sym.st_shndx = _bfd_elf_section_from_bfd_section
-             (abfd, syms[idx]->section);
-         }
-       else
-         {
-           asection *sec = syms[idx]->section;
-           int shndx;
+      if ((flags & BSF_SECTION_SYM) == 0
+         && bfd_is_com_section (syms[idx]->section))
+       {
+         /* ELF common symbols put the alignment into the `value' field,
+            and the size into the `size' field.  This is backwards from
+            how BFD handles it, so reverse it here.  */
+         sym.st_size = value;
+         if (type_ptr == NULL
+             || type_ptr->internal_elf_sym.st_value == 0)
+           sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value));
+         else
+           sym.st_value = type_ptr->internal_elf_sym.st_value;
+         sym.st_shndx = _bfd_elf_section_from_bfd_section
+           (abfd, syms[idx]->section);
+       }
+      else
+       {
+         asection *sec = syms[idx]->section;
+         int shndx;
 
-           if (sec->output_section)
-             {
-               value += sec->output_offset;
-               sec = sec->output_section;
-             }
-           /* Don't add in the section vma for relocatable output.  */
-           if (! relocatable_p)
-             value += sec->vma;
-           sym.st_value = value;
-           sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0;
-
-           if (bfd_is_abs_section (sec)
-               && type_ptr != NULL
-               && type_ptr->internal_elf_sym.st_shndx != 0)
-             {
-               /* This symbol is in a real ELF section which we did
-                   not create as a BFD section.  Undo the mapping done
-                   by copy_private_symbol_data.  */
-               shndx = type_ptr->internal_elf_sym.st_shndx;
-               switch (shndx)
-                 {
-                 case MAP_ONESYMTAB:
-                   shndx = elf_onesymtab (abfd);
-                   break;
-                 case MAP_DYNSYMTAB:
-                   shndx = elf_dynsymtab (abfd);
-                   break;
-                 case MAP_STRTAB:
-                   shndx = elf_tdata (abfd)->strtab_section;
-                   break;
-                 case MAP_SHSTRTAB:
-                   shndx = elf_tdata (abfd)->shstrtab_section;
-                   break;
-                 default:
-                   break;
-                 }
-             }
-           else
-             {
-               shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
+         if (sec->output_section)
+           {
+             value += sec->output_offset;
+             sec = sec->output_section;
+           }
+         /* Don't add in the section vma for relocatable output.  */
+         if (! relocatable_p)
+           value += sec->vma;
+         sym.st_value = value;
+         sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0;
+
+         if (bfd_is_abs_section (sec)
+             && type_ptr != NULL
+             && type_ptr->internal_elf_sym.st_shndx != 0)
+           {
+             /* This symbol is in a real ELF section which we did
+                not create as a BFD section.  Undo the mapping done
+                by copy_private_symbol_data.  */
+             shndx = type_ptr->internal_elf_sym.st_shndx;
+             switch (shndx)
+               {
+               case MAP_ONESYMTAB:
+                 shndx = elf_onesymtab (abfd);
+                 break;
+               case MAP_DYNSYMTAB:
+                 shndx = elf_dynsymtab (abfd);
+                 break;
+               case MAP_STRTAB:
+                 shndx = elf_tdata (abfd)->strtab_section;
+                 break;
+               case MAP_SHSTRTAB:
+                 shndx = elf_tdata (abfd)->shstrtab_section;
+                 break;
+               default:
+                 break;
+               }
+           }
+         else
+           {
+             shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
 
-               if (shndx == -1)
-                 {
-                   asection *sec2;
-
-                   /* Writing this would be a hell of a lot easier if
-                      we had some decent documentation on bfd, and
-                      knew what to expect of the library, and what to
-                      demand of applications.  For example, it
-                      appears that `objcopy' might not set the
-                      section of a symbol to be a section that is
-                      actually in the output file.  */
-                   sec2 = bfd_get_section_by_name (abfd, sec->name);
-                   BFD_ASSERT (sec2 != 0);
-                   shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
-                   BFD_ASSERT (shndx != -1);
-                 }
-             }
+             if (shndx == -1)
+               {
+                 asection *sec2;
+
+                 /* Writing this would be a hell of a lot easier if
+                    we had some decent documentation on bfd, and
+                    knew what to expect of the library, and what to
+                    demand of applications.  For example, it
+                    appears that `objcopy' might not set the
+                    section of a symbol to be a section that is
+                    actually in the output file.  */
+                 sec2 = bfd_get_section_by_name (abfd, sec->name);
+                 BFD_ASSERT (sec2 != 0);
+                 shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
+                 BFD_ASSERT (shndx != -1);
+               }
+           }
 
-           sym.st_shndx = shndx;
-         }
+         sym.st_shndx = shndx;
+       }
 
-       if ((flags & BSF_FUNCTION) != 0)
-         type = STT_FUNC;
-       else if ((flags & BSF_OBJECT) != 0)
-         type = STT_OBJECT;
-       else
-         type = STT_NOTYPE;
+      if ((flags & BSF_FUNCTION) != 0)
+       type = STT_FUNC;
+      else if ((flags & BSF_OBJECT) != 0)
+       type = STT_OBJECT;
+      else
+       type = STT_NOTYPE;
 
-        /* Processor-specific types */
-        if (type_ptr != NULL
-           && bed->elf_backend_get_symbol_type)
-          type = (*bed->elf_backend_get_symbol_type) (&type_ptr->internal_elf_sym, type);
+      /* Processor-specific types */
+      if (type_ptr != NULL
+         && bed->elf_backend_get_symbol_type)
+       type = ((*bed->elf_backend_get_symbol_type)
+               (&type_ptr->internal_elf_sym, type));
 
-       if (flags & BSF_SECTION_SYM)
-         {
-           if (flags & BSF_GLOBAL)
-             sym.st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
-           else
-             sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
-         }
-       else if (bfd_is_com_section (syms[idx]->section))
-         sym.st_info = ELF_ST_INFO (STB_GLOBAL, type);
-       else if (bfd_is_und_section (syms[idx]->section))
-         sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK)
-                                     ? STB_WEAK
-                                     : STB_GLOBAL),
-                                    type);
-       else if (flags & BSF_FILE)
-         sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
-       else
-         {
-           int bind = STB_LOCAL;
+      if (flags & BSF_SECTION_SYM)
+       {
+         if (flags & BSF_GLOBAL)
+           sym.st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
+         else
+           sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
+       }
+      else if (bfd_is_com_section (syms[idx]->section))
+       sym.st_info = ELF_ST_INFO (STB_GLOBAL, type);
+      else if (bfd_is_und_section (syms[idx]->section))
+       sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK)
+                                   ? STB_WEAK
+                                   : STB_GLOBAL),
+                                  type);
+      else if (flags & BSF_FILE)
+       sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
+      else
+       {
+         int bind = STB_LOCAL;
 
-           if (flags & BSF_LOCAL)
-             bind = STB_LOCAL;
-           else if (flags & BSF_WEAK)
-             bind = STB_WEAK;
-           else if (flags & BSF_GLOBAL)
-             bind = STB_GLOBAL;
+         if (flags & BSF_LOCAL)
+           bind = STB_LOCAL;
+         else if (flags & BSF_WEAK)
+           bind = STB_WEAK;
+         else if (flags & BSF_GLOBAL)
+           bind = STB_GLOBAL;
 
-           sym.st_info = ELF_ST_INFO (bind, type);
-         }
+         sym.st_info = ELF_ST_INFO (bind, type);
+       }
 
-       if (type_ptr != NULL)
-         sym.st_other = type_ptr->internal_elf_sym.st_other;
-       else
-         sym.st_other = 0;
+      if (type_ptr != NULL)
+       sym.st_other = type_ptr->internal_elf_sym.st_other;
+      else
+       sym.st_other = 0;
 
-       bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
-       outbound_syms += bed->s->sizeof_sym;
-      }
+      bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
+      outbound_syms += bed->s->sizeof_sym;
+    }
 
-    *sttp = stt;
-    symstrtab_hdr->sh_size = _bfd_stringtab_size (stt);
-    symstrtab_hdr->sh_type = SHT_STRTAB;
+  *sttp = stt;
+  symstrtab_hdr->sh_size = _bfd_stringtab_size (stt);
+  symstrtab_hdr->sh_type = SHT_STRTAB;
 
-    symstrtab_hdr->sh_flags = 0;
-    symstrtab_hdr->sh_addr = 0;
-    symstrtab_hdr->sh_entsize = 0;
-    symstrtab_hdr->sh_link = 0;
-    symstrtab_hdr->sh_info = 0;
-    symstrtab_hdr->sh_addralign = 1;
-  }
+  symstrtab_hdr->sh_flags = 0;
+  symstrtab_hdr->sh_addr = 0;
+  symstrtab_hdr->sh_entsize = 0;
+  symstrtab_hdr->sh_link = 0;
+  symstrtab_hdr->sh_info = 0;
+  symstrtab_hdr->sh_addralign = 1;
 
   return true;
 }
@@ -5551,7 +5621,7 @@ _bfd_elf_close_and_cleanup (abfd)
   if (bfd_get_format (abfd) == bfd_object)
     {
       if (elf_shstrtab (abfd) != NULL)
-       _bfd_stringtab_free (elf_shstrtab (abfd));
+       _bfd_elf_strtab_free (elf_shstrtab (abfd));
     }
 
   return _bfd_generic_close_and_cleanup (abfd);
@@ -6032,8 +6102,9 @@ elfcore_grok_win32pstatus (abfd, note)
        return false;
 
       sect->_raw_size = sizeof (pstatus.data.thread_info.thread_context);
-      sect->filepos = note->descpos + offsetof (struct win32_pstatus,
-                                               data.thread_info.thread_context);
+      sect->filepos = (note->descpos
+                      + offsetof (struct win32_pstatus,
+                                  data.thread_info.thread_context));
       sect->flags = SEC_HAS_CONTENTS;
       sect->alignment_power = 2;
 
This page took 0.0396 seconds and 4 git commands to generate.