From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 2A91C3858C50 for ; Sun, 7 Aug 2022 17:19:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A91C3858C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1451A1FBAC for ; Sun, 7 Aug 2022 17:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1659892788; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tT4faQA3iQ6wztBPDuweyg4+/xnZrNlov7Ogk2vwA00=; b=eFnDFTc/KYH6yX2euvEbwUT/k2pYmgJXabHWK8XLUHWJzWvWXeEVAF3hNbELLHei4nyM05 w77wVLqcQGgx7lEY35i/Vh7LGFYgpCfFQGdtfktaUbQUEkYatOBbHAa7BziO6F0IraWSbM fkbfWgdMNw86zmZB8kRqNlnJfcl2Vvk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1659892788; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tT4faQA3iQ6wztBPDuweyg4+/xnZrNlov7Ogk2vwA00=; b=/7LXnbrx8WpSUH8Q33n3GEnFGu41KmiLtU6ixoMa1Qz0Co5EPR9HQmJHIKSVMe28rRjBm2 6Mm2pcpq4vW59DBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 06B3113A12 for ; Sun, 7 Aug 2022 17:19:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ja8NADT072LjTwAAMHmgww (envelope-from ) for ; Sun, 07 Aug 2022 17:19:47 +0000 Message-ID: Date: Sun, 7 Aug 2022 19:19:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] dwarf: use find_abstract_instance for vars and DW_AT_specification To: binutils@sourceware.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Aug 2022 17:19:50 -0000 The following simple test case fails when dwz is used: $ cat demo.C namespace std { enum { _S_fixed, _S_floatfield = _S_fixed }; struct { struct {}; } __ioinit; } int main() { return 0; } $ g++ demo.C -g && cp a.out b.out && dwz -m xxx.so a.out b.out && objdump -S a.out >/dev/null objdump: DWARF error: could not find variable specification at offset 0x3d3 As seen the reference is defined in xxx.so shared part: $ eu-readelf -w -N a.out | grep -A3 -B3 3d3 decl_column (data1) 11 sibling (ref_udata) [ 387] [ 387] variable abbrev: 30 specification (GNU_ref_alt) [ 3d3] location (exprloc) [ 0] addr 0x404019 [ 396] subprogram abbrev: 32 $ eu-readelf -w -N a.out | less ... Compilation unit at offset 920: Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4 Unit type: partial (3) ... [ 3d3] variable abbrev: 31 name (strp) "__ioinit" decl_file (data1) demo.C (10) decl_line (data1) 6 decl_column (data1) 3 type (ref_udata) [ 3c4] declaration (flag_present) yes With the patch the same output is emitted as before usage of dwz. bfd/ChangeLog: PR 29442 * dwarf2.c (struct varinfo): Use const char * type. (scan_unit_for_symbols): Call find_abstract_instance for DW_AT_specification for variables that can be in a different CU (e.g. done by dwz) --- bfd/dwarf2.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 47618788513..fbe9dd2070b 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -1801,7 +1801,7 @@ struct varinfo /* The type of this variable. */ int tag; /* The name of the variable, if it has one. */ - char *name; + const char *name; /* The address of the variable. */ bfd_vma addr; /* Where the symbol is defined. */ @@ -4094,11 +4094,12 @@ scan_unit_for_symbols (struct comp_unit *unit) case DW_AT_specification: if (is_int_form (&attr) && attr.u.val) { - struct varinfo * spec_var; - - spec_var = lookup_var_by_offset (attr.u.val, - unit->variable_table); - if (spec_var == NULL) + bool is_linkage; + if (!find_abstract_instance (unit, &attr, 0, + &var->name, + &is_linkage, + &var->file, + &var->line)) { _bfd_error_handler (_("DWARF error: could not find " "variable specification " @@ -4106,15 +4107,6 @@ scan_unit_for_symbols (struct comp_unit *unit) (unsigned long) attr.u.val); break; } - - if (var->name == NULL) - var->name = spec_var->name; - if (var->file == NULL && spec_var->file != NULL) - var->file = strdup (spec_var->file); - if (var->line == 0) - var->line = spec_var->line; - if (var->sec == NULL) - var->sec = spec_var->sec; } break; -- 2.37.1