Replace sh_size/sh_entsize with NUM_SHDR_ENTRIES
[binutils-gdb.git] / bfd / elflink.h
index 4973ae36f21100718c11d293cdf2fb202db61ca5..0f5c71252035be930b51c2f8d0d20414ec2c080f 100644 (file)
@@ -895,7 +895,6 @@ elf_link_add_object_symbols (abfd, info)
   Elf_External_Sym *buf = NULL;
   struct elf_link_hash_entry **sym_hash;
   boolean dynamic;
-  bfd_byte *dynver = NULL;
   Elf_External_Versym *extversym = NULL;
   Elf_External_Versym *ever;
   Elf_External_Dyn *dynbuf = NULL;
@@ -1023,7 +1022,7 @@ elf_link_add_object_symbols (abfd, info)
          Elf_Internal_Shdr *versymhdr;
 
          versymhdr = &elf_tdata (abfd)->dynversym_hdr;
-         extversym = (Elf_External_Versym *) bfd_malloc (hdr->sh_size);
+         extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size);
          if (extversym == NULL)
            goto error_return;
          if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0
@@ -1322,7 +1321,7 @@ elf_link_add_object_symbols (abfd, info)
       /* Save the SONAME, if there is one, because sometimes the
          linker emulation code will need to know it.  */
       if (*name == '\0')
-       name = bfd_get_filename (abfd);
+       name = basename (bfd_get_filename (abfd));
       elf_dt_name (abfd) = name;
     }
 
@@ -2186,8 +2185,6 @@ elf_link_add_object_symbols (abfd, info)
     free (buf);
   if (dynbuf != NULL)
     free (dynbuf);
-  if (dynver != NULL)
-    free (dynver);
   if (extversym != NULL)
     free (extversym);
   return false;
@@ -2468,7 +2465,7 @@ elf_link_read_relocs_from_section (abfd, shdr, external_relocs,
       Elf_Internal_Rel *irel;
 
       erel = (Elf_External_Rel *) external_relocs;
-      erelend = erel + shdr->sh_size / shdr->sh_entsize;
+      erelend = erel + NUM_SHDR_ENTRIES (shdr);
       irela = internal_relocs;
       irel = bfd_alloc (abfd, (bed->s->int_rels_per_ext_rel
                               * sizeof (Elf_Internal_Rel)));
@@ -2498,7 +2495,7 @@ elf_link_read_relocs_from_section (abfd, shdr, external_relocs,
       BFD_ASSERT (shdr->sh_entsize == sizeof (Elf_External_Rela));
 
       erela = (Elf_External_Rela *) external_relocs;
-      erelaend = erela + shdr->sh_size / shdr->sh_entsize;
+      erelaend = erela + NUM_SHDR_ENTRIES (shdr);
       irela = internal_relocs;
       for (; erela < erelaend; erela++, irela += bed->s->int_rels_per_ext_rel)
        {
@@ -2578,7 +2575,7 @@ NAME(_bfd_elf,link_read_relocs) (abfd, o, external_relocs, internal_relocs,
       (abfd,
        elf_section_data (o)->rel_hdr2,
        ((bfd_byte *) external_relocs) + rel_hdr->sh_size,
-       internal_relocs + (rel_hdr->sh_size / rel_hdr->sh_entsize
+       internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr)
                          * bed->s->int_rels_per_ext_rel)))
     goto error_return;
 
@@ -3133,7 +3130,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
              const char *name;
              bfd_size_type indx;
 
-             name = output_bfd->filename;
+             name = basename (output_bfd->filename);
              def.vd_hash = bfd_elf_hash (name);
              indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
                                            name, true, false);
@@ -3317,7 +3314,8 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
                                             true, false);
                else
                  indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
-                                            t->vn_bfd->filename, true, false);
+                                            basename (t->vn_bfd->filename),
+                                            true, false);
                if (indx == (bfd_size_type) -1)
                  return false;
                t->vn_file = indx;
@@ -4415,11 +4413,9 @@ elf_bfd_final_link (abfd, info)
                  rel_count2 = &esdo->rel_count;
                }
 
-             *rel_count += (esdi->rel_hdr.sh_size
-                            / esdi->rel_hdr.sh_entsize);
+             *rel_count += NUM_SHDR_ENTRIES (& esdi->rel_hdr);
              if (esdi->rel_hdr2)
-               *rel_count2 += (esdi->rel_hdr2->sh_size
-                               / esdi->rel_hdr2->sh_entsize);
+               *rel_count2 += NUM_SHDR_ENTRIES (esdi->rel_hdr2);
            }
        }
 
@@ -5444,7 +5440,7 @@ elf_link_output_relocs (output_bfd, input_section, input_rel_hdr,
 
   bed = get_elf_backend_data (output_bfd);
   irela = internal_relocs;
-  irelaend = irela + input_rel_hdr->sh_size / input_rel_hdr->sh_entsize;
+  irelaend = irela + NUM_SHDR_ENTRIES (input_rel_hdr);
   if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
     {
       Elf_External_Rel *erel;
@@ -5479,7 +5475,7 @@ elf_link_output_relocs (output_bfd, input_section, input_rel_hdr,
 
   /* Bump the counter, so that we know where to add the next set of
      relocations.  */
-  *rel_countp += input_rel_hdr->sh_size / input_rel_hdr->sh_entsize;
+  *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);
 }
 
 /* Link an input file into the linker output file.  This function
@@ -5941,8 +5937,7 @@ elf_link_input_bfd (finfo, input_bfd)
              elf_link_output_relocs (output_bfd, o,
                                      input_rel_hdr,
                                      internal_relocs);
-             internal_relocs
-               += input_rel_hdr->sh_size / input_rel_hdr->sh_entsize;
+             internal_relocs += NUM_SHDR_ENTRIES (input_rel_hdr);
              input_rel_hdr = elf_section_data (o)->rel_hdr2;
              if (input_rel_hdr)
                elf_link_output_relocs (output_bfd, o,