daily update
[deliverable/binutils-gdb.git] / bfd / elf32-frv.c
index e839cd1fcd43578321dba8fa9f8125a32f757147..3a3124347b5d4cdaeaac7f58e179866652529d78 100644 (file)
@@ -1,5 +1,5 @@
 /* FRV-specific support for 32-bit ELF.
-   Copyright 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+   Copyright 2002, 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -57,12 +57,6 @@ static bfd_boolean elf32_frv_add_symbol_hook
 static bfd_reloc_status_type frv_final_link_relocate
   PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
           Elf_Internal_Rela *, bfd_vma));
-static bfd_boolean elf32_frv_gc_sweep_hook
-  PARAMS ((bfd *, struct bfd_link_info *, asection *, const
-          Elf_Internal_Rela *));
-static asection * elf32_frv_gc_mark_hook
-  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
-          struct elf_link_hash_entry *, Elf_Internal_Sym *));
 static bfd_boolean elf32_frv_check_relocs
   PARAMS ((bfd *, struct bfd_link_info *, asection *,
           const Elf_Internal_Rela *));
@@ -78,6 +72,10 @@ static bfd_boolean frv_elf_merge_private_bfd_data
   PARAMS ((bfd *, bfd *));
 static bfd_boolean frv_elf_print_private_bfd_data
   PARAMS ((bfd *, PTR));
+static bfd_boolean elf32_frv_grok_prstatus (bfd * abfd,
+                                           Elf_Internal_Note * note);
+static bfd_boolean elf32_frv_grok_psinfo (bfd * abfd,
+                                         Elf_Internal_Note * note);
 
 static reloc_howto_type elf32_frv_howto_table [] =
 {
@@ -1004,8 +1002,9 @@ frvfdpic_elf_link_hash_table_create (bfd *abfd)
   if (ret == NULL)
     return NULL;
 
-  if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
-                                      _bfd_elf_link_hash_newfunc))
+  if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
+                                     _bfd_elf_link_hash_newfunc,
+                                     sizeof (struct elf_link_hash_entry)))
     {
       free (ret);
       return NULL;
@@ -4140,54 +4139,22 @@ elf32_frv_relocate_section (output_bfd, info, input_bfd, input_section,
    relocation.  */
 
 static asection *
-elf32_frv_gc_mark_hook (sec, info, rel, h, sym)
-     asection *sec;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
-     Elf_Internal_Rela *rel;
-     struct elf_link_hash_entry *h;
-     Elf_Internal_Sym *sym;
+elf32_frv_gc_mark_hook (asection *sec,
+                       struct bfd_link_info *info,
+                       Elf_Internal_Rela *rel,
+                       struct elf_link_hash_entry *h,
+                       Elf_Internal_Sym *sym)
 {
   if (h != NULL)
-    {
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       case R_FRV_GNU_VTINHERIT:
-       case R_FRV_GNU_VTENTRY:
-         break;
-
-       default:
-         switch (h->root.type)
-           {
-           default:
-             break;
-
-           case bfd_link_hash_defined:
-           case bfd_link_hash_defweak:
-             return h->root.u.def.section;
-
-           case bfd_link_hash_common:
-             return h->root.u.c.p->section;
-           }
-       }
-    }
-  else
-    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
-
-  return NULL;
-}
-
-/* Update the got entry reference counts for the section being removed.  */
+    switch (ELF32_R_TYPE (rel->r_info))
+      {
+      case R_FRV_GNU_VTINHERIT:
+      case R_FRV_GNU_VTENTRY:
+       return NULL;
+      }
 
