aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2004-01-22 17:03:45 +0000
committerAndrew Cagney <cagney@redhat.com>2004-01-22 17:03:45 +0000
commitf060829e7f4bc3b2a39325ecf91fde96b20ae76b (patch)
tree380d6c24dbcb8a8f89f52f08306e8bfe193416c3
parenta5dd37ab655106440e987830db5111b43f271ecc (diff)
downloadgdb-cagney_bigcore-20040122-branch.zip
gdb-cagney_bigcore-20040122-branch.tar.gz
gdb-cagney_bigcore-20040122-branch.tar.bz2
Index: bfd/ChangeLogcagney_bigcore-20040122-branch
2004-01-21 Andrew Cagney <cagney@redhat.com> * 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. * 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. * libbfd-in.h: Update copyright. (real_ftell, real_fseek): Declare. * libbfd.h: Re-generate. * elf.c (offset_vma_page_alignment): New function. (assign_file_positions_for_segments): Replace broken modulo code with offset_vma_page_alignment. (assign_file_positions_except_relocs): Ditto. Index: gdb/testsuite/ChangeLog 2004-01-22 Andrew Cagney <cagney@redhat.com> * gdb.base/bigcore.exp: New file. * gdb.base/bigcore.c: New file.
-rw-r--r--bfd/ChangeLog25
-rw-r--r--bfd/bfd-in.h18
-rw-r--r--bfd/bfd-in2.h18
-rw-r--r--bfd/bfdio.c40
-rw-r--r--bfd/cache.c12
-rw-r--r--bfd/config.in21
-rwxr-xr-xbfd/configure144
-rw-r--r--bfd/configure.in25
-rw-r--r--bfd/elf.c46
-rw-r--r--bfd/libbfd-in.h12
-rw-r--r--bfd/libbfd.h12
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/bigcore.c192
-rw-r--r--gdb/testsuite/gdb.base/bigcore.exp172
14 files changed, 682 insertions, 60 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c1c024c..f957dd2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,28 @@
+2004-01-21 Andrew Cagney <cagney@redhat.com>
+
+ * 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.
+ * 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.
+ * libbfd-in.h: Update copyright.
+ (real_ftell, real_fseek): Declare.
+ * libbfd.h: Re-generate.
+ * elf.c (offset_vma_page_alignment): New function.
+ (assign_file_positions_for_segments): Replace broken modulo code
+ with offset_vma_page_alignment.
+ (assign_file_positions_except_relocs): Ditto.
+
2004-01-21 Tom Rix <tcrix@worldnet.att.net>
* reloc.c: New 5 bit reloc, BFD_RELOC_M68HC12_5B, for m68hc12 movb/movw.
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index ccfef1e..30bc844 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -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 @@ typedef unsigned long bfd_size_type;
#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 void bfd_hash_traverse
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 *);
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index f66c29c..74bbccd 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -8,7 +8,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.
@@ -167,16 +167,10 @@ typedef unsigned long bfd_size_type;
#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);
@@ -463,7 +457,7 @@ extern void bfd_hash_traverse
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 *);
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index b196a52..4ef94aa 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -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.
@@ -36,6 +38,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#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 +188,7 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
return nwrote;
}
-bfd_vma
+file_ptr
bfd_tell (bfd *abfd)
{
file_ptr ptr;
@@ -170,7 +196,7 @@ bfd_tell (bfd *abfd)
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 +243,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
{
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 +304,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
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 +333,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
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;
diff --git a/bfd/cache.c b/bfd/cache.c
index b309165..5ee9f10 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -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.
@@ -155,7 +157,7 @@ close_one (void)
return TRUE;
}
- kill->where = ftell ((FILE *) kill->iostream);
+ kill->where = real_ftell ((FILE *) kill->iostream);
return bfd_cache_delete (kill);
}
@@ -354,9 +356,9 @@ bfd_cache_lookup_worker (bfd *abfd)
{
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;
}
diff --git a/bfd/config.in b/bfd/config.in
index ab273c8..ef9eca4 100644
--- a/bfd/config.in
+++ b/bfd/config.in
@@ -61,6 +61,18 @@
/* Define if you have the fdopen function. */
#undef HAVE_FDOPEN
+/* Define if you have the fseeko function. */
+#undef HAVE_FSEEKO
+
+/* Define if you have the fseeko64 function. */
+#undef HAVE_FSEEKO64
+
+/* Define if you have the ftello function. */
+#undef HAVE_FTELLO
+
+/* Define if you have the ftello64 function. */
+#undef HAVE_FTELLO64
+
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
@@ -190,6 +202,12 @@
/* Define as 1 if you have gettext and don't want to use GNU gettext. */
#undef HAVE_GETTEXT
+/* The number of bytes in type long long */
+#undef SIZEOF_LONG_LONG
+
+/* The number of bytes in type long */
+#undef SIZEOF_LONG
+
/* Use b modifier when opening binary files? */
#undef USE_BINARY_FOPEN
@@ -262,6 +280,9 @@
/* Name of host specific header file to include in trad-core.c. */
#undef TRAD_HEADER
+/* The number of bytes in type off_t */
+#undef SIZEOF_OFF_T
+
/* Use mmap if it's available? */
#undef USE_MMAP
diff --git a/bfd/configure b/bfd/configure
index 5704aef..22d246d 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -6619,6 +6619,124 @@ esac
+# 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.
+for ac_func in ftello ftello64 fseeko fseeko64
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:6631: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 6636 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $ac_func(); below. */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error. */
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char $ac_func();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+$ac_func();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:6659: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=yes"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+
+else
+ echo "$ac_t""no" 1>&6
+fi
+done
+
+echo $ac_n "checking file_ptr type""... $ac_c" 1>&6
+echo "configure:6684: checking file_ptr type" >&5
+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
+ echo $ac_n "checking size of off_t""... $ac_c" 1>&6
+echo "configure:6689: checking size of off_t" >&5
+if eval "test \"`echo '$''{'ac_cv_sizeof_off_t'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ for ac_size in 4 8 1 2 16 12 ; do # List sizes in rough order of prevalence.
+ cat > conftest.$ac_ext <<EOF
+#line 6695 "configure"
+#include "confdefs.h"
+#include "confdefs.h"
+#include <sys/types.h>
+
+
+int main() {
+switch (0) case 0: case (sizeof (off_t) == $ac_size):;
+; return 0; }
+EOF
+if { (eval echo configure:6705: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+ rm -rf conftest*
+ ac_cv_sizeof_off_t=$ac_size
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+fi
+rm -f conftest*
+ if test x$ac_cv_sizeof_off_t != x ; then break; fi
+done
+
+fi
+
+if test x$ac_cv_sizeof_off_t = x ; then
+ { echo "configure: error: cannot determine a size for off_t" 1>&2; exit 1; }
+fi
+echo "$ac_t""$ac_cv_sizeof_off_t" 1>&6
+cat >> confdefs.h <<EOF
+#define SIZEOF_OFF_T $ac_cv_sizeof_off_t
+EOF
+
+
+ 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
+echo "$ac_t""$bfd_file_ptr" 1>&6
+
+
+
+
tdefaults=""
test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"
@@ -6631,17 +6749,17 @@ for ac_hdr in unistd.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:6635: checking for $ac_hdr" >&5
+echo "configure:6753: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6640 "configure"
+#line 6758 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:6645: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:6763: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
@@ -6670,12 +6788,12 @@ done
for ac_func in getpagesize
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:6674: checking for $ac_func" >&5
+echo "configure:6792: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6679 "configure"
+#line 6797 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -6698,7 +6816,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:6702: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:6820: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@@ -6723,7 +6841,7 @@ fi
done
echo $ac_n "checking for working mmap""... $ac_c" 1>&6
-echo "configure:6727: checking for working mmap" >&5
+echo "configure:6845: checking for working mmap" >&5
if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -6731,7 +6849,7 @@ else
ac_cv_func_mmap_fixed_mapped=no
else
cat > conftest.$ac_ext <<EOF
-#line 6735 "configure"
+#line 6853 "configure"
#include "confdefs.h"
/* Thanks to Mike Haertel and Jim Avera for this test.
@@ -6871,7 +6989,7 @@ main()
}
EOF
-if { (eval echo configure:6875: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:6993: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_mmap_fixed_mapped=yes
else
@@ -6896,12 +7014,12 @@ fi
for ac_func in madvise mprotect
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:6900: checking for $ac_func" >&5
+echo "configure:7018: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 6905 "configure"
+#line 7023 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -6924,7 +7042,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:6928: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:7046: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@@ -7174,6 +7292,8 @@ s%@all_backends@%$all_backends%g
s%@bfd_backends@%$bfd_backends%g
s%@bfd_machines@%$bfd_machines%g
s%@bfd_default_target_size@%$bfd_default_target_size%g
+s%@bfd_file_ptr@%$bfd_file_ptr%g
+s%@bfd_ufile_ptr@%$bfd_ufile_ptr%g
s%@tdefaults@%$tdefaults%g
CEOF
diff --git a/bfd/configure.in b/bfd/configure.in
index 760bfe3..72f4580 100644
--- a/bfd/configure.in
+++ b/bfd/configure.in
@@ -917,6 +917,31 @@ AC_SUBST(bfd_backends)
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}'"
diff --git a/bfd/elf.c b/bfd/elf.c
index cd107bd..7999bf3 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3571,6 +3571,34 @@ elf_sort_sections (const void *arg1, const void *arg2)
return sec1->target_index - sec2->target_index;
}
+/* Ian Lance Taylor writes:
+
+ We shouldn't be using % with a negative signed number. That's just
+ not good. We have to make sure either that the number is not
+ negative, or that the number has an unsigned type. When the types
+ are all the same size they wind up as unsigned. When file_ptr is a
+ larger signed type, the arithmetic winds up as signed long long,
+ which is wrong.
+
+ What we're trying to say here is something like ``increase OFF by
+ the least amount that will cause it to be equal to the VMA modulo
+ the page size.'' */
+/* In other words, something like:
+
+ vma_offset = m->sections[0]->vma % bed->maxpagesize;
+ off_offset = off % bed->maxpagesize;
+ if (vma_offset < off_offset)
+ adjustment = vma_offset + bed->maxpagesize - off_offset;
+ else
+ adjustment = vma_offset - off_offset;
+
+ this can be colapsed into the expression below. */
+static file_ptr
+offset_vma_page_adjustment (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
+{
+ return ((vma - off) % maxpagesize);
+}
+
/* Assign file positions to the sections based on the mapping from
sections to segments. This function also sets up some fields in
the file header, and writes out the program headers. */
@@ -3698,7 +3726,8 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
&& (m->sections[0]->flags & SEC_ALLOC) != 0)
{
if ((abfd->flags & D_PAGED) != 0)
- off += (m->sections[0]->vma - off) % bed->maxpagesize;
+ off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+ bed->maxpagesize);
else
{
bfd_size_type align;
@@ -3713,7 +3742,8 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
align = secalign;
}
- off += (m->sections[0]->vma - off) % (1 << align);
+ off += offset_vma_page_adjustment (m->sections[0]->vma, off,
+ 1 << align);
}
}
@@ -3875,9 +3905,11 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info)
not have the SEC_LOAD case just above, and then
this was necessary, but now I'm not sure. */
if ((abfd->flags & D_PAGED) != 0)
- adjust = (sec->vma - voff) % bed->maxpagesize;
+ adjust = offset_vma_page_adjustment (sec->vma, voff,
+ bed->maxpagesize);
else
- adjust = (sec->vma - voff) % align;
+ adjust = offset_vma_page_adjustment (sec->vma, voff,
+ align);
}
else
adjust = 0;
@@ -4211,9 +4243,11 @@ assign_file_positions_except_relocs (bfd *abfd,
? "*unknown*"
: hdr->bfd_section->name)));
if ((abfd->flags & D_PAGED) != 0)
- off += (hdr->sh_addr - off) % bed->maxpagesize;
+ off += offset_vma_page_adjustment (hdr->sh_addr, off,
+ bed->maxpagesize);
else
- off += (hdr->sh_addr - off) % hdr->sh_addralign;
+ off += offset_vma_page_adjustment (hdr->sh_addr, off,
+ hdr->sh_addralign);
off = _bfd_elf_assign_file_position_for_section (hdr, off,
FALSE);
}
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index 0ec808d..10cafef 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -1,8 +1,9 @@
/* libbfd.h -- Declarations used by bfd library *implementation*.
(This include file is not for users of the library.)
- 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.
@@ -594,6 +595,11 @@ extern void _bfd_abort
#undef abort
#define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
+/* Manipulate a system FILE but using BFD's "file_ptr", rather than
+ the system "off_t" or "off64_t", as the offset. */
+extern file_ptr real_ftell (FILE *file);
+extern int real_fseek (FILE *file, file_ptr offset, int whence);
+
FILE * bfd_cache_lookup_worker
(bfd *);
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 40e1b78..62043f3 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -5,9 +5,10 @@
/* libbfd.h -- Declarations used by bfd library *implementation*.
(This include file is not for users of the library.)
- 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.
@@ -599,6 +600,11 @@ extern void _bfd_abort
#undef abort
#define abort() _bfd_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
+/* Manipulate a system FILE but using BFD's "file_ptr", rather than
+ the system "off_t" or "off64_t", as the offset. */
+extern file_ptr real_ftell (FILE *file);
+extern int real_fseek (FILE *file, file_ptr offset, int whence);
+
FILE * bfd_cache_lookup_worker
(bfd *);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1501073..0ff0490 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-01-22 Andrew Cagney <cagney@redhat.com>
+
+ * gdb.base/bigcore.exp: New file.
+ * gdb.base/bigcore.c: New file.
+
2004-01-20 Nick Roberts <nick@nick.uklinux.net>
* gdb.mi/mi-stack.exp (test_stack_locals_listing): Test for
diff --git a/gdb/testsuite/gdb.base/bigcore.c b/gdb/testsuite/gdb.base/bigcore.c
new file mode 100644
index 0000000..d6a6ef4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bigcore.c
@@ -0,0 +1,192 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2004 Free Software Foundation, Inc.
+
+ 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.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+
+/* Print routines:
+
+ The following are so that printf et.al. can be avoided. Those
+ might try to use malloc() and that, for this code, would be a
+ disaster. */
+
+#define printf do not use
+
+const char digit[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+static void
+print_char (char c)
+{
+ write (1, &c, sizeof (c));
+}
+
+static void
+print_unsigned (unsigned long u)
+{
+ if (u >= 10)
+ print_unsigned (u / 10);
+ print_char (digit[u % 10]);
+}
+
+static void
+print_hex (unsigned long u)
+{
+ if (u >= 16)
+ print_hex (u / 16);
+ print_char (digit[u % 16]);
+}
+
+static void
+print_string (const char *s)
+{
+ for (; (*s) != '\0'; s++)
+ print_char ((*s));
+}
+
+static void
+print_address (const void *a)
+{
+ print_string ("0x");
+ print_hex ((unsigned long) a);
+}
+
+/* Print the current values of RESOURCE. */
+
+static void
+print_rlimit (int resource)
+{
+ struct rlimit rl;
+ getrlimit (resource, &rl);
+ print_string ("cur=0x");
+ print_hex (rl.rlim_cur);
+ print_string (" max=0x");
+ print_hex (rl.rlim_max);
+}
+
+static void
+maximize_rlimit (int resource, const char *prefix)
+{
+ struct rlimit rl;
+ print_string (" ");
+ print_string (prefix);
+ print_string (": ");
+ print_rlimit (resource);
+ getrlimit (resource, &rl);
+ rl.rlim_cur = rl.rlim_max;
+ setrlimit (resource, &rl);
+ print_string (" -> ");
+ print_rlimit (resource);
+ print_string ("\n");
+}
+
+struct list
+{
+ struct list *next;
+ size_t size;
+};
+
+/* Put the "heap" pointer in the BSS section. That way it is more
+ likely that the variable will occur early in the core file (an
+ address before the heap) and hence more likely that GDB will at
+ least get its value right. */
+
+static struct list *heap;
+static struct list *stack;
+
+int
+main ()
+{
+ size_t max_chunk_size;
+
+ /* Try to expand all the resource limits beyond the point of sanity
+ - we're after the biggest possible core file. */
+
+ print_string ("Maximize resource limits ...\n");
+#ifdef RLIMIT_CORE
+ maximize_rlimit (RLIMIT_CORE, "core");
+#endif
+#ifdef RLIMIT_DATA
+ maximize_rlimit (RLIMIT_DATA, "data");
+#endif
+#ifdef RLIMIT_STACK
+ maximize_rlimit (RLIMIT_STACK, "stack");
+#endif
+#ifdef RLIMIT_AS
+ maximize_rlimit (RLIMIT_AS, "stack");
+#endif
+
+ /* Compute an initial chunk size. The math is dodgy but it works
+ for the moment. Perhaphs there's a constant around somewhere. */
+ {
+ size_t tmp;
+ for (tmp = 1; tmp > 0; tmp <<= 1)
+ max_chunk_size = tmp;
+ }
+
+ /* Allocate as much memory as possible creating a linked list of
+ each section. The linking ensures that some, but not all, the
+ memory is allocated. NB: Some kernels handle this efficiently -
+ only allocating and writing out referenced pages leaving holes in
+ the file for unreferend pages - while others handle this poorly -
+ writing out all pages including those that wern't referenced. */
+
+ print_string ("Alocating the entire heap ...\n");
+ {
+ /* Create a linked list of memory chunks. Start with
+ MAX_CHUNK_SIZE blocks of memory and then try allocating smaller
+ and smaller amounts until all (well at least most) memory has
+ been allocated. */
+ size_t chunk_size = max_chunk_size;
+ heap = NULL;
+ while (chunk_size >= sizeof (struct list))
+ {
+ while (1)
+ {
+ struct list *chunk = malloc (chunk_size);
+ if (chunk == NULL)
+ {
+ if (heap != NULL && heap->size == chunk_size)
+ print_string ("\n");
+ break;
+ }
+ if (heap == NULL || heap->size != chunk_size)
+ {
+ print_string (" ");
+ print_unsigned (chunk_size);
+ print_string (" bytes @ ");
+ }
+ else
+ print_string (", ");
+ chunk->size = chunk_size;
+ chunk->next = heap;
+ print_address (chunk);
+ heap = chunk;
+ }
+ chunk_size >>= 1;
+ }
+ }
+
+ /* Push everything out to disk. */
+
+ print_string ("Dump core ....\n");
+ *(char*)0 = 0;
+}
diff --git a/gdb/testsuite/gdb.base/bigcore.exp b/gdb/testsuite/gdb.base/bigcore.exp
new file mode 100644
index 0000000..82b01b3
--- /dev/null
+++ b/gdb/testsuite/gdb.base/bigcore.exp
@@ -0,0 +1,172 @@
+# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
+# Free Software Foundation, Inc.
+
+# 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.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file is based on corefile.exp which was written by Fred
+# Fish. (fnf@cygnus.com)
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# are we on a target board
+if ![isnative] then {
+ return
+}
+
+set testfile "bigcore"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set corefile ${objdir}/${subdir}/${testfile}.corefile
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+# Create a core file named "TESTFILE.corefile" rather than just
+# "core", to avoid problems with sys admin types that like to
+# regularly prune all files named "core" from the system.
+
+# Some systems append "core" to the name of the program; others append
+# the name of the program to "core"; still others (like Linux, as of
+# May 2003) create cores named "core.PID". In the latter case, we
+# could have many core files lying around, and it may be difficult to
+# tell which one is ours, so let's run the program in a subdirectory.
+
+set found 0
+set coredir "${objdir}/${subdir}/coredir.[getpid]"
+file mkdir $coredir
+catch "system \"(cd ${coredir}; ${binfile}; true) >/dev/null 2>&1\""
+set names [glob -nocomplain -directory $coredir *core*]
+if {[llength $names] == 1} {
+ set file [file join $coredir [lindex $names 0]]
+ remote_exec build "mv $file $corefile"
+ set found 1
+}
+
+# Try to clean up after ourselves.
+remote_file build delete [file join $coredir coremmap.data]
+remote_exec build "rmdir $coredir"
+
+if { $found == 0 } {
+ warning "can't generate a core file - core tests suppressed - check ulimit -c"
+ return 0
+}
+
+# Run GDB on the bigcore program up-to where it will dump core.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+gdb_test "set print sevenbit-strings" "" \
+ "set print sevenbit-strings; ${testfile}"
+gdb_test "set width 0" "" \
+ "set width 0; ${testfile}"
+if { ![runto_main] } then {
+ gdb_suppress_tests;
+}
+set print_core_line [gdb_get_line_number "Dump core"]
+gdb_test "tbreak $print_core_line"
+gdb_test continue ".*print_string.*"
+gdb_test next ".*0 = 0.*"
+
+# Traverse bigcore's linked list, saving each chunk's address. I
+# don't know why but expect_out didn't work with gdb_test_multiple.
+
+set heap ""
+set test "extract heap"
+set lim 0
+send_gdb "print heap\n"
+gdb_expect {
+ -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
+ pass "$test"
+ }
+ -re " = \\(struct list \\*\\) (0x\[0-9a-f\]*).*$gdb_prompt $" {
+ set heap [concat $heap $expect_out(1,string)]
+ if { $lim > 100 } {
+ fail "$test (limit $lim exceeded)"
+ } else {
+ incr lim
+ send_gdb "print $.next\n"
+ exp_continue
+ }
+ }
+ -re ".*$gdb_prompt $" {
+ fail "$test (entry $lim)"
+ }
+ timeout {
+ fail "$test (timeout)"
+ }
+}
+
+# Now load up that core file
+
+set test "load corefile"
+gdb_test_multiple "core $corefile" "$test" {
+ -re "A program is being debugged already. Kill it. .y or n. " {
+ send_gdb "y\n"
+ exp_continue
+ }
+ -re "Core was generated by.*$gdb_prompt $" {
+ pass "$test"
+ }
+}
+
+# Finally, re-traverse bigcore's linked list, checking each chunk's
+# address against the executable. Don't use gdb_test_multiple as want
+# only one pass/fail.
+
+set test "check heap"
+set lim 0
+set ok 1
+send_gdb "print heap\n"
+while { $ok } {
+ gdb_expect {
+ -re " = \\(struct list \\*\\) 0x0.*$gdb_prompt $" {
+ set ok 0
+ if { $lim == [llength $heap] } {
+ pass "$test"
+ } else {
+ fail "$test (short list)"
+ }
+ }
+ -re " = \\(struct list \\*\\) [lindex $heap $lim].*$gdb_prompt $" {
+ incr lim
+ if { $lim > 100 } {
+ set ok 0
+ fail "$test (limit $lim exceeded)"
+ } else {
+ send_gdb "print \$.next\n"
+ }
+ }
+ -re ".*$gdb_prompt $" {
+ set ok 0
+ setup_kfail i*86-*-linux* gdb/1509
+ fail "$test (address [lindex $heap $lim])"
+ }
+ timeout {
+ set ok 0
+ fail "$test (timeout)"
+ }
+ }
+}