public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Introduce DWARF_VERSION_DEFAULT (and redefine for VxWorks)
@ 2022-09-30 16:17 Olivier Hainque
  2022-10-06 12:15 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Hainque @ 2022-09-30 16:17 UTC (permalink / raw)
  To: gcc-patches; +Cc: Olivier Hainque

[-- Attachment #1: Type: text/plain, Size: 1435 bytes --]

Hello,

This change is a proposal to introduce a target overridable macro
to replace the hardcoded value used in common.opt to initialize
dwarf_version.

The main advantage compared to special code in a target
override_options hook is that redefinitions by target config files
are visible by both the compiler proper and by the driver, which
might refer to dwarf_version in ASM_DEBUG_SPECs and friends.

This is useful at least on VxWorks, where we usually need to
default to dwarf 4 or even 2 to accommodate non-gdb debuggers
provided by the environment, including for assembly sources
used in libgcc for some ports (witnessed with lse.S on aarch64).

We have been using this in a lot of gcc-11 based toolchains
for various configurations for a while, cross and native.

This is a noop for anything but VxWorks and helped cure crashes
of target debuggers in VxWorks environments.

Bootstrapped and regression tested for mainline on x86_64-linux.

Is this ok to commit?

Thanks in advance!

Best Regards,

Olivier

2022-09-30  Olivier Hainque  <hainque@adacore.com>

gcc/
	* defaults.h (DWARF_DEFAULT_VERSION): Define if not
	defined already.
	* common.opt (gdwarf-): Use it.
	* doc/tm.texi.in (DWARF_DEFAULT_VERSION): Document.
	* doc/tm.texi: Update accordingly.

	* config/vxworks.h (DWARF_DEFAULT_VERSION): Redefine.
	* config/vxworks.cc: Remove code setting dwarf_version, now
	handled by the DWARF_DEFAULT_VERSION redefinition.


[-- Attachment #2: 0012-Introduce-DWARF_VERSION_DEFAULT-and-redefine-for-VxW.patch --]
[-- Type: application/octet-stream, Size: 5949 bytes --]

From 066876a82af48bdcc826ce38404cc7725a1a68f3 Mon Sep 17 00:00:00 2001
From: Olivier Hainque <hainque@adacore.com>
Date: Mon, 26 Sep 2022 16:05:48 +0000
Subject: [PATCH 12/18] Introduce DWARF_VERSION_DEFAULT and redefine for
 VxWorks

This change introduces a target overridable macro to replace
the hardcoded value used to initialize dwarf_version from common.opt.

The main advantage compared to special code in a target
override_options hook is that redefinitions by target config files
are visible by both the compiler proper and by the driver, which
might refer to dwarf_version in ASM_DEBUG_SPECs and friends.

This is useful at least on VxWorks, where we usually need to
default to dwarf 4 or even 2 to accommodate non-gdb debuggers
provided by the environment, including for assembly sources
used in libgcc for some ports (witnessed with lse.S on aarch64).

2022-02-28  Olivier Hainque  <hainque@adacore.com>

gcc/
	* defaults.h (DWARF_DEFAULT_VERSION): Define if not
	defined already.
	* common.opt (gdwarf-): Use it.
	* doc/tm.texi.in (DWARF_DEFAULT_VERSION): Document.
	* doc/tm.texi: Update accordingly.

	* config/vxworks.h (DWARF_DEFAULT_VERSION): Redefine.
	* config/vxworks.cc: Remove code setting dwarf_version, now
	handled by the DWARF_DEFAULT_VERSION redefinition.
---
 gcc/common.opt        |  2 +-
 gcc/config/vxworks.cc | 10 ++--------
 gcc/config/vxworks.h  |  8 ++++----
 gcc/defaults.h        |  6 ++++++
 gcc/doc/tm.texi       |  6 ++++++
 gcc/doc/tm.texi.in    |  6 ++++++
 6 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 296d6f194bf..8460bc1a6e5 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3317,7 +3317,7 @@ Common Driver JoinedOrMissing Negative(gdwarf-)
 Generate debug information in default version of DWARF format.
 
 gdwarf-
-Common Driver Joined UInteger Var(dwarf_version) Init(5)
+Common Driver Joined UInteger Var(dwarf_version) Init(DWARF_VERSION_DEFAULT)
 Generate debug information in DWARF v2 (or later) format.
 
 gdwarf32
diff --git a/gcc/config/vxworks.cc b/gcc/config/vxworks.cc
index 9d2587391b4..f0c0df29367 100644
--- a/gcc/config/vxworks.cc
+++ b/gcc/config/vxworks.cc
@@ -164,16 +164,10 @@ vxworks_override_options (void)
   if (flag_pic > 0 && !TARGET_VXWORKS_RTP)
     error ("PIC is only supported for RTPs");
 
-  /* VxWorks comes with non-gdb debuggers which only support strict
-     dwarf up to certain version.  Default dwarf control to friendly
-     values for these.  */
-
+  /* VxWorks comes with non-gdb debuggers which only support strict dwarf
+     up to certain versions, as controlled by DWARF_VERSION_DEFAULT.  */
   if (!OPTION_SET_P (dwarf_strict))
     dwarf_strict = 1;
-
-  if (!OPTION_SET_P (dwarf_version))
-    dwarf_version = VXWORKS_DWARF_VERSION_DEFAULT;
-
 }
 
 /* We don't want to use library symbol __clear_cache on SR0640.  Avoid
diff --git a/gcc/config/vxworks.h b/gcc/config/vxworks.h
index e644b88a253..1ad927e8aba 100644
--- a/gcc/config/vxworks.h
+++ b/gcc/config/vxworks.h
@@ -406,11 +406,11 @@ extern void vxworks_asm_out_destructor (rtx symbol, int priority);
   vxworks_emit_call_builtin___clear_cache
 extern void vxworks_emit_call_builtin___clear_cache (rtx begin, rtx end);
 
-/* Default dwarf control values, for non-gdb debuggers that come with
-   VxWorks.  */
+/* Default dwarf control values, accounting for non-gdb debuggers that come
+   with VxWorks.  */
 
-#undef VXWORKS_DWARF_VERSION_DEFAULT
-#define VXWORKS_DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 4 : 2)
+#undef DWARF_VERSION_DEFAULT
+#define DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 4 : 2)
 
 #undef DWARF_GNAT_ENCODINGS_DEFAULT
 #define DWARF_GNAT_ENCODINGS_DEFAULT \
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 953605c1627..376687d91b1 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -1441,6 +1441,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define DWARF_GNAT_ENCODINGS_DEFAULT DWARF_GNAT_ENCODINGS_GDB
 #endif
 
+/* When generating dwarf info, the default standard version we'll honor
+   and advertise in absence of -gdwarf-<N> on the command line.  */
+#ifndef DWARF_VERSION_DEFAULT
+#define DWARF_VERSION_DEFAULT 5
+#endif
+
 #ifndef USED_FOR_TARGET
 /* Done this way to keep gengtype happy.  */
 #if BITS_PER_UNIT == 8
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 858bfb80cec..3111d74c418 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -3294,6 +3294,12 @@ someone decided it was a good idea to use that register number to
 terminate the stack backtrace.  New ports should avoid this.
 @end defmac
 
+@defmac DWARF_VERSION_DEFAULT
+A C expression whose value is the default dwarf standard version we'll honor
+and advertise when generating dwarf debug information, in absence of
+an explicit @option{-gdwarf-@var{version}} option on the command line.
+@end defmac
+
 @deftypefn {Target Hook} void TARGET_DWARF_HANDLE_FRAME_UNSPEC (const char *@var{label}, rtx @var{pattern}, int @var{index})
 This target hook allows the backend to emit frame-related insns that
 contain UNSPECs or UNSPEC_VOLATILEs.  The DWARF 2 call frame debugging
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 21b849ea32a..501ddf147e4 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -2575,6 +2575,12 @@ someone decided it was a good idea to use that register number to
 terminate the stack backtrace.  New ports should avoid this.
 @end defmac
 
+@defmac DWARF_VERSION_DEFAULT
+A C expression whose value is the default dwarf standard version we'll honor
+and advertise when generating dwarf debug information, in absence of
+an explicit @option{-gdwarf-@var{version}} option on the command line.
+@end defmac
+
 @hook TARGET_DWARF_HANDLE_FRAME_UNSPEC
 
 @hook TARGET_DWARF_POLY_INDETERMINATE_VALUE
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-06 16:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 16:17 [PATCH] Introduce DWARF_VERSION_DEFAULT (and redefine for VxWorks) Olivier Hainque
2022-10-06 12:15 ` Richard Biener
2022-10-06 16:48   ` Olivier Hainque

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).