This patch makes the driver use the common and target option handling hooks, so making the option state in the driver much closer to that in the core compiler as needed for it to drive multilib selection. opts.o is put in libcommon-target; a few cases of global state usage in opts.c (either missed in my previous changes, or recently added) are fixed. In a few cases where the driver has its own handling of a common option, or where the common handling may not work in the driver at present, common_handle_option is made to return early in the driver. In particular, this applies to --help (right now the driver has its own code reporting help information for driver options and they generally don't have help text in the .opt files; it would be good to integrate things better so that there is only one set of --help machinery used) and to -Werror= (the diagnostic machinery is initialized in the driver without the support for individual option control, which doesn't seem particularly useful there).
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied to mainline. 2011-06-28 Joseph Myers <jos...@codesourcery.com> * common.opt (in_lto_p): New Variable entry. * flags.h (in_lto_p): Move to common.opt. * gcc.c: Include params.h. (set_option_handlers): Also use common_handle_option and target_handle_option. (main): Call global_init_params, finish_params and init_options_struct. * opts.c (debug_type_names): Move from toplev.c. (print_filtered_help): Access quiet_flag through opts pointer. (common_handle_option): Return early in the driver for some options. Access in_lto_p, dwarf_version and warn_maybe_uninitialized through opts pointer. * toplev.c (in_lto_p): Move to common.opt. (debug_type_names): Move to opts.c. * Makefile.in (OBJS): Remove opts.o. (OBJS-libcommon-target): Add opts.o. (gcc.o): Update dependencies. Index: gcc/flags.h =================================================================== --- gcc/flags.h (revision 175330) +++ gcc/flags.h (working copy) @@ -1,6 +1,6 @@ /* Compilation switch flag definitions for GCC. Copyright (C) 1987, 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, - 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 + 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of GCC. @@ -34,13 +34,6 @@ extern const char *const debug_type_name extern void strip_off_ending (char *, int); extern int base_of_path (const char *path, const char **base_out); -/* True if this is the LTO front end (lto1). This is used to disable - gimple generation and lowering passes that are normally run on the - output of a front end. These passes must be bypassed for lto since - they have already been done before the gimple was written. */ - -extern bool in_lto_p; - /* Return true iff flags are set as if -ffast-math. */ extern bool fast_math_flags_set_p (const struct gcc_options *); extern bool fast_math_flags_struct_set_p (struct cl_optimization *); Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 175330) +++ gcc/gcc.c (working copy) @@ -43,6 +43,7 @@ compilation is specified by a string cal #include "diagnostic.h" #include "flags.h" #include "opts.h" +#include "params.h" #include "vec.h" #include "filenames.h" @@ -3532,9 +3533,13 @@ set_option_handlers (struct cl_option_ha handlers->unknown_option_callback = driver_unknown_option_callback; handlers->wrong_lang_callback = driver_wrong_lang_callback; handlers->post_handling_callback = driver_post_handling_callback; - handlers->num_handlers = 1; + handlers->num_handlers = 3; handlers->handlers[0].handler = driver_handle_option; handlers->handlers[0].mask = CL_DRIVER; + handlers->handlers[1].handler = common_handle_option; + handlers->handlers[1].mask = CL_COMMON; + handlers->handlers[2].handler = target_handle_option; + handlers->handlers[2].mask = CL_TARGET; } /* Create the vector `switches' and its contents. @@ -6156,7 +6161,11 @@ main (int argc, char **argv) if (argv != old_argv) at_file_supplied = true; - global_options = global_options_init; + /* Register the language-independent parameters. */ + global_init_params (); + finish_params (); + + init_options_struct (&global_options, &global_options_set); decode_cmdline_options_to_array (argc, CONST_CAST2 (const char **, char **, argv), Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 175330) +++ gcc/toplev.c (working copy) @@ -125,13 +125,6 @@ unsigned int save_decoded_options_count; const struct gcc_debug_hooks *debug_hooks; -/* True if this is the lto front end. This is used to disable - gimple generation and lowering passes that are normally run on the - output of a front end. These passes must be bypassed for lto since - they have already been done before the gimple was written. */ - -bool in_lto_p = false; - /* The FUNCTION_DECL for the function currently being compiled, or 0 if between functions. */ tree current_function_decl; @@ -658,12 +651,6 @@ compile_file (void) timevar_stop (TV_PHASE_GENERATE); } -/* Indexed by enum debug_info_type. */ -const char *const debug_type_names[] = -{ - "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" -}; - /* Print version information to FILE. Each line begins with INDENT (for the case where FILE is the assembler output file). */ Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 175330) +++ gcc/opts.c (working copy) @@ -36,6 +36,12 @@ along with GCC; see the file COPYING3. #include "insn-attr.h" /* For INSN_SCHEDULING and DELAY_SLOTS. */ #include "common/common-target.h" +/* Indexed by enum debug_info_type. */ +const char *const debug_type_names[] = +{ + "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" +}; + /* Parse the -femit-struct-debug-detailed option value and set the flag variables. */ @@ -987,7 +993,7 @@ print_filtered_help (unsigned int includ /* With the -Q option enabled we change the descriptive text associated with an option to be an indication of its current setting. */ - if (!quiet_flag) + if (!opts->x_quiet_flag) { void *flag_var = option_flag_var (i, opts); @@ -1247,6 +1253,9 @@ common_handle_option (struct gcc_options unsigned int undoc_mask; unsigned int i; + if (lang_mask == CL_DRIVER) + break;; + undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings) ? 0 : CL_UNDOCUMENTED); @@ -1266,6 +1275,9 @@ common_handle_option (struct gcc_options } case OPT__target_help: + if (lang_mask == CL_DRIVER) + break; + print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask); opts->x_exit_after_options = true; break; @@ -1281,6 +1293,9 @@ common_handle_option (struct gcc_options --help=target,^undocumented */ unsigned int exclude_flags = 0; + if (lang_mask == CL_DRIVER) + break; + /* Walk along the argument string, parsing each word in turn. The format is: arg = [^]{word}[,{arg}] @@ -1391,6 +1406,9 @@ common_handle_option (struct gcc_options } case OPT__version: + if (lang_mask == CL_DRIVER) + break; + opts->x_exit_after_options = true; break; @@ -1401,6 +1419,9 @@ common_handle_option (struct gcc_options break; case OPT_Werror_: + if (lang_mask == CL_DRIVER) + break; + enable_warning_as_error (arg, value, lang_mask, handlers, opts, opts_set, loc, dc); break; @@ -1577,7 +1598,7 @@ common_handle_option (struct gcc_options /* FIXME: Instrumentation we insert makes ipa-reference bitmaps quadratic. Disable the pass until better memory representation is done. */ - if (!opts_set->x_flag_ipa_reference && in_lto_p) + if (!opts_set->x_flag_ipa_reference && opts->x_in_lto_p) opts->x_flag_ipa_reference = false; break; @@ -1667,7 +1688,7 @@ common_handle_option (struct gcc_options if (value < 2 || value > 4) error_at (loc, "dwarf version %d is not supported", value); else - dwarf_version = value; + opts->x_dwarf_version = value; set_debug_level (DWARF2_DEBUG, false, "", opts, opts_set, loc); break; @@ -1714,7 +1735,7 @@ common_handle_option (struct gcc_options case OPT_Wuninitialized: /* Also turn on maybe uninitialized warning. */ - warn_maybe_uninitialized = value; + opts->x_warn_maybe_uninitialized = value; break; default: Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 175330) +++ gcc/common.opt (working copy) @@ -37,6 +37,13 @@ int optimize_size Variable int optimize_fast +; True if this is the lto front end. This is used to disable gimple +; generation and lowering passes that are normally run on the output +; of a front end. These passes must be bypassed for lto since they +; have already been done before the gimple was written. +Variable +bool in_lto_p = false + ; 0 means straightforward implementation of complex divide acceptable. ; 1 means wide ranges of inputs must work for complex divide. ; 2 means C99-like requirements for complex multiply and divide. Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 175330) +++ gcc/Makefile.in (working copy) @@ -1354,7 +1354,6 @@ OBJS = \ optabs.o \ options-save.o \ opts-global.o \ - opts.o \ passes.o \ plugin.o \ pointer-set.o \ @@ -1504,7 +1503,7 @@ OBJS-libcommon = diagnostic.o pretty-pri # Objects in libcommon-target.a, used by drivers and by the core # compiler and containing target-dependent code. OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \ - opts-common.o options.o vec.o hooks.o common/common-targhooks.o + opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o # This lists all host objects for the front ends. ALL_HOST_FRONTEND_OBJS = $(C_OBJS) \ @@ -2259,7 +2258,7 @@ DRIVER_DEFINES = \ gcc.o: gcc.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) intl.h multilib.h \ Makefile $(lang_specs_files) specs.h prefix.h $(GCC_H) $(FLAGS_H) \ - configargs.h $(OBSTACK_H) $(OPTS_H) $(DIAGNOSTIC_H) $(VEC_H) + configargs.h $(OBSTACK_H) $(OPTS_H) $(DIAGNOSTIC_H) $(VEC_H) $(PARAMS_H) (SHLIB_LINK='$(SHLIB_LINK)'; \ $(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \ $(DRIVER_DEFINES) \ -- Joseph S. Myers jos...@codesourcery.com