-static bfd_boolean
-elf32_frv_gc_sweep_hook (abfd, info, sec, relocs)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
-     asection *sec ATTRIBUTE_UNUSED;
-     const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
-{
-  return TRUE;
+  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
-
 \f
 /* Hook called by the linker routine which adds symbols from an object
    file.  We use it to put .comm items in .scomm, and not .comm.  */
@@ -4394,10 +4361,14 @@ _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
 
   /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
      .plt section.  */
-  if (bed->want_plt_sym
-      && !_bfd_elf_define_linkage_sym (abfd, info, s,
-                                      "_PROCEDURE_LINKAGE_TABLE_"))
-    return FALSE;
+  if (bed->want_plt_sym)
+    {
+      h = _bfd_elf_define_linkage_sym (abfd, info, s,
+                                      "_PROCEDURE_LINKAGE_TABLE_");
+      elf_hash_table (info)->hplt = h;
+      if (h == NULL)
+       return FALSE;
+    }
 
   /* FRV-specific: we want rel relocations for the plt.  */
   s = bfd_make_section_with_flags (abfd, ".rel.plt",
@@ -5594,7 +5565,6 @@ elf32_frvfdpic_always_size_sections (bfd *output_bfd,
   if (!info->relocatable)
     {
       struct elf_link_hash_entry *h;
-      asection *sec;
 
       /* Force a PT_GNU_STACK segment to be created.  */
       if (! elf_tdata (output_bfd)->stack_flags)
@@ -5621,13 +5591,6 @@ elf32_frvfdpic_always_size_sections (bfd *output_bfd,
          h->type = STT_OBJECT;
          /* This one must NOT be hidden.  */
        }
-
-      /* Create a stack section, and set its alignment.  */
-      sec = bfd_make_section (output_bfd, ".stack");
-
-      if (sec == NULL
-         || ! bfd_set_section_alignment (output_bfd, sec, 3))
-       return FALSE;
     }
 
   return TRUE;
@@ -5709,48 +5672,45 @@ elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
 }
 
 static bfd_boolean
-elf32_frvfdpic_modify_segment_map (bfd *output_bfd,
-                                  struct bfd_link_info *info)
+elf32_frvfdpic_modify_program_headers (bfd *output_bfd,
+                                      struct bfd_link_info *info)
 {
+  struct elf_obj_tdata *tdata = elf_tdata (output_bfd);
   struct elf_segment_map *m;
+  Elf_Internal_Phdr *p;
 
   /* objcopy and strip preserve what's already there using
      elf32_frvfdpic_copy_private_bfd_data ().  */
   if (! info)
     return TRUE;
 
-  for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next)
+  for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++)
     if (m->p_type == PT_GNU_STACK)
       break;
 
   if (m)
     {
-      asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
       struct elf_link_hash_entry *h;
 
-      if (sec)
+      /* Obtain the pointer to the __stacksize symbol.  */
+      h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
+                               FALSE, FALSE, FALSE);
+      if (h)
        {
-         /* Obtain the pointer to the __stacksize symbol.  */
-         h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize",
-                                   FALSE, FALSE, FALSE);
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
-           h = (struct elf_link_hash_entry *)h->root.u.i.link;
+           h = (struct elf_link_hash_entry *) h->root.u.i.link;
          BFD_ASSERT (h->root.type == bfd_link_hash_defined);
+       }
 
-         /* Set the section size from the symbol value.  We
-            intentionally ignore the symbol section.  */
-         if (h->root.type == bfd_link_hash_defined)
-           sec->size = h->root.u.def.value;
-         else
-           sec->size = DEFAULT_STACK_SIZE;
+      /* Set the header p_memsz from the symbol value.  We
+        intentionally ignore the symbol section.  */
+      if (h && h->root.type == bfd_link_hash_defined)
+       p->p_memsz = h->root.u.def.value;
+      else
+       p->p_memsz = DEFAULT_STACK_SIZE;
 
-         /* Add the stack section to the PT_GNU_STACK segment,
-            such that its size and alignment requirements make it
-            to the segment.  */
-         m->sections[m->count] = sec;
-         m->count++;
-       }
+      p->p_align = 8;
     }
 
   return TRUE;
@@ -6823,6 +6783,86 @@ frv_elf_print_private_bfd_data (abfd, ptr)
 }
 
 \f
