* configure.host: Change irix5 to irix[56]*.
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index ed9f1cf3ae7bc009743978bcf13a359aff207d74..f31bd3856695b7839aa841d1434e675884dfd028 100644 (file)
@@ -48,6 +48,9 @@ open_mapped_file PARAMS ((char *filename, long mtime, int mapped));
 static CORE_ADDR
 map_to_address PARAMS ((void));
 
+static PTR
+map_to_file PARAMS ((int));
+
 #endif  /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
 
 /* Externally visible variables that are owned by this module.
@@ -84,7 +87,7 @@ add_to_objfile_sections (abfd, asect, objfile_p_char)
   section.the_bfd_section = asect;
   section.addr = bfd_section_vma (abfd, asect);
   section.endaddr = section.addr + bfd_section_size (abfd, asect);
-  obstack_grow (&objfile->psymbol_obstack, &section, sizeof(section));
+  obstack_grow (&objfile->psymbol_obstack, (char *) &section, sizeof(section));
   objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1);
 }
 
@@ -144,11 +147,9 @@ allocate_objfile (abfd, mapped)
                           mapped);
     if (fd >= 0)
       {
-       CORE_ADDR mapto;
        PTR md;
 
-       if (((mapto = map_to_address ()) == 0) ||
-           ((md = mmalloc_attach (fd, (PTR) mapto)) == NULL))
+       if ((md = map_to_file (fd)) == NULL)
          {
            close (fd);
          }
@@ -870,6 +871,50 @@ map_to_address ()
 
 }
 
+static PTR
+map_to_file (fd)
+     int fd;
+{
+  PTR md;
+  CORE_ADDR mapto;
+  int tempfd;
+
+  md = mmalloc_attach (fd, (PTR) 0);
+  if (md != NULL)
+    {
+      mapto = (CORE_ADDR) mmalloc_getkey (md, 1);
+      md = mmalloc_detach (md);
+      if (md != NULL)
+       {
+         /* FIXME: should figure out why detach failed */
+         md = NULL;
+       }
+      else if (mapto != (CORE_ADDR) NULL)
+       {
+         /* This mapping file needs to be remapped at "mapto" */
+         md = mmalloc_attach (fd, (PTR) mapto);
+       }
+      else
+       {
+         /* This is a freshly created mapping file. */
+         mapto = (CORE_ADDR) mmalloc_findbase (20 * 1024 * 1024);
+         if (mapto != 0)
+           {
+             /* To avoid reusing the freshly created mapping file, at the 
+                address selected by mmap, we must truncate it before trying
+                to do an attach at the address we want. */
+             ftruncate (fd, 0);
+             md = mmalloc_attach (fd, (PTR) mapto);
+             if (md != NULL)
+               {
+                 mmalloc_setkey (md, 1, (PTR) mapto);
+               }
+           }
+       }
+    }
+  return (md);
+}
+
 #endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
 
 /* Returns a section whose range includes PC or NULL if none found. */
This page took 0.033242 seconds and 4 git commands to generate.