[gdb/symtab] Work around PR gas/29517, dwarf2 case

Message ID 20240501144441.4921-1-tdevries@suse.de
State Committed
Headers
Series [gdb/symtab] Work around PR gas/29517, dwarf2 case |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries May 1, 2024, 2:44 p.m. UTC
  In commit 1d45d90934b ("[gdb/symtab] Work around PR gas/29517") we added a
workaround for PR gas/29517.

The problem is present in gas version 2.39, and fixed in 2.40, so the
workaround is only active for gas version == 2.39.

However, the problem in gas is only fixed for dwarf version >= 3, which
supports DW_TAG_unspecified_type.

Fix this by also activating the workaround for dwarf version == 2.

Tested on x86_64-linux.

PR symtab/31689
https://sourceware.org/bugzilla/show_bug.cgi?id=31689
---
 gdb/dwarf2/read.c                             |  5 +++-
 .../gdb.dwarf2/dw2-unspecified-type-foo.c     |  7 ++++++
 .../gdb.dwarf2/dw2-unspecified-type.c         |  3 ++-
 .../gdb.dwarf2/dw2-unspecified-type.exp       | 23 ++++++++++++++++++-
 4 files changed, 35 insertions(+), 3 deletions(-)


base-commit: 347775edd49c0d8f6fda3d13a39c8cac6196da30
  

Comments

Kevin Buettner May 2, 2024, 2:07 a.m. UTC | #1
On Wed,  1 May 2024 16:44:41 +0200
Tom de Vries <tdevries@suse.de> wrote:

> In commit 1d45d90934b ("[gdb/symtab] Work around PR gas/29517") we added a
> workaround for PR gas/29517.
> 
> The problem is present in gas version 2.39, and fixed in 2.40, so the
> workaround is only active for gas version == 2.39.
> 
> However, the problem in gas is only fixed for dwarf version >= 3, which
> supports DW_TAG_unspecified_type.
> 
> Fix this by also activating the workaround for dwarf version == 2.
> 
> Tested on x86_64-linux.
> 
> PR symtab/31689
> https://sourceware.org/bugzilla/show_bug.cgi?id=31689

LGTM.

Approved-by: Kevin Buettner <kevinb@redhat.com>
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7eacafc25b5..00e8608f9ce 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14549,10 +14549,13 @@  read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 
   type = die_type (die, cu);
 
+  /* PR gas/29517 occurs in 2.39, and is fixed in 2.40, but it's only fixed
+     for dwarf version >= 3 which supports DW_TAG_unspecified_type.  */
   if (type->code () == TYPE_CODE_VOID
       && !type->is_stub ()
       && die->child == nullptr
-      && producer_is_gas_2_39 (cu))
+      && (cu->per_cu->version () == 2
+	  || producer_is_gas_2_39 (cu)))
     {
       /* Work around PR gas/29517, pretend we have an DW_TAG_unspecified_type
 	 return type.  */
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c
index 46c543b7b59..76b8b15a7b9 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c
+++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type-foo.c
@@ -21,3 +21,10 @@  foo (void)
   asm ("foo_label: .globl foo_label");
   return 0;
 }
+
+int
+foo2 (void)
+{
+  asm ("foo2_label: .globl foo2_label");
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c
index 666c7b70bba..7f3add04c1b 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c
+++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c
@@ -16,6 +16,7 @@ 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 extern int foo (void);
+extern int foo2 (void);
 
 int
 bar (void)
@@ -27,6 +28,6 @@  bar (void)
 int
 main (void)
 {
-  int res = foo () + bar ();
+  int res = foo () + bar () + foo2 ();
   return res;
 }
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp
index 84c27fc2e1d..82b5bf8f003 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp
@@ -34,11 +34,19 @@  lassign $bar_res \
     bar_start bar_len
 set bar_end "$bar_start + $bar_len"
 
+set foo2_res \
+    [function_range foo2 \
+	 [list ${srcdir}/${subdir}/$srcfile ${srcdir}/${subdir}/$srcfile2]]
+lassign $foo2_res \
+    foo2_start foo2_len
+set foo2_end "$foo2_start + $foo2_len"
+
 # Create the DWARF.
 set asm_file [standard_output_file $srcfile3]
 Dwarf::assemble $asm_file {
     global foo_start foo_end
     global bar_start bar_end
+    global foo2_start foo2_end
     declare_labels unspecified_type_label
 
     cu {} {
@@ -68,6 +76,19 @@  Dwarf::assemble $asm_file {
 	    }
 	}
     }
+
+    cu { version 2 } {
+	compile_unit {
+	    {language @DW_LANG_Mips_Assembler}
+	    {producer "GNU AS 2.40.0"}
+	} {
+	    DW_TAG_subprogram {
+		{name foo2}
+		{low_pc $foo2_start addr}
+		{high_pc $foo2_end addr}
+	    }
+	}
+    }
 }
 
 if [prepare_for_testing "failed to prepare" $testfile \
@@ -79,7 +100,7 @@  if ![runto_main] {
     return -1
 }
 
-foreach f {foo bar} {
+foreach f {foo bar foo2} {
     # Print the function type.  Return type should be stub type, which is printed
     # as void.
     gdb_test "ptype $f" "type = void \\(void\\)"