This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Large corefile support; Was: [wip]


Hello,

Here's todays version. It now uses autoconf magic to hard-wire the underlying type of file_ptr. I've used the heuristic:

if fseeko64 && ftello64
	there must be off64_t
	make file_ptr 64-bit
else if fseeko && ftello
	there must be off_t >= sizeof long
	make file_ptr 64-bit (if off_t is 8) or long otherwize
else
	make file_ptr long
fi

I've called the internal functions "real_fseek" and "real_fread" (to match real_read). The header "bfdio.h" makes them available to "cache.c".

My bigcore GDB testcase (along with the rest of the GDB testsuite look ok). Need to double check the binutils testsuite.

After that, ok?
Andrew
2004-01-19  Andrew Cagney  <cagney@redhat.com>

	* bfd-in.h: Update copyright.
	(file_ptr, ufile_ptr): Specify type using @BFD_FILE_PTR@.
	(bfd_tell): Make return-type "file_ptr".
	* bfd-in2.h: Re-generate.
	* configure.in (AC_CHECK_FUNCS): Check for ftello, ftello64,
	fseeko and fseeko64.
	* config.in, configure: Re-generate.
	* bfdio.h: New file.
	* bfdio.c: Update copyright.  Include "bfdio.h".
	(real_ftell, real_fseek): New functions.
	(bfd_tell): Use real_ftell, change return-type to file_ptr.
	(bfd_seek): Use real_ftell and real_fseek.  Change type of
	file_position to a file_ptr.
	* cache.c: Update copyright.  Include "bfdio.h".
	(close_one): Use real_ftell.
	(bfd_cache_lookup_worker): Use real_fseek, use ufile_ptr in cast.

Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.70
diff -u -r1.70 bfd-in.h
--- bfd-in.h	24 Nov 2003 18:06:39 -0000	1.70
+++ bfd-in.h	20 Jan 2004 00:30:15 -0000
@@ -1,7 +1,7 @@
 /* Main header file for the bfd library -- portable access to object files.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -160,16 +160,10 @@
 
 #endif /* not BFD64  */
 
-/* A pointer to a position in a file.  */
-/* FIXME:  This should be using off_t from <sys/types.h>.
-   For now, try to avoid breaking stuff by not including <sys/types.h> here.
-   This will break on systems with 64-bit file offsets (e.g. 4.4BSD).
-   Probably the best long-term answer is to avoid using file_ptr AND off_t
-   in this header file, and to handle this in the BFD implementation
-   rather than in its interface.  */
-/* typedef off_t	file_ptr; */
-typedef bfd_signed_vma file_ptr;
-typedef bfd_vma ufile_ptr;
+/* An offset into a file.  BFD always uses the largest possible offset
+   based on the build time availability of fseek, fseeko, or fseeko64.  */
+typedef @bfd_file_ptr@ file_ptr;
+typedef unsigned @bfd_file_ptr@ ufile_ptr;
 
 extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
 extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
@@ -456,7 +450,7 @@
 extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
 extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
 extern int bfd_seek (bfd *, file_ptr, int);
-extern ufile_ptr bfd_tell (bfd *);
+extern file_ptr bfd_tell (bfd *);
 extern int bfd_flush (bfd *);
 extern int bfd_stat (bfd *, struct stat *);
 
Index: bfdio.c
===================================================================
RCS file: /cvs/src/src/bfd/bfdio.c,v
retrieving revision 1.4
diff -u -r1.4 bfdio.c
--- bfdio.c	24 Nov 2003 18:06:39 -0000	1.4
+++ bfdio.c	20 Jan 2004 00:30:15 -0000
@@ -1,6 +1,8 @@
 /* Low-level I/O routines for BFDs.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -24,6 +26,8 @@
 #include "bfd.h"
 #include "libbfd.h"
 
+#include "bfdio.h"
+
 #include <limits.h>
 
 #ifndef S_IXUSR
@@ -36,6 +40,30 @@
 #define S_IXOTH 0001    /* Execute by others.  */
 #endif
 
+file_ptr
+real_ftell (FILE *file)
+{
+#if defined (HAVE_FTELLO64)
+  return ftello64 (file);
+#elif defined (HAVE_FTELLO)
+  return ftello (file);
+#else
+  return ftell (file);
+#endif
+}
+
+int
+real_fseek (FILE *file, file_ptr offset, int whence)
+{
+#if defined (HAVE_FTELLO64)
+  return fseeko64 (file, offset, whence);
+#elif defined (HAVE_FTELLO)
+  return fseeko (file, offset, whence);
+#else
+  return fseek (file, offset, whence);
+#endif
+}
+
 /* Note that archive entries don't have streams; they share their parent's.
    This allows someone to play with the iostream behind BFD's back.
 
@@ -162,7 +190,7 @@
   return nwrote;
 }
 
-bfd_vma
+file_ptr
 bfd_tell (bfd *abfd)
 {
   file_ptr ptr;
@@ -170,7 +198,7 @@
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     return abfd->where;
 
-  ptr = ftell (bfd_cache_lookup (abfd));
+  ptr = real_ftell (bfd_cache_lookup (abfd));
 
   if (abfd->my_archive)
     ptr -= abfd->origin;
@@ -217,7 +245,7 @@
 {
   int result;
   FILE *f;
-  long file_position;
+  file_ptr file_position;
   /* For the time being, a BFD may not seek to it's end.  The problem
      is that we don't easily have a way to recognize the end of an
      element in an archive.  */
