Hi! ASM_DEBUG_SPEC uses usually %{g:%{!g0:--gdwarf2}} or something similar. In the past, it used to be %{g:--gdwarf2}. Both have problems (and thus this is also a regression). The problem with the current ASM_DEBUG_SPEC is that if one uses -g0 -g, which normally means that -g overrides -g0, we still don't supply --gdwarf2 to as. Also, there are many options starting with -g, so if one just uses gcc -grecord-gcc-switches foo.s, --gdwarf2 is passed to as too, even when gcc -grecord-gcc-switches foo.c actually doesn't emit any debug info. The problem with older ASM_DEBUG_SPEC has been that even -g0 resulted in --gdwarf2 being passed to as, or -g -g0 too.
The following patch fixes that by introducing a new spec function, which compares debug_info_level against its argument (so in some other place we could e.g. check if debug_info_level >= 3 and similar if needed). To make this work, I had to mark all the -g* options with the Driver flag, so that debug_info_level isn't computed just in the FEs, but also in the driver. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-01-10 Jakub Jelinek <ja...@redhat.com> PR driver/49726 * gcc.c (debug_level_greater_than_spec_func): New function. (static_spec_functions): Add debug-level-gt spec function. (ASM_DEBUG_SPEC, cpp_options): Use %:debug-level-gt(0) instead of !g0. * config/darwin.h (DSYMUTIL_SPEC, ASM_DEBUG_SPEC): Likewise. * config/darwin9.h (DSYMUTIL_SPEC, ASM_DEBUG_SPEC): Likewise. * common.opt (g, gcoff, gdwarf, gdwarf-, ggdb, gno-pubnames, gpubnames, ggnu-pubnames, gno-record-gcc-switches, grecord-gcc-switches, gno-strict-dwarf, gstrict-dwarf, gstabs, gstabs+, gtoggle, gvms, gxcoff, gxcoff+): Add Driver flag. c-family/ * c.opt (gen-decls): Add Driver flag. ada/ * gcc-interface/lang.opt (gant, gnatO, gnat): Add Driver flag. --- gcc/gcc.c.jj 2017-01-10 10:42:52.000000000 +0100 +++ gcc/gcc.c 2017-01-10 12:55:52.847230312 +0100 @@ -402,6 +402,7 @@ static const char *compare_debug_auxbase static const char *pass_through_libs_spec_func (int, const char **); static const char *replace_extension_spec_func (int, const char **); static const char *greater_than_spec_func (int, const char **); +static const char *debug_level_greater_than_spec_func (int, const char **); static char *convert_white_space (char *); /* The Specs Language @@ -833,14 +834,16 @@ proper position among the other output f && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) # define ASM_DEBUG_SPEC \ (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \ - ? "%{!g0:%{gdwarf*:--gdwarf2}%{!gdwarf*:%{g*:--gstabs}}}" ASM_MAP \ - : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP) + ? "%{%:debug-level-gt(0):" \ + "%{gdwarf*:--gdwarf2}%{!gdwarf*:%{g*:--gstabs}}}" ASM_MAP \ + : "%{%:debug-level-gt(0):" \ + "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP) # else # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG) -# define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP +# define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):--gstabs}}" ASM_MAP # endif # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) -# define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP +# define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):--gdwarf2}}" ASM_MAP # endif # endif #endif @@ -1119,7 +1122,8 @@ static const char *cpp_unique_options = in turn cause preprocessor symbols to be defined specially. */ static const char *cpp_options = "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ - %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\ + %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\ + %{!fno-working-directory:-fworking-directory}}} %{O*}\ %{undef} %{save-temps*:-fpch-preprocess}"; /* This contains cpp options which are not passed when the preprocessor @@ -1639,6 +1643,7 @@ static const struct spec_function static { "pass-through-libs", pass_through_libs_spec_func }, { "replace-extension", replace_extension_spec_func }, { "gt", greater_than_spec_func }, + { "debug-level-gt", debug_level_greater_than_spec_func }, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -9861,6 +9866,27 @@ greater_than_spec_func (int argc, const return ""; return NULL; +} + +/* Returns "" if debug_info_level is greater than ARGV[ARGC-1]. + Otherwise, return NULL. */ + +static const char * +debug_level_greater_than_spec_func (int argc, const char **argv) +{ + char *converted; + + if (argc != 1) + fatal_error (input_location, + "wrong number of arguments to %%:debug-level-gt"); + + long arg = strtol (argv[0], &converted, 10); + gcc_assert (converted != argv[0]); + + if (debug_info_level > arg) + return ""; + + return NULL; } /* Insert backslash before spaces in ORIG (usually a file path), to --- gcc/config/darwin.h.jj 2017-01-01 12:45:40.000000000 +0100 +++ gcc/config/darwin.h 2017-01-10 12:48:46.357823233 +0100 @@ -202,9 +202,9 @@ extern GTY(()) int darwin_ms_struct; #define DSYMUTIL_SPEC \ "%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %{v} \ - %{gdwarf-2:%{!gstabs*:%{!g0: -idsym}}}\ + %{gdwarf-2:%{!gstabs*:%{%:debug-level-gt(0): -idsym}}}\ %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \ - %{gdwarf-2:%{!gstabs*:%{!g0: -dsym}}}}}}}}}}}" + %{gdwarf-2:%{!gstabs*:%{%:debug-level-gt(0): -dsym}}}}}}}}}}}" #define LINK_COMMAND_SPEC LINK_COMMAND_SPEC_A DSYMUTIL_SPEC @@ -424,7 +424,7 @@ extern GTY(()) int darwin_ms_struct; /* Default ASM_DEBUG_SPEC. Darwin's as cannot currently produce dwarf debugging data. */ -#define ASM_DEBUG_SPEC "%{g*:%{!g0:%{!gdwarf*:--gstabs}}}" +#define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):%{!gdwarf*:--gstabs}}}" /* We still allow output of STABS if the assembler supports it. */ #ifdef HAVE_AS_STABS_DIRECTIVE --- gcc/config/darwin9.h.jj 2017-01-01 12:45:39.000000000 +0100 +++ gcc/config/darwin9.h 2017-01-10 12:49:14.028460364 +0100 @@ -28,9 +28,9 @@ along with GCC; see the file COPYING3. #define DSYMUTIL_SPEC \ "%{!fdump=*:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %{v} \ - %{g*:%{!gstabs*:%{!g0: -idsym}}}\ + %{g*:%{!gstabs*:%{%:debug-level-gt(0): -idsym}}}\ %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|.f95|.f03|.f77|.for|.F|.F90|.F95|.F03: \ - %{g*:%{!gstabs*:%{!g0: -dsym}}}}}}}}}}}" + %{g*:%{!gstabs*:%{%:debug-level-gt(0): -dsym}}}}}}}}}}}" /* Tell collect2 to run dsymutil for us as necessary. */ #define COLLECT_RUN_DSYMUTIL 1 @@ -45,7 +45,7 @@ along with GCC; see the file COPYING3. yet generate dwarf.) */ #undef ASM_DEBUG_SPEC -#define ASM_DEBUG_SPEC "%{g*:%{!g0:%{gstabs:--gstabs}}}" +#define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):%{gstabs:--gstabs}}}" #undef ASM_OUTPUT_ALIGNED_COMMON #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \ --- gcc/common.opt.jj 2017-01-09 22:46:03.000000000 +0100 +++ gcc/common.opt 2017-01-10 13:00:12.230828792 +0100 @@ -2795,43 +2795,43 @@ Common Report Var(flag_zero_initialized_ Put zero initialized data in the bss section. g -Common JoinedOrMissing +Common Driver JoinedOrMissing Generate debug information in default format. gcoff -Common JoinedOrMissing Negative(gdwarf) +Common Driver JoinedOrMissing Negative(gdwarf) Generate debug information in COFF format. gdwarf -Common JoinedOrMissing Negative(gdwarf-) +Common Driver JoinedOrMissing Negative(gdwarf-) Generate debug information in default version of DWARF format. gdwarf- -Common Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs) +Common Driver Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs) Generate debug information in DWARF v2 (or later) format. ggdb -Common JoinedOrMissing +Common Driver JoinedOrMissing Generate debug information in default extended format. gno-pubnames -Common Negative(gpubnames) Var(debug_generate_pub_sections, 0) Init(-1) +Common Driver Negative(gpubnames) Var(debug_generate_pub_sections, 0) Init(-1) Don't generate DWARF pubnames and pubtypes sections. gpubnames -Common Negative(ggnu-pubnames) Var(debug_generate_pub_sections, 1) +Common Driver Negative(ggnu-pubnames) Var(debug_generate_pub_sections, 1) Generate DWARF pubnames and pubtypes sections. ggnu-pubnames -Common Negative(gno-pubnames) Var(debug_generate_pub_sections, 2) +Common Driver Negative(gno-pubnames) Var(debug_generate_pub_sections, 2) Generate DWARF pubnames and pubtypes sections with GNU extensions. gno-record-gcc-switches -Common RejectNegative Var(dwarf_record_gcc_switches,0) Init(1) +Common Driver RejectNegative Var(dwarf_record_gcc_switches,0) Init(1) Don't record gcc command line switches in DWARF DW_AT_producer. grecord-gcc-switches -Common RejectNegative Var(dwarf_record_gcc_switches,1) +Common Driver RejectNegative Var(dwarf_record_gcc_switches,1) Record gcc command line switches in DWARF DW_AT_producer. gno-split-dwarf @@ -2843,35 +2843,35 @@ Common Driver RejectNegative Var(dwarf_s Generate debug information in separate .dwo files. gstabs -Common JoinedOrMissing Negative(gstabs+) +Common Driver JoinedOrMissing Negative(gstabs+) Generate debug information in STABS format. gstabs+ -Common JoinedOrMissing Negative(gvms) +Common Driver JoinedOrMissing Negative(gvms) Generate debug information in extended STABS format. gno-strict-dwarf -Common RejectNegative Var(dwarf_strict,0) Init(0) +Common Driver RejectNegative Var(dwarf_strict,0) Init(0) Emit DWARF additions beyond selected version. gstrict-dwarf -Common Report RejectNegative Var(dwarf_strict,1) +Common Driver Report RejectNegative Var(dwarf_strict,1) Don't emit DWARF additions beyond selected version. gtoggle -Common Report Var(flag_gtoggle) +Common Driver Report Var(flag_gtoggle) Toggle debug information generation. gvms -Common JoinedOrMissing Negative(gxcoff) +Common Driver JoinedOrMissing Negative(gxcoff) Generate debug information in VMS format. gxcoff -Common JoinedOrMissing Negative(gxcoff+) +Common Driver JoinedOrMissing Negative(gxcoff+) Generate debug information in XCOFF format. gxcoff+ -Common JoinedOrMissing Negative(gcoff) +Common Driver JoinedOrMissing Negative(gcoff) Generate debug information in extended XCOFF format. Enum --- gcc/c-family/c.opt.jj 2017-01-09 22:46:03.000000000 +0100 +++ gcc/c-family/c.opt 2017-01-10 19:39:27.226712003 +0100 @@ -1762,7 +1762,7 @@ ObjC ObjC++ Var(flag_zero_link) Generate lazy class lookup (via objc_getClass()) for use in Zero-Link mode. gen-decls -ObjC ObjC++ Var(flag_gen_declaration) +ObjC ObjC++ Driver Var(flag_gen_declaration) Dump declarations to a .decl file. femit-struct-debug-baseonly --- gcc/ada/gcc-interface/lang.opt.jj 2016-01-20 17:51:52.000000000 +0100 +++ gcc/ada/gcc-interface/lang.opt 2017-01-10 19:10:24.726499253 +0100 @@ -81,15 +81,15 @@ Ada AdaWhy AdaSCIL Make \"char\" signed by default. gant -Ada AdaWhy AdaSCIL Joined Undocumented +Ada AdaWhy AdaSCIL Driver Joined Undocumented Catch typos. gnatO -Ada AdaWhy AdaSCIL Separate +Ada AdaWhy AdaSCIL Driver Separate Set name of output ALI file (internal switch). gnat -Ada AdaWhy AdaSCIL Joined +Ada AdaWhy AdaSCIL Driver Joined -gnat<options> Specify options to GNAT. fbuiltin-printf Jakub