Correct spelling of "relocatable".
[deliverable/binutils-gdb.git] / bfd / elf32-sh.c
index d1e618b460690a8f2a7aea57bc28e9286d5b2fea..af8dd6718a65c70358b6c2546e928ac24055f89d 100644 (file)
@@ -1,4 +1,4 @@
-/* Hitachi SH specific support for 32-bit ELF
+/* Renesas / SuperH SH specific support for 32-bit ELF
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Contributed by Ian Lance Taylor, Cygnus Support.
@@ -90,6 +90,8 @@ static bfd_boolean sh_elf_create_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_vma dtpoff_base
   PARAMS ((struct bfd_link_info *));
+static bfd_vma tpoff
+  PARAMS ((struct bfd_link_info *, bfd_vma));
 static asection * sh_elf_gc_mark_hook
   PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
           struct elf_link_hash_entry *, Elf_Internal_Sym *));
@@ -179,6 +181,8 @@ static reloc_howto_type sh_elf_howto_table[] =
         TRUE),                 /* pcrel_offset */
 
   /* 12 bit PC relative branch divided by 2.  */
+  /* This cannot be partial_inplace because relaxation can't know the
+     eventual value of a symbol.  */
   HOWTO (R_SH_IND12W,          /* type */
         1,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
@@ -186,10 +190,10 @@ static reloc_howto_type sh_elf_howto_table[] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        sh_elf_reloc,          /* special_function */
+        NULL,                  /* special_function */
         "R_SH_IND12W",         /* name */
-        TRUE,                  /* partial_inplace */
-        0xfff,                 /* src_mask */
+        FALSE,                 /* partial_inplace */
+        0x0,                   /* src_mask */
         0xfff,                 /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
@@ -2030,7 +2034,7 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   *again = FALSE;
 
-  if (link_info->relocateable
+  if (link_info->relocatable
       || (sec->flags & SEC_RELOC) == 0
       || sec->reloc_count == 0)
     return TRUE;
@@ -2050,7 +2054,7 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
-  internal_relocs = (_bfd_elf32_link_read_relocs
+  internal_relocs = (_bfd_elf_link_read_relocs
                     (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
                      link_info->keep_memory));
   if (internal_relocs == NULL)
@@ -2232,6 +2236,12 @@ sh_elf_relax_section (abfd, sec, link_info, again)
       /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
         replace the jsr with a bsr.  */
       irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
+      /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
+        here, but that only checks if the symbol is an external symbol,
+        not if the symbol is in a different section.  Besides, we need
+        a consistent meaning for the relocation, so we just assume here that
+        the value of the symbol is not available.  */
+#if 0
       if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
        {
          /* If this needs to be changed because of future relaxing,
@@ -2242,12 +2252,14 @@ sh_elf_relax_section (abfd, sec, link_info, again)
                      contents + irel->r_offset);
        }
       else
+#endif
        {
          /* We can't fully resolve this yet, because the external
             symbol value may be changed by future relaxing.  We let
             the final link phase handle it.  */
          bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
        }
+      irel->r_addend = -4;
 
       /* See if there is another R_SH_USES reloc referring to the same
         register load.  */
@@ -2316,7 +2328,8 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   /* Look for load and store instructions that we can align on four
      byte boundaries.  */
-  if (have_code)
+  if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
+      && have_code)
     {
       bfd_boolean swapped;
 
@@ -2542,14 +2555,28 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
          break;
 
        case R_SH_IND12W:
-         if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
-           start = stop = addr;
+         off = insn & 0xfff;
+         if (! off)
+           {
+             /* This has been made by previous relaxation.  Since the
+                relocation will be against an external symbol, the
+                final relocation will just do the right thing.  */
+             start = stop = addr;
+           }
          else
            {
-             off = insn & 0xfff;
              if (off & 0x800)
                off -= 0x1000;
              stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
+
+             /* The addend will be against the section symbol, thus
+                for adjusting the addend, the relevant start is the
+                start of the section.
+                N.B. If we want to abandom in-place changes here and
+                test directly using symbol + addend, we have to take into
+                account that the addend has already been adjusted by -4.  */
+             if (stop > addr && stop < toaddr)
+               irel->r_addend -= count;
            }
          break;
 
@@ -2709,7 +2736,7 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
       /* We always cache the relocs.  Perhaps, if info->keep_memory is
         FALSE, we should free them, if we are permitted to, when we
         leave sh_coff_relax_section.  */
-      internal_relocs = (_bfd_elf32_link_read_relocs
+      internal_relocs = (_bfd_elf_link_read_relocs
                         (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
                          TRUE));
       if (internal_relocs == NULL)
@@ -3524,9 +3551,6 @@ struct elf_sh_link_hash_entry
   enum {
     GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
   } tls_type;
-
-  /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated.  */
-  bfd_boolean tls_tpoff32;
 };
 
 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
@@ -3630,7 +3654,6 @@ sh_elf_link_hash_newfunc (entry, table, string)
       ret->datalabel_got.refcount = ret->root.got.refcount;
 #endif
       ret->tls_type = GOT_UNKNOWN;
-      ret->tls_tpoff32 = FALSE;
     }
 
   return (struct bfd_hash_entry *) ret;
@@ -3917,6 +3940,10 @@ sh_elf_adjust_dynamic_symbol (info, h)
                  || h->weakdef->root.type == bfd_link_hash_defweak);
       h->root.u.def.section = h->weakdef->root.u.def.section;
       h->root.u.def.value = h->weakdef->root.u.def.value;
+      if (info->nocopyreloc)
+       h->elf_link_hash_flags
+         = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
+            | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
       return TRUE;
     }
 
