From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id obbTL5BgDmm6TSoAWB0awg (envelope-from ) for ; Fri, 07 Nov 2025 16:11:44 -0500 Received: by simark.ca (Postfix, from userid 112) id C0A511E04C; Fri, 07 Nov 2025 16:11:44 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1EAAA1E04C for ; Fri, 07 Nov 2025 16:11:44 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B27A23858D35 for ; Fri, 7 Nov 2025 21:11:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B27A23858D35 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id A1DB73858D32 for ; Fri, 7 Nov 2025 21:10:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1DB73858D32 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1DB73858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762549843; cv=none; b=NeJ2kiRro4kzHziIMxlDGWYMJ/NRpGDjnAcyJeMqMpoIuOciqFTMcyO3oSMpExHYg/2t7jXnxFiMQ8ZngHPYq0RA668GqwgAsUe0rWig7nDmPaKc3Bh9UxVvbf5bGXSjzjU7+msXX/WPsFHsHDLIRDCFqP+qhh4uxGpUlxr+YMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762549843; c=relaxed/simple; bh=j4hOXbQrCNpzXtxhmDUEQrOJRi3YGfDs9FAkhgcXhO0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NI1/ifSCfhLmRdFApwoVsqxLx8OOnLz2/pfbVXq+jdqg7AS5gouZ8UhKsAUb3X3WPXyA9Dd8Xp9xbSqwQuyC5jBuoqflM/0rdxTh1e9LR02jYRmrj4tsVu6PSIEWwlUam2vo+YOoc2hOpault1MP6uXXYemM+DsYOo/Q99Nl5d4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1DB73858D32 Received: by simark.ca (Postfix) id D39721E098; Fri, 07 Nov 2025 16:10:42 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/6] gdb/testsuite/dwarf: use single abbrev table in .dwo files Date: Fri, 7 Nov 2025 16:10:12 -0500 Message-ID: <20251107211041.520697-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20251107211041.520697-1-simon.marchi@efficios.com> References: <20251107211041.520697-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi When I wrote test gdb.dwarf2/fission-with-type-unit.exp, I did not use build_executable_and_dwo_files, because it wouldn't work to have multiple units in the .dwo file, each referring to their own abbrev table using labels. build_executable_and_dwo_files extracts the .dwo file content from the .o using objcopy (just like gcc does, I learned), meaning that the .dwo file never runs through a linker. Anything needing relocation (like labels pointing to abbrev tables) doesn't work. I instead opted to use gdb_compile_shlib to build the .dwo file on its own, so that those labels would get resolved. That causes problems now that I'm trying to write a test with multiple type units in a .dwo file, where each type unit should be in its own .debug_types section. Running the .dwo file through the linker causes all the .debug_types section to be collapsed into one. And generally, I think it was a bad idea to generate a .dwo file using the linker, since the idea behind .dwo files is that they do not need to be linked (therefore improving link times). We want to produce files as close to what an actual compiler would produce. This patch fixes this by doing what compilers do in the same situation: use a single abbrev table shared by all units in the .dwo file. This requires the following changes in lib/dwarf.exp: - Declare a new variable _dwo_abbrev_num, which holds the next abbrev number to use in the .dwo file's abbrev section (.debug_abbrev.dwo). Initialize this variable to 1. - When producing a CU or TU in a .dwo file, use 0 as the abbrev table offset. - When generating a DIE, return $_dwo_abbrev_num or $_abbrev_num, depending on whether the current CU is in a .dwo file. - After producing a CU or TU in a .dwo file, don't append the terminator byte. - After finishing producing the CUs and TUs, append the terminator byte in .debug_abbrev.dwo if we did output anything there. Update gdb.dwarf2/fission-with-type-units.exp to use build_executable_and_dwo_files, as it should. Change-Id: Iabbcf00db97faf2a4fa5fc71652ad273081189f9 --- .../gdb.dwarf2/fission-with-type-unit.exp | 29 +++----- gdb/testsuite/lib/dwarf.exp | 69 +++++++++++++++---- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp b/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp index 58cda296c67b..5c73001ec66b 100644 --- a/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp +++ b/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp @@ -21,25 +21,22 @@ load_lib dwarf.exp # This test can only be run on targets which support DWARF-2 and use gas. require dwarf2_support -standard_testfile .c -dw.S -dwo.S +standard_testfile .c -dw.S -set main_asm_file [standard_output_file $srcfile2] -set dwo_asm_file [standard_output_file $srcfile3] +set asm_file [standard_output_file $srcfile2] -# Debug info in the main file. -Dwarf::assemble $main_asm_file { +Dwarf::assemble $asm_file { + # In the main file. cu { version 5 dwo_id 0xF00D } { compile_unit { - DW_AT_dwo_name ${::gdb_test_file_name}.dwo DW_FORM_strp + DW_AT_dwo_name ${::gdb_test_file_name}-dw.dwo DW_FORM_strp } {} } -} -# Debug info in the DWO file. -Dwarf::assemble $dwo_asm_file { + # In the .dwo file. tu { fission 1 version 5 @@ -79,15 +76,11 @@ Dwarf::assemble $dwo_asm_file { } } -# Build main file. -if { [build_executable "${testfile}.exp" $binfile \ - [list ${srcfile} ${main_asm_file}] {nodebug}] } { - return -} - -# Build DWO file. -set dwo_file [standard_output_file ${testfile}.dwo] -if { [gdb_compile_shlib $dwo_asm_file $dwo_file nodebug] != "" } { +set obj [standard_output_file "${testfile}-dw.o"] +set dwo_file [standard_output_file "${testfile}.dwo"] +if {[build_executable_and_dwo_files "$testfile.exp" "${binfile}" {} \ + [list $asm_file {nodebug split-dwo} $obj] \ + [list $srcfile {nodebug}]]} { return } diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index ba8197d0bb8e..919e2e05687f 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -563,6 +563,9 @@ namespace eval Dwarf { # table. variable _abbrev_num + # The next available abbrev number in the (single) DWO abbrev table. + variable _dwo_abbrev_num + # The string table for this assembly. The key is the string; the # value is the label for that string. variable _strings @@ -1008,8 +1011,17 @@ namespace eval Dwarf { # table. proc _get_abbrev_num {} { variable _abbrev_num - set res $_abbrev_num - incr _abbrev_num + variable _dwo_abbrev_num + variable _cu_is_fission + + if { $_cu_is_fission } { + set res $_dwo_abbrev_num + incr _dwo_abbrev_num + } else { + set res $_abbrev_num + incr _abbrev_num + } + return $res } @@ -1538,8 +1550,17 @@ namespace eval Dwarf { _section $section set cu_num [incr _cu_count] - set my_abbrevs [_compute_label "abbrev${cu_num}_begin"] - set _abbrev_num 1 + + # Since .dwo files are not linked, we can't use a label to point to a + # specific place in the .debug_abbrev section. For .dwo files, we + # therefore use a single abbrev table (at offset 0) shared by all units + # in that file. + if { $_cu_is_fission } { + set my_abbrevs 0 + } else { + set my_abbrevs [_compute_label "abbrev${cu_num}_begin"] + set _abbrev_num 1 + } set _cu_label [_compute_label "cu${cu_num}_begin"] set start_label [_compute_label "cu${cu_num}_start"] @@ -1606,9 +1627,11 @@ namespace eval Dwarf { uplevel $_level $body - _defer_output $_abbrev_section { - # Emit the terminator. - _op .byte 0x0 "Abbrev end - Terminator" + if { !$_cu_is_fission } { + _defer_output $_abbrev_section { + # Emit the terminator. + _op .byte 0x0 "Abbrev end - Terminator" + } } define_label $end_label @@ -1681,8 +1704,17 @@ namespace eval Dwarf { _section $section set cu_num [incr _cu_count] - set my_abbrevs [_compute_label "abbrev${cu_num}_begin"] - set _abbrev_num 1 + + # Since .dwo files are not linked, we can't use a label to point to a + # specific place in the .debug_abbrev section. For .dwo files, we + # therefore use a single abbrev table (at offset 0) shared by all units + # in that file. + if { $_cu_is_fission } { + set my_abbrevs 0 + } else { + set my_abbrevs [_compute_label "abbrev${cu_num}_begin"] + set _abbrev_num 1 + } set _cu_label [_compute_label "cu${cu_num}_begin"] set start_label [_compute_label "cu${cu_num}_start"] @@ -1736,9 +1768,11 @@ namespace eval Dwarf { uplevel $_level $body - _defer_output $_abbrev_section { - # Emit the terminator. - _op .byte 0x0 "Abbrev end - Terminator" + if { !$_cu_is_fission } { + _defer_output $_abbrev_section { + # Emit the terminator. + _op .byte 0x0 "Abbrev end - Terminator" + } } define_label $end_label @@ -3507,6 +3541,7 @@ namespace eval Dwarf { variable _debug_ranges_64_bit variable _debug_addr_index variable _level + variable _dwo_abbrev_num if { [llength $options] == 1 } { set options [list filename [lindex $options 0]] @@ -3539,8 +3574,8 @@ namespace eval Dwarf { set _line_count 0 set _debug_ranges_64_bit [is_64_target] - set _debug_addr_index 0 + set _dwo_abbrev_num 1 # Dummy CU at the start to ensure that the first CU in $body is not # the first in .debug_info. @@ -3562,6 +3597,14 @@ namespace eval Dwarf { dummy_cu } + # If we wrote any abbrev in .debug_abbrev.dwo, write the terminator. + if { $_dwo_abbrev_num > 1 } { + _defer_output .debug_abbrev.dwo { + # Emit the terminator. + _op .byte 0x0 "Abbrev end - Terminator" + } + } + _write_deferred_output _section .note.GNU-stack "" progbits -- 2.51.2