* libxcoff.h (struct xcoff_backend_data_rec): Constify src param
[binutils-gdb.git] / bfd / elf.c
index 5b2114fb0c3556a7638a1e3b8398bba568117e7f..b06417c5e1dfe46733c800644b1bb5e2923ee20d 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -57,10 +57,16 @@ static INLINE int sym_is_global PARAMS ((bfd *, asymbol *));
 static boolean elf_map_symbols PARAMS ((bfd *));
 static bfd_size_type get_program_header_size PARAMS ((bfd *));
 static boolean elfcore_read_notes PARAMS ((bfd *, bfd_vma, bfd_vma));
-static boolean elf_find_function PARAMS ((bfd *, asection *,
-                                         asymbol **,
-                                         bfd_vma, const char **,
-                                         const char **));
+static boolean elf_find_function PARAMS ((bfd *, asection *, asymbol **,
+                                         bfd_vma, const char **,
+                                         const char **));
+static int elfcore_make_pid PARAMS ((bfd *));
+static boolean elfcore_maybe_make_sect PARAMS ((bfd *, char *, asection *));
+static boolean elfcore_make_note_pseudosection PARAMS ((bfd *, char *,
+                                                       Elf_Internal_Note *));
+static boolean elfcore_grok_prfpreg PARAMS ((bfd *, Elf_Internal_Note *));
+static boolean elfcore_grok_prxfpreg PARAMS ((bfd *, Elf_Internal_Note *));
+static boolean elfcore_grok_note PARAMS ((bfd *, Elf_Internal_Note *));
 
 /* Swap version information in and out.  The version information is
    currently size independent.  If that ever changes, this code will
@@ -2677,18 +2683,22 @@ elf_sort_sections (arg1, arg2)
   if (TOEND (sec1))
     {
       if (TOEND (sec2))
-       return sec1->target_index - sec2->target_index;
+       {
+         /* If the indicies are the same, do not return 0
+            here, but continue to try the next comparison.  */
+         if (sec1->target_index - sec2->target_index != 0)
+           return sec1->target_index - sec2->target_index;
+       }
       else
        return 1;
     }
-
-  if (TOEND (sec2))
+  else if (TOEND (sec2))
     return -1;
 
 #undef TOEND
 
-  /* Sort by size, to put zero sized sections before others at the
-     same address.  */
+  /* Sort by size, to put zero sized sections
+     before others at the same address.  */
 
   if (sec1->_raw_size < sec2->_raw_size)
     return -1;
@@ -5410,10 +5420,7 @@ _bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
   sect->flags = SEC_HAS_CONTENTS;
   sect->alignment_power = 2;
 
-  if (! elfcore_maybe_make_sect (abfd, name, sect))
-    return false;
-
-  return true;
+  return elfcore_maybe_make_sect (abfd, name, sect);
 }
 
 /* prstatus_t exists on:
@@ -5423,6 +5430,8 @@ _bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
 */
 
 #if defined (HAVE_PRSTATUS_T)
+static boolean elfcore_grok_prstatus PARAMS ((bfd *, Elf_Internal_Note *));
+
 static boolean
 elfcore_grok_prstatus (abfd, note)
      bfd *abfd;
@@ -5484,11 +5493,8 @@ elfcore_grok_prstatus (abfd, note)
     }
 
   /* Make a ".reg/999" section and a ".reg" section.  */
-  if (! _bfd_elfcore_make_pseudosection (abfd, ".reg",
-                                        raw_size, note->descpos + offset));
-    return false;
-
-  return true;
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+                                         raw_size, note->descpos + offset);
 }
 #endif /* defined (HAVE_PRSTATUS_T) */
 
@@ -5499,7 +5505,8 @@ elfcore_make_note_pseudosection (abfd, name, note)
      char *name;
      Elf_Internal_Note *note;
 {
-  return _bfd_elfcore_make_pseudosection (abfd, name, note->descsz, note->descpos);
+  return _bfd_elfcore_make_pseudosection (abfd, name,
+                                         note->descsz, note->descpos);
 }
 
 /* There isn't a consistent prfpregset_t across platforms,
@@ -5544,7 +5551,7 @@ typedef psinfo32_t elfcore_psinfo32_t;
    most MAX bytes long, possibly without a terminating '\0'.
    the copy will always have a terminating '\0'.  */
 
-char*
+char *
 _bfd_elfcore_strndup (abfd, start, max)
      bfd *abfd;
      char *start;
@@ -5570,6 +5577,7 @@ _bfd_elfcore_strndup (abfd, start, max)
 }
 
 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
+static boolean elfcore_grok_psinfo PARAMS ((bfd *, Elf_Internal_Note *));
 
 static boolean
 elfcore_grok_psinfo (abfd, note)