+/* Support for core dump NOTE sections.  */
+
+static bfd_boolean
+elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+  int offset;
+  unsigned int raw_size;
+
+  switch (note->descsz)
+    {
+      default:
+       return FALSE;
+
+      /* The Linux/FRV elf_prstatus struct is 268 bytes long.  The other
+         hardcoded offsets and sizes listed below (and contained within
+        this lexical block) refer to fields in the target's elf_prstatus
+        struct.  */
+      case 268:        
+       /* `pr_cursig' is at offset 12.  */
+       elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
+
+       /* `pr_pid' is at offset 24.  */
+       elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
+
+       /* `pr_reg' is at offset 72.  */
+       offset = 72;
+
+       /* Most grok_prstatus implementations set `raw_size' to the size
+          of the pr_reg field.  For Linux/FRV, we set `raw_size' to be
+          the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
+          and `pr_interp_fdpic_loadmap', both of which (by design)
+          immediately follow `pr_reg'.  This will allow these fields to
+          be viewed by GDB as registers.
+          
+          `pr_reg' is 184 bytes long.  `pr_exec_fdpic_loadmap' and
+          `pr_interp_fdpic_loadmap' are 4 bytes each.  */
+       raw_size = 184 + 4 + 4;
+
+       break;
+    }
+
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
+                                         note->descpos + offset);
+}
+
+static bfd_boolean
+elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+  switch (note->descsz)
+    {
+      default:
+       return FALSE;
+
+      /* The Linux/FRV elf_prpsinfo struct is 124 bytes long.  */
+      case 124:
+
+       /* `pr_fname' is found at offset 28 and is 16 bytes long.  */
+       elf_tdata (abfd)->core_program
+         = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
+
+       /* `pr_psargs' is found at offset 44 and is 80 bytes long.  */
+       elf_tdata (abfd)->core_command
+         = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
+    }
+
+  /* Note that for some reason, a spurious space is tacked
+     onto the end of the args in some (at least one anyway)
+     implementations, so strip it off if it exists.  */
+
+  {
+    char *command = elf_tdata (abfd)->core_command;
+    int n = strlen (command);
+
+    if (0 < n && command[n - 1] == ' ')
+      command[n - 1] = '\0';
+  }
+
+  return TRUE;
+}
 #define ELF_ARCH               bfd_arch_frv
 #define ELF_MACHINE_CODE       EM_CYGNUS_FRV
 #define ELF_MAXPAGESIZE                0x1000
@@ -6833,7 +6873,6 @@ frv_elf_print_private_bfd_data (abfd, ptr)
 #define elf_info_to_howto                      frv_info_to_howto_rela
 #define elf_backend_relocate_section           elf32_frv_relocate_section
 #define elf_backend_gc_mark_hook               elf32_frv_gc_mark_hook
-#define elf_backend_gc_sweep_hook              elf32_frv_gc_sweep_hook
 #define elf_backend_check_relocs                elf32_frv_check_relocs
 #define elf_backend_object_p                   elf32_frv_object_p
 #define elf_backend_add_symbol_hook             elf32_frv_add_symbol_hook
@@ -6857,6 +6896,9 @@ frv_elf_print_private_bfd_data (abfd, ptr)
 #define elf_backend_finish_dynamic_sections \
                elf32_frv_finish_dynamic_sections
 
+#define elf_backend_grok_prstatus      elf32_frv_grok_prstatus
+#define elf_backend_grok_psinfo                elf32_frv_grok_psinfo
+
 #include "elf32-target.h"
 
 #undef ELF_MAXPAGESIZE
@@ -6878,9 +6920,9 @@ frv_elf_print_private_bfd_data (abfd, ptr)
 #undef elf_backend_always_size_sections
 #define elf_backend_always_size_sections \
                elf32_frvfdpic_always_size_sections
-#undef elf_backend_modify_segment_map
-#define elf_backend_modify_segment_map \
-               elf32_frvfdpic_modify_segment_map
+#undef elf_backend_modify_program_headers
+#define elf_backend_modify_program_headers \
+               elf32_frvfdpic_modify_program_headers
 #undef bfd_elf32_bfd_copy_private_bfd_data
 #define bfd_elf32_bfd_copy_private_bfd_data \
                elf32_frvfdpic_copy_private_bfd_data
This page took 0.027304 seconds and 4 git commands to generate.