aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-10-07 10:55:35 +0200
committerJakub Jelinek <jakub@redhat.com>2020-10-07 10:55:35 +0200
commit6923255e35a3d54f2083ad0f67edebb3f1b86506 (patch)
tree1213c32f42648ba528ade8ab2e1c02e71ed72c14 /gcc/gcc.c
parente91c34262d2dd06da4b9436744bff89007dee2c9 (diff)
downloadgcc-6923255e35a3d54f2083ad0f67edebb3f1b86506.zip
gcc-6923255e35a3d54f2083ad0f67edebb3f1b86506.tar.gz
gcc-6923255e35a3d54f2083ad0f67edebb3f1b86506.tar.bz2
debug: Pass --gdwarf-N to assembler if fixed gas is detected during configure
> > As for the test assembly, I'd say we should take > > #define F void foo (void) {} > > F > > compile it with > > gcc -S -O2 -g1 -dA -gno-as-loc-support -fno-merge-debug-strings > > remove .cfi_* directives, remove the ret instruction, change @function > > and @progbits to %function and %progbits, change .uleb128 to just .byte, > > I think all the values should be small enough, maybe change .value to > > .2byte and .long to .4byte (whatever is most portable across different > > arches and gas versions), simplify (shorten) strings and adjust > > sizes, and do something with the .quad directives, that is dependent on > > the address size, perhaps just take those attributes out and adjust > > .debug_abbrev? Finally, remove all comments (emit them in the first case > > just to better understand the debug info). > > I'm afraid it is hard to avoid the .quad or .8byte. > Here is a 64-bit address version that assembles fine by both x86_64 and > aarch64 as. > Unfortunately doesn't fail with broken gas versions with -gdwarf-2 without > the nop, so we'll need at least a nop in there. > Fortunately gcc/configure.ac already determines the right nop insn for the > target, in $insn. > So I guess what we want next is have the 32-bit version of this with .4byte > instead of .8byte and just let's try to assemble both versions, first > without -gdwarf-2 and the one that succeeds assemble again with -gdwarf-2 > and check for the duplicate .debug_line sections error. Ok, here it is in patch form. I've briefly tested it, with the older binutils I have around (no --gdwarf-N support), with latest gas (--gdwarf-N that can be passed to as even when compiling C/C++ etc. code and emitting .debug_line) and latest gas with Mark's fix reverted (--gdwarf-N support, but can only pass it to as when assembling user .s/.S files, not when compiling C/C++ etc.). 2020-10-07 Jakub Jelinek <jakub@redhat.com> * configure.ac (HAVE_AS_GDWARF_5_DEBUG_FLAG, HAVE_AS_WORKING_DWARF_4_FLAG): New tests. * gcc.c (ASM_DEBUG_DWARF_OPTION): Define. (ASM_DEBUG_SPEC): Use ASM_DEBUG_DWARF_OPTION instead of "--gdwarf2". Use %{cond:opt1;:opt2} style. (ASM_DEBUG_OPTION_DWARF_OPT): Define. (ASM_DEBUG_OPTION_SPEC): Define. (asm_debug_option): New variable. (asm_options): Add "%(asm_debug_option)". (static_specs): Add asm_debug_option entry. (static_spec_functions): Add dwarf-version-gt. (debug_level_greater_than_spec_func): New function. * config/darwin.h (ASM_DEBUG_OPTION_SPEC): Define. * config/darwin9.h (ASM_DEBUG_OPTION_SPEC): Redefine. * config.in: Regenerated. * configure: Regenerated.
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 531f4e0..ff7b6c4 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -430,6 +430,7 @@ static const char *pass_through_libs_spec_func (int, const char **);
static const char *dumps_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 const char *dwarf_version_greater_than_spec_func (int, const char **);
static const char *find_fortran_preinclude_file (int, const char **);
static char *convert_white_space (char *);
static char *quote_spec (char *);
@@ -876,22 +877,39 @@ proper position among the other output files. */
#endif /* HAVE_LD_COMPRESS_DEBUG >= 2 */
/* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
- to the assembler. */
+ to the assembler, when compiling assembly sources only. */
#ifndef ASM_DEBUG_SPEC
+# if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_4_FLAG)
+/* If --gdwarf-N is supported and as can handle even compiler generated
+ .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather
+ than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc.
+ compilations. */
+# define ASM_DEBUG_DWARF_OPTION ""
+# elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG)
+# define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \
+ "%:dwarf-version-gt(3):--gdwarf-4;" \
+ "%:dwarf-version-gt(2):--gdwarf-3;" \
+ ":--gdwarf2}"
+# else
+# define ASM_DEBUG_DWARF_OPTION "--gdwarf2"
+# endif
# if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
&& defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
# define ASM_DEBUG_SPEC \
(PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
? "%{%:debug-level-gt(0):" \
- "%{gdwarf*:--gdwarf2}%{!gdwarf*:%{g*:--gstabs}}}" ASM_MAP \
+ "%{gdwarf*:" ASM_DEBUG_DWARF_OPTION "};" \
+ ":%{g*:--gstabs}}" ASM_MAP \
: "%{%:debug-level-gt(0):" \
- "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP)
+ "%{gstabs*:--gstabs;" \
+ ":%{g*:" ASM_DEBUG_DWARF_OPTION "}}}" ASM_MAP)
# else
# if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
# 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*:%{%:debug-level-gt(0):--gdwarf2}}" ASM_MAP
+# define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \
+ ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP
# endif
# endif
#endif
@@ -899,6 +917,32 @@ proper position among the other output files. */
# define ASM_DEBUG_SPEC ""
#endif
+/* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g'
+ to the assembler when compiling all sources. */
+#ifndef ASM_DEBUG_OPTION_SPEC
+# if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_4_FLAG)
+# define ASM_DEBUG_OPTION_DWARF_OPT \
+ "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \
+ "%:dwarf-version-gt(3):--gdwarf-4 ;" \
+ "%:dwarf-version-gt(2):--gdwarf-3 ;" \
+ ":--gdwarf2 }"
+# if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO)
+# define ASM_DEBUG_OPTION_SPEC \
+ (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
+ ? "%{%:debug-level-gt(0):" \
+ "%{gdwarf*:" ASM_DEBUG_OPTION_DWARF_OPT "}}" \
+ : "%{%:debug-level-gt(0):" \
+ "%{!gstabs*:%{g*:" ASM_DEBUG_OPTION_DWARF_OPT "}}}")
+# elif defined(DWARF2_DEBUGGING_INFO)
+# define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \
+ ASM_DEBUG_OPTION_DWARF_OPT "}}"
+# endif
+# endif
+#endif
+#ifndef ASM_DEBUG_OPTION_SPEC
+# define ASM_DEBUG_OPTION_SPEC ""
+#endif
+
/* Here is the spec for running the linker, after compiling all files. */
/* This is overridable by the target in case they need to specify the
@@ -1113,6 +1157,7 @@ proper position among the other output files. */
#endif
static const char *asm_debug = ASM_DEBUG_SPEC;
+static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC;
static const char *cpp_spec = CPP_SPEC;
static const char *cc1_spec = CC1_SPEC;
static const char *cc1plus_spec = CC1PLUS_SPEC;
@@ -1212,6 +1257,7 @@ static const char *asm_options =
to the assembler equivalents. */
"%{v} %{w:-W} %{I*} "
#endif
+"%(asm_debug_option)"
ASM_COMPRESS_DEBUG_SPEC
"%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
@@ -1608,6 +1654,7 @@ static struct spec_list static_specs[] =
{
INIT_STATIC_SPEC ("asm", &asm_spec),
INIT_STATIC_SPEC ("asm_debug", &asm_debug),
+ INIT_STATIC_SPEC ("asm_debug_option", &asm_debug_option),
INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
INIT_STATIC_SPEC ("asm_options", &asm_options),
INIT_STATIC_SPEC ("invoke_as", &invoke_as),
@@ -1690,6 +1737,7 @@ static const struct spec_function static_spec_functions[] =
{ "dumps", dumps_spec_func },
{ "gt", greater_than_spec_func },
{ "debug-level-gt", debug_level_greater_than_spec_func },
+ { "dwarf-version-gt", dwarf_version_greater_than_spec_func },
{ "fortran-preinclude-file", find_fortran_preinclude_file},
#ifdef EXTRA_SPEC_FUNCTIONS
EXTRA_SPEC_FUNCTIONS
@@ -10614,6 +10662,27 @@ debug_level_greater_than_spec_func (int argc, const char **argv)
return NULL;
}
+/* Returns "" if dwarf_version is greater than ARGV[ARGC-1].
+ Otherwise, return NULL. */
+
+static const char *
+dwarf_version_greater_than_spec_func (int argc, const char **argv)
+{
+ char *converted;
+
+ if (argc != 1)
+ fatal_error (input_location,
+ "wrong number of arguments to %%:dwarf-version-gt");
+
+ long arg = strtol (argv[0], &converted, 10);
+ gcc_assert (converted != argv[0]);
+
+ if (dwarf_version > arg)
+ return "";
+
+ return NULL;
+}
+
static void
path_prefix_reset (path_prefix *prefix)
{