OSDN Git Service

bfd/
[pf3gnuchains/pf3gnuchains4x.git] / bfd / elf32-cris.c
index 83ef984..563e2c0 100644 (file)
@@ -1,6 +1,6 @@
 /* CRIS-specific support for 32-bit ELF.
    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010  Free Software Foundation, Inc.
+   2010, 2011 Free Software Foundation, Inc.
    Contributed by Axis Communications AB.
    Written by Hans-Peter Nilsson, based on elf32-fr30.c
    PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
@@ -580,7 +580,7 @@ cris_elf_grok_prstatus (abfd, note)
        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
 
        /* pr_pid */
-       elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
+       elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 22);
 
        /* pr_reg */
        offset = 70;
@@ -599,7 +599,7 @@ cris_elf_grok_prstatus (abfd, note)
        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
 
        /* pr_pid */
-       elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
+       elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 22);
 
        /* pr_reg */
        offset = 70;
@@ -1166,7 +1166,11 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
                      || r_type == R_CRIS_16_PCREL
                      || r_type == R_CRIS_32_PCREL))
                relocation = 0;
-             else if (!info->relocatable && unresolved_reloc)
+             else if (!info->relocatable && unresolved_reloc
+                      && (_bfd_elf_section_offset (output_bfd, info,
+                                                   input_section,
+                                                   rel->r_offset)
+                          != (bfd_vma) -1))
                {
                  _bfd_error_handler
                    (_("%B, section %A: unresolvable relocation %s against symbol `%s'"),
@@ -1181,15 +1185,8 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
 
       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;
@@ -1493,7 +1490,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
        case R_CRIS_16:
        case R_CRIS_32:
          if (info->shared
-             && r_symndx != 0
+             && r_symndx != STN_UNDEF
              && (input_section->flags & SEC_ALLOC) != 0
              && ((r_type != R_CRIS_8_PCREL
                   && r_type != R_CRIS_16_PCREL
@@ -1512,7 +1509,7 @@ cris_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
              if (sreloc == NULL)
                {
                  sreloc = _bfd_elf_get_dynamic_reloc_section
-                   (input_bfd, input_section, /*rela?*/ TRUE);
+                   (dynobj, input_section, /*rela?*/ TRUE);
                  /* The section should have been created in cris_elf_check_relocs,
                     but that function will not be called for objects which fail in
                     cris_elf_merge_private_bfd_data.  */
@@ -2157,7 +2154,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
     {
       asection *splt;
       asection *sgotplt;
-      asection *sgot;
       asection *srela;
       bfd_vma got_base;
 
@@ -2197,7 +2193,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
       BFD_ASSERT (h->dynindx != -1);
 
       splt = bfd_get_section_by_name (dynobj, ".plt");
-      sgot = bfd_get_section_by_name (dynobj, ".got");
       sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
       srela = bfd_get_section_by_name (dynobj, ".rela.plt");
       BFD_ASSERT (splt != NULL && sgotplt != NULL
@@ -2672,6 +2667,9 @@ cris_elf_gc_sweep_hook (bfd *abfd,
          /* For local symbols, treat these like GOT relocs.  */
          if (h == NULL)
            goto local_got_reloc;
+         else
+           /* For global symbols, adjust the reloc-specific refcount.  */
+           elf_cris_hash_entry (h)->gotplt_refcount--;
          /* Fall through.  */
 
        case R_CRIS_32_PLT_GOTREL:
@@ -2680,10 +2678,14 @@ cris_elf_gc_sweep_hook (bfd *abfd,
            local_got_refcounts[-1]--;
          /* Fall through.  */
 
+       case R_CRIS_8:
+       case R_CRIS_16:
+       case R_CRIS_32:
        case R_CRIS_8_PCREL:
        case R_CRIS_16_PCREL:
        case R_CRIS_32_PCREL:
        case R_CRIS_32_PLT_PCREL:
+         /* Negate the increment we did in cris_elf_check_relocs.  */
          if (h != NULL)
            {
              if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
@@ -2742,8 +2744,10 @@ elf_cris_adjust_gotplt_to_got (h, p)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) p;
 
-  if (h->root.root.type == bfd_link_hash_warning)
-    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+  /* A GOTPLT reloc, when activated, is supposed to be included into
+     the PLT refcount.  */
+  BFD_ASSERT (h->gotplt_refcount == 0
+             || h->gotplt_refcount <= h->root.plt.refcount);
 
   /* If nobody wanted a GOTPLT with this symbol, we're done.  */
   if (h->gotplt_refcount <= 0)
@@ -3579,6 +3583,12 @@ cris_elf_check_relocs (bfd *abfd,
                 sec,
                 cris_elf_howto_table[r_type].name);
            }
+
+         /* We don't need to handle relocs into sections not going into
+            the "real" output.  */
+         if ((sec->flags & SEC_ALLOC) == 0)
+           break;
+
          if (h != NULL)
            {
              h->non_got_ref = 1;
@@ -3608,11 +3618,6 @@ cris_elf_check_relocs (bfd *abfd,
          if (! info->shared)
            break;
 
-         /* We don't need to handle relocs into sections not going into
-            the "real" output.  */
-         if ((sec->flags & SEC_ALLOC) == 0)
-           break;
-
          /* We may need to create a reloc section in the dynobj and made room
             for this reloc.  */
          if (sreloc == NULL)
@@ -3965,9 +3970,6 @@ elf_cris_discard_excess_dso_dynamics (h, inf)
   struct elf_cris_pcrel_relocs_copied *s;
   struct bfd_link_info *info = (struct bfd_link_info *) inf;
 
-  if (h->root.root.type == bfd_link_hash_warning)
-    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
-
   /* If a symbol has been forced local or we have found a regular
      definition for the symbolic link case, then we won't be needing
      any relocs.  */
@@ -3978,7 +3980,8 @@ elf_cris_discard_excess_dso_dynamics (h, inf)
       for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
        {
          asection *sreloc
-           = _bfd_elf_get_dynamic_reloc_section (s->section->owner,
+           = _bfd_elf_get_dynamic_reloc_section (elf_hash_table (info)
+                                                 ->dynobj,
                                                  s->section,
                                                  /*rela?*/ TRUE);
          sreloc->size -= s->count * sizeof (Elf32_External_Rela);
@@ -4022,9 +4025,6 @@ elf_cris_discard_excess_program_dynamics (h, inf)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) inf;
 
-  if (h->root.root.type == bfd_link_hash_warning)
-    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
-
   /* If we're not creating a shared library and have a symbol which is
      referred to by .got references, but the symbol is defined locally,
      (or rather, not defined by a DSO) then lose the reloc for the .got
@@ -4365,6 +4365,7 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED,
 }
 \f
 #define ELF_ARCH               bfd_arch_cris
+#define ELF_TARGET_ID          CRIS_ELF_DATA
 #define ELF_MACHINE_CODE       EM_CRIS
 #define ELF_MAXPAGESIZE                0x2000