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]

Re: strings and offsets >2G


On Tue, Oct 23, 2001 at 11:19:19AM +0200, Michal Svec wrote:
> Due to the limitation of file_ptr to long, the current implementation of
> strings doesn't support offsets larger than 2GB.
> 
> It can be somehow easily fixed at least for the simple case when scanning
> the whole file by replacing "file_ptr" type (long) with "long long" (see
> attached patch).
> 
> I know it's not very portable and someone may surely find a better (and
> complete) solution, but a partial fix is better then nothing.

Your patch really is not very portable, plus it will work with
cat 8gbfile | strings -t x
but not with
strings -t x 8gbfile

Here is a patch I'm using, which still needs some portability stuff IMHO,
particularly there should be largefile.m4 autoconf testing so that
_FILE_OFFSET_BITS 64 is not defined blindly, plus perhaps 
replacing all defined(__GNUC__) && __GNUC__ >= 2 with
(__STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2))
getc_unlocked speeds it by about 50% btw.

2001-10-11  Jakub Jelinek  <jakub@redhat.com>

	* strings.c (_FILE_OFFSET_BITS, BFD64): Define.
	(get_char): Use getc_unlocked if available.
	(print_strings): If possible print even offsets which don't fit into
	hosts unsigned long.
	* configure.in: Check for getc_unlocked.
	* configure: Rebuilt.
	* config.h.in: Rebuilt.

--- binutils/strings.c.jj	Tue Sep 25 20:27:13 2001
+++ binutils/strings.c	Thu Oct 11 17:32:26 2001
@@ -56,6 +56,11 @@
    Written by Richard Stallman <rms@gnu.ai.mit.edu>
    and David MacKenzie <djm@gnu.ai.mit.edu>.  */
 
+#define _FILE_OFFSET_BITS 64
+#if defined(__GNUC__) && __GNUC__ >= 2
+# define BFD64
+#endif
+
 #include "bfd.h"
 #include <stdio.h>
 #include <getopt.h>
@@ -427,7 +432,11 @@ get_char (stream, address, magiccount, m
 	{
 	  if (stream == NULL)
 	    return EOF;
+#ifdef HAVE_GETC_UNLOCKED
+	  c = getc_unlocked (stream);
+#else
 	  c = getc (stream);
+#endif
 	  if (c == EOF)
 	    return EOF;
 	}
@@ -517,15 +526,42 @@ print_strings (filename, stream, address
 	switch (address_radix)
 	  {
 	  case 8:
-	    printf ("%7lo ", (unsigned long) start);
+#if defined(__GNUC__) && __GNUC__ >= 2
+	    if (sizeof (start) > sizeof (long))
+	      printf ("%7Lo ", (unsigned long long) start);
+	    else
+#else
+# if !BFD_HOST_64BIT_LONG
+	    if (_bfd_int64_high (start))
+	      printf ("++%7lo ", (unsigned long) start);
+	    else
+# endif
+#endif
+	      printf ("%7lo ", (unsigned long) start);
 	    break;
 
 	  case 10:
-	    printf ("%7ld ", (long) start);
+#if defined(__GNUC__) && __GNUC__ >= 2
+	    if (sizeof (start) > sizeof (long))
+	      printf ("%7Ld ", (unsigned long long) start);
+	    else
+#else
+# if !BFD_HOST_64BIT_LONG
+	    if (_bfd_int64_high (start))
+	      printf ("++%7ld ", (unsigned long) start);
+	    else
+# endif
+#endif
+	      printf ("%7ld ", (long) start);
 	    break;
 
 	  case 16:
-	    printf ("%7lx ", (unsigned long) start);
+#if !BFD_HOST_64BIT_LONG
+	    if (_bfd_int64_high (start))
+	      printf ("%lx%8.8lx ", _bfd_int64_high (start), _bfd_int64_low (start));
+	    else
+#endif
+	      printf ("%7lx ", (unsigned long) start);
 	    break;
 	  }
 
--- binutils/configure.in.jj	Mon Aug 13 13:05:31 2001
+++ binutils/configure.in	Wed Oct 10 22:48:14 2001
@@ -100,7 +100,7 @@ AC_SUBST(DEMANGLER_NAME)
 AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h fcntl.h sys/file.h)
 AC_HEADER_SYS_WAIT
 AC_FUNC_ALLOCA
-AC_CHECK_FUNCS(sbrk utimes setmode)
+AC_CHECK_FUNCS(sbrk utimes setmode getc_unlocked)
 
 # Some systems have frexp only in -lm, not in -lc.
 AC_SEARCH_LIBS(frexp, m)
--- binutils/configure.jj	Fri Oct  5 13:03:01 2001
+++ binutils/configure	Wed Oct 10 22:48:27 2001
@@ -4897,7 +4897,7 @@ EOF
 
 fi
 
-for ac_func in sbrk utimes setmode
+for ac_func in sbrk utimes setmode getc_unlocked
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:4904: checking for $ac_func" >&5
--- binutils/config.in.jj	Tue Dec 19 23:22:02 2000
+++ binutils/config.in	Wed Oct 10 22:49:13 2001
@@ -82,6 +82,9 @@
 /* Define if you have the setmode function.  */
 #undef HAVE_SETMODE
 
+/* Define if you have the getc_unlocked function.  */
+#undef HAVE_GETC_UNLOCKED
+
 /* Define if you have the stpcpy function.  */
 #undef HAVE_STPCPY
 


	Jakub


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