* testsuite/Makefile.am: Add -ffunction-sections to compile
[external/binutils.git] / bfd / elf32-vax.c
index 77f8b41..9caa47d 100644 (file)
@@ -1,6 +1,6 @@
 /* VAX series support for 32-bit ELF
    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
 /* VAX series support for 32-bit ELF
    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
    Contributed by Matt Thomas <matt@3am-software.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
    Contributed by Matt Thomas <matt@3am-software.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -599,8 +599,10 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
       switch (ELF32_R_TYPE (rel->r_info))
        {
        case R_VAX_GOT32:
       switch (ELF32_R_TYPE (rel->r_info))
        {
        case R_VAX_GOT32:
-         if (h != NULL
-             && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
+         BFD_ASSERT (h != NULL);
+         if (h->forced_local
+             || h == elf_hash_table (info)->hgot
+             || h == elf_hash_table (info)->hplt)
            break;
 
          /* This symbol requires a global offset table entry.  */
            break;
 
          /* This symbol requires a global offset table entry.  */
@@ -654,10 +656,11 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
                  h->got.refcount++;
                  if (eh->got_addend != (bfd_vma) rel->r_addend)
                    (*_bfd_error_handler)
                  h->got.refcount++;
                  if (eh->got_addend != (bfd_vma) rel->r_addend)
                    (*_bfd_error_handler)
-                     (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
-                             bfd_get_filename (abfd), rel->r_addend,
-                             h->root.root.string,
-                             eh->got_addend);
+                     (_("%s: warning: GOT addend of %ld to `%s' does"
+                        " not match previous GOT addend of %ld"),
+                        bfd_get_filename (abfd), rel->r_addend,
+                        h->root.root.string,
+                        eh->got_addend);
 
                }
            }
 
                }
            }
@@ -673,8 +676,9 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
 
          /* If this is a local symbol, we resolve it directly without
             creating a procedure linkage table entry.  */
 
          /* If this is a local symbol, we resolve it directly without
             creating a procedure linkage table entry.  */
-         if (h == NULL)
-           continue;
+         BFD_ASSERT (h != NULL);
+         if (h->forced_local)
+           break;
 
          h->needs_plt = 1;
          if (h->plt.refcount == -1)
 
          h->needs_plt = 1;
          if (h->plt.refcount == -1)
