* elf32-sh.c (allocate_dynrelocs): Don't allocate dynamic
[deliverable/binutils-gdb.git] / bfd / elf32-sh.c
index 493764340686895c982b69c1bb72e22503f622c3..87d4e4fcbc5e3370c8345fca278169674012b201 100644 (file)
@@ -1,6 +1,7 @@
 /* Renesas / SuperH SH specific support for 32-bit ELF
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   2006, 2007, 2008, 2009, 2010, 2011, 2012
+   Free Software Foundation, Inc.
    Contributed by Ian Lance Taylor, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -2926,13 +2927,6 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
       return TRUE;
     }
 
-  if (h->size == 0)
-    {
-      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
-                            h->root.root.string);
-      return TRUE;
-    }
-
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
      an entry for this symbol in the .dynsym section.  The dynamic
@@ -2950,7 +2944,7 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      copy the initial value out of the dynamic object and into the
      runtime process image.  We need to remember the offset into the
      .rela.bss section we are going to use.  */
-  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
+  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
     {
       asection *srel;
 
@@ -2977,12 +2971,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   if (h->root.type == bfd_link_hash_indirect)
     return TRUE;
 
-  if (h->root.type == bfd_link_hash_warning)
-    /* When warning symbols are created, they **replace** the "real"
-       entry in the hash table, thus we never get to see the real
-       symbol in a hash traversal.  So look at it now.  */
-    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
   info = (struct bfd_link_info *) inf;
   htab = sh_elf_hash_table (info);
   if (htab == NULL)
@@ -3116,6 +3104,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
              && (got_type == GOT_NORMAL || got_type == GOT_FUNCDESC))
            htab->srofixup->size += 4;
        }
+      /* No dynamic relocations required when IE->LE conversion happens.  */
+      else if (got_type == GOT_TLS_IE && !h->def_dynamic && !info->shared)
+       ;
       /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
         R_SH_TLS_GD needs one if local symbol and two if global.  */
       else if ((got_type == GOT_TLS_GD && h->dynindx == -1)
@@ -3321,9 +3312,6 @@ readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   struct elf_sh_link_hash_entry *eh;
   struct elf_sh_dyn_relocs *p;
 
-  if (h->root.type == bfd_link_hash_warning)
-    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
   eh = (struct elf_sh_link_hash_entry *) h;
   for (p = eh->dyn_relocs; p != NULL; p = p->next)
     {
@@ -3797,8 +3785,10 @@ sh_elf_got_offset (struct elf_sh_link_hash_table *htab)
 static unsigned
 sh_elf_osec_to_segment (bfd *output_bfd, asection *osec)
 {
-  Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd,
-                                                                  osec);
+  Elf_Internal_Phdr *p = NULL;
+
+  if (output_bfd->xvec->flavour == bfd_target_elf_flavour)
+    p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
 
   /* FIXME: Nothing ever says what this index is relative to.  The kernel
      supplies data in terms of the number of load segments but this is
@@ -3811,7 +3801,8 @@ sh_elf_osec_readonly_p (bfd *output_bfd, asection *osec)
 {
   unsigned seg = sh_elf_osec_to_segment (output_bfd, osec);
 
-  return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
+  return (seg != (unsigned) -1
+         && ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W));
 }
 
 /* Generate the initial contents of a local function descriptor, along
@@ -4217,7 +4208,11 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                                 STT_DATALABEL on the way to it.  */
                              | ((h->other & STO_SH5_ISA32) != 0
                                 && ! seen_stt_datalabel));
-             else if (!info->relocatable)
+             else if (!info->relocatable
+                      && (_bfd_elf_section_offset (output_bfd, info,
+                                                   input_section,
+                                                   rel->r_offset)
+                          != (bfd_vma) -1))
                {
                  (*_bfd_error_handler)
                    (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
@@ -4246,15 +4241,8 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        }
 
       if (sec != NULL && elf_discarded_section (sec))
-       {
-         /* For relocs against symbols from removed linkonce sections,
-            or sections discarded by a linker script, we just want the
-            section contents zeroed.  Avoid any special processing.  */
-         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
-         rel->r_info = 0;
-         rel->r_addend = 0;
-         continue;
-       }
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, relend, howto, contents);
 
       if (info->relocatable)
        continue;
@@ -5532,7 +5520,7 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 
            check_segment[0] = check_segment[1] = -1;
 
-           if (! info->shared)
+           if (! info->shared || info->pie)
              {
                relocation = tpoff (info, relocation);
                addend = rel->r_addend;
@@ -6630,7 +6618,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
          break;
 
        case R_SH_TLS_LE_32:
-         if (info->shared)
+         if (info->shared && !info->pie)
            {
              (*_bfd_error_handler)
                (_("%B: TLS local exec code cannot be linked into shared objects"),
This page took 0.029131 seconds and 4 git commands to generate.