@@ -4015,9 +4042,9 @@ sh_elf_adjust_dynamic_symbol (info, h)
    will be called from elflink.h.  If elflink.h doesn't call our
    finish_dynamic_symbol routine, we'll need to do something about
    initializing any .plt and .got entries in sh_elf_relocate_section.  */
-#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
+#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
   ((DYN)                                                               \
-   && ((INFO)->shared                                                  \
+   && ((SHARED)                                                                \
        || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)     \
    && ((H)->dynindx != -1                                              \
        || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
@@ -4053,14 +4080,16 @@ allocate_dynrelocs (h, inf)
       && eh->gotplt_refcount > 0)
     {
       /* The symbol has been forced local, or we have some direct got refs,
-         so treat all the gotplt refs as got refs. */
+        so treat all the gotplt refs as got refs. */
       h->got.refcount += eh->gotplt_refcount;
       if (h->plt.refcount >= eh->gotplt_refcount)
        h->plt.refcount -= eh->gotplt_refcount;
     }
 
   if (htab->root.dynamic_sections_created
-      && h->plt.refcount > 0)
+      && h->plt.refcount > 0
+      && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+         || h->root.type != bfd_link_hash_undefweak))
     {
       /* Make sure this symbol is output as a dynamic symbol.
         Undefined weak syms won't yet be marked as dynamic.  */
@@ -4071,7 +4100,8 @@ allocate_dynrelocs (h, inf)
            return FALSE;
        }
 
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
+      if (info->shared
+         || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
        {
          asection *s = htab->splt;
 
@@ -4138,14 +4168,17 @@ allocate_dynrelocs (h, inf)
       if (tls_type == GOT_TLS_GD)
        s->_raw_size += 4;
       dyn = htab->root.dynamic_sections_created;
-      /* R_SH_TLS_IE_32 needs one dynamic relocation,
+      /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
         R_SH_TLS_GD needs one if local symbol and two if global.  */
       if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
-         || tls_type == GOT_TLS_IE)
+         || (tls_type == GOT_TLS_IE && dyn))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
       else if (tls_type == GOT_TLS_GD)
        htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
-      else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+      else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+               || h->root.type != bfd_link_hash_undefweak)
+              && (info->shared
+                  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     }
   else
@@ -4170,7 +4203,7 @@ allocate_dynrelocs (h, inf)
       eh->datalabel_got.offset = s->_raw_size;
       s->_raw_size += 4;
       dyn = htab->root.dynamic_sections_created;
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     }
   else
