diff options
author | Tobias Ulmer <tobiasu@cvs.openbsd.org> | 2014-08-31 13:40:04 +0000 |
---|---|---|
committer | Tobias Ulmer <tobiasu@cvs.openbsd.org> | 2014-08-31 13:40:04 +0000 |
commit | 818d67e61e86f65ddc089262067bd38f3706dec6 (patch) | |
tree | 7dea0937cfb0920e451f84ad95dab9b2af955e28 | |
parent | 3586dd255e8f47c3bb8286abfdbbac0fd1155bb1 (diff) |
Backport @file support from binutils-2.17
@file allows reading command line arguments from a file. Gcc now uses this to
pass very long arguments lists to ld.
ok guenther@ miod@
23 files changed, 331 insertions, 273 deletions
diff --git a/gnu/usr.bin/binutils/binutils/addr2line.c b/gnu/usr.bin/binutils/binutils/addr2line.c index 7fbbdd855df..a3e6752049f 100644 --- a/gnu/usr.bin/binutils/binutils/addr2line.c +++ b/gnu/usr.bin/binutils/binutils/addr2line.c @@ -1,6 +1,7 @@ /* addr2line.c -- convert addresses to line number and function name - Copyright 1997 Free Software Foundation, Inc. - Contributed by Ulrich Lauther <Ulrich.Lauther@zfe.siemens.de> + Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 + Free Software Foundation, Inc. + Contributed by Ulrich Lauther <Ulrich.Lauther@mchp.siemens.de> This file is part of GNU Binutils. @@ -18,17 +19,16 @@ along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Derived from objdump.c and nm.c by Ulrich.Lauther@zfe.siemens.de +/* Derived from objdump.c and nm.c by Ulrich.Lauther@mchp.siemens.de - Usage: + Usage: addr2line [options] addr addr ... or - addr2line [options] + addr2line [options] both forms write results to stdout, the second form reads addresses to be converted from stdin. */ -#include <ctype.h> #include <string.h> #include "bfd.h" @@ -36,12 +36,11 @@ #include "libiberty.h" #include "demangle.h" #include "bucomm.h" +#include "budemang.h" -extern char *program_version; - -static boolean with_functions; /* -f, show function names. */ -static boolean do_demangle; /* -C, demangle names. */ -static boolean base_names; /* -s, strip directory names. */ +static bfd_boolean with_functions; /* -f, show function names. */ +static bfd_boolean do_demangle; /* -C, demangle names. */ +static bfd_boolean base_names; /* -s, strip directory names. */ static int naddr; /* Number of addresses to process. */ static char **addr; /* Hex addresses to process. */ @@ -51,7 +50,7 @@ static asymbol **syms; /* Symbol table. */ static struct option long_options[] = { {"basenames", no_argument, NULL, 's'}, - {"demangle", no_argument, NULL, 'C'}, + {"demangle", optional_argument, NULL, 'C'}, {"exe", required_argument, NULL, 'e'}, {"functions", no_argument, NULL, 'f'}, {"target", required_argument, NULL, 'b'}, @@ -60,49 +59,51 @@ static struct option long_options[] = {0, no_argument, 0, 0} }; -static void usage PARAMS ((FILE *, int)); -static void slurp_symtab PARAMS ((bfd *)); -static void find_address_in_section PARAMS ((bfd *, asection *, PTR)); -static void translate_addresses PARAMS ((bfd *)); -static void process_file PARAMS ((const char *, const char *)); +static void usage (FILE *, int); +static void slurp_symtab (bfd *); +static void find_address_in_section (bfd *, asection *, void *); +static void translate_addresses (bfd *); +static void process_file (const char *, const char *); /* Print a usage message to STREAM and exit with STATUS. */ static void -usage (stream, status) - FILE *stream; - int status; +usage (FILE *stream, int status) { - fprintf (stream, "\ -Usage: %s [-CfsHV] [-b bfdname] [--target=bfdname]\n\ - [-e executable] [--exe=executable] [--demangle]\n\ - [--basenames] [--functions] [addr addr ...]\n", - program_name); + fprintf (stream, _("Usage: %s [option(s)] [addr(s)]\n"), program_name); + fprintf (stream, _(" Convert addresses into line number/file name pairs.\n")); + fprintf (stream, _(" If no addresses are specified on the command line, they will be read from stdin\n")); + fprintf (stream, _(" The options are:\n\ + -b --target=<bfdname> Set the binary file format\n\ + -e --exe=<executable> Set the input file name (default is a.out)\n\ + -s --basenames Strip directory names\n\ + -f --functions Show function names\n\ + -C --demangle[=style] Demangle function names\n\ + -h --help Display this information\n\ + -v --version Display the program's version\n\ +\n")); + list_supported_targets (program_name, stream); if (status == 0) - fprintf (stream, "Report bugs to bug-gnu-utils@prep.ai.mit.edu\n"); + fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); exit (status); } /* Read in the symbol table. */ static void -slurp_symtab (abfd) - bfd *abfd; +slurp_symtab (bfd *abfd) { - long storage; long symcount; + unsigned int size; if ((bfd_get_file_flags (abfd) & HAS_SYMS) == 0) return; - storage = bfd_get_symtab_upper_bound (abfd); - if (storage < 0) - bfd_fatal (bfd_get_filename (abfd)); + symcount = bfd_read_minisymbols (abfd, FALSE, (void *) &syms, &size); + if (symcount == 0) + symcount = bfd_read_minisymbols (abfd, TRUE /* dynamic */, (void *) &syms, &size); - syms = (asymbol **) xmalloc (storage); - - symcount = bfd_canonicalize_symtab (abfd, syms); if (symcount < 0) bfd_fatal (bfd_get_filename (abfd)); } @@ -114,18 +115,17 @@ static bfd_vma pc; static const char *filename; static const char *functionname; static unsigned int line; -static boolean found; +static bfd_boolean found; /* Look for an address in a section. This is called via bfd_map_over_sections. */ static void -find_address_in_section (abfd, section, data) - bfd *abfd; - asection *section; - PTR data; +find_address_in_section (bfd *abfd, asection *section, + void *data ATTRIBUTE_UNUSED) { bfd_vma vma; + bfd_size_type size; if (found) return; @@ -137,6 +137,10 @@ find_address_in_section (abfd, section, data) if (pc < vma) return; + size = bfd_get_section_size_before_reloc (section); + if (pc >= vma + size) + return; + found = bfd_find_nearest_line (abfd, section, syms, pc - vma, &filename, &functionname, &line); } @@ -145,8 +149,7 @@ find_address_in_section (abfd, section, data) file_name:line_number and optionally function name. */ static void -translate_addresses (abfd) - bfd *abfd; +translate_addresses (bfd *abfd) { int read_stdin = (naddr == 0); @@ -158,18 +161,18 @@ translate_addresses (abfd) if (fgets (addr_hex, sizeof addr_hex, stdin) == NULL) break; - pc = strtol (addr_hex, NULL, 16); + pc = bfd_scan_vma (addr_hex, NULL, 16); } else { if (naddr <= 0) break; --naddr; - pc = strtol (*addr++, NULL, 16); + pc = bfd_scan_vma (*addr++, NULL, 16); } - found = false; - bfd_map_over_sections (abfd, find_address_in_section, (PTR) NULL); + found = FALSE; + bfd_map_over_sections (abfd, find_address_in_section, NULL); if (! found) { @@ -181,26 +184,25 @@ translate_addresses (abfd) { if (with_functions) { - if (*functionname == '\0') - printf ("??\n"); - else if (! do_demangle) - printf ("%s\n", functionname); - else + const char *name; + char *alloc = NULL; + + name = functionname; + if (name == NULL || *name == '\0') + name = "??"; + else if (do_demangle) { - char *res; - - res = cplus_demangle (functionname, DMGL_ANSI | DMGL_PARAMS); - if (res == NULL) - printf ("%s\n", functionname); - else - { - printf ("%s\n", res); - free (res); - } + alloc = demangle (abfd, name); + name = alloc; } + + printf ("%s\n", name); + + if (alloc != NULL) + free (alloc); } - if (base_names) + if (base_names && filename != NULL) { char *h; @@ -209,7 +211,7 @@ translate_addresses (abfd) filename = h + 1; } - printf ("%s:%u\n", filename, line); + printf ("%s:%u\n", filename ? filename : "??", line); } /* fflush() is essential for using this command as a server @@ -223,19 +225,20 @@ translate_addresses (abfd) /* Process a file. */ static void -process_file (filename, target) - const char *filename; - const char *target; +process_file (const char *file_name, const char *target) { bfd *abfd; char **matching; - abfd = bfd_openr (filename, target); + if (get_file_size (file_name) < 1) + return; + + abfd = bfd_openr (file_name, target); if (abfd == NULL) - bfd_fatal (filename); + bfd_fatal (file_name); if (bfd_check_format (abfd, bfd_archive)) - fatal ("%s: can not get addresses from archive", filename); + fatal (_("%s: can not get addresses from archive"), file_name); if (! bfd_check_format_matches (abfd, bfd_object, &matching)) { @@ -261,48 +264,72 @@ process_file (filename, target) bfd_close (abfd); } +int main (int, char **); + int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { - char *filename; + const char *file_name; char *target; int c; +#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) + setlocale (LC_MESSAGES, ""); +#endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); +#endif + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + program_name = *argv; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); - filename = NULL; + file_name = NULL; target = NULL; - while ((c = getopt_long (argc, argv, "b:Ce:sfHV", long_options, (int *) 0)) + while ((c = getopt_long (argc, argv, "b:Ce:sfHhVv", long_options, (int *) 0)) != EOF) { switch (c) { case 0: - break; /* we've been given a long option */ + break; /* We've been given a long option. */ case 'b': target = optarg; break; case 'C': - do_demangle = true; + do_demangle = TRUE; + if (optarg != NULL) + { + enum demangling_styles style; + + style = cplus_demangle_name_to_style (optarg); + if (style == unknown_demangling) + fatal (_("unknown demangling style `%s'"), + optarg); + + cplus_demangle_set_style (style); + } break; case 'e': - filename = optarg; + file_name = optarg; break; case 's': - base_names = true; + base_names = TRUE; break; case 'f': - with_functions = true; + with_functions = TRUE; break; + case 'v': case 'V': print_version ("addr2line"); break; + case 'h': case 'H': usage (stdout, 0); break; @@ -312,13 +339,13 @@ main (argc, argv) } } - if (filename == NULL) - filename = "a.out"; + if (file_name == NULL) + file_name = "a.out"; addr = argv + optind; naddr = argc - optind; - process_file (filename, target); + process_file (file_name, target); return 0; } diff --git a/gnu/usr.bin/binutils/binutils/ar.c b/gnu/usr.bin/binutils/binutils/ar.c index 99597795f6d..dec8dbe5951 100644 --- a/gnu/usr.bin/binutils/binutils/ar.c +++ b/gnu/usr.bin/binutils/binutils/ar.c @@ -367,6 +367,8 @@ main (int argc, char **argv) program_name = argv[0]; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + if (is_ranlib < 0) { char *temp; diff --git a/gnu/usr.bin/binutils/binutils/coffdump.c b/gnu/usr.bin/binutils/binutils/coffdump.c index 039b9553621..808e886dc91 100644 --- a/gnu/usr.bin/binutils/binutils/coffdump.c +++ b/gnu/usr.bin/binutils/binutils/coffdump.c @@ -496,6 +496,8 @@ main (int ac, char **av) program_name = av[0]; xmalloc_set_program_name (program_name); + expandargv (&ac, &av); + while ((opt = getopt_long (ac, av, "HhVv", long_options, (int *) NULL)) != EOF) diff --git a/gnu/usr.bin/binutils/binutils/cxxfilt.c b/gnu/usr.bin/binutils/binutils/cxxfilt.c index e4289c8ea1b..ad0e64fee30 100644 --- a/gnu/usr.bin/binutils/binutils/cxxfilt.c +++ b/gnu/usr.bin/binutils/binutils/cxxfilt.c @@ -1,6 +1,6 @@ /* Demangler for GNU C++ - main program Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002 Free Software Foundation, Inc. + 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.uucp) Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling Modified by Satish Pai (pai@apollo.hp.com) for HP demangling @@ -32,13 +32,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE; -static void demangle_it PARAMS ((char *)); -static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN; -static void print_demangler_list PARAMS ((FILE *)); +static void demangle_it (char *); +static void usage (FILE *, int) ATTRIBUTE_NORETURN; +static void print_demangler_list (FILE *); static void -demangle_it (mangled_name) - char *mangled_name; +demangle_it (char *mangled_name) { char *result; @@ -55,14 +54,13 @@ demangle_it (mangled_name) } } -static void -print_demangler_list (stream) - FILE *stream; +static void +print_demangler_list (FILE *stream) { - const struct demangler_engine *demangler; + const struct demangler_engine *demangler; fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name); - + for (demangler = libiberty_demanglers + 1; demangler->demangling_style != unknown_demangling; ++demangler) @@ -72,12 +70,11 @@ print_demangler_list (stream) } static void -usage (stream, status) - FILE *stream; - int status; +usage (FILE *stream, int status) { fprintf (stream, "\ -Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores] \n", +Usage: %s [-_] [-n] [--strip-underscores] [--no-strip-underscores]\n\ + [-p] [--no-params]\n", program_name); fprintf (stream, "\ @@ -104,23 +101,22 @@ static const struct option long_options[] = { {"strip-underscores", no_argument, 0, '_'}, {"format", required_argument, 0, 's'}, {"help", no_argument, 0, 'h'}, + {"no-params", no_argument, 0, 'p'}, {"no-strip-underscores", no_argument, 0, 'n'}, {"version", no_argument, 0, 'v'}, {0, no_argument, 0, 0} }; -static const char * -standard_symbol_characters PARAMS ((void)); +static const char *standard_symbol_characters (void); -static const char * -hp_symbol_characters PARAMS ((void)); +static const char *hp_symbol_characters (void); -/* Return the string of non-alnum characters that may occur +/* Return the string of non-alnum characters that may occur as a valid symbol component, in the standard assembler symbol syntax. */ static const char * -standard_symbol_characters () +standard_symbol_characters (void) { return "_$."; } @@ -157,17 +153,15 @@ standard_symbol_characters () So have fun. */ static const char * -hp_symbol_characters () +hp_symbol_characters (void) { return "_$.<>#,*&[]:(){}"; } -extern int main PARAMS ((int, char **)); +extern int main (int, char **); int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *result; int c; @@ -177,9 +171,11 @@ main (argc, argv) program_name = argv[0]; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + strip_underscore = TARGET_PREPENDS_UNDERSCORE; - while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF) + while ((c = getopt_long (argc, argv, "_nps:", long_options, (int *) 0)) != EOF) { switch (c) { @@ -191,6 +187,9 @@ main (argc, argv) case 'n': strip_underscore = 0; break; + case 'p': + flags &= ~ DMGL_PARAMS; + break; case 'v': print_version ("c++filt"); return (0); diff --git a/gnu/usr.bin/binutils/binutils/deflex.c b/gnu/usr.bin/binutils/binutils/deflex.c index cf38e17a1b1..7d6ec14edeb 100644 --- a/gnu/usr.bin/binutils/binutils/deflex.c +++ b/gnu/usr.bin/binutils/binutils/deflex.c @@ -1,7 +1,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/binutils/deflex.c,v 1.2 2004/11/02 20:45:16 miod Exp $ + * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/binutils/deflex.c,v 1.3 2014/08/31 13:40:02 tobiasu Exp $ */ #define FLEX_SCANNER diff --git a/gnu/usr.bin/binutils/binutils/dlltool.c b/gnu/usr.bin/binutils/binutils/dlltool.c index 9a9d7f94bb4..fac1ea0585f 100644 --- a/gnu/usr.bin/binutils/binutils/dlltool.c +++ b/gnu/usr.bin/binutils/binutils/dlltool.c @@ -3202,6 +3202,8 @@ main (int ac, char **av) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + expandargv (&ac, &av); + while ((c = getopt_long (ac, av, #ifdef DLLTOOL_MCORE_ELF "m:e:l:aD:d:z:b:xcCuUkAS:f:nvVHhM:L:F:", diff --git a/gnu/usr.bin/binutils/binutils/dllwrap.c b/gnu/usr.bin/binutils/binutils/dllwrap.c index 725d87164e8..29dcc47659e 100644 --- a/gnu/usr.bin/binutils/binutils/dllwrap.c +++ b/gnu/usr.bin/binutils/binutils/dllwrap.c @@ -639,6 +639,8 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + expandargv (&argc, &argv); + saved_argv = (char **) xmalloc (argc * sizeof (char*)); dlltool_arg_indices = (int *) xmalloc (argc * sizeof (int)); driver_arg_indices = (int *) xmalloc (argc * sizeof (int)); diff --git a/gnu/usr.bin/binutils/binutils/nlmconv.c b/gnu/usr.bin/binutils/binutils/nlmconv.c index 5a644e44669..e53d61908a8 100644 --- a/gnu/usr.bin/binutils/binutils/nlmconv.c +++ b/gnu/usr.bin/binutils/binutils/nlmconv.c @@ -214,6 +214,8 @@ main (int argc, char **argv) program_name = argv[0]; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); diff --git a/gnu/usr.bin/binutils/binutils/nm.c b/gnu/usr.bin/binutils/binutils/nm.c index bac7d388ce2..2ed16541bf8 100644 --- a/gnu/usr.bin/binutils/binutils/nm.c +++ b/gnu/usr.bin/binutils/binutils/nm.c @@ -364,6 +364,8 @@ main (int argc, char **argv) START_PROGRESS (program_name, 0); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); diff --git a/gnu/usr.bin/binutils/binutils/objcopy.c b/gnu/usr.bin/binutils/binutils/objcopy.c index 0f7ce85561e..c3404f773a2 100644 --- a/gnu/usr.bin/binutils/binutils/objcopy.c +++ b/gnu/usr.bin/binutils/binutils/objcopy.c @@ -3030,6 +3030,8 @@ main (int argc, char *argv[]) START_PROGRESS (program_name, 0); + expandargv (&argc, &argv); + strip_symbols = STRIP_UNDEF; discard_locals = LOCALS_UNDEF; diff --git a/gnu/usr.bin/binutils/binutils/objdump.c b/gnu/usr.bin/binutils/binutils/objdump.c index f67aacb8881..c720fb2d4d2 100644 --- a/gnu/usr.bin/binutils/binutils/objdump.c +++ b/gnu/usr.bin/binutils/binutils/objdump.c @@ -2719,6 +2719,8 @@ main (int argc, char **argv) START_PROGRESS (program_name, 0); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); diff --git a/gnu/usr.bin/binutils/binutils/rclex.c b/gnu/usr.bin/binutils/binutils/rclex.c index 1767169005e..d29cdbaf610 100644 --- a/gnu/usr.bin/binutils/binutils/rclex.c +++ b/gnu/usr.bin/binutils/binutils/rclex.c @@ -1,7 +1,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/binutils/rclex.c,v 1.2 2004/11/02 20:45:18 miod Exp $ + * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/binutils/rclex.c,v 1.3 2014/08/31 13:40:02 tobiasu Exp $ */ #define FLEX_SCANNER diff --git a/gnu/usr.bin/binutils/binutils/readelf.c b/gnu/usr.bin/binutils/binutils/readelf.c index f5fc740e0b7..f507e04a738 100644 --- a/gnu/usr.bin/binutils/binutils/readelf.c +++ b/gnu/usr.bin/binutils/binutils/readelf.c @@ -10634,6 +10634,8 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + expandargv (&argc, &argv); + parse_args (argc, argv); if (optind < (argc - 1)) diff --git a/gnu/usr.bin/binutils/binutils/size.c b/gnu/usr.bin/binutils/binutils/size.c index 98754934a98..a0ccfff98e2 100644 --- a/gnu/usr.bin/binutils/binutils/size.c +++ b/gnu/usr.bin/binutils/binutils/size.c @@ -134,6 +134,8 @@ main (int argc, char **argv) program_name = *argv; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); diff --git a/gnu/usr.bin/binutils/binutils/srconv.c b/gnu/usr.bin/binutils/binutils/srconv.c index 0ffa0588347..025d47280da 100644 --- a/gnu/usr.bin/binutils/binutils/srconv.c +++ b/gnu/usr.bin/binutils/binutils/srconv.c @@ -1896,6 +1896,8 @@ main (int ac, char **av) program_name = av[0]; xmalloc_set_program_name (program_name); + expandargv (&ac, &av); + while ((opt = getopt_long (ac, av, "dHhVvqn", long_options, (int *) NULL)) != EOF) diff --git a/gnu/usr.bin/binutils/binutils/strings.c b/gnu/usr.bin/binutils/binutils/strings.c index 68c244cafbd..18b41dc5f58 100644 --- a/gnu/usr.bin/binutils/binutils/strings.c +++ b/gnu/usr.bin/binutils/binutils/strings.c @@ -168,6 +168,9 @@ main (int argc, char **argv) program_name = argv[0]; xmalloc_set_program_name (program_name); + + expandargv (&argc, &argv); + string_min = -1; print_addresses = FALSE; print_filenames = FALSE; diff --git a/gnu/usr.bin/binutils/binutils/sysdump.c b/gnu/usr.bin/binutils/binutils/sysdump.c index a1df1e05b7a..32589cf2e76 100644 --- a/gnu/usr.bin/binutils/binutils/sysdump.c +++ b/gnu/usr.bin/binutils/binutils/sysdump.c @@ -772,6 +772,8 @@ main (int ac, char **av) program_name = av[0]; xmalloc_set_program_name (program_name); + expandargv (&ac, &av); + while ((opt = getopt_long (ac, av, "HhVv", long_options, (int *) NULL)) != EOF) { switch (opt) diff --git a/gnu/usr.bin/binutils/binutils/windres.c b/gnu/usr.bin/binutils/binutils/windres.c index 89f0ac2ecc2..e6ec24e8165 100644 --- a/gnu/usr.bin/binutils/binutils/windres.c +++ b/gnu/usr.bin/binutils/binutils/windres.c @@ -1,5 +1,6 @@ /* windres.c -- a program to manipulate Windows resources - Copyright 1997, 98, 99, 2000 Free Software Foundation, Inc. + Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 + Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. This file is part of GNU Binutils. @@ -31,22 +32,19 @@ * The rcl program, written by Gunther Ebert <gunther.ebert@ixos-leipzig.de>. - * The res2coff program, written by Pedro A. Aranda <paag@tid.es>. - - */ + * The res2coff program, written by Pedro A. Aranda <paag@tid.es>. */ #include "bfd.h" #include "getopt.h" #include "bucomm.h" #include "libiberty.h" +#include "safe-ctype.h" #include "obstack.h" #include "windres.h" - #include <assert.h> -#include <ctype.h> #include <time.h> -/* used by resrc.c at least */ +/* Used by resrc.c at least. */ int verbose = 0; @@ -104,47 +102,17 @@ struct include_dir static struct include_dir *include_dirs; -/* Long options. */ - -/* 150 isn't special; it's just an arbitrary non-ASCII char value. */ - -#define OPTION_DEFINE 150 -#define OPTION_HELP (OPTION_DEFINE + 1) -#define OPTION_INCLUDE_DIR (OPTION_HELP + 1) -#define OPTION_LANGUAGE (OPTION_INCLUDE_DIR + 1) -#define OPTION_PREPROCESSOR (OPTION_LANGUAGE + 1) -#define OPTION_USE_TEMP_FILE (OPTION_PREPROCESSOR + 1) -#define OPTION_NO_USE_TEMP_FILE (OPTION_USE_TEMP_FILE + 1) -#define OPTION_VERSION (OPTION_NO_USE_TEMP_FILE + 1) -#define OPTION_YYDEBUG (OPTION_VERSION + 1) - -static const struct option long_options[] = -{ - {"define", required_argument, 0, OPTION_DEFINE}, - {"help", no_argument, 0, OPTION_HELP}, - {"include-dir", required_argument, 0, OPTION_INCLUDE_DIR}, - {"input-format", required_argument, 0, 'I'}, - {"language", required_argument, 0, OPTION_LANGUAGE}, - {"output-format", required_argument, 0, 'O'}, - {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR}, - {"target", required_argument, 0, 'F'}, - {"use-temp-file", no_argument, 0, OPTION_USE_TEMP_FILE}, - {"no-use-temp-file", no_argument, 0, OPTION_NO_USE_TEMP_FILE}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, OPTION_VERSION}, - {"yydebug", no_argument, 0, OPTION_YYDEBUG}, - {0, no_argument, 0, 0} -}; - /* Static functions. */ -static void res_init PARAMS ((void)); -static int extended_menuitems PARAMS ((const struct menuitem *)); -static enum res_format format_from_name PARAMS ((const char *)); -static enum res_format format_from_filename PARAMS ((const char *, int)); -static void usage PARAMS ((FILE *, int)); -static int cmp_res_entry PARAMS ((const PTR, const PTR)); -static struct res_directory *sort_resources PARAMS ((struct res_directory *)); +static void res_init (void); +static int extended_menuitems (const struct menuitem *); +static enum res_format format_from_name (const char *, int); +static enum res_format format_from_filename (const char *, int); +static void usage (FILE *, int); +static int cmp_res_entry (const void *, const void *); +static struct res_directory *sort_resources (struct res_directory *); +static void reswr_init (void); +static const char * quot (const char *); /* When we are building a resource tree, we allocate everything onto an obstack, so that we can free it all at once if we want. */ @@ -159,18 +127,17 @@ static struct obstack res_obstack; /* Initialize the resource building obstack. */ static void -res_init () +res_init (void) { obstack_init (&res_obstack); } /* Allocate space on the resource building obstack. */ -PTR -res_alloc (bytes) - size_t bytes; +void * +res_alloc (size_t bytes) { - return (PTR) obstack_alloc (&res_obstack, bytes); + return (void *) obstack_alloc (&res_obstack, bytes); } /* We also use an obstack to save memory used while writing out a set @@ -181,28 +148,24 @@ static struct obstack reswr_obstack; /* Initialize the resource writing obstack. */ static void -reswr_init () +reswr_init (void) { obstack_init (&reswr_obstack); } /* Allocate space on the resource writing obstack. */ -PTR -reswr_alloc (bytes) - size_t bytes; +void * +reswr_alloc (size_t bytes) { - return (PTR) obstack_alloc (&reswr_obstack, bytes); + return (void *) obstack_alloc (&reswr_obstack, bytes); } /* Open a file using the include directory search list. */ FILE * -open_file_search (filename, mode, errmsg, real_filename) - const char *filename; - const char *mode; - const char *errmsg; - char **real_filename; +open_file_search (const char *filename, const char *mode, const char *errmsg, + char **real_filename) { FILE *e; struct include_dir *d; @@ -245,9 +208,7 @@ open_file_search (filename, mode, errmsg, real_filename) section. */ int -res_id_cmp (a, b) - struct res_id a; - struct res_id b; +res_id_cmp (struct res_id a, struct res_id b) { if (! a.named) { @@ -295,10 +256,7 @@ res_id_cmp (a, b) /* Print a resource ID. */ void -res_id_print (stream, id, quote) - FILE *stream; - struct res_id id; - int quote; +res_id_print (FILE *stream, struct res_id id, int quote) { if (! id.named) fprintf (stream, "%lu", id.u.id); @@ -315,10 +273,7 @@ res_id_print (stream, id, quote) /* Print a list of resource ID's. */ void -res_ids_print (stream, cids, ids) - FILE *stream; - int cids; - const struct res_id *ids; +res_ids_print (FILE *stream, int cids, const struct res_id *ids) { int i; @@ -333,9 +288,7 @@ res_ids_print (stream, cids, ids) /* Convert an ASCII string to a resource ID. */ void -res_string_to_id (res_id, string) - struct res_id *res_id; - const char *string; +res_string_to_id (struct res_id *res_id, const char *string) { res_id->named = 1; unicode_from_ascii (&res_id->u.n.length, &res_id->u.n.name, string); @@ -350,11 +303,8 @@ res_string_to_id (res_id, string) one. */ struct res_resource * -define_resource (resources, cids, ids, dupok) - struct res_directory **resources; - int cids; - const struct res_id *ids; - int dupok; +define_resource (struct res_directory **resources, int cids, + const struct res_id *ids, int dupok) { struct res_entry *re = NULL; int i; @@ -441,11 +391,9 @@ define_resource (resources, cids, ids, dupok) re->u.res = ((struct res_resource *) res_alloc (sizeof (struct res_resource))); + memset (re->u.res, 0, sizeof (struct res_resource)); re->u.res->type = RES_TYPE_UNINITIALIZED; - memset (&re->u.res->res_info, 0, sizeof (struct res_res_info)); - memset (&re->u.res->coff_info, 0, sizeof (struct res_coff_info)); - return re->u.res; } @@ -453,12 +401,8 @@ define_resource (resources, cids, ids, dupok) that just takes type, name, and language arguments. */ struct res_resource * -define_standard_resource (resources, type, name, language, dupok) - struct res_directory **resources; - int type; - struct res_id name; - int language; - int dupok; +define_standard_resource (struct res_directory **resources, int type, + struct res_id name, int language, int dupok) { struct res_id a[3]; @@ -473,9 +417,7 @@ define_standard_resource (resources, type, name, language, dupok) /* Comparison routine for resource sorting. */ static int -cmp_res_entry (p1, p2) - const PTR p1; - const PTR p2; +cmp_res_entry (const void *p1, const void *p2) { const struct res_entry **re1, **re2; @@ -487,8 +429,7 @@ cmp_res_entry (p1, p2) /* Sort the resources. */ static struct res_directory * -sort_resources (resdir) - struct res_directory *resdir; +sort_resources (struct res_directory *resdir) { int c, i; struct res_entry *re; @@ -530,8 +471,7 @@ sort_resources (resdir) DIALOGEX. */ int -extended_dialog (dialog) - const struct dialog *dialog; +extended_dialog (const struct dialog *dialog) { const struct dialog_control *c; @@ -548,15 +488,13 @@ extended_dialog (dialog) /* Return whether MENUITEMS are a MENU or a MENUEX. */ int -extended_menu (menu) - const struct menu *menu; +extended_menu (const struct menu *menu) { return extended_menuitems (menu->items); } static int -extended_menuitems (menuitems) - const struct menuitem *menuitems; +extended_menuitems (const struct menuitem *menuitems) { const struct menuitem *mi; @@ -588,8 +526,7 @@ extended_menuitems (menuitems) /* Convert a string to a format type, or exit if it can't be done. */ static enum res_format -format_from_name (name) - const char *name; +format_from_name (const char *name, int exit_on_error) { const struct format_map *m; @@ -597,7 +534,7 @@ format_from_name (name) if (strcasecmp (m->name, name) == 0) break; - if (m->name == NULL) + if (m->name == NULL && exit_on_error) { non_fatal (_("unknown format type `%s'"), name); fprintf (stderr, _("%s: supported formats:"), program_name); @@ -614,9 +551,7 @@ format_from_name (name) it's OK to look at the file itself. */ static enum res_format -format_from_filename (filename, input) - const char *filename; - int input; +format_from_filename (const char *filename, int input) { const char *ext; FILE *e; @@ -638,13 +573,11 @@ format_from_filename (filename, input) /* If we don't recognize the name of an output file, assume it's a COFF file. */ - if (! input) return RES_FORMAT_COFF; /* Read the first few bytes of the file to see if we can guess what it is. */ - e = fopen (filename, FOPEN_RB); if (e == NULL) fatal ("%s: %s", filename, strerror (errno)); @@ -679,11 +612,11 @@ format_from_filename (filename, input) return RES_FORMAT_RES; /* If every character is printable or space, assume it's an RC file. */ - if ((isprint (b1) || isspace (b1)) - && (isprint (b2) || isspace (b2)) - && (isprint (b3) || isspace (b3)) - && (isprint (b4) || isspace (b4)) - && (isprint (b5) || isspace (b5))) + if ((ISPRINT (b1) || ISSPACE (b1)) + && (ISPRINT (b2) || ISSPACE (b2)) + && (ISPRINT (b3) || ISSPACE (b3)) + && (ISPRINT (b4) || ISSPACE (b4)) + && (ISPRINT (b5) || ISSPACE (b5))) return RES_FORMAT_RC; /* Otherwise, we give up. */ @@ -697,50 +630,50 @@ format_from_filename (filename, input) /* Print a usage message and exit. */ static void -usage (stream, status) - FILE *stream; - int status; +usage (FILE *stream, int status) { - fprintf (stream, _("Usage: %s [options] [input-file] [output-file]\n"), + fprintf (stream, _("Usage: %s [option(s)] [input-file] [output-file]\n"), program_name); - fprintf (stream, _("\ -Options:\n\ - -i FILE, --input FILE Name input file\n\ - -o FILE, --output FILE Name output file\n\ - -I FORMAT, --input-format FORMAT\n\ - Specify input format\n\ - -O FORMAT, --output-format FORMAT\n\ - Specify output format\n\ - -F TARGET, --target TARGET Specify COFF target\n\ - --preprocessor PROGRAM Program to use to preprocess rc file\n\ - --include-dir DIR Include directory when preprocessing rc file\n\ - -DSYM[=VAL], --define SYM[=VAL]\n\ - Define SYM when preprocessing rc file\n\ - -v Verbose - tells you what it's doing\n\ - --language VAL Set language when reading rc file\n\ - --use-temp-file Use a temporary file instead of popen to read\n\ - the preprocessor output\n\ - --no-use-temp-file Use popen (default)\n")); + fprintf (stream, _(" The options are:\n\ + -i --input=<file> Name input file\n\ + -o --output=<file> Name output file\n\ + -J --input-format=<format> Specify input format\n\ + -O --output-format=<format> Specify output format\n\ + -F --target=<target> Specify COFF target\n\ + --preprocessor=<program> Program to use to preprocess rc file\n\ + -I --include-dir=<dir> Include directory when preprocessing rc file\n\ + -D --define <sym>[=<val>] Define SYM when preprocessing rc file\n\ + -U --undefine <sym> Undefine SYM when preprocessing rc file\n\ + -v --verbose Verbose - tells you what it's doing\n\ + -l --language=<val> Set language when reading rc file\n\ + --use-temp-file Use a temporary file instead of popen to read\n\ + the preprocessor output\n\ + --no-use-temp-file Use popen (default)\n")); #ifdef YYDEBUG fprintf (stream, _("\ - --yydebug Turn on parser debugging\n")); + --yydebug Turn on parser debugging\n")); #endif fprintf (stream, _("\ - --help Print this help message\n\ - --version Print version information\n")); + -r Ignored for compatibility with rc\n\ + -h --help Print this help message\n\ + -V --version Print version information\n")); fprintf (stream, _("\ FORMAT is one of rc, res, or coff, and is deduced from the file name\n\ extension if not specified. A single file name is an input file.\n\ No input-file is stdin, default rc. No output-file is stdout, default rc.\n")); + list_supported_targets (program_name, stream); + if (status == 0) fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); + exit (status); } -/* Quote characters that will confuse the shell when we run the preprocessor */ -static const char *quot (string) - const char *string; +/* Quote characters that will confuse the shell when we run the preprocessor. */ + +static const char * +quot (const char *string) { static char *buf = 0; static int buflen = 0; @@ -766,17 +699,49 @@ static const char *quot (string) return buf; } +/* Long options. */ + +/* 150 isn't special; it's just an arbitrary non-ASCII char value. */ + +#define OPTION_PREPROCESSOR 150 +#define OPTION_USE_TEMP_FILE (OPTION_PREPROCESSOR + 1) +#define OPTION_NO_USE_TEMP_FILE (OPTION_USE_TEMP_FILE + 1) +#define OPTION_YYDEBUG (OPTION_NO_USE_TEMP_FILE + 1) + +static const struct option long_options[] = +{ + {"input", required_argument, 0, 'i'}, + {"output", required_argument, 0, 'o'}, + {"input-format", required_argument, 0, 'J'}, + {"output-format", required_argument, 0, 'O'}, + {"target", required_argument, 0, 'F'}, + {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR}, + {"include-dir", required_argument, 0, 'I'}, + {"define", required_argument, 0, 'D'}, + {"undefine", required_argument, 0, 'U'}, + {"verbose", no_argument, 0, 'v'}, + {"language", required_argument, 0, 'l'}, + {"use-temp-file", no_argument, 0, OPTION_USE_TEMP_FILE}, + {"no-use-temp-file", no_argument, 0, OPTION_NO_USE_TEMP_FILE}, + {"yydebug", no_argument, 0, OPTION_YYDEBUG}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {0, no_argument, 0, 0} +}; + +/* This keeps gcc happy when using -Wmissing-prototypes -Wstrict-prototypes. */ +int main (int, char **); + /* The main function. */ int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { int c; char *input_filename; char *output_filename; enum res_format input_format; + enum res_format input_format_tmp; enum res_format output_format; char *target; char *preprocessor; @@ -789,12 +754,17 @@ main (argc, argv) #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, ""); #endif +#if defined (HAVE_SETLOCALE) + setlocale (LC_CTYPE, ""); +#endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; xmalloc_set_program_name (program_name); + expandargv (&argc, &argv); + bfd_init (); set_default_bfd_target (); @@ -807,10 +777,10 @@ main (argc, argv) target = NULL; preprocessor = NULL; preprocargs = NULL; - language = -1; + language = 0x409; /* LANG_ENGLISH, SUBLANG_ENGLISH_US. */ use_temp_file = 0; - while ((c = getopt_long (argc, argv, "i:o:I:O:F:D:v", long_options, + while ((c = getopt_long (argc, argv, "f:i:l:o:I:J:O:F:D:U:rhHvV", long_options, (int *) 0)) != EOF) { switch (c) @@ -819,16 +789,32 @@ main (argc, argv) input_filename = optarg; break; + case 'f': + /* For compatibility with rc we accept "-fo <name>" as being the + equivalent of "-o <name>". We do not advertise this fact + though, as we do not want users to use non-GNU like command + line switches. */ + if (*optarg != 'o') + fatal (_("invalid option -f\n")); + optarg++; + if (* optarg == 0) + { + if (optind == argc) + fatal (_("No filename following the -fo option.\n")); + optarg = argv [optind++]; + } + /* Fall through. */ + case 'o': output_filename = optarg; break; - case 'I': - input_format = format_from_name (optarg); + case 'J': + input_format = format_from_name (optarg, 1); break; case 'O': - output_format = format_from_name (optarg); + output_format = format_from_name (optarg, 1); break; case 'F': @@ -840,12 +826,12 @@ main (argc, argv) break; case 'D': - case OPTION_DEFINE: + case 'U': if (preprocargs == NULL) { quotedarg = quot (optarg); preprocargs = xmalloc (strlen (quotedarg) + 3); - sprintf (preprocargs, "-D%s", quotedarg); + sprintf (preprocargs, "-%c%s", c, quotedarg); } else { @@ -853,17 +839,30 @@ main (argc, argv) quotedarg = quot (optarg); n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 4); - sprintf (n, "%s -D%s", preprocargs, quotedarg); + sprintf (n, "%s -%c%s", preprocargs, c, quotedarg); free (preprocargs); preprocargs = n; } break; + case 'r': + /* Ignored for compatibility with rc. */ + break; + case 'v': verbose ++; break; - case OPTION_INCLUDE_DIR: + case 'I': + /* For backward compatibility, should be removed in the future. */ + input_format_tmp = format_from_name (optarg, 0); + if (input_format_tmp != RES_FORMAT_UNKNOWN) + { + fprintf (stderr, _("Option -I is deprecated for setting the input format, please use -J instead.\n")); + input_format = input_format_tmp; + break; + } + if (preprocargs == NULL) { quotedarg = quot (optarg); @@ -895,7 +894,7 @@ main (argc, argv) break; - case OPTION_LANGUAGE: + case 'l': language = strtol (optarg, (char **) NULL, 16); break; @@ -913,11 +912,12 @@ main (argc, argv) break; #endif - case OPTION_HELP: + case 'h': + case 'H': usage (stdout, 0); break; - case OPTION_VERSION: + case 'V': print_version ("windres"); break; @@ -959,7 +959,6 @@ main (argc, argv) } /* Read the input file. */ - switch (input_format) { default: @@ -981,11 +980,9 @@ main (argc, argv) /* Sort the resources. This is required for COFF, convenient for rc, and unimportant for res. */ - resources = sort_resources (resources); /* Write the output file. */ - reswr_init (); switch (output_format) @@ -1006,4 +1003,3 @@ main (argc, argv) xexit (0); return 0; } - diff --git a/gnu/usr.bin/binutils/gas/as.c b/gnu/usr.bin/binutils/gas/as.c index 8b64433003a..081a669483f 100644 --- a/gnu/usr.bin/binutils/gas/as.c +++ b/gnu/usr.bin/binutils/gas/as.c @@ -1014,6 +1014,8 @@ main (int argc, char ** argv) myname = argv[0]; xmalloc_set_program_name (myname); + expandargv (&argc, &argv); + START_PROGRESS (myname, 0); #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME diff --git a/gnu/usr.bin/binutils/gas/itbl-lex.c b/gnu/usr.bin/binutils/gas/itbl-lex.c index 99c5063646a..9a785bd3bea 100644 --- a/gnu/usr.bin/binutils/gas/itbl-lex.c +++ b/gnu/usr.bin/binutils/gas/itbl-lex.c @@ -1,7 +1,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/gas/itbl-lex.c,v 1.2 2004/11/02 20:45:24 miod Exp $ + * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils/gas/itbl-lex.c,v 1.3 2014/08/31 13:40:02 tobiasu Exp $ */ #define FLEX_SCANNER diff --git a/gnu/usr.bin/binutils/gprof/gprof.c b/gnu/usr.bin/binutils/gprof/gprof.c index 260dbebb4a7..08f87516b84 100644 --- a/gnu/usr.bin/binutils/gprof/gprof.c +++ b/gnu/usr.bin/binutils/gprof/gprof.c @@ -202,6 +202,8 @@ main (argc, argv) whoami = argv[0]; xmalloc_set_program_name (whoami); + expandargv (&argc, &argv); + while ((ch = getopt_long (argc, argv, "aA::bBcCd::De:E:f:F:hiI:J::k:lLm:n::N::O:p::P::q::Q::st:Tvw:xyzZ::", long_options, 0)) diff --git a/gnu/usr.bin/binutils/include/libiberty.h b/gnu/usr.bin/binutils/include/libiberty.h index 761b2cf060f..2da37386333 100644 --- a/gnu/usr.bin/binutils/include/libiberty.h +++ b/gnu/usr.bin/binutils/include/libiberty.h @@ -62,6 +62,9 @@ extern void freeargv PARAMS ((char **)); extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; +/* Expand "@file" arguments in argv. */ + +extern void expandargv PARAMS ((int *, char ***)); /* Return the last component of a path name. Note that we can't use a prototype here because the parameter is declared inconsistently diff --git a/gnu/usr.bin/binutils/ld/ldmain.c b/gnu/usr.bin/binutils/ld/ldmain.c index 188422c7b5c..36f2fff53f7 100644 --- a/gnu/usr.bin/binutils/ld/ldmain.c +++ b/gnu/usr.bin/binutils/ld/ldmain.c @@ -190,6 +190,8 @@ main (int argc, char **argv) START_PROGRESS (program_name, 0); + expandargv (&argc, &argv); + bfd_init (); bfd_set_error_program_name (program_name); |