From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YXdbNr1gDmm6TSoAWB0awg (envelope-from ) for ; Fri, 07 Nov 2025 16:12:29 -0500 Received: by simark.ca (Postfix, from userid 112) id DAC7E1E04C; Fri, 07 Nov 2025 16:12:29 -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 64D861E04C for ; Fri, 07 Nov 2025 16:12:29 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EF4D3858C42 for ; Fri, 7 Nov 2025 21:12:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EF4D3858C42 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id A48623858D35 for ; Fri, 7 Nov 2025 21:10:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A48623858D35 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 A48623858D35 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=s3QiCrYgFvYbpUTwkTij1tUgW6TSORrdmfO9DfU4YQz78wLWbAQLEPKAuMMU7awrJeqBF5ldXvkIPV9M1HHgvJn2Iw26pXlPEpD9iGV2oPwg9yl6LEv4oRLIir7bmsMXLe2UCPN9aMRifnUVk7dAm2NPbmTCcZDBMNB46jaBTq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1762549843; c=relaxed/simple; bh=uyEHsG8DCgLh2P2640cUgR/Qe9TpC2wVaPO55b5IRAg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XllHrz+tBx8gs/TpoI8UqAUeAdc7Jg2mA/4FSqv/FGt54Dq9Gysg6JlqqchxzwBfrA9P1fTMdsuylGH99uZr3Hkav3eEbEgskWwLjevZmRLKtL44avWXz1uhJ4LtZEulIqBu2Ngkj1Ax+HP7hwp7L7gA/RokrQLoPxduCaBl7io= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A48623858D35 Received: by simark.ca (Postfix) id 267A91E0C0; Fri, 07 Nov 2025 16:10:43 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/6] gdb/testsuite/dwarf: emit type unit sections as COMDAT Date: Fri, 7 Nov 2025 16:10:14 -0500 Message-ID: <20251107211041.520697-4-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 In an effort to generate ELF files and DWARF info as close as possible as an actual compiler would generate, change how we emit type unit sections to emit each type unit in its own section, in COMDAT section groups. We currently emit all type units in a single, standard section (either .debug_info or .debug_types, depending on the DWARF version). Compilers emit each type unit in its own .debug_types section. Each section is placed in a COMDAT section group with a signature based on the type unit's signature. This lets the linker deduplicate identical type units by discarding section groups with identical signatures (keeping only one group with a given signature). Looking at a .s file generated by gcc, we can see that this is how it specifies the section for a type unit: .section .debug_info,"G",@progbits,wi.006fd2152a3054a6,comdat The "G" flag tells the assembler to place the section in a section group with signature "wi.006fd2152a3054a6". That string was generated from the type unit, signature. Finally, the comdat linkage field indicates that the section group should have the COMDAT flag. Update the tu proc to emit a section with these properties. In this case, it's mandatory to specify the type of the section (progbits). Update the _section proc to accept the new options "group_signature" and "linkage". As a result, if you look at the .debug_types section in a .o file from gcc: $ readelf -g main.o COMDAT group section [ 1] `.group' [wt.006fd2152a3054a6] contains 2 sections: [Index] Name [ 11] .debug_types [ 12] .rela.debug_types COMDAT group section [ 2] `.group' [wt.c621aa8e3c23e450] contains 2 sections: [Index] Name [ 13] .debug_types [ 14] .rela.debug_types And a .o file created by our DWARF assembler: $ readelf -g testsuite/outputs/gdb.dwarf2/struct-with-sig/struct-with-sig1.o COMDAT group section [ 1] `.group' [sig.0x0000000000000001] contains 2 sections: [Index] Name [ 10] .debug_types [ 11] .rela.debug_types COMDAT group section [ 2] `.group' [sig.0x0000000000000002] contains 2 sections: [Index] Name [ 12] .debug_types [ 13] .rela.debug_types In both cases, in the fully linked files, there is a single .debug_types section containing the two type units, as expected. Before this patch, when I run gdb.dwarf2/fission-with-type-unit.exp, the resulting .dwo file has a single .debug_info.dwo. After this patch it has two: one with the type unit and one with the compile unit (the test uses DWARF 5). Based on what I see gcc generate when using "-gdwarf-5 -gsplit-dwarf -fdebug-types-section", this is what we expect. Change-Id: Ie1954dc697fe100b5dbe664d148c71fa02888d96 --- gdb/testsuite/lib/dwarf.exp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 5536b7656b8c..c3c35d43607d 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -1075,6 +1075,8 @@ namespace eval Dwarf { parse_options { { flags "" } { type "" } + { group_signature "" } + { linkage "" } } set directive ".section $name" @@ -1097,6 +1099,14 @@ namespace eval Dwarf { append directive ", %$type" } + if { $group_signature != "" } { + append directive ", $group_signature" + } + + if { $linkage != "" } { + append directive ", $linkage" + } + _emit " $directive" } @@ -1717,7 +1727,13 @@ namespace eval Dwarf { set _abbrev_section "$_abbrev_section.dwo" } - _section $section + # The specific format of the signature is arbitrary. + _section $section { + flags G + type progbits + group_signature sig.$signature + linkage comdat + } set cu_num [incr _cu_count] -- 2.51.2