summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/binutils
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/binutils/binutils')
-rw-r--r--contrib/binutils/binutils/nm.c347
-rw-r--r--contrib/binutils/binutils/strings.c181
2 files changed, 226 insertions, 302 deletions
diff --git a/contrib/binutils/binutils/nm.c b/contrib/binutils/binutils/nm.c
index b9689b1..bac7d38 100644
--- a/contrib/binutils/binutils/nm.c
+++ b/contrib/binutils/binutils/nm.c
@@ -1,6 +1,6 @@
/* nm.c -- Describe symbol table of a rel file.
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002
+ 2001, 2002, 2003
Free Software Foundation, Inc.
This file is part of GNU Binutils.
@@ -37,7 +37,7 @@
struct size_sym
{
- const PTR minisym;
+ const void *minisym;
bfd_vma size;
};
@@ -68,66 +68,69 @@ struct extended_symbol_info
#define SYM_SIZE(sym) \
(sym->elfinfo ? sym->elfinfo->internal_elf_sym.st_size: sym->ssize)
-static void usage PARAMS ((FILE *, int));
-static void set_print_radix PARAMS ((char *));
-static void set_output_format PARAMS ((char *));
-static void display_archive PARAMS ((bfd *));
-static boolean display_file PARAMS ((char *));
-static void display_rel_file PARAMS ((bfd *, bfd *));
-static long filter_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int));
-static long sort_symbols_by_size PARAMS ((bfd *, boolean, PTR, long, unsigned int, struct size_sym **));
-static void print_symbols PARAMS ((bfd *, boolean, PTR, long, unsigned int, bfd *));
-static void print_size_symbols PARAMS ((bfd *, boolean, struct size_sym *, long, bfd *));
-static void print_symname PARAMS ((const char *, const char *, bfd *));
-static void print_symbol PARAMS ((bfd *, asymbol *, bfd_vma ssize, bfd *));
-static void print_symdef_entry PARAMS ((bfd *));
+static void usage (FILE *, int);
+static void set_print_radix (char *);
+static void set_output_format (char *);
+static void display_archive (bfd *);
+static bfd_boolean display_file (char *);
+static void display_rel_file (bfd *, bfd *);
+static long filter_symbols (bfd *, bfd_boolean, void *, long, unsigned int);
+static long sort_symbols_by_size
+ (bfd *, bfd_boolean, void *, long, unsigned int, struct size_sym **);
+static void print_symbols
+ (bfd *, bfd_boolean, void *, long, unsigned int, bfd *);
+static void print_size_symbols
+ (bfd *, bfd_boolean, struct size_sym *, long, bfd *);
+static void print_symname (const char *, const char *, bfd *);
+static void print_symbol (bfd *, asymbol *, bfd_vma ssize, bfd *);
+static void print_symdef_entry (bfd *);
/* The sorting functions. */
-static int numeric_forward PARAMS ((const PTR, const PTR));
-static int numeric_reverse PARAMS ((const PTR, const PTR));
-static int non_numeric_forward PARAMS ((const PTR, const PTR));
-static int non_numeric_reverse PARAMS ((const PTR, const PTR));
-static int size_forward1 PARAMS ((const PTR, const PTR));
-static int size_forward2 PARAMS ((const PTR, const PTR));
+static int numeric_forward (const void *, const void *);
+static int numeric_reverse (const void *, const void *);
+static int non_numeric_forward (const void *, const void *);
+static int non_numeric_reverse (const void *, const void *);
+static int size_forward1 (const void *, const void *);
+static int size_forward2 (const void *, const void *);
/* The output formatting functions. */
-static void print_object_filename_bsd PARAMS ((char *));
-static void print_object_filename_sysv PARAMS ((char *));
-static void print_object_filename_posix PARAMS ((char *));
-static void print_archive_filename_bsd PARAMS ((char *));
-static void print_archive_filename_sysv PARAMS ((char *));
-static void print_archive_filename_posix PARAMS ((char *));
-static void print_archive_member_bsd PARAMS ((char *, const char *));
-static void print_archive_member_sysv PARAMS ((char *, const char *));
-static void print_archive_member_posix PARAMS ((char *, const char *));
-static void print_symbol_filename_bsd PARAMS ((bfd *, bfd *));
-static void print_symbol_filename_sysv PARAMS ((bfd *, bfd *));
-static void print_symbol_filename_posix PARAMS ((bfd *, bfd *));
-static void print_value PARAMS ((bfd *, bfd_vma));
-static void print_symbol_info_bsd PARAMS ((struct extended_symbol_info *, bfd *));
-static void print_symbol_info_sysv PARAMS ((struct extended_symbol_info *, bfd *));
-static void print_symbol_info_posix PARAMS ((struct extended_symbol_info *, bfd *));
-static void get_relocs PARAMS ((bfd *, asection *, PTR));
-static const char * get_symbol_type PARAMS ((unsigned int));
+static void print_object_filename_bsd (char *);
+static void print_object_filename_sysv (char *);
+static void print_object_filename_posix (char *);
+static void print_archive_filename_bsd (char *);
+static void print_archive_filename_sysv (char *);
+static void print_archive_filename_posix (char *);
+static void print_archive_member_bsd (char *, const char *);
+static void print_archive_member_sysv (char *, const char *);
+static void print_archive_member_posix (char *, const char *);
+static void print_symbol_filename_bsd (bfd *, bfd *);
+static void print_symbol_filename_sysv (bfd *, bfd *);
+static void print_symbol_filename_posix (bfd *, bfd *);
+static void print_value (bfd *, bfd_vma);
+static void print_symbol_info_bsd (struct extended_symbol_info *, bfd *);
+static void print_symbol_info_sysv (struct extended_symbol_info *, bfd *);
+static void print_symbol_info_posix (struct extended_symbol_info *, bfd *);
+static void get_relocs (bfd *, asection *, void *);
+static const char * get_symbol_type (unsigned int);
/* Support for different output formats. */
struct output_fns
{
/* Print the name of an object file given on the command line. */
- void (*print_object_filename) PARAMS ((char *));
+ void (*print_object_filename) (char *);
/* Print the name of an archive file given on the command line. */
- void (*print_archive_filename) PARAMS ((char *));
+ void (*print_archive_filename) (char *);
/* Print the name of an archive member file. */
- void (*print_archive_member) PARAMS ((char *, const char *));
+ void (*print_archive_member) (char *, const char *);
/* Print the name of the file (and archive, if there is one)
containing a symbol. */
- void (*print_symbol_filename) PARAMS ((bfd *, bfd *));
+ void (*print_symbol_filename) (bfd *, bfd *);
/* Print a line of information about a symbol. */
- void (*print_symbol_info) PARAMS ((struct extended_symbol_info *, bfd *));
+ void (*print_symbol_info) (struct extended_symbol_info *, bfd *);
};
static struct output_fns formats[] =
@@ -239,9 +242,7 @@ static struct option long_options[] =
/* Some error-reporting functions. */
static void
-usage (stream, status)
- FILE *stream;
- int status;
+usage (FILE *stream, int status)
{
fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
fprintf (stream, _(" List symbols in [file(s)] (a.out by default).\n"));
@@ -251,7 +252,8 @@ usage (stream, status)
-B Same as --format=bsd\n\
-C, --demangle[=STYLE] Decode low-level symbol names into user-level names\n\
The STYLE, if specified, can be `auto' (the default),\n\
- `gnu', 'lucid', 'arm', 'hp', 'edg' or 'gnu-new-abi'\n\
+ `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'\n\
+ or `gnat'\n\
--no-demangle Do not demangle low-level symbol names\n\
-D, --dynamic Display dynamic symbols instead of normal symbols\n\
--defined-only Display only defined symbols\n\
@@ -285,8 +287,7 @@ usage (stream, status)
/* Set the radix for the symbol value and size according to RADIX. */
static void
-set_print_radix (radix)
- char *radix;
+set_print_radix (char *radix)
{
switch (*radix)
{
@@ -316,8 +317,7 @@ set_print_radix (radix)
}
static void
-set_output_format (f)
- char *f;
+set_output_format (char *f)
{
int i;
@@ -341,12 +341,10 @@ set_output_format (f)
format = &formats[i];
}
-int main PARAMS ((int, char **));
+int main (int, char **);
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
int c;
int retval;
@@ -446,7 +444,7 @@ main (argc, argv)
break;
case 'X':
/* Ignored for (partial) AIX compatibility. On AIX, the
- argument has values 32, 64, or 32_64, and specfies that
+ argument has values 32, 64, or 32_64, and specifies that
only 32-bit, only 64-bit, or both kinds of objects should
be examined. The default is 32. So plain AIX nm on a
library archive with both kinds of objects will ignore
@@ -471,6 +469,13 @@ main (argc, argv)
if (show_version)
print_version ("nm");
+ if (sort_by_size && undefined_only)
+ {
+ non_fatal (_("Using the --size-sort and --undefined-only options together"));
+ non_fatal (_("will produce no output, since undefined symbols have no size."));
+ return 0;
+ }
+
/* OK, all options now parsed. If no filename specified, do a.out. */
if (optind == argc)
return !display_file ("a.out");
@@ -504,8 +509,7 @@ main (argc, argv)
}
static const char *
-get_symbol_type (type)
- unsigned int type;
+get_symbol_type (unsigned int type)
{
static char buff [32];
@@ -530,8 +534,7 @@ get_symbol_type (type)
}
static void
-display_archive (file)
- bfd *file;
+display_archive (bfd *file)
{
bfd *arfile = NULL;
bfd *last_arfile = NULL;
@@ -592,19 +595,21 @@ display_archive (file)
}
}
-static boolean
-display_file (filename)
- char *filename;
+static bfd_boolean
+display_file (char *filename)
{
- boolean retval = true;
+ bfd_boolean retval = TRUE;
bfd *file;
char **matching;
+ if (get_file_size (filename) < 1)
+ return FALSE;
+
file = bfd_openr (filename, target);
if (file == NULL)
{
bfd_nonfatal (filename);
- return false;
+ return FALSE;
}
if (bfd_check_format (file, bfd_archive))
@@ -628,10 +633,10 @@ display_file (filename)
list_matching_formats (matching);
free (matching);
}
- retval = false;
+ retval = FALSE;
}
- if (bfd_close (file) == false)
+ if (!bfd_close (file))
bfd_fatal (filename);
lineno_cache_bfd = NULL;
@@ -643,7 +648,7 @@ display_file (filename)
/* These globals are used to pass information into the sorting
routines. */
static bfd *sort_bfd;
-static boolean sort_dynamic;
+static bfd_boolean sort_dynamic;
static asymbol *sort_x;
static asymbol *sort_y;
@@ -655,9 +660,7 @@ static asymbol *sort_y;
specially -- i.e., their sizes are used as their "values". */
static int
-numeric_forward (P_x, P_y)
- const PTR P_x;
- const PTR P_y;
+numeric_forward (const void *P_x, const void *P_y)
{
asymbol *x, *y;
asection *xs, *ys;
@@ -684,17 +687,13 @@ numeric_forward (P_x, P_y)
}
static int
-numeric_reverse (x, y)
- const PTR x;
- const PTR y;
+numeric_reverse (const void *x, const void *y)
{
return - numeric_forward (x, y);
}
static int
-non_numeric_forward (P_x, P_y)
- const PTR P_x;
- const PTR P_y;
+non_numeric_forward (const void *P_x, const void *P_y)
{
asymbol *x, *y;
const char *xn, *yn;
@@ -727,14 +726,12 @@ non_numeric_forward (P_x, P_y)
}
static int
-non_numeric_reverse (x, y)
- const PTR x;
- const PTR y;
+non_numeric_reverse (const void *x, const void *y)
{
return - non_numeric_forward (x, y);
}
-static int (*(sorters[2][2])) PARAMS ((const PTR, const PTR)) =
+static int (*(sorters[2][2])) (const void *, const void *) =
{
{ non_numeric_forward, non_numeric_reverse },
{ numeric_forward, numeric_reverse }
@@ -752,9 +749,7 @@ static int (*(sorters[2][2])) PARAMS ((const PTR, const PTR)) =
value. */
static int
-size_forward1 (P_x, P_y)
- const PTR P_x;
- const PTR P_y;
+size_forward1 (const void *P_x, const void *P_y)
{
asymbol *x, *y;
asection *xs, *ys;
@@ -824,9 +819,7 @@ size_forward1 (P_x, P_y)
an array of size_sym structures into size order. */
static int
-size_forward2 (P_x, P_y)
- const PTR P_x;
- const PTR P_y;
+size_forward2 (const void *P_x, const void *P_y)
{
const struct size_sym *x = (const struct size_sym *) P_x;
const struct size_sym *y = (const struct size_sym *) P_y;
@@ -845,13 +838,9 @@ size_forward2 (P_x, P_y)
size. */
static long
-sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
- bfd *abfd;
- boolean dynamic;
- PTR minisyms;
- long symcount;
- unsigned int size;
- struct size_sym **symsizesp;
+sort_symbols_by_size (bfd *abfd, bfd_boolean dynamic, void *minisyms,
+ long symcount, unsigned int size,
+ struct size_sym **symsizesp)
{
struct size_sym *symsizes;
bfd_byte *from, *fromend;
@@ -876,7 +865,7 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
if (from < fromend)
{
- sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from,
+ sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const void *) from,
store_sym);
if (sym == NULL)
bfd_fatal (bfd_get_filename (abfd));
@@ -893,7 +882,7 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
{
next = bfd_minisymbol_to_symbol (abfd,
dynamic,
- (const PTR) (from + size),
+ (const void *) (from + size),
store_next);
if (next == NULL)
bfd_fatal (bfd_get_filename (abfd));
@@ -920,7 +909,7 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
if (sz != 0)
{
- symsizes->minisym = (const PTR) from;
+ symsizes->minisym = (const void *) from;
symsizes->size = sz;
++symsizes;
}
@@ -935,7 +924,7 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
symcount = symsizes - *symsizesp;
/* We must now sort again by size. */
- qsort ((PTR) *symsizesp, symcount, sizeof (struct size_sym), size_forward2);
+ qsort ((void *) *symsizesp, symcount, sizeof (struct size_sym), size_forward2);
return symcount;
}
@@ -943,12 +932,10 @@ sort_symbols_by_size (abfd, dynamic, minisyms, symcount, size, symsizesp)
/* If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. */
static void
-display_rel_file (abfd, archive_bfd)
- bfd *abfd;
- bfd *archive_bfd;
+display_rel_file (bfd *abfd, bfd *archive_bfd)
{
long symcount;
- PTR minisyms;
+ void *minisyms;
unsigned int size;
struct size_sym *symsizes;
@@ -1008,12 +995,8 @@ display_rel_file (abfd, archive_bfd)
Return the number of symbols to be printed. */
static long
-filter_symbols (abfd, dynamic, minisyms, symcount, size)
- bfd *abfd;
- boolean dynamic;
- PTR minisyms;
- long symcount;
- unsigned int size;
+filter_symbols (bfd *abfd, bfd_boolean dynamic, void *minisyms,
+ long symcount, unsigned int size)
{
bfd_byte *from, *fromend, *to;
asymbol *store;
@@ -1033,7 +1016,7 @@ filter_symbols (abfd, dynamic, minisyms, symcount, size)
PROGRESS (1);
- sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const PTR) from, store);
+ sym = bfd_minisymbol_to_symbol (abfd, dynamic, (const void *) from, store);
if (sym == NULL)
bfd_fatal (bfd_get_filename (abfd));
@@ -1079,10 +1062,7 @@ filter_symbols (abfd, dynamic, minisyms, symcount, size)
demangling it if requested. */
static void
-print_symname (format, name, abfd)
- const char *format;
- const char *name;
- bfd *abfd;
+print_symname (const char *format, const char *name, bfd *abfd)
{
if (do_demangle && *name)
{
@@ -1100,13 +1080,8 @@ print_symname (format, name, abfd)
containing ABFD. */
static void
-print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd)
- bfd *abfd;
- boolean dynamic;
- PTR minisyms;
- long symcount;
- unsigned int size;
- bfd *archive_bfd;
+print_symbols (bfd *abfd, bfd_boolean dynamic, void *minisyms, long symcount,
+ unsigned int size, bfd *archive_bfd)
{
asymbol *store;
bfd_byte *from, *fromend;
@@ -1132,12 +1107,9 @@ print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd)
/* Print the symbols when sorting by size. */
static void
-print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
- bfd *abfd;
- boolean dynamic;
- struct size_sym *symsizes;
- long symcount;
- bfd *archive_bfd;
+print_size_symbols (bfd *abfd, bfd_boolean dynamic,
+ struct size_sym *symsizes, long symcount,
+ bfd *archive_bfd)
{
asymbol *store;
struct size_sym *from, *fromend;
@@ -1170,35 +1142,23 @@ print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd)
/* Print a single symbol. */
static void
-print_symbol (abfd, sym, ssize, archive_bfd)
- bfd *abfd;
- asymbol *sym;
- bfd_vma ssize;
- bfd *archive_bfd;
+print_symbol (bfd *abfd, asymbol *sym, bfd_vma ssize, bfd *archive_bfd)
{
+ symbol_info syminfo;
+ struct extended_symbol_info info;
+
PROGRESS (1);
(*format->print_symbol_filename) (archive_bfd, abfd);
- if (undefined_only)
- {
- if (bfd_is_und_section (bfd_get_section (sym)))
- print_symname ("%s", bfd_asymbol_name (sym), abfd);
- }
+ bfd_get_symbol_info (abfd, sym, &syminfo);
+ info.sinfo = &syminfo;
+ info.ssize = ssize;
+ if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+ info.elfinfo = (elf_symbol_type *) sym;
else
- {
- symbol_info syminfo;
- struct extended_symbol_info info;
-
- bfd_get_symbol_info (abfd, sym, &syminfo);
- info.sinfo = &syminfo;
- info.ssize = ssize;
- if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
- info.elfinfo = (elf_symbol_type *) sym;
- else
- info.elfinfo = NULL;
- (*format->print_symbol_info) (&info, abfd);
- }
+ info.elfinfo = NULL;
+ (*format->print_symbol_info) (&info, abfd);
if (line_numbers)
{
@@ -1267,7 +1227,7 @@ print_symbol (abfd, sym, ssize, archive_bfd)
info.relocs = relocs;
info.relcount = relcount;
info.syms = syms;
- bfd_map_over_sections (abfd, get_relocs, (PTR) &info);
+ bfd_map_over_sections (abfd, get_relocs, (void *) &info);
lineno_cache_rel_bfd = abfd;
}
@@ -1324,16 +1284,14 @@ print_symbol (abfd, sym, ssize, archive_bfd)
/* Print the name of an object file given on the command line. */
static void
-print_object_filename_bsd (filename)
- char *filename;
+print_object_filename_bsd (char *filename)
{
if (filename_per_file && !filename_per_symbol)
printf ("\n%s:\n", filename);
}
static void
-print_object_filename_sysv (filename)
- char *filename;
+print_object_filename_sysv (char *filename)
{
if (undefined_only)
printf (_("\n\nUndefined symbols from %s:\n\n"), filename);
@@ -1348,8 +1306,7 @@ Name Value Class Type Size
}
static void
-print_object_filename_posix (filename)
- char *filename;
+print_object_filename_posix (char *filename)
{
if (filename_per_file && !filename_per_symbol)
printf ("%s:\n", filename);
@@ -1358,40 +1315,34 @@ print_object_filename_posix (filename)
/* Print the name of an archive file given on the command line. */
static void
-print_archive_filename_bsd (filename)
- char *filename;
+print_archive_filename_bsd (char *filename)
{
if (filename_per_file)
printf ("\n%s:\n", filename);
}
static void
-print_archive_filename_sysv (filename)
- char *filename ATTRIBUTE_UNUSED;
+print_archive_filename_sysv (char *filename ATTRIBUTE_UNUSED)
{
}
static void
-print_archive_filename_posix (filename)
- char *filename ATTRIBUTE_UNUSED;
+print_archive_filename_posix (char *filename ATTRIBUTE_UNUSED)
{
}
/* Print the name of an archive member file. */
static void
-print_archive_member_bsd (archive, filename)
- char *archive ATTRIBUTE_UNUSED;
- const char *filename;
+print_archive_member_bsd (char *archive ATTRIBUTE_UNUSED,
+ const char *filename)
{
if (!filename_per_symbol)
printf ("\n%s:\n", filename);
}
static void
-print_archive_member_sysv (archive, filename)
- char *archive;
- const char *filename;
+print_archive_member_sysv (char *archive, const char *filename)
{
if (undefined_only)
printf (_("\n\nUndefined symbols from %s[%s]:\n\n"), archive, filename);
@@ -1406,9 +1357,7 @@ Name Value Class Type Size
}
static void
-print_archive_member_posix (archive, filename)
- char *archive;
- const char *filename;
+print_archive_member_posix (char *archive, const char *filename)
{
if (!filename_per_symbol)
printf ("%s[%s]:\n", archive, filename);
@@ -1418,8 +1367,7 @@ print_archive_member_posix (archive, filename)
containing a symbol. */
static void
-print_symbol_filename_bsd (archive_bfd, abfd)
- bfd *archive_bfd, *abfd;
+print_symbol_filename_bsd (bfd *archive_bfd, bfd *abfd)
{
if (filename_per_symbol)
{
@@ -1430,8 +1378,7 @@ print_symbol_filename_bsd (archive_bfd, abfd)
}
static void
-print_symbol_filename_sysv (archive_bfd, abfd)
- bfd *archive_bfd, *abfd;
+print_symbol_filename_sysv (bfd *archive_bfd, bfd *abfd)
{
if (filename_per_symbol)
{
@@ -1442,8 +1389,7 @@ print_symbol_filename_sysv (archive_bfd, abfd)
}
static void
-print_symbol_filename_posix (archive_bfd, abfd)
- bfd *archive_bfd, *abfd;
+print_symbol_filename_posix (bfd *archive_bfd, bfd *abfd)
{
if (filename_per_symbol)
{
@@ -1458,9 +1404,7 @@ print_symbol_filename_posix (archive_bfd, abfd)
/* Print a symbol value. */
static void
-print_value (abfd, val)
- bfd *abfd ATTRIBUTE_UNUSED;
- bfd_vma val;
+print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val)
{
#if ! defined (BFD64) || BFD_HOST_64BIT_LONG
printf (value_format, val);
@@ -1490,9 +1434,7 @@ print_value (abfd, val)
/* Print a line of information about a symbol. */
static void
-print_symbol_info_bsd (info, abfd)
- struct extended_symbol_info *info;
- bfd *abfd;
+print_symbol_info_bsd (struct extended_symbol_info *info, bfd *abfd)
{
if (bfd_is_undefined_symclass (SYM_TYPE (info)))
{
@@ -1502,11 +1444,18 @@ print_symbol_info_bsd (info, abfd)
}
else
{
- print_value (abfd, SYM_VALUE (info));
+ /* Normally we print the value of the symbol. If we are printing the
+ size or sorting by size then we print its size, except for the
+ (weird) special case where both flags are defined, in which case we
+ print both values. This conforms to documented behaviour. */
+ if (sort_by_size && !print_size)
+ print_value (abfd, SYM_SIZE (info));
+ else
+ print_value (abfd, SYM_VALUE (info));
if (print_size && SYM_SIZE (info))
{
- printf(" ");
+ printf (" ");
print_value (abfd, SYM_SIZE (info));
}
}
@@ -1526,9 +1475,7 @@ print_symbol_info_bsd (info, abfd)
}
static void
-print_symbol_info_sysv (info, abfd)
- struct extended_symbol_info *info;
- bfd *abfd;
+print_symbol_info_sysv (struct extended_symbol_info *info, bfd *abfd)
{
print_symname ("%-20s|", SYM_NAME (info), abfd);
@@ -1547,9 +1494,9 @@ print_symbol_info_sysv (info, abfd)
if (SYM_TYPE (info) == '-')
{
/* A stab. */
- printf ("%18s| ", SYM_STAB_NAME (info)); /* (C) Type */
- printf (desc_format, SYM_STAB_DESC (info)); /* Size */
- printf ("| |"); /* Line, Section */
+ printf ("%18s| ", SYM_STAB_NAME (info)); /* (C) Type. */
+ printf (desc_format, SYM_STAB_DESC (info)); /* Size. */
+ printf ("| |"); /* Line, Section. */
}
else
{
@@ -1578,9 +1525,7 @@ print_symbol_info_sysv (info, abfd)
}
static void
-print_symbol_info_posix (info, abfd)
- struct extended_symbol_info *info;
- bfd *abfd;
+print_symbol_info_posix (struct extended_symbol_info *info, bfd *abfd)
{
print_symname ("%s ", SYM_NAME (info), abfd);
printf ("%c ", SYM_TYPE (info));
@@ -1597,12 +1542,11 @@ print_symbol_info_posix (info, abfd)
}
static void
-print_symdef_entry (abfd)
- bfd *abfd;
+print_symdef_entry (bfd *abfd)
{
symindex idx = BFD_NO_MORE_SYMBOLS;
carsym *thesym;
- boolean everprinted = false;
+ bfd_boolean everprinted = FALSE;
for (idx = bfd_get_next_mapent (abfd, idx, &thesym);
idx != BFD_NO_MORE_SYMBOLS;
@@ -1612,7 +1556,7 @@ print_symdef_entry (abfd)
if (!everprinted)
{
printf (_("\nArchive index:\n"));
- everprinted = true;
+ everprinted = TRUE;
}
elt = bfd_get_elt_at_index (abfd, idx);
if (elt == NULL)
@@ -1629,10 +1573,7 @@ print_symdef_entry (abfd)
It is called via bfd_map_over_sections. */
static void
-get_relocs (abfd, sec, dataarg)
- bfd *abfd;
- asection *sec;
- PTR dataarg;
+get_relocs (bfd *abfd, asection *sec, void *dataarg)
{
struct get_relocs_info *data = (struct get_relocs_info *) dataarg;
diff --git a/contrib/binutils/binutils/strings.c b/contrib/binutils/binutils/strings.c
index dade244..68c244c 100644
--- a/contrib/binutils/binutils/strings.c
+++ b/contrib/binutils/binutils/strings.c
@@ -1,6 +1,6 @@
/* strings -- print the strings of printable characters in files
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002 Free Software Foundation, Inc.
+ 2002, 2003 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
@@ -39,10 +39,11 @@
-o Like -to. (Some other implementations have -o like -to,
others like -td. We chose one arbitrarily.)
- --encoding={s,b,l,B,L}
- -e {s,b,l,B,L}
- Select character encoding: single-byte, bigendian 16-bit,
- littleendian 16-bit, bigendian 32-bit, littleendian 32-bit
+ --encoding={s,S,b,l,B,L}
+ -e {s,S,b,l,B,L}
+ Select character encoding: 7-bit-character, 8-bit-character,
+ bigendian 16-bit, littleendian 16-bit, bigendian 32-bit,
+ littleendian 32-bit.
--target=BFDNAME
Specify a non-default object file format.
@@ -80,11 +81,14 @@
#endif
#if O_BINARY
#include <io.h>
-#define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0)
+#define SET_BINARY(f) do { if (!isatty (f)) setmode (f,O_BINARY); } while (0)
#endif
#endif
-#define isgraphic(c) (ISPRINT (c) || (c) == '\t')
+#define STRING_ISGRAPHIC(c) \
+ ( (c) >= 0 \
+ && (c) <= 255 \
+ && ((c) == '\t' || ISPRINT (c) || (encoding == 'S' && (c) > 127)))
#ifndef errno
extern int errno;
@@ -95,10 +99,10 @@ extern int errno;
#ifdef HAVE_FOPEN64
typedef off64_t file_off;
-#define file_open(s,m) fopen64(s,m)
+#define file_open(s,m) fopen64(s, m)
#else
typedef off_t file_off;
-#define file_open(s,m) fopen(s,m)
+#define file_open(s,m) fopen(s, m)
#endif
/* Radix for printing addresses (must be 8, 10 or 16). */
@@ -107,17 +111,17 @@ static int address_radix;
/* Minimum length of sequence of graphic chars to trigger output. */
static int string_min;
-/* true means print address within file for each string. */
-static boolean print_addresses;
+/* TRUE means print address within file for each string. */
+static bfd_boolean print_addresses;
-/* true means print filename for each string. */
-static boolean print_filenames;
+/* TRUE means print filename for each string. */
+static bfd_boolean print_filenames;
-/* true means for object files scan only the data section. */
-static boolean datasection_only;
+/* TRUE means for object files scan only the data section. */
+static bfd_boolean datasection_only;
-/* true if we found an initialized data section in the current file. */
-static boolean got_a_section;
+/* TRUE if we found an initialized data section in the current file. */
+static bfd_boolean got_a_section;
/* The BFD object file format. */
static char *target;
@@ -139,27 +143,22 @@ static struct option long_options[] =
{NULL, 0, NULL, 0}
};
-static void strings_a_section PARAMS ((bfd *, asection *, PTR));
-static boolean strings_object_file PARAMS ((const char *));
-static boolean strings_file PARAMS ((char *file));
-static int integer_arg PARAMS ((char *s));
-static void print_strings PARAMS ((const char *filename, FILE *stream,
- file_off address, int stop_point,
- int magiccount, char *magic));
-static void usage PARAMS ((FILE *stream, int status));
-static long get_char PARAMS ((FILE *stream, file_off *address,
- int *magiccount, char **magic));
+static void strings_a_section (bfd *, asection *, void *);
+static bfd_boolean strings_object_file (const char *);
+static bfd_boolean strings_file (char *file);
+static int integer_arg (char *s);
+static void print_strings (const char *, FILE *, file_off, int, int, char *);
+static void usage (FILE *, int);
+static long get_char (FILE *, file_off *, int *, char **);
-int main PARAMS ((int, char **));
+int main (int, char **);
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
int optc;
int exit_status = 0;
- boolean files_given = false;
+ bfd_boolean files_given = FALSE;
#if defined (HAVE_SETLOCALE)
setlocale (LC_ALL, "");
@@ -170,9 +169,9 @@ main (argc, argv)
program_name = argv[0];
xmalloc_set_program_name (program_name);
string_min = -1;
- print_addresses = false;
- print_filenames = false;
- datasection_only = true;
+ print_addresses = FALSE;
+ print_filenames = FALSE;
+ datasection_only = TRUE;
target = NULL;
encoding = 's';
@@ -182,11 +181,11 @@ main (argc, argv)
switch (optc)
{
case 'a':
- datasection_only = false;
+ datasection_only = FALSE;
break;
case 'f':
- print_filenames = true;
+ print_filenames = TRUE;
break;
case 'H':
@@ -196,18 +195,16 @@ main (argc, argv)
case 'n':
string_min = integer_arg (optarg);
if (string_min < 1)
- {
- fatal (_("invalid number %s"), optarg);
- }
+ fatal (_("invalid number %s"), optarg);
break;
case 'o':
- print_addresses = true;
+ print_addresses = TRUE;
address_radix = 8;
break;
case 't':
- print_addresses = true;
+ print_addresses = TRUE;
if (optarg[1] != '\0')
usage (stderr, 1);
switch (optarg[0])
@@ -261,6 +258,7 @@ main (argc, argv)
switch (encoding)
{
+ case 'S':
case 's':
encoding_bytes = 1;
break;
@@ -281,28 +279,28 @@ main (argc, argv)
if (optind >= argc)
{
- datasection_only = false;
+ datasection_only = FALSE;
#ifdef SET_BINARY
SET_BINARY (fileno (stdin));
#endif
print_strings ("{standard input}", stdin, 0, 0, 0, (char *) NULL);
- files_given = true;
+ files_given = TRUE;
}
else
{
for (; optind < argc; ++optind)
{
if (strcmp (argv[optind], "-") == 0)
- datasection_only = false;
+ datasection_only = FALSE;
else
{
- files_given = true;
- exit_status |= (strings_file (argv[optind]) == false);
+ files_given = TRUE;
+ exit_status |= strings_file (argv[optind]) == FALSE;
}
}
}
- if (files_given == false)
+ if (!files_given)
usage (stderr, 1);
return (exit_status);
@@ -313,20 +311,18 @@ main (argc, argv)
set `got_a_section' and print the strings in it. */
static void
-strings_a_section (abfd, sect, filearg)
- bfd *abfd;
- asection *sect;
- PTR filearg;
+strings_a_section (bfd *abfd, asection *sect, void *filearg)
{
const char *file = (const char *) filearg;
if ((sect->flags & DATA_FLAGS) == DATA_FLAGS)
{
bfd_size_type sz = bfd_get_section_size_before_reloc (sect);
- PTR mem = xmalloc (sz);
+ void *mem = xmalloc (sz);
+
if (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sz))
{
- got_a_section = true;
+ got_a_section = TRUE;
print_strings (file, (FILE *) NULL, sect->filepos, 0, sz, mem);
}
free (mem);
@@ -336,48 +332,47 @@ strings_a_section (abfd, sect, filearg)
/* Scan all of the sections in FILE, and print the strings
in the initialized data section(s).
- Return true if successful,
- false if not (such as if FILE is not an object file). */
+ Return TRUE if successful,
+ FALSE if not (such as if FILE is not an object file). */
-static boolean
-strings_object_file (file)
- const char *file;
+static bfd_boolean
+strings_object_file (const char *file)
{
bfd *abfd = bfd_openr (file, target);
if (abfd == NULL)
- {
- /* Treat the file as a non-object file. */
- return false;
- }
+ /* Treat the file as a non-object file. */
+ return FALSE;
/* This call is mainly for its side effect of reading in the sections.
We follow the traditional behavior of `strings' in that we don't
complain if we don't recognize a file to be an object file. */
- if (bfd_check_format (abfd, bfd_object) == false)
+ if (!bfd_check_format (abfd, bfd_object))
{
bfd_close (abfd);
- return false;
+ return FALSE;
}
- got_a_section = false;
- bfd_map_over_sections (abfd, strings_a_section, (PTR) file);
+ got_a_section = FALSE;
+ bfd_map_over_sections (abfd, strings_a_section, (void *) file);
if (!bfd_close (abfd))
{
bfd_nonfatal (file);
- return false;
+ return FALSE;
}
return got_a_section;
}
-/* Print the strings in FILE. Return true if ok, false if an error occurs. */
+/* Print the strings in FILE. Return TRUE if ok, FALSE if an error occurs. */
-static boolean
-strings_file (file)
- char *file;
+static bfd_boolean
+strings_file (char *file)
{
+ if (get_file_size (file) < 1)
+ return FALSE;
+
/* If we weren't told to scan the whole file,
try to open it as an object file and only look at
initialized data sections. If that fails, fall back to the
@@ -391,7 +386,7 @@ strings_file (file)
{
fprintf (stderr, "%s: ", program_name);
perror (file);
- return false;
+ return FALSE;
}
print_strings (file, stream, (file_off) 0, 0, 0, (char *) 0);
@@ -400,11 +395,11 @@ strings_file (file)
{
fprintf (stderr, "%s: ", program_name);
perror (file);
- return false;
+ return FALSE;
}
}
- return true;
+ return TRUE;
}
/* Read the next character, return EOF if none available.
@@ -418,11 +413,7 @@ strings_file (file)
MAGICCOUNT is how many characters are in it. */
static long
-get_char (stream, address, magiccount, magic)
- FILE *stream;
- file_off *address;
- int *magiccount;
- char **magic;
+get_char (FILE *stream, file_off *address, int *magiccount, char **magic)
{
int c, i;
long r = EOF;
@@ -454,6 +445,7 @@ get_char (stream, address, magiccount, magic)
switch (encoding)
{
+ case 'S':
case 's':
r = buf[0];
break;
@@ -492,13 +484,8 @@ get_char (stream, address, magiccount, magic)
Those characters come at address ADDRESS and the data in STREAM follow. */
static void
-print_strings (filename, stream, address, stop_point, magiccount, magic)
- const char *filename;
- FILE *stream;
- file_off address;
- int stop_point;
- int magiccount;
- char *magic;
+print_strings (const char *filename, FILE *stream, file_off address,
+ int stop_point, int magiccount, char *magic)
{
char *buf = (char *) xmalloc (sizeof (char) * (string_min + 1));
@@ -518,7 +505,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic)
c = get_char (stream, &address, &magiccount, &magic);
if (c == EOF)
return;
- if (c > 255 || c < 0 || !isgraphic (c))
+ if (! STRING_ISGRAPHIC (c))
/* Found a non-graphic. Try again starting with next char. */
goto tryline;
buf[i] = c;
@@ -586,7 +573,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic)
c = get_char (stream, &address, &magiccount, &magic);
if (c == EOF)
break;
- if (c > 255 || c < 0 || !isgraphic (c))
+ if (! STRING_ISGRAPHIC (c))
break;
putchar (c);
}
@@ -599,8 +586,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic)
but allowing octal and hex numbers as in C. */
static int
-integer_arg (s)
- char *s;
+integer_arg (char *s)
{
int value;
int radix = 10;
@@ -636,16 +622,13 @@ integer_arg (s)
p--;
if (*p)
- {
- fatal (_("invalid integer argument %s"), s);
- }
+ fatal (_("invalid integer argument %s"), s);
+
return value;
}
static void
-usage (stream, status)
- FILE *stream;
- int status;
+usage (FILE *stream, int status)
{
fprintf (stream, _("Usage: %s [option(s)] [file(s)]\n"), program_name);
fprintf (stream, _(" Display printable strings in [file(s)] (stdin by default)\n"));
@@ -657,8 +640,8 @@ usage (stream, status)
-t --radix={o,x,d} Print the location of the string in base 8, 10 or 16\n\
-o An alias for --radix=o\n\
-T --target=<BFDNAME> Specify the binary file format\n\
- -e --encoding={s,b,l,B,L} Select character size and endianness:\n\
- s = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
+ -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
+ s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
-h --help Display this information\n\
-v --version Print the program's version number\n"));
list_supported_targets (program_name, stream);
OpenPOWER on IntegriCloud