@@ -4204,12 +4237,15 @@ allocate_dynrelocs (h, inf)
                pp = &p->next;
            }
        }
+
+      /* Also discard relocs on undefined weak syms with non-default
+        visibility.  */
+      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+         && h->root.type == bfd_link_hash_undefweak)
+       eh->dyn_relocs = NULL;
     }
   else
     {
-      if (sh_elf_hash_entry (h)->tls_tpoff32)
-       goto keep;
-
       /* For the non-shared case, discard space for relocs against
         symbols which turn out to need copy relocs or are not
         dynamic.  */
@@ -4302,7 +4338,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
   if (htab->root.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -4464,7 +4500,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (! add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
@@ -4614,9 +4650,9 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
             (info,
              _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
              input_bfd, input_section, rel->r_offset));
-         if (info->relocateable)
+         if (info->relocatable)
            {
-             /* This is a relocateable link.  We don't have to change
+             /* This is a relocatable link.  We don't have to change
                 anything, unless the reloc is against a section symbol,
                 in which case we have to adjust according to where the
                 section symbol winds up in the output section.  */
@@ -4685,8 +4721,8 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          /* Section symbol are never (?) placed in the hash table, so
             we can just ignore hash relocations when creating a
-            relocateable object file.  */
-         if (info->relocateable)
+            relocatable object file.  */
+         if (info->relocatable)
            continue;
 
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
@@ -4727,7 +4763,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                       || r_type == R_SH_GOT_MEDLOW16
                       || r_type == R_SH_GOT_MEDHI16
                       || r_type == R_SH_GOT_HI16)
-                     && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+                     && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
                      && (! info->shared
                          || (! info->symbolic && h->dynindx != -1)
                          || (h->elf_link_hash_flags
@@ -4785,7 +4821,6 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
          else if (info->shared
-                  && (! info->symbolic || info->allow_shlib_undefined)
                   && ! info->no_undefined
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
@@ -4812,7 +4847,6 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          break;
 
        case R_SH_IND12W:
-         relocation -= 4;
          goto final_link_relocate;
 
        case R_SH_DIR8WPN:
@@ -4865,6 +4899,9 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_SH_DIR32:
        case R_SH_REL32:
          if (info->shared
+             && (h == NULL
+                 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                 || h->root.type != bfd_link_hash_undefweak)
              && r_symndx != 0
              && (input_section->flags & SEC_ALLOC) != 0
              && (r_type != R_SH_REL32
@@ -5029,11 +5066,13 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              BFD_ASSERT (off != (bfd_vma) -1);
 
              dyn = htab->root.dynamic_sections_created;
-             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
                  || (info->shared
                      && (info->symbolic || h->dynindx == -1
                          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+                 || (ELF_ST_VISIBILITY (h->other)
+                     && h->root.type == bfd_link_hash_undefweak))
                {
                  /* This is actually a static link, or it is a
                     -Bsymbolic link and the symbol is defined
@@ -5256,9 +5295,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              tls_type = sh_elf_hash_entry (h)->tls_type;
              if (! info->shared
                  && (h->dynindx == -1
-                     || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
-                 && (tls_type == GOT_TLS_IE
-                     || sh_elf_hash_entry (h)->tls_tpoff32))
+                     || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
                r_type = R_SH_TLS_LE_32;
            }
 
@@ -5269,9 +5306,6 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              bfd_vma offset;
              unsigned short insn;
-             int indx;
-             Elf_Internal_Rela outrel;
-             bfd_byte *loc;
 
              if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
                {
@@ -5348,39 +5382,8 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
                }
 
-             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)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
-               }
-
-             indx = (h && h->dynindx != -1) ? h->dynindx : 0;
-             outrel.r_offset = (input_section->output_section->vma
-                                + input_section->output_offset
-                                + rel->r_offset);
-             outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
-             if (indx == 0)
-               outrel.r_addend = relocation - dtpoff_base (info);
-             else
-               outrel.r_addend = 0;
-
-             loc = sreloc->contents;
-             loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
-             bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+             bfd_put_32 (output_bfd, tpoff (info, relocation),
+                         contents + rel->r_offset);
              continue;
            }
 
@@ -5398,9 +5401,21 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              off = local_got_offsets[r_symndx];
            }
 
+         /* Relocate R_SH_TLS_IE_32 directly when statically linking.  */
+         if (r_type == R_SH_TLS_IE_32
+             && ! htab->root.dynamic_sections_created)
+           {
+             off &= ~1;
+             bfd_put_32 (output_bfd, tpoff (info, relocation),
+                         sgot->contents + off);
+             bfd_put_32 (output_bfd, sgot->output_offset + off,
+                         contents + rel->r_offset);
+             continue;
+           }
+
          if ((off & 1) != 0)
            off &= ~1;
-          else
+         else
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -5415,7 +5430,11 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              outrel.r_offset = (sgot->output_section->vma
                                 + sgot->output_offset + off);
 
-             indx = (h && h->dynindx != -1) ? h->dynindx : 0;
+             if (h == NULL || h->dynindx == -1)
+               indx = 0;
+             else
+               indx = h->dynindx;
+
              dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
                         R_SH_TLS_TPOFF32);
              if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
@@ -5597,46 +5616,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_SH_TLS_LDO_32:
          if (! info->shared)
-           {
-             int indx;
-             Elf_Internal_Rela outrel;
-             bfd_byte *loc;
-
-             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)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
-               }
-
-             indx = (h && h->dynindx != -1) ? h->dynindx : 0;
-             outrel.r_offset = (input_section->output_section->vma
-                                + input_section->output_offset
-                                + rel->r_offset);
-             outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
-             if (indx == 0)
-               outrel.r_addend = relocation - dtpoff_base (info);
-             else
-               outrel.r_addend = 0;
-
-             loc = sreloc->contents;
-             loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
-             bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
-             continue;
-           }
+           relocation = tpoff (info, relocation);
          else
            relocation -= dtpoff_base (info);
 
@@ -5649,6 +5629,13 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            Elf_Internal_Rela outrel;
            bfd_byte *loc;
 
+           if (! info->shared)
+             {
+               relocation = tpoff (info, relocation);
+               addend = rel->r_addend;
+               goto final_link_relocate;
+             }
+
            if (sreloc == NULL)
              {
                const char *name;
@@ -5669,7 +5656,11 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                BFD_ASSERT (sreloc != NULL);
              }
 
-           indx = (h && h->dynindx != -1) ? h->dynindx : 0;
+           if (h == NULL || h->dynindx == -1)
+             indx = 0;
+           else
+             indx = h->dynindx;
+
            outrel.r_offset = (input_section->output_section->vma
                               + input_section->output_offset
                               + rel->r_offset);
@@ -5727,12 +5718,12 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
 static bfd_byte *
 sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
-                                      data, relocateable, symbols)
+                                      data, relocatable, symbols)
      bfd *output_bfd;
      struct bfd_link_info *link_info;
      struct bfd_link_order *link_order;
      bfd_byte *data;
-     bfd_boolean relocateable;
+     bfd_boolean relocatable;
      asymbol **symbols;
 {
   Elf_Internal_Shdr *symtab_hdr;
@@ -5744,11 +5735,11 @@ sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
 
   /* We only need to handle the case of relaxing, or of having a
      particular set of section contents, specially.  */
-  if (relocateable
+  if (relocatable
       || elf_section_data (input_section)->this_hdr.contents == NULL)
     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
                                                       link_order, data,
-                                                      relocateable,
+                                                      relocatable,
                                                       symbols);
 
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -5763,7 +5754,7 @@ sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
       Elf_Internal_Sym *isym, *isymend;
       bfd_size_type amt;
 
-      internal_relocs = (_bfd_elf32_link_read_relocs
+      internal_relocs = (_bfd_elf_link_read_relocs
                         (input_bfd, input_section, (PTR) NULL,
                          (Elf_Internal_Rela *) NULL, FALSE));
       if (internal_relocs == NULL)
@@ -5839,12 +5830,27 @@ static bfd_vma
 dtpoff_base (info)
      struct bfd_link_info *info;
 {
- /* If tls_segment is NULL, we should have signalled an error already.  */
- if (elf_hash_table (info)->tls_segment == NULL)
-   return 0;
 /* If tls_segment is NULL, we should have signalled an error already.  */
 if (elf_hash_table (info)->tls_segment == NULL)
+    return 0;
   return elf_hash_table (info)->tls_segment->start;
 }
 
+/* Return the relocation value for R_SH_TLS_TPOFF32..  */
+
+static bfd_vma
+tpoff (info, address)
+     struct bfd_link_info *info;
+     bfd_vma address;
+{
+  /* If tls_segment is NULL, we should have signalled an error already.  */
+  if (elf_hash_table (info)->tls_segment == NULL)
+    return 0;
+  /* SH TLS ABI is variant I and static TLS block start just after tcbhead
+     structure which has 2 pointer fields.  */
+  return (address - dtpoff_base (info) + 8);
+}
+
 static asection *
 sh_elf_gc_mark_hook (sec, info, rel, h, sym)
      asection *sec;
@@ -5900,9 +5906,6 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
   struct elf_link_hash_entry **sym_hashes;
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
-  unsigned long r_symndx;
-  struct elf_link_hash_entry *h;
-  struct elf_sh_link_hash_entry *eh;
 
   elf_section_data (sec)->local_dynrel = NULL;
 
@@ -5913,15 +5916,20 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; rel++)
     {
+      unsigned long r_symndx;
+      unsigned int r_type;
+      struct elf_link_hash_entry *h = NULL;
 #ifdef INCLUDE_SHMEDIA
       int seen_stt_datalabel = 0;
 #endif
 
       r_symndx = ELF32_R_SYM (rel->r_info);
-      if (r_symndx < symtab_hdr->sh_info)
-       h = NULL;
-      else
+      if (r_symndx >= symtab_hdr->sh_info)
        {
+         struct elf_sh_link_hash_entry *eh;
+         struct elf_sh_dyn_relocs **pp;
+         struct elf_sh_dyn_relocs *p;
+
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 #ifdef INCLUDE_SHMEDIA
          while (h->root.type == bfd_link_hash_indirect
@@ -5931,12 +5939,18 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
              h = (struct elf_link_hash_entry *) h->root.u.i.link;
            }
 #endif
+         eh = (struct elf_sh_link_hash_entry *) h;
+         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+           if (p->sec == sec)
+             {
+               /* Everything must go for SEC.  */
+               *pp = p->next;
+               break;
+             }
        }
-      eh = (struct elf_sh_link_hash_entry *) h;
 
-      switch (sh_elf_optimized_tls_reloc (info, ELF32_R_TYPE (rel->r_info),
-                                         ELF32_R_SYM (rel->r_info)
-                                         >= symtab_hdr->sh_info))
+      r_type = ELF32_R_TYPE (rel->r_info);
+      switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
        {
        case R_SH_TLS_LD_32:
          if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
@@ -5969,6 +5983,8 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 #ifdef INCLUDE_SHMEDIA
              if (seen_stt_datalabel)
                {
+                 struct elf_sh_link_hash_entry *eh;
+                 eh = (struct elf_sh_link_hash_entry *) h;
                  if (eh->datalabel_got.refcount > 0)
                    eh->datalabel_got.refcount -= 1;
                }
@@ -5994,27 +6010,9 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 
        case R_SH_DIR32:
        case R_SH_REL32:
-         if (h != NULL)
-           {
-             struct elf_sh_dyn_relocs **pp;
-             struct elf_sh_dyn_relocs *p;
-
-
-             if (!info->shared && h->plt.refcount > 0)
-               h->plt.refcount -= 1;
-
-             for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-               if (p->sec == sec)
-                 {
-                   if (ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
-                     p->pc_count -= 1;
-                   p->count -= 1;
-                   if (p->count == 0)
-                     *pp = p->next;
-                   break;
-                 }
-           }
-         break;
+         if (info->shared)
+           break;
+         /* Fall thru */
 
        case R_SH_PLT32:
 #ifdef INCLUDE_SHMEDIA
@@ -6041,6 +6039,8 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 #endif
          if (h != NULL)
            {
+             struct elf_sh_link_hash_entry *eh;
+             eh = (struct elf_sh_link_hash_entry *) h;
              if (eh->gotplt_refcount > 0)
                {
                  eh->gotplt_refcount -= 1;
@@ -6147,7 +6147,17 @@ sh_elf_copy_indirect_symbol (bed, dir, ind)
       eind->tls_type = GOT_UNKNOWN;
     }
 
-  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+  if (ind->root.type != bfd_link_hash_indirect
+      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+    /* If called to transfer flags for a weakdef during processing
+       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+    dir->elf_link_hash_flags |=
+      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+                                  | ELF_LINK_HASH_REF_REGULAR
+                                  | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+  else
+    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 
 static int
@@ -6201,7 +6211,7 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
   srelgot = NULL;
   sreloc = NULL;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -6312,12 +6322,12 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
            return FALSE;
          break;
 
-       force_got:
        case R_SH_TLS_IE_32:
          if (info->shared)
            info->flags |= DF_STATIC_TLS;
 
          /* FALLTHROUGH */
+       force_got:
        case R_SH_TLS_GD_32:
        case R_SH_GOT32:
 #ifdef INCLUDE_SHMEDIA
@@ -6613,92 +6623,10 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
              return FALSE;
            }
 
-         if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_LD_32)
-           break;
+         break;
 
-         /* FALLTHROUGH */
        case R_SH_TLS_LDO_32:
-         /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
-            copy relocation.  */
-         if (! info->shared)
-           {
-             struct elf_sh_dyn_relocs *p;
-             struct elf_sh_dyn_relocs **head;
-
-             if (dynobj == NULL)
-               htab->root.dynobj = dynobj = abfd;
-
-             if (sreloc == NULL)
-               {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (abfd,
-                          elf_elfheader (abfd)->e_shstrndx,
-                          elf_section_data (sec)->rel_hdr.sh_name));
-                 if (name == NULL)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (abfd, sec),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 if (sreloc == NULL)
-                   {
-                     flagword flags;
-
-                     sreloc = bfd_make_section (dynobj, name);
-                     flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                     if ((sec->flags & SEC_ALLOC) != 0)
-                       flags |= SEC_ALLOC | SEC_LOAD;
-                     if (sreloc == NULL
-                         || ! bfd_set_section_flags (dynobj, sreloc, flags)
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 2))
-                       return FALSE;
-                   }
-                 elf_section_data (sec)->sreloc = sreloc;
-                 if (sec->flags & SEC_READONLY)
-                   info->flags |= DF_TEXTREL;
-               }
-
-             /* If this is a global symbol, we count the number of
-                relocations we need for this symbol.  */
-             if (h != NULL)
-               head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
-             else
-               {
-                 asection *s;
-
-                 /* Track dynamic relocs needed for local syms too.  */
-                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
-                                                sec, r_symndx);
-                 if (s == NULL)
-                   return FALSE;
-
-                 head = ((struct elf_sh_dyn_relocs **)
-                         &elf_section_data (s)->local_dynrel);
-               }
-
-             p = *head;
-             if (p == NULL || p->sec != sec)
-               {
-                 bfd_size_type amt = sizeof (*p);
-                 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
-                 if (p == NULL)
-                   return FALSE;
-                 p->next = *head;
-                 *head = p;
-                 p->sec = sec;
-                 p->count = 0;
-                 p->pc_count = 0;
-               }
-
-             p->count += 1;
-             if (h)
-               sh_elf_hash_entry (h)->tls_tpoff32 = TRUE;
-           }
+         /* Nothing to do.  */
          break;
 
        default:
@@ -6724,6 +6652,9 @@ sh_elf_set_mach_from_flags (abfd)
     case EF_SH2:
       bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2);
       break;
+    case EF_SH2E:
+      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh2e);
+      break;
     case EF_SH_DSP:
       bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh_dsp);
       break;
This page took 0.036852 seconds and 4 git commands to generate.