* elf32-sparc.c (elf32_sparc_relocate_section): Revert
[external/binutils.git] / bfd / elf32-sparc.c
index 889d83f..d540efe 100644 (file)
@@ -1176,9 +1176,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         relocation = (sec->output_section->vma
-                       + sec->output_offset
-                       + sym->st_value);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
        }
       else
        {
@@ -1223,7 +1221,15 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
                          || ((r_type == R_SPARC_PC10
                               || r_type == R_SPARC_PC22)
                              && strcmp (h->root.root.string,
-                                        "_GLOBAL_OFFSET_TABLE_") != 0))))
+                                        "_GLOBAL_OFFSET_TABLE_") != 0))
+                     && ((input_section->flags & SEC_ALLOC) != 0
+                         /* DWARF will emit R_SPARC_32 relocations in its
+                            sections against symbols defined externally
+                            in shared libraries.  We can't do anything
+                            with them here.  */
+                         || ((input_section->flags & SEC_DEBUGGING) != 0
+                             && (h->elf_link_hash_flags
+                                 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
                {
                  /* In these cases, we don't need the relocation
                      value.  We check specially because in some
@@ -1409,7 +1415,9 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_SPARC_LO10:
        case R_SPARC_UA16:
        case R_SPARC_UA32:
-         if (info->shared && (input_section->flags & SEC_ALLOC))
+         if (info->shared
+             && r_symndx != 0
+             && (input_section->flags & SEC_ALLOC))
            {
              Elf_Internal_Rela outrel;
              boolean skip;
@@ -1440,22 +1448,11 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
 
              skip = false;
 
-             if (elf_section_data (input_section)->stab_info == NULL)
-               outrel.r_offset = rel->r_offset;
-             else
-               {
-                 bfd_vma off;
-
-                 off = (_bfd_stab_section_offset
-                        (output_bfd, &elf_hash_table (info)->stab_info,
-                         input_section,
-                         &elf_section_data (input_section)->stab_info,
-                         rel->r_offset));
-                 if (off == (bfd_vma) -1)
-                   skip = true;
-                 outrel.r_offset = off;
-               }
-
+             outrel.r_offset =
+               _bfd_elf_section_offset (output_bfd, info, input_section,
+                                        rel->r_offset);
+             if (outrel.r_offset == (bfd_vma) -1)
+               skip = true;
              outrel.r_offset += (input_section->output_section->vma
                                  + input_section->output_offset);
 
@@ -1496,7 +1493,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
                }
              else
                {
-                 if (r_type == R_SPARC_32 || r_type == R_SPARC_UA32)
+                 if (r_type == R_SPARC_32)
                    {
                      outrel.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE);
                      outrel.r_addend = relocation + rel->r_addend;