Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] dwarf2: avoid decoding .debug_line for type units
@ 2026-03-18 13:35 Bratislav Filipovic
  2026-04-01 14:54 ` [PING][PATCH] " Filipovic, Bratislav
  2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
  0 siblings, 2 replies; 10+ messages in thread
From: Bratislav Filipovic @ 2026-03-18 13:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: simon.marchi, Bratislav Filipovic

Running gdb.dwarf2/pr13961.exp with clang fails with an internal error:

  gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu:
  Assertion `!cu->per_cu->is_debug_types ()' failed.

pr13961 is a legacy .S test that references a .debug_line label from
both a CU and a TU.  The assembly includes an empty .debug_line section
declaration:

  .section .debug_line,"",%progbits
.Ldebug_line0:

With gcc this results in a dummy (valid, but content-less) .debug_line
header being emitted, so GDB can build a line header and resolve file
indices.  With clang the .debug_line section can be missing/empty,
leaving the line header unset.

During symbol creation, new_symbol may then try to lazily decode the
CU-only line header while processing a type unit, which triggers the
assertion above.

Fix this by only decoding the line header for non-type units.  If no
line header is available, emit a complaint and continue without setting
the symtab rather than attempting CU-only line decoding from a TU.

Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang)
---
 gdb/dwarf2/read.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8b87d58d..2e897e65 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15484,23 +15484,32 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	  if (index_cst.has_value ())
 	    {
 	      file_name_index file_index = (file_name_index) *index_cst;
-	      struct file_entry *fe;
 
-	      if (file_cu->line_header == nullptr)
+	      /* Resolve DW_AT_decl_file/DW_AT_call_file.  These attributes are
+		 indices into the file-name table, which lives in the unit's
+		 decoded .debug_line header.
+		 decode_line_header_for_cu is CU-only and asserts on debug_types.
+		 For type units, the TU setup code runs before processing child
+		 DIEs, so if line_header is still nullptr here it means there is no
+		 usable line table for this unit.  */
+	      if (file_cu->line_header == nullptr
+		  && !file_cu->per_cu->is_debug_types ())
 		{
 		  file_and_directory fnd (nullptr, nullptr);
 		  decode_line_header_for_cu (file_cu->dies, file_cu, fnd);
 		}
 
 	      if (file_cu->line_header != nullptr)
-		fe = file_cu->line_header->file_name_at (file_index);
-	      else
-		fe = NULL;
-
-	      if (fe == NULL)
-		complaint (_("file index out of range"));
+		{
+		  if (file_entry *fe
+		      = file_cu->line_header->file_name_at (file_index);
+		      fe != nullptr)
+		    sym->set_symtab (fe->symtab (*file_cu));
+		  else
+		    complaint (_("file index out of range"));
+		}
 	      else
-		sym->set_symtab (fe->symtab (*file_cu));
+		complaint (_("missing .debug_line information to resolve file index"));
 	    }
 	}
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [PATCH] gdb/testsuite: skip ada-valprint-error with clang
@ 2026-03-31 14:49 Tom de Vries
  2026-04-01 10:33 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
  0 siblings, 1 reply; 10+ messages in thread
From: Tom de Vries @ 2026-03-31 14:49 UTC (permalink / raw)
  To: Bratislav Filipovic, gdb-patches; +Cc: simon.marchi

On 3/31/26 4:29 PM, Bratislav Filipovic wrote:
> The ada-valprint-error.exp test fails when compiled with clang due
> to a linker relocation issue in the test infrastructure, not a GDB
> bug.
> 
> The test compiles ada-valprint-error.c with nodebug flags, then
> links it with a separate DWARF .o file generated by lib/dwarf.exp.
> The C source defines:
> 
>      int buffer[] = {0, 0};
>      void *fd__global = &buffer;
> 
> This requires the linker to apply an R_X86_64_64 relocation to
> store buffer's address into fd__global.  With GCC, the linker
> correctly applies this relocation.  With clang, the linker fails
> to apply it, leaving fd__global as NULL.
> 
> Binary evidence:
> - GCC binary: fd__global = 0x4020 (correct address of buffer)
> - Clang binary: fd__global = 0x0 (NULL)
> 
> Both .o files contain the R_X86_64_64 relocation entry, but the
> final linked binary differs:
> - GCC emits fd__global in .data.rel.local section -> relocation works
> - Clang emits fd__global in .data section -> relocation fails
> 
> This appears to be a toolchain/testsuite compatibility issue when
> linking nodebug object files with separate DWARF objects.  Skip
> the test for clang to avoid false failures.
> 
> Tested on x86_64-linux-gnu with both GCC and clang.
> 
> ---
>   gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> index f3d61e91..c23d58a8 100644
> --- a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> +++ b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> @@ -14,6 +14,14 @@
>   # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>   load_lib dwarf.exp
>   
> +# Clang's linker fails to apply relocations when linking nodebug .o
> +# with separate DWARF .o, resulting in fd__global being NULL instead
> +# of pointing to buffer.
> +if {[test_compiler_info "clang-*"]} {
> +    unsupported "clang linker relocation issue with nodebug+DWARF linking"
> +    return
> +}

Hi,

I think it would be useful if you'd document what version of clang 
you're having this problem with.

And since it's not clear to me from your explanation whether it's a 
compiler or linker bug, perhaps linker version as well?

Also, this test-case passes for me with clang (17.0.6, 19.1.7, with ld 
2.45.0), so disabling it entirely for clang seems too intrusive.

How about printing the value of fd__global, and declaring the test-case 
unsupported if the value is nullptr?

Thanks,
- Tom

> +
>   # This test can only be run on targets which support DWARF-2 and use gas.
>   require dwarf2_support
>   


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

end of thread, other threads:[~2026-04-16 15:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-18 13:35 [PATCH] dwarf2: avoid decoding .debug_line for type units Bratislav Filipovic
2026-04-01 14:54 ` [PING][PATCH] " Filipovic, Bratislav
2026-04-16 14:10 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
2026-04-16 15:14   ` Tom de Vries
2026-03-31 14:49 [PATCH] gdb/testsuite: skip ada-valprint-error with clang Tom de Vries
2026-04-01 10:33 ` [PATCH] testsuite: ada-valprint-error relocation issue Bratislav Filipovic
2026-04-01 11:12   ` Tom de Vries
2026-04-01 14:10     ` Bratislav Filipovic
2026-04-01 18:12       ` Tom de Vries
2026-04-02 13:12         ` Filipovic, Bratislav
2026-04-03  6:18           ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox