[PATCH/RFC] Add --with-dwarf4 configure option.

Message ID 00f401da4720$64e86b90$2eb942b0$@nextmovesoftware.com
State New
Headers
Series [PATCH/RFC] Add --with-dwarf4 configure option. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Roger Sayle Jan. 14, 2024, 7:32 p.m. UTC
  This patch fixes three of the four unexpected failures that I'm seeing
in the gcc testsuite on x86_64-pc-linux-gnu.  The three FAILs are:
FAIL: gcc.c-torture/execute/fprintf-2.c   -O3 -g  (test for excess errors)
FAIL: gcc.c-torture/execute/printf-2.c   -O3 -g  (test for excess errors)
FAIL: gcc.c-torture/execute/user-printf.c   -O3 -g  (test for excess errors)

and are caused by the linker/toolchain (GNU ld 2.27 on RedHat 7) issuing
a link-time warning:
/usr/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles
version 2, 3 and 4 information.

This also explains why these c-torture tests only fail with -g.

One solution might be to tweak/improve GCC's testsuite to ignore
these warnings.  However, ideally it should also be possible to
configure gcc not to generate dwarf5 debugging information on
systems that don't/can't support it.  This patch supplements the
current --with-dwarf2 configure option with the addition of a
--with-dwarf4 option that adds a tm-dwarf4.h to $tm_file (using
the same mechanism as --with-dwarf2) that changes/redefines
DWARF_VERSION_DEFAULT to 4 (overriding the current default of 5),

This patch has been tested on x86_64-pc-linux-gnu, with a full
make bootstrap, both with and without --with-dwarf4.  This is
fixes the three failures above, and causes no new failures outside
of the gcc.dg/guality directory.  Unfortunately, the guality
testsuite contains a large number of tests that assume support
for dwarf5 and don't (yet) check check_effective_target_dwarf5.
Hopefully, adding --with-dwarf4 will help improve/test the
portability of the guality testsuite.

Ok for mainline?  An alternative implementation might be to
allow integer values for $with_dwarf such that --with-dwarf5,
--with-dwarf3 etc. do the right thing.  In fact, I'd originally
misread the documentation and assumed --with-dwarf4 was already
supported.


2024-01-14  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * configure.ac: Add a with --with dwarf4 option.
        * configure: Regenerate.
        * config/tm-dwarf4.h: New target file to define
        DWARF_VERSION_DEFAULT to 4.


Thanks in advance,
Roger
--
  

Comments

Richard Biener Jan. 15, 2024, 9:22 a.m. UTC | #1
On Sun, Jan 14, 2024 at 8:32 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch fixes three of the four unexpected failures that I'm seeing
> in the gcc testsuite on x86_64-pc-linux-gnu.  The three FAILs are:
> FAIL: gcc.c-torture/execute/fprintf-2.c   -O3 -g  (test for excess errors)
> FAIL: gcc.c-torture/execute/printf-2.c   -O3 -g  (test for excess errors)
> FAIL: gcc.c-torture/execute/user-printf.c   -O3 -g  (test for excess errors)
>
> and are caused by the linker/toolchain (GNU ld 2.27 on RedHat 7) issuing
> a link-time warning:
> /usr/bin/ld: Dwarf Error: found dwarf version '5', this reader only handles
> version 2, 3 and 4 information.

We're patching GCC on old systems to avoid this (and fallout from tools
not supporting DWARF5).

> This also explains why these c-torture tests only fail with -g.
>
> One solution might be to tweak/improve GCC's testsuite to ignore
> these warnings.  However, ideally it should also be possible to
> configure gcc not to generate dwarf5 debugging information on
> systems that don't/can't support it.  This patch supplements the
> current --with-dwarf2 configure option with the addition of a
> --with-dwarf4 option that adds a tm-dwarf4.h to $tm_file (using
> the same mechanism as --with-dwarf2) that changes/redefines
> DWARF_VERSION_DEFAULT to 4 (overriding the current default of 5),
>
> This patch has been tested on x86_64-pc-linux-gnu, with a full
> make bootstrap, both with and without --with-dwarf4.  This is
> fixes the three failures above, and causes no new failures outside
> of the gcc.dg/guality directory.  Unfortunately, the guality
> testsuite contains a large number of tests that assume support
> for dwarf5 and don't (yet) check check_effective_target_dwarf5.
> Hopefully, adding --with-dwarf4 will help improve/test the
> portability of the guality testsuite.
>
> Ok for mainline?  An alternative implementation might be to
> allow integer values for $with_dwarf such that --with-dwarf5,
> --with-dwarf3 etc. do the right thing.  In fact, I'd originally
> misread the documentation and assumed --with-dwarf4 was already
> supported.

The only thing to watch out for is ordering of tm_file since there's

./config/vxworks.h:#undef DWARF_VERSION_DEFAULT
./config/vxworks.h:#define DWARF_VERSION_DEFAULT (TARGET_VXWORKS7 ? 3 : 2)

it looks like the --with-dwarf4 adjustment is before the vxworks handling
so the vxworks handling will prevail even with --with-dwarf4.  Not sure
if that's intended?

I think this also needs documenting in install.texi (and mention whether
target specific defaults will prevail or not)

Richard.

>
> 2024-01-14  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * configure.ac: Add a with --with dwarf4 option.
>         * configure: Regenerate.
>         * config/tm-dwarf4.h: New target file to define
>         DWARF_VERSION_DEFAULT to 4.
>
>
> Thanks in advance,
> Roger
> --
>
  

Patch

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 596e5f2..2ce9093 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1036,6 +1036,11 @@  AC_ARG_WITH(dwarf2,
 dwarf2="$with_dwarf2",
 dwarf2=no)
 
+AC_ARG_WITH(dwarf4,
+[AS_HELP_STRING([--with-dwarf4], [force the default debug format to be DWARF 4])],
+dwarf4="$with_dwarf4",
+dwarf4=no)
+
 AC_ARG_ENABLE(shared,
 [AS_HELP_STRING([--disable-shared], [don't provide a shared libgcc])],
 [
@@ -1916,6 +1921,10 @@  if test x"$dwarf2" = xyes
 then tm_file="$tm_file tm-dwarf2.h"
 fi
 
+if test x"$dwarf4" = xyes
+then tm_file="$tm_file tm-dwarf4.h"
+fi
+
 # Say what files are being used for the output code and MD file.
 echo "Using \`$srcdir/config/$out_file' for machine-specific logic."
 echo "Using \`$srcdir/config/$md_file' as machine description file."
diff --git a/gcc/config/tm-dwarf4.h b/gcc/config/tm-dwarf4.h
new file mode 100644
index 0000000..9557b40
--- /dev/null
+++ b/gcc/config/tm-dwarf4.h
@@ -0,0 +1,3 @@ 
+/* Make Dwarf4 debugging info the default */
+#undef	 DWARF_VERSION_DEFAULT
+#define  DWARF_VERSION_DEFAULT 4