@@ -5583,10 +5591,12 @@ elfcore_grok_psinfo (abfd, note)
       memcpy (&psinfo, note->descdata, sizeof (psinfo));
 
       elf_tdata (abfd)->core_program
-       = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
+       = _bfd_elfcore_strndup (abfd, psinfo.pr_fname,
+                               sizeof (psinfo.pr_fname));
 
       elf_tdata (abfd)->core_command
-       = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
+       = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs,
+                               sizeof (psinfo.pr_psargs));
     }
 #if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
   else if (note->descsz == sizeof (elfcore_psinfo32_t))
@@ -5597,10 +5607,12 @@ elfcore_grok_psinfo (abfd, note)
       memcpy (&psinfo, note->descdata, sizeof (psinfo));
 
       elf_tdata (abfd)->core_program
-       = _bfd_elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
+       = _bfd_elfcore_strndup (abfd, psinfo.pr_fname,
+                               sizeof (psinfo.pr_fname));
 
       elf_tdata (abfd)->core_command
-       = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
+       = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs,
+                               sizeof (psinfo.pr_psargs));
     }
 #endif
 
@@ -5742,10 +5754,7 @@ elfcore_grok_lwpstatus (abfd, note)
   sect->flags = SEC_HAS_CONTENTS;
   sect->alignment_power = 2;
 
-  if (!elfcore_maybe_make_sect (abfd, ".reg2", sect))
-    return false;
-
-  return true;
+  return elfcore_maybe_make_sect (abfd, ".reg2", sect);
 }
 #endif /* defined (HAVE_LWPSTATUS_T) */
 
@@ -5938,21 +5947,6 @@ elfcore_read_notes (abfd, offset, size)
   free (buf);
   return true;
 }
-
-/* FIXME: This function is now unnecessary.  Callers can just call
-   bfd_section_from_phdr directly.  */
-
-boolean
-_bfd_elfcore_section_from_phdr (abfd, phdr, sec_num)
-     bfd *abfd;
-     Elf_Internal_Phdr* phdr;
-     int sec_num;
-{
-  if (! bfd_section_from_phdr (abfd, phdr, sec_num))
-    return false;
-
-  return true;
-}
 \f
 /* Providing external access to the ELF program header table.  */
 
@@ -5970,8 +5964,7 @@ bfd_get_elf_phdr_upper_bound (abfd)
       return -1;
     }
 
-  return (elf_elfheader (abfd)->e_phnum
-         * sizeof (Elf_Internal_Phdr));
+  return elf_elfheader (abfd)->e_phnum * sizeof (Elf_Internal_Phdr);
 }
 
 /* Copy ABFD's program header table entries to *PHDRS.  The entries
@@ -6001,3 +5994,62 @@ bfd_get_elf_phdrs (abfd, phdrs)
 
   return num_phdrs;
 }
+
+void
+bfd_elf_sprintf_vma (abfd, buf, value)
+     bfd *abfd;
+     char *buf;
+     bfd_vma value;
+{
+#ifdef BFD64
+  Elf_Internal_Ehdr *i_ehdrp;  /* Elf file header, internal form */
+
+  i_ehdrp = elf_elfheader (abfd);
+  if (i_ehdrp == NULL)
+    sprintf_vma (buf, value);
+  else
+    {
+      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
+#if BFD_HOST_64BIT_LONG
+       sprintf (buf, "%016lx", value);
+#else
+       sprintf (buf, "%08lx%08lx", _bfd_int64_high (value),
+                _bfd_int64_low (value));
+#endif
+      else
+       sprintf (buf, "%08lx", (unsigned long) (value & 0xffffffff));
+    }
+#else
+  sprintf_vma (buf, value);
+#endif
+}
+
+void
+bfd_elf_fprintf_vma (abfd, stream, value)
+     bfd *abfd;
+     PTR stream;
+     bfd_vma value;
+{
+#ifdef BFD64
+  Elf_Internal_Ehdr *i_ehdrp;  /* Elf file header, internal form */
+
+  i_ehdrp = elf_elfheader (abfd);
+  if (i_ehdrp == NULL)
+    fprintf_vma ((FILE *) stream, value);
+  else
+    {
+      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
+#if BFD_HOST_64BIT_LONG
+       fprintf ((FILE *) stream, "%016lx", value);
+#else
+       fprintf ((FILE *) stream, "%08lx%08lx",
+                _bfd_int64_high (value), _bfd_int64_low (value));
+#endif
+      else
+       fprintf ((FILE *) stream, "%08lx",
+                (unsigned long) (value & 0xffffffff));
+    }
+#else
+  fprintf_vma ((FILE *) stream, value);
+#endif
+}