This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] Simplify strings.c largefile support
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: binutils at sourceware dot org
- Cc: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 9 Nov 2009 15:11:30 +0100
- Subject: [patch] Simplify strings.c largefile support
Hi,
There was a patch:
[PATCH] Handle > 2GB objects in strings, speed it up
http://sourceware.org/ml/binutils/2001-10/msg00499.html
http://sourceware.org/ml/binutils/2001-12/msg00012.html
d96acc247496e56d1e1ac255021ddc5e7c590206
+
[PATCH] Fix strings to work with > 2GB files again on 32-bit arches
http://sourceware.org/ml/binutils/2004-10/msg00167.html
ee0ac24f01dd3bf3cc2aa2a91a9ae8c7f876fca1
It was a special largefile support only for strings.c:
Jakub Jelinek wrote:
# (I didn't want to use largefile.m4 because I don't think any program
# in binutils but strings need to be LFS in the near future).
As AC_SYS_LARGEFILE is already present in binutils/:
[patch] Include AC_SYS_LARGEFILE everywhere
http://sourceware.org/ml/binutils/2008-08/msg00003.html
061401df0e7435ac2407cad01e14b9023182c249
+
http://sourceware.org/bugzilla/show_bug.cgi?id=9992
12f8b90b34ae3c21ad3a8a10545523a28a7e7f26
The special largefile support became redundant now. It would be useful on
systems supporting _LARGEFILE64_SOURCE but not _FILE_OFFSET_BITS == 64.
I do not think such systems exists.
Tested on {x86_64,i686}-fedora12-linux-gnu. Tested various disabled parts to
verify >4GB file is still processed by strings (unless one removes both the
_LARGEFILE64_SOURCE and AC_SYS_LARGEFILE support).
This patch should have no effect on any functionality and it is just
a cleanup.
Diff of the the generated parts is at:
http://people.redhat.com/jkratoch/largefile/simplify-generated.patch
Thanks,
Jan
binutils/
2009-11-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* configure.in: Stop checking for fopen64 and stat64.
* strings.c (file_off, file_open, statbuf, file_stat): Remove.
(strings_file): Change file_off to file_ptr, file_open to fopen,
statbuf to struct stat and file_stat to stat.
(get_char): Change parameter type file_off * to file_ptr *.
(print_strings): Change parameter and variable `start' type file_off to
file_ptr.
* configure: Regenerate.
* config.in: Regenerate.
--- a/binutils/configure.in
+++ b/binutils/configure.in
@@ -106,45 +89,6 @@ AC_CHECK_FUNC([mkdtemp],
AC_DEFINE([HAVE_MKDTEMP], 1,
[Define to 1 if you have the `mkdtemp' function.]))
-# Check whether fopen64 is available and whether _LARGEFILE64_SOURCE
-# needs to be defined for it
-AC_MSG_CHECKING([for fopen64])
-AC_CACHE_VAL(bu_cv_have_fopen64,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [FILE *f = fopen64 ("/tmp/foo","r");])],
-bu_cv_have_fopen64=yes,
-[saved_CPPFLAGS=$CPPFLAGS
- CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [FILE *f = fopen64 ("/tmp/foo","r");])],
- bu_cv_have_fopen64="need -D_LARGEFILE64_SOURCE",
- bu_cv_have_fopen64=no)
- CPPFLAGS=$saved_CPPFLAGS])])
-AC_MSG_RESULT($bu_cv_have_fopen64)
-if test "$bu_cv_have_fopen64" != no; then
- AC_DEFINE([HAVE_FOPEN64], 1,
- [Is fopen64 available?])
-fi
-AC_MSG_CHECKING([for stat64])
-AC_CACHE_VAL(bu_cv_have_stat64,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <sys/stat.h>], [struct stat64 st; stat64 ("/tmp/foo", &st);])],
-bu_cv_have_stat64=yes,
-[saved_CPPFLAGS=$CPPFLAGS
- CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <sys/stat.h>], [struct stat64 st; stat64 ("/tmp/foo", &st);])],
- bu_cv_have_stat64="need -D_LARGEFILE64_SOURCE",
- bu_cv_have_stat64=no)
- CPPFLAGS=$saved_CPPFLAGS])])
-AC_MSG_RESULT($bu_cv_have_stat64)
-if test "$bu_cv_have_stat64" != no; then
- AC_DEFINE([HAVE_STAT64], 1,
- [Is stat64 available?])
-fi
-if test "$bu_cv_have_fopen64" = "need -D_LARGEFILE64_SOURCE" \
- || test "$bu_cv_have_stat64" = "need -D_LARGEFILE64_SOURCE"; then
- AC_DEFINE([_LARGEFILE64_SOURCE], 1,
- [Enable LFS])
- CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
-fi
-
# Some systems have frexp only in -lm, not in -lc.
AC_SEARCH_LIBS(frexp, m)
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -80,21 +80,6 @@ extern int errno;
/* The BFD section flags that identify an initialized data section. */
#define DATA_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS)
-#ifdef HAVE_FOPEN64
-typedef off64_t file_off;
-#define file_open(s,m) fopen64(s, m)
-#else
-typedef off_t file_off;
-#define file_open(s,m) fopen(s, m)
-#endif
-#ifdef HAVE_STAT64
-typedef struct stat64 statbuf;
-#define file_stat(f,s) stat64(f, s)
-#else
-typedef struct stat statbuf;
-#define file_stat(f,s) stat(f, s)
-#endif
-
/* Radix for printing addresses (must be 8, 10 or 16). */
static int address_radix;
@@ -145,9 +130,9 @@ typedef struct
static void strings_a_section (bfd *, asection *, void *);
static bfd_boolean strings_object_file (const char *);
static bfd_boolean strings_file (char *file);
-static void print_strings (const char *, FILE *, file_off, int, int, char *);
+static void print_strings (const char *, FILE *, file_ptr, int, int, char *);
static void usage (FILE *, int);
-static long get_char (FILE *, file_off *, int *, char **);
+static long get_char (FILE *, file_ptr *, int *, char **);
int main (int, char **);
@@ -414,9 +399,11 @@ strings_object_file (const char *file)
static bfd_boolean
strings_file (char *file)
{
- statbuf st;
+ struct stat st;
+
+ /* get_file_size does not support non-S_ISREG files. */
- if (file_stat (file, &st) < 0)
+ if (stat (file, &st) < 0)
{
if (errno == ENOENT)
non_fatal (_("'%s': No such file"), file);
@@ -434,7 +421,7 @@ strings_file (char *file)
{
FILE *stream;
- stream = file_open (file, FOPEN_RB);
+ stream = fopen (file, FOPEN_RB);
if (stream == NULL)
{
fprintf (stderr, "%s: ", program_name);
@@ -442,7 +429,7 @@ strings_file (char *file)
return FALSE;
}
- print_strings (file, stream, (file_off) 0, 0, 0, (char *) 0);
+ print_strings (file, stream, (file_ptr) 0, 0, 0, (char *) 0);
if (fclose (stream) == EOF)
{
@@ -466,7 +453,7 @@ strings_file (char *file)
MAGICCOUNT is how many characters are in it. */
static long
-get_char (FILE *stream, file_off *address, int *magiccount, char **magic)
+get_char (FILE *stream, file_ptr *address, int *magiccount, char **magic)
{
int c, i;
long r = EOF;
@@ -542,14 +529,14 @@ get_char (FILE *stream, file_off *address, int *magiccount, char **magic)
Those characters come at address ADDRESS and the data in STREAM follow. */
static void
-print_strings (const char *filename, FILE *stream, file_off address,
+print_strings (const char *filename, FILE *stream, file_ptr address,
int stop_point, int magiccount, char *magic)
{
char *buf = (char *) xmalloc (sizeof (char) * (string_min + 1));
while (1)
{
- file_off start;
+ file_ptr start;
int i;
long c;