From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 487BA3874C1D for ; Tue, 2 Mar 2021 13:57:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 487BA3874C1D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5CF00AFEF; Tue, 2 Mar 2021 13:57:16 +0000 (UTC) Date: Tue, 2 Mar 2021 14:57:14 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [PATCH] Fix .debug_line reference above end of section Message-ID: <20210302135713.GA22526@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Mar 2021 13:57:18 -0000 Hi, Consider the file test-import-repeatedly from PR26738, combined with a trivial a.out: ... $ cp test-import-repeatedly 1 $ gcc -m32 -g ~/hello.c $ cp a.out 2 ... When doing multifile optimization, we run into: ... $ dwz -m 3 2 1 dwz: 3: .debug_line reference above end of section ... Using --devel-save-temps and src/contrib/gen-dwz-debug-all.sh we get the unoptimized multifile, and find there a CU: ... Compilation Unit @ offset 0x371: Length: 0x6d (32-bit) Version: 4 Abbrev Offset: 0x14d Pointer Size: 4 <0><37c>: Abbrev Number: 1 (DW_TAG_compile_unit) <37d> DW_AT_stmt_list : 0xda <381> DW_AT_language : 0 (Unknown: 0) <382> DW_AT_comp_dir : ./build-3.8 ... which refers to a .debug_line offset 0xda, but the debug_line section only contains an entry at offset 0x0. This can be explained as follows. The DIEs written into the CU do not contain a single DW_AT_decl_file. Consequently, htab_line will be NULL once we get here in write_multifile: ... || (line_htab != NULL && write_multifile_line ())) ... and no .debug_line contribution will be added. However, the CU DIE referencing the .debug_line contribution is written regardless. We could fix this by not writing the DW_AT_stmt_list for the CU DIE in this case, but that would require changing the order in which abbreviations are computed. Instead, fix this conservatively, by removing "line_htab != NULL &&", such we get a minimal .debug_line contribution. Any comments? Thanks, - Tom Fix .debug_line reference above end of section 2021-03-02 Tom de Vries PR dwz/26738 * dwz.c (write_multifile): Also call write_multifile_line when line_htab == NULL. --- dwz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwz.c b/dwz.c index af1c5af..5effbc1 100644 --- a/dwz.c +++ b/dwz.c @@ -15150,7 +15150,7 @@ write_multifile (DSO *dso) debug_sections[DEBUG_MACRO].new_size) != (ssize_t) debug_sections[DEBUG_MACRO].new_size) || (strp_htab != NULL && write_multifile_strp ()) - || (line_htab != NULL && write_multifile_line ())) + || write_multifile_line ()) { error (0, 0, "Error writing multi-file temporary files"); ret = 1;