@@ -278,7 +306,7 @@
 	 tripping the abort, we can probably safely disable this code,
 	 so that the real optimizations happen.  */
       file_ptr where_am_i_now;
-      where_am_i_now = ftell (bfd_cache_lookup (abfd));
+      where_am_i_now = real_ftell (bfd_cache_lookup (abfd));
       if (abfd->my_archive)
 	where_am_i_now -= abfd->origin;
       if (where_am_i_now != abfd->where)
@@ -307,7 +335,7 @@
   if (direction == SEEK_SET && abfd->my_archive != NULL)
     file_position += abfd->origin;
 
-  result = fseek (f, file_position, direction);
+  result = real_fseek (f, file_position, direction);
   if (result != 0)
     {
       int hold_errno = errno;
Index: bfdio.h
===================================================================
RCS file: bfdio.h
diff -N bfdio.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bfdio.h	20 Jan 2004 00:30:15 -0000
@@ -0,0 +1,32 @@
+/* Low-level I/O routines for BFDs.
+
+   Copyright 2004 Free Software Foundation, Inc.
+
+   This file is part of BFD, the Binary File Descriptor library.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
+
+#ifndef BFDIO_H
+#define BFDIO_H
+
+/* Internal only routines for manipulating a system FILE but using
+   BFD's "file_ptr", rather than the system "off_t" or "off64_t", for
+   offsets.  */
+
+extern file_ptr real_ftell (FILE *file);
+extern int real_fseek (FILE *file, file_ptr offset, int whence);
+
+#endif
Index: cache.c
===================================================================
RCS file: /cvs/src/src/bfd/cache.c,v
retrieving revision 1.10
diff -u -r1.10 cache.c
--- cache.c	29 Jun 2003 10:06:39 -0000	1.10
+++ cache.c	20 Jan 2004 00:30:15 -0000
@@ -1,6 +1,8 @@
 /* BFD library -- caching of file descriptors.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+
+   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002,
+   2003, 2004 Free Software Foundation, Inc.
+
    Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -39,6 +41,7 @@
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
+#include "bfdio.h"
 
 static bfd_boolean bfd_cache_delete (bfd *);
 
@@ -155,7 +158,7 @@
       return TRUE;
     }
 
-  kill->where = ftell ((FILE *) kill->iostream);
+  kill->where = real_ftell ((FILE *) kill->iostream);
 
   return bfd_cache_delete (kill);
 }
@@ -354,9 +357,9 @@
     {
       if (bfd_open_file (abfd) == NULL)
 	return NULL;
-      if (abfd->where != (unsigned long) abfd->where)
+      if (abfd->where != (ufile_ptr) abfd->where)
 	return NULL;
-      if (fseek ((FILE *) abfd->iostream, (long) abfd->where, SEEK_SET) != 0)
+      if (real_fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
 	return NULL;
     }
 
Index: configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.142
diff -u -r1.142 configure.in
--- configure.in	19 Dec 2003 11:43:53 -0000	1.142
+++ configure.in	20 Jan 2004 00:30:16 -0000
@@ -917,6 +917,31 @@
 AC_SUBST(bfd_machines)
 AC_SUBST(bfd_default_target_size)
 
+# Determine the host dependant file_ptr a.k.a. off_t type.  In order
+# prefer: off64_t - if ftello64 and fseeko64, off_t - if ftello and
+# fseeko, long.  This assumes that sizeof off_t is .ge. sizeof long.
+# Hopefully a reasonable assumption since fseeko et.al. should be
+# upward compatible.
+AC_CHECK_FUNCS(ftello ftello64 fseeko fseeko64)
+AC_MSG_CHECKING([file_ptr type])
+bfd_file_ptr="long"
+bfd_ufile_ptr="unsigned long"
+if test x"$ac_cv_func_ftello" = xyes -a x"$ac_cv_func_fseeko" = xyes; then
+    AC_COMPILE_CHECK_SIZEOF(off_t)
+    if test "x${ac_cv_sizeof_off_t}" = "x8"; then
+	bfd_file_ptr=BFD_HOST_64_BIT
+	bfd_ufile_ptr=BFD_HOST_U_64_BIT
+    fi
+fi
+if test x"$ac_cv_func_ftello64" = xyes -a x"$ac_cv_func_fseeko64" = xyes; then
+    bfd_file_ptr=BFD_HOST_64_BIT
+    bfd_ufile_ptr=BFD_HOST_U_64_BIT
+fi
+AC_MSG_RESULT($bfd_file_ptr)
+AC_SUBST(bfd_file_ptr)
+AC_SUBST(bfd_ufile_ptr)
+
+
 tdefaults=""
 test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
 test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]