@@ -702,7 +706,7 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
                && (!info->symbolic
                    || !h->def_regular)))
            {
                && (!info->symbolic
                    || !h->def_regular)))
            {
-             if (h != NULL)
+             if (h != NULL && !h->forced_local)
                {
                  /* Make sure a plt entry is created for this symbol if
                     it turns out to be a function defined by a dynamic
                {
                  /* Make sure a plt entry is created for this symbol if
                     it turns out to be a function defined by a dynamic
@@ -714,6 +718,9 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
                }
              break;
            }
                }
              break;
            }
+         if (h != NULL && h->forced_local)
+           break;
+
          /* Fall through.  */
        case R_VAX_8:
        case R_VAX_16:
          /* Fall through.  */
        case R_VAX_8:
        case R_VAX_16:
@@ -738,34 +745,12 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
                 section in dynobj and make room for this reloc.  */
              if (sreloc == NULL)
                {
                 section in dynobj and make room for this reloc.  */
              if (sreloc == NULL)
                {
-                 const char *name;
+                 sreloc = _bfd_elf_make_dynamic_reloc_section
+                   (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
 
 
-                 name = (bfd_elf_string_from_elf_section
-                         (abfd,
-                          elf_elfheader (abfd)->e_shstrndx,
-                          elf_section_data (sec)->rel_hdr.sh_name));
-                 if (name == NULL)
+                 if (sreloc == NULL)
                    return FALSE;
 
                    return FALSE;
 
-                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
-                             && strcmp (bfd_get_section_name (abfd, sec),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 if (sreloc == NULL)
-                   {
-                     sreloc = bfd_make_section_with_flags (dynobj,
-                                                           name,
-                                                           (SEC_ALLOC
-                                                            | SEC_LOAD
-                                                            | SEC_HAS_CONTENTS
-                                                            | SEC_IN_MEMORY
-                                                            | SEC_LINKER_CREATED
-                                                            | SEC_READONLY));
-                     if (sreloc == NULL
-                         || !bfd_set_section_alignment (dynobj, sreloc, 2))
-                       return FALSE;
-                   }
                  if (sec->flags & SEC_READONLY)
                    info->flags |= DF_TEXTREL;
                }
                  if (sec->flags & SEC_READONLY)
                    info->flags |= DF_TEXTREL;
                }
@@ -1327,7 +1312,8 @@ elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, PTR infoptr)
   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
 
   if (!elf_hash_table (info)->dynamic_sections_created
   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
 
   if (!elf_hash_table (info)->dynamic_sections_created
-      || (info->shared && info->symbolic))
+      || (info->shared && info->symbolic)
+      || h->forced_local)
     {
       h->got.refcount = 0;
       h->got.offset = (bfd_vma) -1;
     {
       h->got.refcount = 0;
       h->got.offset = (bfd_vma) -1;
@@ -1431,10 +1417,11 @@ elf_vax_relocate_section (bfd *output_bfd,
              || h->root.type == bfd_link_hash_defweak)
              && ((r_type == R_VAX_PLT32
                   && h->plt.offset != (bfd_vma) -1
              || h->root.type == bfd_link_hash_defweak)
              && ((r_type == R_VAX_PLT32
                   && h->plt.offset != (bfd_vma) -1
+                  && !h->forced_local
                   && elf_hash_table (info)->dynamic_sections_created)
                  || (r_type == R_VAX_GOT32
                   && elf_hash_table (info)->dynamic_sections_created)
                  || (r_type == R_VAX_GOT32
-                     && strcmp (h->root.root.string,
-                                "_GLOBAL_OFFSET_TABLE_") != 0
+                     && h->got.offset != (bfd_vma) -1
+                     && !h->forced_local
                      && elf_hash_table (info)->dynamic_sections_created
                      && (! info->shared
                          || (! info->symbolic && h->dynindx != -1)
                      && elf_hash_table (info)->dynamic_sections_created
                      && (! info->shared
                          || (! info->symbolic && h->dynindx != -1)
@@ -1452,10 +1439,7 @@ elf_vax_relocate_section (bfd *output_bfd,
                              && h->def_dynamic))
                      && (r_type == R_VAX_8
                          || r_type == R_VAX_16
                              && h->def_dynamic))
                      && (r_type == R_VAX_8
                          || r_type == R_VAX_16
-                         || r_type == R_VAX_32
-                         || r_type == R_VAX_PC8
-                         || r_type == R_VAX_PC16
-                         || r_type == R_VAX_PC32))))
+                         || r_type == R_VAX_32))))
            /* In these cases, we don't need the relocation
               value.  We check specially because in some
               obscure cases sec->output_section will be NULL.  */
            /* In these cases, we don't need the relocation
               value.  We check specially because in some
               obscure cases sec->output_section will be NULL.  */
@@ -1481,7 +1465,7 @@ elf_vax_relocate_section (bfd *output_bfd,
        case R_VAX_GOT32:
          /* Relocation is to the address of the entry for this symbol
             in the global offset table.  */
        case R_VAX_GOT32:
          /* Relocation is to the address of the entry for this symbol
             in the global offset table.  */
-         if (h == NULL || h->got.offset == (bfd_vma) -1)
+         if (h == NULL || h->got.offset == (bfd_vma) -1 || h->forced_local)
            break;
 
          /* Relocation is the offset of the entry for this symbol in
            break;
 
          /* Relocation is the offset of the entry for this symbol in
@@ -1543,7 +1527,7 @@ elf_vax_relocate_section (bfd *output_bfd,
 
          /* Resolve a PLTxx reloc against a local symbol directly,
             without using the procedure linkage table.  */
 
          /* Resolve a PLTxx reloc against a local symbol directly,
             without using the procedure linkage table.  */
-         if (h == NULL)
+         if (h == NULL || h->forced_local)
            break;
 
          if (h->plt.offset == (bfd_vma) -1
            break;
 
          if (h->plt.offset == (bfd_vma) -1
@@ -1597,7 +1581,7 @@ elf_vax_relocate_section (bfd *output_bfd,
        case R_VAX_PC8:
        case R_VAX_PC16:
        case R_VAX_PC32:
        case R_VAX_PC8:
        case R_VAX_PC16:
        case R_VAX_PC32:
-         if (h == NULL)
+         if (h == NULL || h->forced_local)
            break;
          /* Fall through.  */
        case R_VAX_8:
            break;
          /* Fall through.  */
        case R_VAX_8:
@@ -1622,22 +1606,10 @@ elf_vax_relocate_section (bfd *output_bfd,
                 time.  */
              if (sreloc == NULL)
                {
                 time.  */
              if (sreloc == NULL)
                {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (input_bfd,
-                          elf_elfheader (input_bfd)->e_shstrndx,
-                          elf_section_data (input_section)->rel_hdr.sh_name));
-                 if (name == NULL)
+                 sreloc = _bfd_elf_get_dynamic_reloc_section
+                   (input_bfd, input_section, /*rela?*/ TRUE);
+                 if (sreloc == NULL)
                    return FALSE;
                    return FALSE;
-
-                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
                }
 
              skip = FALSE;
                }
 
              skip = FALSE;